MediaWiki  master
ChangesList.php
Go to the documentation of this file.
1 <?php
26 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
34 use OOUI\IconWidget;
36 
37 class ChangesList extends ContextSource {
38  use ProtectedHookAccessorTrait;
39 
40  public const CSS_CLASS_PREFIX = 'mw-changeslist-';
41 
42  protected $watchlist = false;
43  protected $lastdate;
44  protected $message;
45  protected $rc_cache;
46  protected $rcCacheIndex;
47  protected $rclistOpen;
48  protected $rcMoveIndex;
49 
52 
54  protected $watchMsgCache;
55 
59  protected $linkRenderer;
60 
64  protected $commentFormatter;
65 
69  protected $formattedComments;
70 
74  protected $filterGroups;
75 
80  public function __construct( $context, array $filterGroups = [] ) {
81  $this->setContext( $context );
82  $this->preCacheMessages();
83  $this->watchMsgCache = new MapCacheLRU( 50 );
84  $this->filterGroups = $filterGroups;
85 
86  $services = MediaWikiServices::getInstance();
87  $this->linkRenderer = $services->getLinkRenderer();
88  $this->commentFormatter = $services->getRowCommentFormatter();
89  }
90 
99  public static function newFromContext( IContextSource $context, array $groups = [] ) {
100  $user = $context->getUser();
101  $sk = $context->getSkin();
102  $list = null;
103  if ( Hooks::runner()->onFetchChangesList( $user, $sk, $list, $groups ) ) {
104  $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
105  $new = $context->getRequest()->getBool(
106  'enhanced',
107  $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
108  );
109 
110  return $new ?
111  new EnhancedChangesList( $context, $groups ) :
112  new OldChangesList( $context, $groups );
113  } else {
114  return $list;
115  }
116  }
117 
129  public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
130  throw new RuntimeException( 'recentChangesLine should be implemented' );
131  }
132 
139  protected function getHighlightsContainerDiv() {
140  $highlightColorDivs = '';
141  foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
142  $highlightColorDivs .= Html::rawElement(
143  'div',
144  [
145  'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
146  'data-color' => $color
147  ]
148  );
149  }
150 
151  return Html::rawElement(
152  'div',
153  [ 'class' => 'mw-rcfilters-ui-highlights' ],
154  $highlightColorDivs
155  );
156  }
157 
162  public function setWatchlistDivs( $value = true ) {
163  $this->watchlist = $value;
164  }
165 
170  public function isWatchlist() {
171  return (bool)$this->watchlist;
172  }
173 
178  private function preCacheMessages() {
179  if ( !isset( $this->message ) ) {
180  $this->message = [];
181  foreach ( [
182  'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
183  'semicolon-separator', 'pipe-separator' ] as $msg
184  ) {
185  $this->message[$msg] = $this->msg( $msg )->escaped();
186  }
187  }
188  }
189 
196  public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
197  $f = '';
198  foreach (
199  array_keys( $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) ) as $flag
200  ) {
201  $f .= isset( $flags[$flag] ) && $flags[$flag]
202  ? self::flag( $flag, $this->getContext() )
203  : $nothing;
204  }
205 
206  return $f;
207  }
208 
217  protected function getHTMLClasses( $rc, $watched ) {
218  $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
219  $logType = $rc->mAttribs['rc_log_type'];
220 
221  if ( $logType ) {
222  $classes[] = self::CSS_CLASS_PREFIX . 'log';
223  $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
224  } else {
225  $classes[] = self::CSS_CLASS_PREFIX . 'edit';
226  $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
227  $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
228  }
229 
230  // Indicate watched status on the line to allow for more
231  // comprehensive styling.
232  $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
233  ? self::CSS_CLASS_PREFIX . 'line-watched'
234  : self::CSS_CLASS_PREFIX . 'line-not-watched';
235 
236  $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
237 
238  return $classes;
239  }
240 
248  protected function getHTMLClassesForFilters( $rc ) {
249  $classes = [];
250 
251  $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
252  $rc->mAttribs['rc_namespace'] );
253 
254  $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
255  $classes[] = Sanitizer::escapeClass(
256  self::CSS_CLASS_PREFIX .
257  'ns-' .
258  ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
259  );
260 
261  foreach ( $this->filterGroups as $filterGroup ) {
262  foreach ( $filterGroup->getFilters() as $filter ) {
263  $filter->applyCssClassIfNeeded( $this, $rc, $classes );
264  }
265  }
266 
267  return $classes;
268  }
269 
280  public static function flag( $flag, IContextSource $context = null ) {
281  static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
282  static $flagInfos = null;
283 
284  if ( $flagInfos === null ) {
285  $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
286  ->get( MainConfigNames::RecentChangesFlags );
287  $flagInfos = [];
288  foreach ( $recentChangesFlags as $key => $value ) {
289  $flagInfos[$key]['letter'] = $value['letter'];
290  $flagInfos[$key]['title'] = $value['title'];
291  // Allow customized class name, fall back to flag name
292  $flagInfos[$key]['class'] = $value['class'] ?? $key;
293  }
294  }
295 
297 
298  // Inconsistent naming, kept for b/c
299  if ( isset( $map[$flag] ) ) {
300  $flag = $map[$flag];
301  }
302 
303  $info = $flagInfos[$flag];
304  return Html::element( 'abbr', [
305  'class' => $info['class'],
306  'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
307  ], wfMessage( $info['letter'] )->setContext( $context )->text() );
308  }
309 
314  public function beginRecentChangesList() {
315  $this->rc_cache = [];
316  $this->rcMoveIndex = 0;
317  $this->rcCacheIndex = 0;
318  $this->lastdate = '';
319  $this->rclistOpen = false;
320  $this->getOutput()->addModuleStyles( [
321  'mediawiki.interface.helpers.styles',
322  'mediawiki.special.changeslist'
323  ] );
324 
325  return '<div class="mw-changeslist">';
326  }
327 
331  public function initChangesListRows( $rows ) {
332  $this->getHookRunner()->onChangesListInitRows( $this, $rows );
333  $this->formattedComments = $this->commentFormatter->createBatch()
334  ->comments(
335  $this->commentFormatter->rows( $rows )
336  ->commentKey( 'rc_comment' )
337  ->namespaceField( 'rc_namespace' )
338  ->titleField( 'rc_title' )
339  ->indexField( 'rc_id' )
340  )
341  ->useBlock()
342  ->execute();
343  }
344 
355  public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
356  if ( !$context ) {
358  }
359 
360  $new = (int)$new;
361  $old = (int)$old;
362  $szdiff = $new - $old;
363 
365  $config = $context->getConfig();
366  $code = $lang->getCode();
367  static $fastCharDiff = [];
368  if ( !isset( $fastCharDiff[$code] ) ) {
369  $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
370  || $context->msg( 'rc-change-size' )->plain() === '$1';
371  }
372 
373  $formattedSize = $lang->formatNum( $szdiff );
374 
375  if ( !$fastCharDiff[$code] ) {
376  $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
377  }
378 
379  if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
380  $tag = 'strong';
381  } else {
382  $tag = 'span';
383  }
384 
385  if ( $szdiff === 0 ) {
386  $formattedSizeClass = 'mw-plusminus-null';
387  } elseif ( $szdiff > 0 ) {
388  $formattedSize = '+' . $formattedSize;
389  $formattedSizeClass = 'mw-plusminus-pos';
390  } else {
391  $formattedSizeClass = 'mw-plusminus-neg';
392  }
393  $formattedSizeClass .= ' mw-diff-bytes';
394 
395  $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
396 
397  return Html::element( $tag,
398  [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
399  $formattedSize ) . $lang->getDirMark();
400  }
401 
409  public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
410  $oldlen = $old->mAttribs['rc_old_len'];
411 
412  if ( $new ) {
413  $newlen = $new->mAttribs['rc_new_len'];
414  } else {
415  $newlen = $old->mAttribs['rc_new_len'];
416  }
417 
418  if ( $oldlen === null || $newlen === null ) {
419  return '';
420  }
421 
422  return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
423  }
424 
429  public function endRecentChangesList() {
430  $out = $this->rclistOpen ? "</ul>\n" : '';
431  $out .= '</div>';
432 
433  return $out;
434  }
435 
447  public static function revDateLink(
448  RevisionRecord $rev,
449  Authority $performer,
450  Language $lang,
451  $title = null
452  ) {
453  $ts = $rev->getTimestamp();
454  $time = $lang->userTime( $ts, $performer->getUser() );
455  $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
456  if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
457  $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
458  $title ?? $rev->getPageAsLinkTarget(),
459  $date,
460  [ 'class' => 'mw-changeslist-date' ],
461  [ 'oldid' => $rev->getId() ]
462  );
463  } else {
464  $link = htmlspecialchars( $date );
465  }
466  if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
467  $deletedClass = Linker::getRevisionDeletedClass( $rev );
468  $link = "<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
469  }
470  return Html::element( 'span', [
471  'class' => 'mw-changeslist-time'
472  ], $time ) . $link;
473  }
474 
479  public function insertDateHeader( &$s, $rc_timestamp ) {
480  # Make date header if necessary
481  $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
482  if ( $date != $this->lastdate ) {
483  if ( $this->lastdate != '' ) {
484  $s .= "</ul>\n";
485  }
486  $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
487  $this->lastdate = $date;
488  $this->rclistOpen = true;
489  }
490  }
491 
498  public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
499  $page = new LogPage( $logtype );
500  $logname = $page->getName()->setContext( $this->getContext() )->text();
501  $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
502  'class' => $useParentheses ? '' : 'mw-changeslist-links'
503  ] );
504  if ( $useParentheses ) {
505  $s .= $this->msg( 'parentheses' )->rawParams(
506  $link
507  )->escaped();
508  } else {
509  $s .= $link;
510  }
511  }
512 
518  public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
519  # Diff link
520  if (
521  $rc->mAttribs['rc_type'] == RC_NEW ||
522  $rc->mAttribs['rc_type'] == RC_LOG ||
523  $rc->mAttribs['rc_type'] == RC_CATEGORIZE
524  ) {
525  $diffLink = $this->message['diff'];
526  } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
527  $diffLink = $this->message['diff'];
528  } else {
529  $query = [
530  'curid' => $rc->mAttribs['rc_cur_id'],
531  'diff' => $rc->mAttribs['rc_this_oldid'],
532  'oldid' => $rc->mAttribs['rc_last_oldid']
533  ];
534 
535  $diffLink = $this->linkRenderer->makeKnownLink(
536  $rc->getTitle(),
537  new HtmlArmor( $this->message['diff'] ),
538  [ 'class' => 'mw-changeslist-diff' ],
539  $query
540  );
541  }
542  if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
543  $histLink = $this->message['hist'];
544  } else {
545  $histLink = $this->linkRenderer->makeKnownLink(
546  $rc->getTitle(),
547  new HtmlArmor( $this->message['hist'] ),
548  [ 'class' => 'mw-changeslist-history' ],
549  [
550  'curid' => $rc->mAttribs['rc_cur_id'],
551  'action' => 'history'
552  ]
553  );
554  }
555 
556  $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
557  Html::rawElement( 'span', [], $diffLink ) .
558  Html::rawElement( 'span', [], $histLink )
559  ) .
560  ' <span class="mw-changeslist-separator"></span> ';
561  }
562 
573  public function getArticleLink( &$rc, $unpatrolled, $watched ) {
574  $params = [];
575  if ( $rc->getTitle()->isRedirect() ) {
576  $params = [ 'redirect' => 'no' ];
577  }
578 
579  $articlelink = $this->linkRenderer->makeLink(
580  $rc->getTitle(),
581  null,
582  [ 'class' => 'mw-changeslist-title' ],
583  $params
584  );
585  if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
586  $class = 'history-deleted';
587  if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
588  $class .= ' mw-history-suppressed';
589  }
590  $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
591  }
592  # To allow for boldening pages watched by this user
593  $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
594  # RTL/LTR marker
595  $articlelink .= $this->getLanguage()->getDirMark();
596 
597  # TODO: Deprecate the $s argument, it seems happily unused.
598  $s = '';
599  $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
600  $s, $rc, $unpatrolled, $watched );
601 
602  // Watchlist expiry icon.
603  $watchlistExpiry = '';
604  if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
605  $watchlistExpiry = $this->getWatchlistExpiry( $rc );
606  }
607 
608  return "{$s} {$articlelink}{$watchlistExpiry}";
609  }
610 
617  public function getWatchlistExpiry( RecentChange $recentChange ): string {
618  $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
619  // Guard against expired items, even though they shouldn't come here.
620  if ( $item->isExpired() ) {
621  return '';
622  }
623  $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
624  // Matching widget is also created in ChangesListSpecialPage, for the legend.
625  $widget = new IconWidget( [
626  'icon' => 'clock',
627  'title' => $daysLeftText,
628  'classes' => [ 'mw-changesList-watchlistExpiry' ],
629  ] );
630  $widget->setAttributes( [
631  // Add labels for assistive technologies.
632  'role' => 'img',
633  'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
634  // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
635  'data-days-left' => $item->getExpiryInDays(),
636  ] );
637  // Add spaces around the widget (the page title is to one side,
638  // and a semicolon or opening-parenthesis to the other).
639  return " $widget ";
640  }
641 
650  public function getTimestamp( $rc ) {
651  // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
652  // because in that case the timestamp is preceded by a clock icon.
653  // A space is important after `.mw-changeslist-separator--semicolon` to make sure
654  // that whatever comes before it is distinguishable.
655  // (Otherwise your have the text of titles pushing up against the timestamp)
656  // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
657  // as the `.mw-changeslist-date` class is used in a variety
658  // of other places with a different position and the information proceeding getTimestamp can vary.
659  // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
660  // contain the full date (month, year) and adds consistency with Special:Contributions
661  // and other pages.
662  $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
663  return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
664  '<span class="mw-changeslist-date mw-changeslist-time">' .
665  htmlspecialchars( $this->getLanguage()->userTime(
666  $rc->mAttribs['rc_timestamp'],
667  $this->getUser()
668  ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
669  }
670 
677  public function insertTimestamp( &$s, $rc ) {
678  $s .= $this->getTimestamp( $rc );
679  }
680 
687  public function insertUserRelatedLinks( &$s, &$rc ) {
688  if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
689  $deletedClass = 'history-deleted';
690  if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
691  $deletedClass .= ' mw-history-suppressed';
692  }
693  $s .= ' <span class="' . $deletedClass . '">' .
694  $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
695  } else {
696  $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
697  $rc->mAttribs['rc_user_text'] );
699  $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
700  false, 0, null,
701  // The text content of tools is not wrapped with parentheses or "piped".
702  // This will be handled in CSS (T205581).
703  false
704  );
705  }
706  }
707 
714  public function insertLogEntry( $rc ) {
715  $formatter = LogFormatter::newFromRow( $rc->mAttribs );
716  $formatter->setContext( $this->getContext() );
717  $formatter->setShowUserToolLinks( true );
718  $mark = $this->getLanguage()->getDirMark();
719 
720  return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
721  . $formatter->getActionText() . " $mark" . $formatter->getComment()
722  . Html::closeElement( 'span' );
723  }
724 
730  public function insertComment( $rc ) {
731  if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
732  $deletedClass = 'history-deleted';
733  if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
734  $deletedClass .= ' mw-history-suppressed';
735  }
736  return ' <span class="' . $deletedClass . ' comment">' .
737  $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
738  } elseif ( isset( $rc->mAttribs['rc_id'] )
739  && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
740  ) {
741  return $this->formattedComments[$rc->mAttribs['rc_id']];
742  } else {
743  return $this->commentFormatter->formatBlock(
744  $rc->mAttribs['rc_comment'],
745  $rc->getTitle(),
746  // Whether section links should refer to local page (using default false)
747  false,
748  // wikid to generate links for (using default null) */
749  null,
750  // whether parentheses should be rendered as part of the message
751  false
752  );
753  }
754  }
755 
761  protected function numberofWatchingusers( $count ) {
762  if ( $count <= 0 ) {
763  return '';
764  }
765 
766  return $this->watchMsgCache->getWithSetCallback(
767  "watching-users-msg:$count",
768  function () use ( $count ) {
769  return $this->msg( 'number-of-watching-users-for-recent-changes' )
770  ->numParams( $count )->escaped();
771  }
772  );
773  }
774 
781  public static function isDeleted( $rc, $field ) {
782  return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
783  }
784 
794  public static function userCan( $rc, $field, Authority $performer = null ) {
795  if ( $performer === null ) {
796  $performer = RequestContext::getMain()->getAuthority();
797  }
798 
799  if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
800  return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
801  }
802 
803  return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
804  }
805 
811  protected function maybeWatchedLink( $link, $watched = false ) {
812  if ( $watched ) {
813  return '<strong class="mw-watched">' . $link . '</strong>';
814  } else {
815  return '<span class="mw-rc-unwatched">' . $link . '</span>';
816  }
817  }
818 
825  public function insertRollback( &$s, &$rc ) {
826  if ( $rc->mAttribs['rc_type'] == RC_EDIT
827  && $rc->mAttribs['rc_this_oldid']
828  && $rc->mAttribs['rc_cur_id']
829  && $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
830  ) {
831  $title = $rc->getTitle();
835  if ( $this->getAuthority()->probablyCan( 'rollback', $title ) ) {
836  $revRecord = new MutableRevisionRecord( $title );
837  $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
838  $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
839  $user = new UserIdentityValue(
840  (int)$rc->mAttribs['rc_user'],
841  $rc->mAttribs['rc_user_text']
842  );
843  $revRecord->setUser( $user );
844 
845  $s .= ' ';
847  $revRecord,
848  $this->getContext(),
849  [ 'noBrackets' ]
850  );
851  }
852  }
853  }
854 
860  public function getRollback( RecentChange $rc ) {
861  $s = '';
862  $this->insertRollback( $s, $rc );
863  return $s;
864  }
865 
871  public function insertTags( &$s, &$rc, &$classes ) {
872  if ( empty( $rc->mAttribs['ts_tags'] ) ) {
873  return;
874  }
875 
876  list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
877  $rc->mAttribs['ts_tags'],
878  'changeslist',
879  $this->getContext()
880  );
881  $classes = array_merge( $classes, $newClasses );
882  $s .= ' ' . $tagSummary;
883  }
884 
891  public function getTags( RecentChange $rc, array &$classes ) {
892  $s = '';
893  $this->insertTags( $s, $rc, $classes );
894  return $s;
895  }
896 
897  public function insertExtra( &$s, &$rc, &$classes ) {
898  // Empty, used for subclasses to add anything special.
899  }
900 
901  protected function showAsUnpatrolled( RecentChange $rc ) {
902  return self::isUnpatrolled( $rc, $this->getUser() );
903  }
904 
910  public static function isUnpatrolled( $rc, User $user ) {
911  if ( $rc instanceof RecentChange ) {
912  $isPatrolled = $rc->mAttribs['rc_patrolled'];
913  $rcType = $rc->mAttribs['rc_type'];
914  $rcLogType = $rc->mAttribs['rc_log_type'];
915  } else {
916  $isPatrolled = $rc->rc_patrolled;
917  $rcType = $rc->rc_type;
918  $rcLogType = $rc->rc_log_type;
919  }
920 
921  if ( !$isPatrolled ) {
922  if ( $user->useRCPatrol() ) {
923  return true;
924  }
925  if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
926  return true;
927  }
928  if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
929  return true;
930  }
931  }
932 
933  return false;
934  }
935 
945  protected function isCategorizationWithoutRevision( $rcObj ) {
946  return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
947  && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
948  }
949 
955  protected function getDataAttributes( RecentChange $rc ) {
956  $attrs = [];
957 
958  $type = $rc->getAttribute( 'rc_source' );
959  switch ( $type ) {
962  $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
963  break;
965  $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
966  $attrs['data-mw-logaction'] =
967  $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
968  break;
969  }
970 
971  $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
972 
973  return $attrs;
974  }
975 
983  public function setChangeLinePrefixer( callable $prefixer ) {
984  $this->changeLinePrefixer = $prefixer;
985  }
986 }
getUser()
getAuthority()
UserOptionsLookup $userOptionsLookup
const RC_NEW
Definition: Defines.php:116
const RC_LOG
Definition: Defines.php:117
const RC_EDIT
Definition: Defines.php:115
const RC_CATEGORIZE
Definition: Defines.php:119
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getContext()
static formatSummaryRow( $tags, $page, MessageLocalizer $localizer=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:182
static newFromContext(IContextSource $context, array $groups=[])
Fetch an appropriate changes list class for the specified context Some users might want to use an enh...
Definition: ChangesList.php:99
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:64
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:80
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:51
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:54
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:59
preCacheMessages()
As we use the same small set of messages in various methods and that they are called often,...
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:40
insertLog(&$s, $title, $logtype, $useParentheses=true)
insertTags(&$s, &$rc, &$classes)
ChangesListFilterGroup[] $filterGroups
Definition: ChangesList.php:74
string[] $formattedComments
Comments indexed by rc_id.
Definition: ChangesList.php:69
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()
IContextSource $context
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:173
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:236
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:256
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:320
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:45
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1091
static getRevisionDeletedClass(RevisionRecord $revisionRecord)
Returns css class of a deleted revision.
Definition: Linker.php:1326
static generateRollback(RevisionRecord $revRecord, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1809
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:1136
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:39
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 ...
Class that generates HTML anchor link elements for pages.
A class containing constants representing the names of configuration variables.
MediaWikiServices is the service locator for the application scope of MediaWiki.
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.
Value object representing a user's identity.
Utility class for creating new RC entries.
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:1107
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:68
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition: User.php:2635
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition: User.php:2620
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition: User.php:2610
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:43
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.
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.
msg( $key,... $params)
This is the method for getting translated interface messages.
Result wrapper for grabbing data queried from an IDatabase object.
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
if(!isset( $args[0])) $lang