OldChangesList.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 = array_filter( $attribs,
  57. [ Sanitizer::class, 'isReservedDataAttribute' ],
  58. ARRAY_FILTER_USE_KEY
  59. );
  60. $dateheader = ''; // $html now contains only <li>...</li>, for hooks' convenience.
  61. $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
  62. $html = $this->getHighlightsContainerDiv() . $html;
  63. $attribs['class'] = implode( ' ', $classes );
  64. return $dateheader . Html::rawElement( 'li', $attribs, $html ) . "\n";
  65. }
  66. /**
  67. * @param RecentChange $rc
  68. * @param string[] &$classes
  69. * @param bool $watched
  70. *
  71. * @return string
  72. */
  73. private function formatChangeLine( RecentChange $rc, array &$classes, $watched ) {
  74. $html = '';
  75. $unpatrolled = $this->showAsUnpatrolled( $rc );
  76. if ( $rc->mAttribs['rc_log_type'] ) {
  77. $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
  78. $this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'], false );
  79. $flags = $this->recentChangesFlags( [ 'unpatrolled' => $unpatrolled,
  80. 'bot' => $rc->mAttribs['rc_bot'] ], '' );
  81. if ( $flags !== '' ) {
  82. $html .= ' ' . $flags;
  83. }
  84. // Log entries (old format) or log targets, and special pages
  85. } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
  86. list( $name, $htmlubpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
  87. resolveAlias( $rc->mAttribs['rc_title'] );
  88. if ( $name == 'Log' ) {
  89. $this->insertLog( $html, $rc->getTitle(), $htmlubpage, false );
  90. }
  91. // Regular entries
  92. } else {
  93. $this->insertDiffHist( $html, $rc );
  94. # M, N, b and ! (minor, new, bot and unpatrolled)
  95. $html .= $this->recentChangesFlags(
  96. [
  97. 'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
  98. 'minor' => $rc->mAttribs['rc_minor'],
  99. 'unpatrolled' => $unpatrolled,
  100. 'bot' => $rc->mAttribs['rc_bot']
  101. ],
  102. ''
  103. );
  104. $html .= $this->getArticleLink( $rc, $unpatrolled, $watched );
  105. }
  106. # Edit/log timestamp
  107. $this->insertTimestamp( $html, $rc );
  108. # Bytes added or removed
  109. if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
  110. $cd = $this->formatCharacterDifference( $rc );
  111. if ( $cd !== '' ) {
  112. $html .= $cd . ' <span class="mw-changeslist-separator"></span> ';
  113. }
  114. }
  115. if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
  116. $html .= $this->insertLogEntry( $rc );
  117. } elseif ( $this->isCategorizationWithoutRevision( $rc ) ) {
  118. $html .= $this->insertComment( $rc );
  119. } else {
  120. # User tool links
  121. $this->insertUserRelatedLinks( $html, $rc );
  122. # LTR/RTL direction mark
  123. $html .= $this->getLanguage()->getDirMark();
  124. $html .= $this->insertComment( $rc );
  125. }
  126. # Tags
  127. $this->insertTags( $html, $rc, $classes );
  128. # Rollback
  129. $this->insertRollback( $html, $rc );
  130. # For subclasses
  131. $this->insertExtra( $html, $rc, $classes );
  132. # How many users watch this page
  133. if ( $rc->numberofWatchingusers > 0 ) {
  134. $html .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
  135. }
  136. $html = Html::rawElement( 'span', [
  137. 'class' => 'mw-changeslist-line-inner',
  138. 'data-target-page' => $rc->getTitle(), // Used for reliable determination of the affiliated page
  139. ], $html );
  140. if ( is_callable( $this->changeLinePrefixer ) ) {
  141. $prefix = call_user_func( $this->changeLinePrefixer, $rc, $this, false );
  142. $html = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix ) . $html;
  143. }
  144. return $html;
  145. }
  146. }