MediaWiki  master
ChangesList.php
Go to the documentation of this file.
1 <?php
27 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
38 use OOUI\IconWidget;
40 
41 class ChangesList extends ContextSource {
42  use ProtectedHookAccessorTrait;
43 
44  public const CSS_CLASS_PREFIX = 'mw-changeslist-';
45 
46  protected $watchlist = false;
47  protected $lastdate;
48  protected $message;
49  protected $rc_cache;
50  protected $rcCacheIndex;
51  protected $rclistOpen;
52  protected $rcMoveIndex;
53 
56 
58  protected $watchMsgCache;
59 
63  protected $linkRenderer;
64 
68  protected $commentFormatter;
69 
73  protected $formattedComments;
74 
78  protected $filterGroups;
79 
84  public function __construct( $context, array $filterGroups = [] ) {
85  $this->setContext( $context );
86  $this->preCacheMessages();
87  $this->watchMsgCache = new MapCacheLRU( 50 );
88  $this->filterGroups = $filterGroups;
89 
90  $services = MediaWikiServices::getInstance();
91  $this->linkRenderer = $services->getLinkRenderer();
92  $this->commentFormatter = $services->getRowCommentFormatter();
93  }
94 
103  public static function newFromContext( IContextSource $context, array $groups = [] ) {
104  $user = $context->getUser();
105  $sk = $context->getSkin();
106  $services = MediaWikiServices::getInstance();
107  $list = null;
108  if ( ( new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
109  $userOptionsLookup = $services->getUserOptionsLookup();
110  $new = $context->getRequest()->getBool(
111  'enhanced',
112  $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
113  );
114 
115  return $new ?
116  new EnhancedChangesList( $context, $groups ) :
117  new OldChangesList( $context, $groups );
118  } else {
119  return $list;
120  }
121  }
122 
134  public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
135  throw new RuntimeException( 'recentChangesLine should be implemented' );
136  }
137 
144  protected function getHighlightsContainerDiv() {
145  $highlightColorDivs = '';
146  foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
147  $highlightColorDivs .= Html::rawElement(
148  'div',
149  [
150  'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
151  'data-color' => $color
152  ]
153  );
154  }
155 
156  return Html::rawElement(
157  'div',
158  [ 'class' => 'mw-rcfilters-ui-highlights' ],
159  $highlightColorDivs
160  );
161  }
162 
167  public function setWatchlistDivs( $value = true ) {
168  $this->watchlist = $value;
169  }
170 
175  public function isWatchlist() {
176  return (bool)$this->watchlist;
177  }
178 
183  private function preCacheMessages() {
184  if ( !isset( $this->message ) ) {
185  $this->message = [];
186  foreach ( [
187  'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
188  'semicolon-separator', 'pipe-separator' ] as $msg
189  ) {
190  $this->message[$msg] = $this->msg( $msg )->escaped();
191  }
192  }
193  }
194 
201  public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
202  $f = '';
203  foreach (
204  array_keys( $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) ) as $flag
205  ) {
206  $f .= isset( $flags[$flag] ) && $flags[$flag]
207  ? self::flag( $flag, $this->getContext() )
208  : $nothing;
209  }
210 
211  return $f;
212  }
213 
222  protected function getHTMLClasses( $rc, $watched ) {
223  $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
224  $logType = $rc->mAttribs['rc_log_type'];
225 
226  if ( $logType ) {
227  $classes[] = self::CSS_CLASS_PREFIX . 'log';
228  $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
229  } else {
230  $classes[] = self::CSS_CLASS_PREFIX . 'edit';
231  $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
232  $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
233  }
234 
235  // Indicate watched status on the line to allow for more
236  // comprehensive styling.
237  $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
238  ? self::CSS_CLASS_PREFIX . 'line-watched'
239  : self::CSS_CLASS_PREFIX . 'line-not-watched';
240 
241  $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
242 
243  return $classes;
244  }
245 
253  protected function getHTMLClassesForFilters( $rc ) {
254  $classes = [];
255 
256  $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
257  $rc->mAttribs['rc_namespace'] );
258 
259  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
260  $classes[] = Sanitizer::escapeClass(
261  self::CSS_CLASS_PREFIX .
262  'ns-' .
263  ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
264  );
265 
266  foreach ( $this->filterGroups as $filterGroup ) {
267  foreach ( $filterGroup->getFilters() as $filter ) {
268  $filter->applyCssClassIfNeeded( $this, $rc, $classes );
269  }
270  }
271 
272  return $classes;
273  }
274 
285  public static function flag( $flag, IContextSource $context = null ) {
286  static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
287  static $flagInfos = null;
288 
289  if ( $flagInfos === null ) {
290  $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
291  ->get( MainConfigNames::RecentChangesFlags );
292  $flagInfos = [];
293  foreach ( $recentChangesFlags as $key => $value ) {
294  $flagInfos[$key]['letter'] = $value['letter'];
295  $flagInfos[$key]['title'] = $value['title'];
296  // Allow customized class name, fall back to flag name
297  $flagInfos[$key]['class'] = $value['class'] ?? $key;
298  }
299  }
300 
301  $context = $context ?: RequestContext::getMain();
302 
303  // Inconsistent naming, kept for b/c
304  if ( isset( $map[$flag] ) ) {
305  $flag = $map[$flag];
306  }
307 
308  $info = $flagInfos[$flag];
309  return Html::element( 'abbr', [
310  'class' => $info['class'],
311  'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
312  ], wfMessage( $info['letter'] )->setContext( $context )->text() );
313  }
314 
319  public function beginRecentChangesList() {
320  $this->rc_cache = [];
321  $this->rcMoveIndex = 0;
322  $this->rcCacheIndex = 0;
323  $this->lastdate = '';
324  $this->rclistOpen = false;
325  $this->getOutput()->addModuleStyles( [
326  'mediawiki.interface.helpers.styles',
327  'mediawiki.special.changeslist'
328  ] );
329 
330  return '<div class="mw-changeslist">';
331  }
332 
336  public function initChangesListRows( $rows ) {
337  $this->getHookRunner()->onChangesListInitRows( $this, $rows );
338  $this->formattedComments = $this->commentFormatter->createBatch()
339  ->comments(
340  $this->commentFormatter->rows( $rows )
341  ->commentKey( 'rc_comment' )
342  ->namespaceField( 'rc_namespace' )
343  ->titleField( 'rc_title' )
344  ->indexField( 'rc_id' )
345  )
346  ->useBlock()
347  ->execute();
348  }
349 
360  public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
361  if ( !$context ) {
362  $context = RequestContext::getMain();
363  }
364 
365  $new = (int)$new;
366  $old = (int)$old;
367  $szdiff = $new - $old;
368 
369  $lang = $context->getLanguage();
370  $config = $context->getConfig();
371  $code = $lang->getCode();
372  static $fastCharDiff = [];
373  if ( !isset( $fastCharDiff[$code] ) ) {
374  $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
375  || $context->msg( 'rc-change-size' )->plain() === '$1';
376  }
377 
378  $formattedSize = $lang->formatNum( $szdiff );
379 
380  if ( !$fastCharDiff[$code] ) {
381  $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
382  }
383 
384  if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
385  $tag = 'strong';
386  } else {
387  $tag = 'span';
388  }
389 
390  if ( $szdiff === 0 ) {
391  $formattedSizeClass = 'mw-plusminus-null';
392  } elseif ( $szdiff > 0 ) {
393  $formattedSize = '+' . $formattedSize;
394  $formattedSizeClass = 'mw-plusminus-pos';
395  } else {
396  $formattedSizeClass = 'mw-plusminus-neg';
397  }
398  $formattedSizeClass .= ' mw-diff-bytes';
399 
400  $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
401 
402  return Html::element( $tag,
403  [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
404  $formattedSize ) . $lang->getDirMark();
405  }
406 
414  public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
415  $oldlen = $old->mAttribs['rc_old_len'];
416 
417  if ( $new ) {
418  $newlen = $new->mAttribs['rc_new_len'];
419  } else {
420  $newlen = $old->mAttribs['rc_new_len'];
421  }
422 
423  if ( $oldlen === null || $newlen === null ) {
424  return '';
425  }
426 
427  return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
428  }
429 
434  public function endRecentChangesList() {
435  $out = $this->rclistOpen ? "</ul>\n" : '';
436  $out .= '</div>';
437 
438  return $out;
439  }
440 
452  public static function revDateLink(
453  RevisionRecord $rev,
454  Authority $performer,
455  Language $lang,
456  $title = null
457  ) {
458  $ts = $rev->getTimestamp();
459  $time = $lang->userTime( $ts, $performer->getUser() );
460  $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
461  if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
462  $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
463  $title ?? $rev->getPageAsLinkTarget(),
464  $date,
465  [ 'class' => 'mw-changeslist-date' ],
466  [ 'oldid' => $rev->getId() ]
467  );
468  } else {
469  $link = htmlspecialchars( $date );
470  }
471  if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
472  $deletedClass = Linker::getRevisionDeletedClass( $rev );
473  $link = "<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
474  }
475  return Html::element( 'span', [
476  'class' => 'mw-changeslist-time'
477  ], $time ) . $link;
478  }
479 
484  public function insertDateHeader( &$s, $rc_timestamp ) {
485  # Make date header if necessary
486  $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
487  if ( $date != $this->lastdate ) {
488  if ( $this->lastdate != '' ) {
489  $s .= "</ul>\n";
490  }
491  $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
492  $this->lastdate = $date;
493  $this->rclistOpen = true;
494  }
495  }
496 
503  public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
504  $page = new LogPage( $logtype );
505  $logname = $page->getName()->setContext( $this->getContext() )->text();
506  $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
507  'class' => $useParentheses ? '' : 'mw-changeslist-links'
508  ] );
509  if ( $useParentheses ) {
510  $s .= $this->msg( 'parentheses' )->rawParams(
511  $link
512  )->escaped();
513  } else {
514  $s .= $link;
515  }
516  }
517 
523  public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
524  # Diff link
525  if (
526  $rc->mAttribs['rc_type'] == RC_NEW ||
527  $rc->mAttribs['rc_type'] == RC_LOG ||
528  $rc->mAttribs['rc_type'] == RC_CATEGORIZE
529  ) {
530  $diffLink = $this->message['diff'];
531  } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
532  $diffLink = $this->message['diff'];
533  } else {
534  $query = [
535  'curid' => $rc->mAttribs['rc_cur_id'],
536  'diff' => $rc->mAttribs['rc_this_oldid'],
537  'oldid' => $rc->mAttribs['rc_last_oldid']
538  ];
539 
540  $diffLink = $this->linkRenderer->makeKnownLink(
541  $rc->getTitle(),
542  new HtmlArmor( $this->message['diff'] ),
543  [ 'class' => 'mw-changeslist-diff' ],
544  $query
545  );
546  }
547  if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
548  $histLink = $this->message['hist'];
549  } else {
550  $histLink = $this->linkRenderer->makeKnownLink(
551  $rc->getTitle(),
552  new HtmlArmor( $this->message['hist'] ),
553  [ 'class' => 'mw-changeslist-history' ],
554  [
555  'curid' => $rc->mAttribs['rc_cur_id'],
556  'action' => 'history'
557  ]
558  );
559  }
560 
561  $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
562  Html::rawElement( 'span', [], $diffLink ) .
563  Html::rawElement( 'span', [], $histLink )
564  ) .
565  ' <span class="mw-changeslist-separator"></span> ';
566  }
567 
578  public function getArticleLink( &$rc, $unpatrolled, $watched ) {
579  $params = [];
580  if ( $rc->getTitle()->isRedirect() ) {
581  $params = [ 'redirect' => 'no' ];
582  }
583 
584  $articlelink = $this->linkRenderer->makeLink(
585  $rc->getTitle(),
586  null,
587  [ 'class' => 'mw-changeslist-title' ],
588  $params
589  );
590  if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
591  $class = 'history-deleted';
592  if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
593  $class .= ' mw-history-suppressed';
594  }
595  $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
596  }
597  # To allow for boldening pages watched by this user
598  $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
599  # RTL/LTR marker
600  $articlelink .= $this->getLanguage()->getDirMark();
601 
602  # TODO: Deprecate the $s argument, it seems happily unused.
603  $s = '';
604  $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
605  $s, $rc, $unpatrolled, $watched );
606 
607  // Watchlist expiry icon.
608  $watchlistExpiry = '';
609  if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
610  $watchlistExpiry = $this->getWatchlistExpiry( $rc );
611  }
612 
613  return "{$s} {$articlelink}{$watchlistExpiry}";
614  }
615 
622  public function getWatchlistExpiry( RecentChange $recentChange ): string {
623  $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
624  // Guard against expired items, even though they shouldn't come here.
625  if ( $item->isExpired() ) {
626  return '';
627  }
628  $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
629  // Matching widget is also created in ChangesListSpecialPage, for the legend.
630  $widget = new IconWidget( [
631  'icon' => 'clock',
632  'title' => $daysLeftText,
633  'classes' => [ 'mw-changesList-watchlistExpiry' ],
634  ] );
635  $widget->setAttributes( [
636  // Add labels for assistive technologies.
637  'role' => 'img',
638  'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
639  // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
640  'data-days-left' => $item->getExpiryInDays(),
641  ] );
642  // Add spaces around the widget (the page title is to one side,
643  // and a semicolon or opening-parenthesis to the other).
644  return " $widget ";
645  }
646 
655  public function getTimestamp( $rc ) {
656  // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
657  // because in that case the timestamp is preceded by a clock icon.
658  // A space is important after `.mw-changeslist-separator--semicolon` to make sure
659  // that whatever comes before it is distinguishable.
660  // (Otherwise your have the text of titles pushing up against the timestamp)
661  // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
662  // as the `.mw-changeslist-date` class is used in a variety
663  // of other places with a different position and the information proceeding getTimestamp can vary.
664  // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
665  // contain the full date (month, year) and adds consistency with Special:Contributions
666  // and other pages.
667  $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
668  return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
669  '<span class="mw-changeslist-date mw-changeslist-time">' .
670  htmlspecialchars( $this->getLanguage()->userTime(
671  $rc->mAttribs['rc_timestamp'],
672  $this->getUser()
673  ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
674  }
675 
682  public function insertTimestamp( &$s, $rc ) {
683  $s .= $this->getTimestamp( $rc );
684  }
685 
692  public function insertUserRelatedLinks( &$s, &$rc ) {
693  if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
694  $deletedClass = 'history-deleted';
695  if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
696  $deletedClass .= ' mw-history-suppressed';
697  }
698  $s .= ' <span class="' . $deletedClass . '">' .
699  $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
700  } else {
701  $s .= $this->getLanguage()->getDirMark() . Linker::userLink(
702  $rc->mAttribs['rc_user'],
703  $rc->mAttribs['rc_user_text'],
704  false,
705  [ 'data-mw-revid' => $rc->mAttribs['rc_this_oldid'] ]
706  );
707  $s .= Linker::userToolLinks(
708  $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
709  false, 0, null,
710  // The text content of tools is not wrapped with parentheses or "piped".
711  // This will be handled in CSS (T205581).
712  false
713  );
714  }
715  }
716 
723  public function insertLogEntry( $rc ) {
724  $formatter = LogFormatter::newFromRow( $rc->mAttribs );
725  $formatter->setContext( $this->getContext() );
726  $formatter->setShowUserToolLinks( true );
727  $mark = $this->getLanguage()->getDirMark();
728 
729  return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
730  . $formatter->getActionText()
731  . " $mark"
732  . $formatter->getComment()
733  . $this->msg( 'word-separator' )->escaped()
734  . $formatter->getActionLinks()
735  . Html::closeElement( 'span' );
736  }
737 
743  public function insertComment( $rc ) {
744  if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
745  $deletedClass = 'history-deleted';
746  if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
747  $deletedClass .= ' mw-history-suppressed';
748  }
749  return ' <span class="' . $deletedClass . ' comment">' .
750  $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
751  } elseif ( isset( $rc->mAttribs['rc_id'] )
752  && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
753  ) {
754  return $this->formattedComments[$rc->mAttribs['rc_id']];
755  } else {
756  return $this->commentFormatter->formatBlock(
757  $rc->mAttribs['rc_comment'],
758  $rc->getTitle(),
759  // Whether section links should refer to local page (using default false)
760  false,
761  // wikid to generate links for (using default null) */
762  null,
763  // whether parentheses should be rendered as part of the message
764  false
765  );
766  }
767  }
768 
774  protected function numberofWatchingusers( $count ) {
775  if ( $count <= 0 ) {
776  return '';
777  }
778 
779  return $this->watchMsgCache->getWithSetCallback(
780  "watching-users-msg:$count",
781  function () use ( $count ) {
782  return $this->msg( 'number-of-watching-users-for-recent-changes' )
783  ->numParams( $count )->escaped();
784  }
785  );
786  }
787 
794  public static function isDeleted( $rc, $field ) {
795  return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
796  }
797 
807  public static function userCan( $rc, $field, Authority $performer = null ) {
808  $performer ??= RequestContext::getMain()->getAuthority();
809 
810  if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
811  return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
812  }
813 
814  return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
815  }
816 
822  protected function maybeWatchedLink( $link, $watched = false ) {
823  if ( $watched ) {
824  return '<strong class="mw-watched">' . $link . '</strong>';
825  } else {
826  return '<span class="mw-rc-unwatched">' . $link . '</span>';
827  }
828  }
829 
836  public function insertRollback( &$s, &$rc ) {
837  $this->insertPageTools( $s, $rc );
838  }
839 
848  private function insertPageTools( &$s, &$rc ) {
849  // FIXME Some page tools (e.g. thanks) might make sense for log entries.
850  if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
851  // FIXME When would either of these not exist when type is RC_EDIT? Document.
852  || !$rc->mAttribs['rc_this_oldid']
853  || !$rc->mAttribs['rc_cur_id']
854  ) {
855  return;
856  }
857 
858  // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
859  $title = $rc->getTitle();
860  $revRecord = new MutableRevisionRecord( $title );
861  $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
862  $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
863  $user = new UserIdentityValue(
864  (int)$rc->mAttribs['rc_user'],
865  $rc->mAttribs['rc_user_text']
866  );
867  $revRecord->setUser( $user );
868 
869  $tools = new PagerTools(
870  $revRecord,
871  null,
872  // only show a rollback link on the top-most revision
873  $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
874  && $rc->mAttribs['rc_type'] != RC_NEW,
875  $this->getHookRunner(),
876  $title,
877  $this->getContext(),
878  // @todo: Inject
879  MediaWikiServices::getInstance()->getLinkRenderer()
880  );
881 
882  $s .= $tools->toHTML();
883  }
884 
890  public function getRollback( RecentChange $rc ) {
891  $s = '';
892  $this->insertRollback( $s, $rc );
893  return $s;
894  }
895 
901  public function insertTags( &$s, &$rc, &$classes ) {
902  if ( empty( $rc->mAttribs['ts_tags'] ) ) {
903  return;
904  }
905 
906  [ $tagSummary, $newClasses ] = ChangeTags::formatSummaryRow(
907  $rc->mAttribs['ts_tags'],
908  'changeslist',
909  $this->getContext()
910  );
911  $classes = array_merge( $classes, $newClasses );
912  $s .= ' ' . $tagSummary;
913  }
914 
921  public function getTags( RecentChange $rc, array &$classes ) {
922  $s = '';
923  $this->insertTags( $s, $rc, $classes );
924  return $s;
925  }
926 
927  public function insertExtra( &$s, &$rc, &$classes ) {
928  // Empty, used for subclasses to add anything special.
929  }
930 
931  protected function showAsUnpatrolled( RecentChange $rc ) {
932  return self::isUnpatrolled( $rc, $this->getUser() );
933  }
934 
940  public static function isUnpatrolled( $rc, User $user ) {
941  if ( $rc instanceof RecentChange ) {
942  $isPatrolled = $rc->mAttribs['rc_patrolled'];
943  $rcType = $rc->mAttribs['rc_type'];
944  $rcLogType = $rc->mAttribs['rc_log_type'];
945  } else {
946  $isPatrolled = $rc->rc_patrolled;
947  $rcType = $rc->rc_type;
948  $rcLogType = $rc->rc_log_type;
949  }
950 
951  if ( !$isPatrolled ) {
952  if ( $user->useRCPatrol() ) {
953  return true;
954  }
955  if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
956  return true;
957  }
958  if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
959  return true;
960  }
961  }
962 
963  return false;
964  }
965 
975  protected function isCategorizationWithoutRevision( $rcObj ) {
976  return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
977  && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
978  }
979 
985  protected function getDataAttributes( RecentChange $rc ) {
986  $attrs = [];
987 
988  $type = $rc->getAttribute( 'rc_source' );
989  switch ( $type ) {
992  $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
993  break;
995  $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
996  $attrs['data-mw-logaction'] =
997  $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
998  break;
1000  $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1001  break;
1002  }
1003 
1004  $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1005 
1006  return $attrs;
1007  }
1008 
1016  public function setChangeLinePrefixer( callable $prefixer ) {
1017  $this->changeLinePrefixer = $prefixer;
1018  }
1019 }
getUser()
const RC_NEW
Definition: Defines.php:117
const RC_LOG
Definition: Defines.php:118
const RC_EDIT
Definition: Defines.php:116
const RC_CATEGORIZE
Definition: Defines.php:120
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getContext()
static formatSummaryRow( $tags, $unused, MessageLocalizer $localizer=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:162
static newFromContext(IContextSource $context, array $groups=[])
Fetch an appropriate changes list class for the specified context Some users might want to use an enh...
maybeWatchedLink( $link, $watched=false)
setWatchlistDivs( $value=true)
Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag.
formatCharacterDifference(RecentChange $old, RecentChange $new=null)
Format the character difference of one or several changes.
insertDateHeader(&$s, $rc_timestamp)
insertRollback(&$s, &$rc)
Insert a rollback link.
showAsUnpatrolled(RecentChange $rc)
RowCommentFormatter $commentFormatter
Definition: ChangesList.php:68
static isUnpatrolled( $rc, User $user)
getHighlightsContainerDiv()
Get the container for highlights that are used in the new StructuredFilters system.
static revDateLink(RevisionRecord $rev, Authority $performer, Language $lang, $title=null)
Render the date and time of a revision in the current user language based on whether the user is able...
recentChangesLine(&$rc, $watched=false, $linenumber=null)
Format a line.
__construct( $context, array $filterGroups=[])
Definition: ChangesList.php:84
recentChangesFlags( $flags, $nothing="\u{00A0}")
Returns the appropriate flags for new page, minor change and patrolling.
getDataAttributes(RecentChange $rc)
Get recommended data attributes for a change line.
numberofWatchingusers( $count)
Returns the string which indicates the number of watching users.
getHTMLClasses( $rc, $watched)
Get an array of default HTML class attributes for the change.
getWatchlistExpiry(RecentChange $recentChange)
Get HTML to display the clock icon for watched items that have a watchlist expiry time.
callable $changeLinePrefixer
Definition: ChangesList.php:55
getTags(RecentChange $rc, array &$classes)
getArticleLink(&$rc, $unpatrolled, $watched)
Get the HTML link to the changed page, possibly with a prefix from hook handlers, and a suffix for te...
insertUserRelatedLinks(&$s, &$rc)
Insert links to user page, user talk page and eventually a blocking link.
static showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
getRollback(RecentChange $rc)
MapCacheLRU $watchMsgCache
Definition: ChangesList.php:58
endRecentChangesList()
Returns text for the end of RC.
static flag( $flag, IContextSource $context=null)
Make an "<abbr>" element for a given change flag.
LinkRenderer $linkRenderer
Definition: ChangesList.php:63
insertLogEntry( $rc)
Insert a formatted action.
setChangeLinePrefixer(callable $prefixer)
Sets the callable that generates a change line prefix added to the beginning of each line.
static isDeleted( $rc, $field)
Determine if said field of a revision is hidden.
const CSS_CLASS_PREFIX
Definition: ChangesList.php:44
insertLog(&$s, $title, $logtype, $useParentheses=true)
insertTags(&$s, &$rc, &$classes)
ChangesListFilterGroup[] $filterGroups
Definition: ChangesList.php:78
string[] $formattedComments
Comments indexed by rc_id.
Definition: ChangesList.php:73
insertComment( $rc)
Insert a formatted comment.
static userCan( $rc, $field, Authority $performer=null)
Determine if the current user is allowed to view a particular field of this revision,...
insertExtra(&$s, &$rc, &$classes)
initChangesListRows( $rows)
getTimestamp( $rc)
Get the timestamp from $rc formatted with current user's settings and a separator.
isCategorizationWithoutRevision( $rcObj)
Determines whether a revision is linked to this change; this may not be the case when the categorizat...
getHTMLClassesForFilters( $rc)
Get an array of CSS classes attributed to filters for this row.
insertDiffHist(&$s, &$rc, $unpatrolled=null)
insertTimestamp(&$s, $rc)
Insert time timestamp string from $rc into $s.
beginRecentChangesList()
Returns text for the start of the tabular part of RC.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
Base class for language-specific code.
Definition: Language.php:57
static userCanBitfield( $bitfield, $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this log row,...
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Class to simplify the use of log pages.
Definition: LogPage.php:41
Handles a simple LRU key/value map with a maximum number of entries.
Definition: MapCacheLRU.php:36
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:565
This class is a collection of static functions that serve two purposes:
Definition: Html.php:55
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition: Linker.php:67
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Page revision base class.
getTimestamp()
MCR migration note: this replaced Revision::getTimestamp.
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
userCan( $field, Authority $performer)
Determine if the give authority is allowed to view a particular field of this revision,...
isDeleted( $field)
MCR migration note: this replaced Revision::isDeleted.
getId( $wikiId=self::LOCAL)
Get revision ID.
Represents a title within MediaWiki.
Definition: Title.php:82
Value object representing a user's identity.
Generate a set of tools for a revision.
Definition: PagerTools.php:14
Utility class for creating new RC entries.
const SRC_CATEGORIZE
getAttribute( $name)
Get an attribute value.
static getMain()
Get the RequestContext object associated with the main request.
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:1108
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:71
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition: User.php:2404
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition: User.php:2389
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition: User.php:2379
Representation of a pair of user and title for watchlist entries.
Definition: WatchedItem.php:36
getExpiryInDaysText(MessageLocalizer $msgLocalizer, $isDropdownOption=false)
Get days remaining until a watched item expires as a text.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:44
Interface for objects which can provide a MediaWiki context on request.
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
getUser()
Returns the performer of the actions associated with this authority.
Result wrapper for grabbing data queried from an IDatabase object.
if(!isset( $args[0])) $lang