OldChangesList.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Generate a list of changes using the good old system (no javascript).
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. */
  22. use MediaWiki\MediaWikiServices;
  23. class OldChangesList extends ChangesList {
  24. /**
  25. * Format a line using the old system (aka without any javascript).
  26. *
  27. * @param RecentChange &$rc Passed by reference
  28. * @param bool $watched (default false)
  29. * @param int|null $linenumber (default null)
  30. *
  31. * @return string|bool
  32. */
  33. public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
  34. $classes = $this->getHTMLClasses( $rc, $watched );
  35. // use mw-line-even/mw-line-odd class only if linenumber is given (feature from T16468)
  36. if ( $linenumber ) {
  37. if ( $linenumber & 1 ) {
  38. $classes[] = 'mw-line-odd';
  39. } else {
  40. $classes[] = 'mw-line-even';
  41. }
  42. }
  43. $html = $this->formatChangeLine( $rc, $classes, $watched );
  44. if ( $this->watchlist ) {
  45. $classes[] = Sanitizer::escapeClass( 'watchlist-' .
  46. $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
  47. }
  48. $attribs = $this->getDataAttributes( $rc );
  49. // Avoid PHP 7.1 warning from passing $this by reference
  50. $list = $this;
  51. if ( !Hooks::run( 'OldChangesListRecentChangesLine',
  52. [ &$list, &$html, $rc, &$classes, &$attribs ] )
  53. ) {
  54. return false;
  55. }
  56. $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
  57. $dateheader = ''; // $html now contains only <li>...</li>, for hooks' convenience.
  58. $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
  59. $html = $this->getHighlightsContainerDiv() . $html;
  60. $attribs['class'] = implode( ' ', $classes );
  61. return $dateheader . Html::rawElement( 'li', $attribs, $html ) . "\n";
  62. }
  63. /**
  64. * @param RecentChange $rc
  65. * @param string[] &$classes
  66. * @param bool $watched
  67. *
  68. * @return string
  69. */
  70. private function formatChangeLine( RecentChange $rc, array &$classes, $watched ) {
  71. $html = '';
  72. $unpatrolled = $this->showAsUnpatrolled( $rc );
  73. if ( $rc->mAttribs['rc_log_type'] ) {
  74. $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
  75. $this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'] );
  76. $flags = $this->recentChangesFlags( [ 'unpatrolled' => $unpatrolled,
  77. 'bot' => $rc->mAttribs['rc_bot'] ], '' );
  78. if ( $flags !== '' ) {
  79. $html .= ' ' . $flags;
  80. }
  81. // Log entries (old format) or log targets, and special pages
  82. } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
  83. list( $name, $htmlubpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
  84. resolveAlias( $rc->mAttribs['rc_title'] );
  85. if ( $name == 'Log' ) {
  86. $this->insertLog( $html, $rc->getTitle(), $htmlubpage );
  87. }
  88. // Regular entries
  89. } else {
  90. $this->insertDiffHist( $html, $rc );
  91. # M, N, b and ! (minor, new, bot and unpatrolled)
  92. $html .= $this->recentChangesFlags(
  93. [
  94. 'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
  95. 'minor' => $rc->mAttribs['rc_minor'],
  96. 'unpatrolled' => $unpatrolled,
  97. 'bot' => $rc->mAttribs['rc_bot']
  98. ],
  99. ''
  100. );
  101. $html .= $this->getArticleLink( $rc, $unpatrolled, $watched );
  102. }
  103. # Edit/log timestamp
  104. $this->insertTimestamp( $html, $rc );
  105. # Bytes added or removed
  106. if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
  107. $cd = $this->formatCharacterDifference( $rc );
  108. if ( $cd !== '' ) {
  109. $html .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
  110. }
  111. }
  112. if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
  113. $html .= $this->insertLogEntry( $rc );
  114. } elseif ( $this->isCategorizationWithoutRevision( $rc ) ) {
  115. $html .= $this->insertComment( $rc );
  116. } else {
  117. # User tool links
  118. $this->insertUserRelatedLinks( $html, $rc );
  119. # LTR/RTL direction mark
  120. $html .= $this->getLanguage()->getDirMark();
  121. $html .= $this->insertComment( $rc );
  122. }
  123. # Tags
  124. $this->insertTags( $html, $rc, $classes );
  125. # Rollback
  126. $this->insertRollback( $html, $rc );
  127. # For subclasses
  128. $this->insertExtra( $html, $rc, $classes );
  129. # How many users watch this page
  130. if ( $rc->numberofWatchingusers > 0 ) {
  131. $html .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
  132. }
  133. $html = Html::rawElement( 'span', [
  134. 'class' => 'mw-changeslist-line-inner',
  135. 'data-target-page' => $rc->getTitle(), // Used for reliable determination of the affiliated page
  136. ], $html );
  137. if ( is_callable( $this->changeLinePrefixer ) ) {
  138. $prefix = call_user_func( $this->changeLinePrefixer, $rc, $this, false );
  139. $html = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix ) . $html;
  140. }
  141. return $html;
  142. }
  143. }