MediaWiki 1.43.1
ChangesList.php
Go to the documentation of this file.
1<?php
26use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
42use OOUI\IconWidget;
44
54 use ProtectedHookAccessorTrait;
55
56 public const CSS_CLASS_PREFIX = 'mw-changeslist-';
57
59 protected $watchlist = false;
61 protected $lastdate;
63 protected $message;
65 protected $rc_cache;
67 protected $rcCacheIndex;
69 protected $rclistOpen;
71 protected $rcMoveIndex;
72
75
77 protected $watchMsgCache;
78
82 protected $linkRenderer;
83
88
93
97 protected $filterGroups;
98
102 protected $tagsCache;
103
107 protected $userLinkCache;
108
109 private LogFormatterFactory $logFormatterFactory;
110
115 public function __construct( $context, array $filterGroups = [] ) {
116 $this->setContext( $context );
117 $this->preCacheMessages();
118 $this->watchMsgCache = new MapCacheLRU( 50 );
119 $this->filterGroups = $filterGroups;
120
121 $services = MediaWikiServices::getInstance();
122 $this->linkRenderer = $services->getLinkRenderer();
123 $this->commentFormatter = $services->getRowCommentFormatter();
124 $this->logFormatterFactory = $services->getLogFormatterFactory();
125 $this->tagsCache = new MapCacheLRU( 50 );
126 $this->userLinkCache = new MapCacheLRU( 50 );
127 }
128
137 public static function newFromContext( IContextSource $context, array $groups = [] ) {
138 $user = $context->getUser();
139 $sk = $context->getSkin();
140 $services = MediaWikiServices::getInstance();
141 $list = null;
142 if ( ( new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
143 $userOptionsLookup = $services->getUserOptionsLookup();
144 $new = $context->getRequest()->getBool(
145 'enhanced',
146 $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
147 );
148
149 return $new ?
150 new EnhancedChangesList( $context, $groups ) :
151 new OldChangesList( $context, $groups );
152 } else {
153 return $list;
154 }
155 }
156
168 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
169 throw new RuntimeException( 'recentChangesLine should be implemented' );
170 }
171
178 protected function getHighlightsContainerDiv() {
179 $highlightColorDivs = '';
180 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
181 $highlightColorDivs .= Html::rawElement(
182 'div',
183 [
184 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
185 'data-color' => $color
186 ]
187 );
188 }
189
190 return Html::rawElement(
191 'div',
192 [ 'class' => 'mw-rcfilters-ui-highlights' ],
193 $highlightColorDivs
194 );
195 }
196
201 public function setWatchlistDivs( $value = true ) {
202 $this->watchlist = $value;
203 }
204
209 public function isWatchlist() {
210 return (bool)$this->watchlist;
211 }
212
217 private function preCacheMessages() {
218 if ( !isset( $this->message ) ) {
219 $this->message = [];
220 foreach ( [
221 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
222 'semicolon-separator', 'pipe-separator', 'word-separator' ] as $msg
223 ) {
224 $this->message[$msg] = $this->msg( $msg )->escaped();
225 }
226 }
227 }
228
235 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
236 $f = '';
237 foreach (
238 $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) as $flag => $_
239 ) {
240 $f .= isset( $flags[$flag] ) && $flags[$flag]
241 ? self::flag( $flag, $this->getContext() )
242 : $nothing;
243 }
244
245 return $f;
246 }
247
256 protected function getHTMLClasses( $rc, $watched ) {
257 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
258 $logType = $rc->mAttribs['rc_log_type'];
259
260 if ( $logType ) {
261 $classes[] = self::CSS_CLASS_PREFIX . 'log';
262 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
263 } else {
264 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
265 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
266 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
267 }
268
269 // Indicate watched status on the line to allow for more
270 // comprehensive styling.
271 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
272 ? self::CSS_CLASS_PREFIX . 'line-watched'
273 : self::CSS_CLASS_PREFIX . 'line-not-watched';
274
275 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
276
277 return $classes;
278 }
279
287 protected function getHTMLClassesForFilters( $rc ) {
288 $classes = [];
289
290 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
291 $rc->mAttribs['rc_namespace'] );
292
293 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
294 $classes[] = Sanitizer::escapeClass(
295 self::CSS_CLASS_PREFIX .
296 'ns-' .
297 ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
298 );
299
300 foreach ( $this->filterGroups as $filterGroup ) {
301 foreach ( $filterGroup->getFilters() as $filter ) {
302 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
303 }
304 }
305
306 return $classes;
307 }
308
319 public static function flag( $flag, ?IContextSource $context = null ) {
320 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
321 static $flagInfos = null;
322
323 if ( $flagInfos === null ) {
324 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
325 ->get( MainConfigNames::RecentChangesFlags );
326 $flagInfos = [];
327 foreach ( $recentChangesFlags as $key => $value ) {
328 $flagInfos[$key]['letter'] = $value['letter'];
329 $flagInfos[$key]['title'] = $value['title'];
330 // Allow customized class name, fall back to flag name
331 $flagInfos[$key]['class'] = $value['class'] ?? $key;
332 }
333 }
334
335 $context = $context ?: RequestContext::getMain();
336
337 // Inconsistent naming, kept for b/c
338 if ( isset( $map[$flag] ) ) {
339 $flag = $map[$flag];
340 }
341
342 $info = $flagInfos[$flag];
343 return Html::element( 'abbr', [
344 'class' => $info['class'],
345 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
346 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
347 }
348
353 public function beginRecentChangesList() {
354 $this->rc_cache = [];
355 $this->rcMoveIndex = 0;
356 $this->rcCacheIndex = 0;
357 $this->lastdate = '';
358 $this->rclistOpen = false;
359 $this->getOutput()->addModuleStyles( [
360 'mediawiki.interface.helpers.styles',
361 'mediawiki.special.changeslist'
362 ] );
363
364 return '<div class="mw-changeslist">';
365 }
366
370 public function initChangesListRows( $rows ) {
371 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
372 $this->formattedComments = $this->commentFormatter->createBatch()
373 ->comments(
374 $this->commentFormatter->rows( $rows )
375 ->commentKey( 'rc_comment' )
376 ->namespaceField( 'rc_namespace' )
377 ->titleField( 'rc_title' )
378 ->indexField( 'rc_id' )
379 )
380 ->useBlock()
381 ->execute();
382 }
383
394 public static function showCharacterDifference( $old, $new, ?IContextSource $context = null ) {
395 if ( !$context ) {
396 $context = RequestContext::getMain();
397 }
398
399 $new = (int)$new;
400 $old = (int)$old;
401 $szdiff = $new - $old;
402
403 $lang = $context->getLanguage();
404 $config = $context->getConfig();
405 $code = $lang->getCode();
406 static $fastCharDiff = [];
407 if ( !isset( $fastCharDiff[$code] ) ) {
408 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
409 || $context->msg( 'rc-change-size' )->plain() === '$1';
410 }
411
412 $formattedSize = $lang->formatNum( $szdiff );
413
414 if ( !$fastCharDiff[$code] ) {
415 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
416 }
417
418 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
419 $tag = 'strong';
420 } else {
421 $tag = 'span';
422 }
423
424 if ( $szdiff === 0 ) {
425 $formattedSizeClass = 'mw-plusminus-null';
426 } elseif ( $szdiff > 0 ) {
427 $formattedSize = '+' . $formattedSize;
428 $formattedSizeClass = 'mw-plusminus-pos';
429 } else {
430 $formattedSizeClass = 'mw-plusminus-neg';
431 }
432 $formattedSizeClass .= ' mw-diff-bytes';
433
434 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
435
436 return Html::element( $tag,
437 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
438 $formattedSize );
439 }
440
448 public function formatCharacterDifference( RecentChange $old, ?RecentChange $new = null ) {
449 $oldlen = $old->mAttribs['rc_old_len'];
450
451 if ( $new ) {
452 $newlen = $new->mAttribs['rc_new_len'];
453 } else {
454 $newlen = $old->mAttribs['rc_new_len'];
455 }
456
457 if ( $oldlen === null || $newlen === null ) {
458 return '';
459 }
460
461 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
462 }
463
468 public function endRecentChangesList() {
469 $out = $this->rclistOpen ? "</ul>\n" : '';
470 $out .= '</div>';
471
472 return $out;
473 }
474
488 public static function revDateLink(
489 RevisionRecord $rev,
490 Authority $performer,
491 Language $lang,
492 $title = null,
493 $className = ''
494 ) {
495 $ts = $rev->getTimestamp();
496 $time = $lang->userTime( $ts, $performer->getUser() );
497 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
498 $class = trim( 'mw-changeslist-date ' . $className );
499 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
500 $link = Html::rawElement( 'bdi', [ 'dir' => $lang->getDir() ],
501 MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
502 $title ?? $rev->getPageAsLinkTarget(),
503 $date,
504 [ 'class' => $class ],
505 [ 'oldid' => $rev->getId() ]
506 )
507 );
508 } else {
509 $link = htmlspecialchars( $date );
510 }
511 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
512 $class = Linker::getRevisionDeletedClass( $rev ) . " $class";
513 $link = "<span class=\"$class\">$link</span>";
514 }
515 return Html::element( 'span', [
516 'class' => 'mw-changeslist-time'
517 ], $time ) . $link;
518 }
519
524 public function insertDateHeader( &$s, $rc_timestamp ) {
525 # Make date header if necessary
526 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
527 if ( $date != $this->lastdate ) {
528 if ( $this->lastdate != '' ) {
529 $s .= "</ul>\n";
530 }
531 $s .= Html::element( 'h4', [], $date ) . "\n<ul class=\"special\">";
532 $this->lastdate = $date;
533 $this->rclistOpen = true;
534 }
535 }
536
543 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
544 $page = new LogPage( $logtype );
545 $logname = $page->getName()->setContext( $this->getContext() )->text();
546 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
547 'class' => $useParentheses ? '' : 'mw-changeslist-links'
548 ] );
549 if ( $useParentheses ) {
550 $s .= $this->msg( 'parentheses' )->rawParams(
551 $link
552 )->escaped();
553 } else {
554 $s .= $link;
555 }
556 }
557
563 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
564 # Diff link
565 if (
566 $rc->mAttribs['rc_type'] == RC_NEW ||
567 $rc->mAttribs['rc_type'] == RC_LOG ||
568 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
569 ) {
570 $diffLink = $this->message['diff'];
571 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
572 $diffLink = $this->message['diff'];
573 } else {
574 $query = [
575 'curid' => $rc->mAttribs['rc_cur_id'],
576 'diff' => $rc->mAttribs['rc_this_oldid'],
577 'oldid' => $rc->mAttribs['rc_last_oldid']
578 ];
579
580 $diffLink = $this->linkRenderer->makeKnownLink(
581 $rc->getTitle(),
582 new HtmlArmor( $this->message['diff'] ),
583 [ 'class' => 'mw-changeslist-diff' ],
584 $query
585 );
586 }
587 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
588 $histLink = $this->message['hist'];
589 } else {
590 $histLink = $this->linkRenderer->makeKnownLink(
591 $rc->getTitle(),
592 new HtmlArmor( $this->message['hist'] ),
593 [ 'class' => 'mw-changeslist-history' ],
594 [
595 'curid' => $rc->mAttribs['rc_cur_id'],
596 'action' => 'history'
597 ]
598 );
599 }
600
601 $s .= Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
602 Html::rawElement( 'span', [], $diffLink ) .
603 Html::rawElement( 'span', [], $histLink )
604 ) .
605 ' <span class="mw-changeslist-separator"></span> ';
606 }
607
618 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
619 $params = [];
620 if ( $rc->getTitle()->isRedirect() ) {
621 $params = [ 'redirect' => 'no' ];
622 }
623
624 $articlelink = $this->linkRenderer->makeLink(
625 $rc->getTitle(),
626 null,
627 [ 'class' => 'mw-changeslist-title' ],
628 $params
629 );
630 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
631 $class = 'history-deleted';
632 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
633 $class .= ' mw-history-suppressed';
634 }
635 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
636 }
637 $dir = $this->getLanguage()->getDir();
638 $articlelink = Html::rawElement( 'bdi', [ 'dir' => $dir ], $articlelink );
639 # To allow for boldening pages watched by this user
640 # Don't wrap result of this with another tag, see T376814
641 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
642
643 # TODO: Deprecate the $s argument, it seems happily unused.
644 $s = '';
645 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
646 $s, $rc, $unpatrolled, $watched );
647
648 // Watchlist expiry icon.
649 $watchlistExpiry = '';
650 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
651 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
652 }
653
654 return "{$s} {$articlelink}{$watchlistExpiry}";
655 }
656
663 public function getWatchlistExpiry( RecentChange $recentChange ): string {
664 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
665 // Guard against expired items, even though they shouldn't come here.
666 if ( $item->isExpired() ) {
667 return '';
668 }
669 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
670 // Matching widget is also created in ChangesListSpecialPage, for the legend.
671 $widget = new IconWidget( [
672 'icon' => 'clock',
673 'title' => $daysLeftText,
674 'classes' => [ 'mw-changesList-watchlistExpiry' ],
675 ] );
676 $widget->setAttributes( [
677 // Add labels for assistive technologies.
678 'role' => 'img',
679 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
680 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
681 'data-days-left' => $item->getExpiryInDays(),
682 ] );
683 // Add spaces around the widget (the page title is to one side,
684 // and a semicolon or opening-parenthesis to the other).
685 return " $widget ";
686 }
687
696 public function getTimestamp( $rc ) {
697 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
698 // because in that case the timestamp is preceded by a clock icon.
699 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
700 // that whatever comes before it is distinguishable.
701 // (Otherwise your have the text of titles pushing up against the timestamp)
702 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
703 // as the `.mw-changeslist-date` class is used in a variety
704 // of other places with a different position and the information proceeding getTimestamp can vary.
705 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
706 // contain the full date (month, year) and adds consistency with Special:Contributions
707 // and other pages.
708 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
709 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
710 '<span class="mw-changeslist-date mw-changeslist-time">' .
711 htmlspecialchars( $this->getLanguage()->userTime(
712 $rc->mAttribs['rc_timestamp'],
713 $this->getUser()
714 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
715 }
716
723 public function insertTimestamp( &$s, $rc ) {
724 $s .= $this->getTimestamp( $rc );
725 }
726
733 public function insertUserRelatedLinks( &$s, &$rc ) {
734 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
735 $deletedClass = 'history-deleted';
736 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
737 $deletedClass .= ' mw-history-suppressed';
738 }
739 $s .= ' <span class="' . $deletedClass . '">' .
740 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
741 } else {
742 # Don't wrap result of this with another tag, see T376814
743 $s .= $this->userLinkCache->getWithSetCallback(
744 $this->userLinkCache->makeKey(
745 $rc->mAttribs['rc_user_text'],
746 $this->getUser()->getName(),
747 $this->getLanguage()->getCode()
748 ),
749 static function () use ( $rc ) {
750 return Linker::userLink(
751 $rc->mAttribs['rc_user'],
752 $rc->mAttribs['rc_user_text']
753 ) . Linker::userToolLinks(
754 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
755 false, 0, null,
756 // The text content of tools is not wrapped with parentheses or "piped".
757 // This will be handled in CSS (T205581).
758 false
759 );
760 }
761 );
762 }
763 }
764
771 public function insertLogEntry( $rc ) {
772 $formatter = $this->logFormatterFactory->newFromRow( $rc->mAttribs );
773 $formatter->setContext( $this->getContext() );
774 $formatter->setShowUserToolLinks( true );
775
776 $comment = $formatter->getComment();
777 if ( $comment !== '' ) {
778 $dir = $this->getLanguage()->getDir();
779 $comment = Html::rawElement( 'bdi', [ 'dir' => $dir ], $comment );
780 }
781
782 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
783 . $formatter->getActionText()
784 . ' '
785 . $comment
786 . $this->message['word-separator']
787 . $formatter->getActionLinks()
788 . Html::closeElement( 'span' );
789 }
790
796 public function insertComment( $rc ) {
797 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
798 $deletedClass = 'history-deleted';
799 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
800 $deletedClass .= ' mw-history-suppressed';
801 }
802 return ' <span class="' . $deletedClass . ' comment">' .
803 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
804 } elseif ( isset( $rc->mAttribs['rc_id'] )
805 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
806 ) {
807 return $this->formattedComments[$rc->mAttribs['rc_id']];
808 } else {
809 return $this->commentFormatter->formatBlock(
810 $rc->mAttribs['rc_comment'],
811 $rc->getTitle(),
812 // Whether section links should refer to local page (using default false)
813 false,
814 // wikid to generate links for (using default null) */
815 null,
816 // whether parentheses should be rendered as part of the message
817 false
818 );
819 }
820 }
821
827 protected function numberofWatchingusers( $count ) {
828 if ( $count <= 0 ) {
829 return '';
830 }
831
832 return $this->watchMsgCache->getWithSetCallback(
833 $this->watchMsgCache->makeKey(
834 'watching-users-msg',
835 strval( $count ),
836 $this->getUser()->getName(),
837 $this->getLanguage()->getCode()
838 ),
839 function () use ( $count ) {
840 return $this->msg( 'number-of-watching-users-for-recent-changes' )
841 ->numParams( $count )->escaped();
842 }
843 );
844 }
845
852 public static function isDeleted( $rc, $field ) {
853 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
854 }
855
865 public static function userCan( $rc, $field, ?Authority $performer = null ) {
866 $performer ??= RequestContext::getMain()->getAuthority();
867
868 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
869 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
870 }
871
872 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
873 }
874
880 protected function maybeWatchedLink( $link, $watched = false ) {
881 if ( $watched ) {
882 return '<strong class="mw-watched">' . $link . '</strong>';
883 } else {
884 return '<span class="mw-rc-unwatched">' . $link . '</span>';
885 }
886 }
887
894 public function insertRollback( &$s, &$rc ) {
895 $this->insertPageTools( $s, $rc );
896 }
897
906 private function insertPageTools( &$s, &$rc ) {
907 // FIXME Some page tools (e.g. thanks) might make sense for log entries.
908 if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
909 // FIXME When would either of these not exist when type is RC_EDIT? Document.
910 || !$rc->mAttribs['rc_this_oldid']
911 || !$rc->mAttribs['rc_cur_id']
912 ) {
913 return;
914 }
915
916 // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
917 $title = $rc->getTitle();
918 $revRecord = new MutableRevisionRecord( $title );
919 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
920 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
921 $user = new UserIdentityValue(
922 (int)$rc->mAttribs['rc_user'],
923 $rc->mAttribs['rc_user_text']
924 );
925 $revRecord->setUser( $user );
926
927 $tools = new PagerTools(
928 $revRecord,
929 null,
930 // only show a rollback link on the top-most revision
931 $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
932 && $rc->mAttribs['rc_type'] != RC_NEW,
933 $this->getHookRunner(),
934 $title,
935 $this->getContext(),
936 // @todo: Inject
937 MediaWikiServices::getInstance()->getLinkRenderer()
938 );
939
940 $s .= $tools->toHTML();
941 }
942
948 public function getRollback( RecentChange $rc ) {
949 $s = '';
950 $this->insertRollback( $s, $rc );
951 return $s;
952 }
953
959 public function insertTags( &$s, &$rc, &$classes ) {
960 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
961 return;
962 }
963
969 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
970 $this->tagsCache->makeKey(
971 $rc->mAttribs['ts_tags'],
972 $this->getUser()->getName(),
973 $this->getLanguage()->getCode()
974 ),
976 $rc->mAttribs['ts_tags'],
977 'changeslist',
978 $this->getContext()
979 )
980 );
981 $classes = array_merge( $classes, $newClasses );
982 $s .= ' ' . $tagSummary;
983 }
984
991 public function getTags( RecentChange $rc, array &$classes ) {
992 $s = '';
993 $this->insertTags( $s, $rc, $classes );
994 return $s;
995 }
996
997 public function insertExtra( &$s, &$rc, &$classes ) {
998 // Empty, used for subclasses to add anything special.
999 }
1000
1001 protected function showAsUnpatrolled( RecentChange $rc ) {
1002 return self::isUnpatrolled( $rc, $this->getUser() );
1003 }
1004
1010 public static function isUnpatrolled( $rc, User $user ) {
1011 if ( $rc instanceof RecentChange ) {
1012 $isPatrolled = $rc->mAttribs['rc_patrolled'];
1013 $rcType = $rc->mAttribs['rc_type'];
1014 $rcLogType = $rc->mAttribs['rc_log_type'];
1015 } else {
1016 $isPatrolled = $rc->rc_patrolled;
1017 $rcType = $rc->rc_type;
1018 $rcLogType = $rc->rc_log_type;
1019 }
1020
1021 if ( $isPatrolled ) {
1022 return false;
1023 }
1024
1025 return $user->useRCPatrol() ||
1026 ( $rcType == RC_NEW && $user->useNPPatrol() ) ||
1027 ( $rcLogType === 'upload' && $user->useFilePatrol() );
1028 }
1029
1039 protected function isCategorizationWithoutRevision( $rcObj ) {
1040 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
1041 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
1042 }
1043
1049 protected function getDataAttributes( RecentChange $rc ) {
1050 $attrs = [];
1051
1052 $type = $rc->getAttribute( 'rc_source' );
1053 switch ( $type ) {
1054 case RecentChange::SRC_EDIT:
1055 case RecentChange::SRC_CATEGORIZE:
1056 case RecentChange::SRC_NEW:
1057 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1058 break;
1059 case RecentChange::SRC_LOG:
1060 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
1061 $attrs['data-mw-logaction'] =
1062 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
1063 break;
1064 }
1065
1066 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1067
1068 return $attrs;
1069 }
1070
1078 public function setChangeLinePrefixer( callable $prefixer ) {
1079 $this->changeLinePrefixer = $prefixer;
1080 }
1081}
const RC_NEW
Definition Defines.php:118
const RC_LOG
Definition Defines.php:119
const RC_EDIT
Definition Defines.php:117
const RC_CATEGORIZE
Definition Defines.php:121
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
static formatSummaryRow( $tags, $unused, ?MessageLocalizer $localizer=null)
Creates HTML for the given tags.
Represents a filter group (used on ChangesListSpecialPage and descendants)
Base class for lists of recent changes shown on special pages.
static showCharacterDifference( $old, $new, ?IContextSource $context=null)
Show formatted char difference.
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)
string $lastdate
setWatchlistDivs( $value=true)
Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag.
insertDateHeader(&$s, $rc_timestamp)
insertRollback(&$s, &$rc)
Insert a rollback link.
showAsUnpatrolled(RecentChange $rc)
RowCommentFormatter $commentFormatter
static isUnpatrolled( $rc, User $user)
getHighlightsContainerDiv()
Get the container for highlights that are used in the new StructuredFilters system.
recentChangesLine(&$rc, $watched=false, $linenumber=null)
Format a line.
__construct( $context, array $filterGroups=[])
recentChangesFlags( $flags, $nothing="\u{00A0}")
Returns the appropriate flags for new page, minor change and patrolling.
MapCacheLRU $userLinkCache
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.
string[] $message
getWatchlistExpiry(RecentChange $recentChange)
Get HTML to display the clock icon for watched items that have a watchlist expiry time.
callable $changeLinePrefixer
getTags(RecentChange $rc, array &$classes)
formatCharacterDifference(RecentChange $old, ?RecentChange $new=null)
Format the character difference of one or several changes.
static userCan( $rc, $field, ?Authority $performer=null)
Determine if the current user is allowed to view a particular field of this revision,...
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.
getRollback(RecentChange $rc)
MapCacheLRU $watchMsgCache
endRecentChangesList()
Returns text for the end of RC.
LinkRenderer $linkRenderer
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
static revDateLink(RevisionRecord $rev, Authority $performer, Language $lang, $title=null, $className='')
Render the date and time of a revision in the current user language based on whether the user is able...
insertLog(&$s, $title, $logtype, $useParentheses=true)
insertTags(&$s, &$rc, &$classes)
array $rc_cache
ChangesListFilterGroup[] $filterGroups
string[] $formattedComments
Comments indexed by rc_id.
insertComment( $rc)
Insert a formatted comment.
MapCacheLRU $tagsCache
insertExtra(&$s, &$rc, &$classes)
static flag( $flag, ?IContextSource $context=null)
Make an "<abbr>" element for a given change flag.
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.
Generate a list of changes using an Enhanced system (uses javascript).
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
Class to simplify the use of log pages.
Definition LogPage.php:46
Store key-value entries in a size-limited in-memory LRU cache.
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
Group all the pieces relevant to the context of a request into one instance.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
Base class for language-specific code.
Definition Language.php:79
userTimeAndDate( $ts, UserIdentity $user, array $options=[])
Get the formatted date and time for the given timestamp and formatted for the given user.
getDir()
Return the correct HTML 'dir' attribute value for this language.
userTime( $ts, UserIdentity $user, array $options=[])
Get the formatted time for the given timestamp and formatted for the given user.
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:63
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Generate a set of tools for a revision.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
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:78
getBoolOption(UserIdentity $user, string $oname, int $queryFlags=IDBAccessObject::READ_NORMAL)
Get the user's current setting for a given option, as a boolean value.
Value object representing a user's identity.
internal since 1.36
Definition User.php:94
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition User.php:2189
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition User.php:2214
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition User.php:2199
Representation of a pair of user and title for watchlist entries.
getExpiryInDaysText(MessageLocalizer $msgLocalizer, $isDropdownOption=false)
Get days remaining until a watched item expires as a text.
Generate a list of changes using the good old system (no javascript).
Utility class for creating and reading rows in the recentchanges table.
getAttribute( $name)
Get an attribute value.
Interface for objects which can provide a MediaWiki context on request.
This interface represents the authority associated with the current execution context,...
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.