MediaWiki master
ChangesList.php
Go to the documentation of this file.
1<?php
30use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
45use OOUI\IconWidget;
47
49 use ProtectedHookAccessorTrait;
50
51 public const CSS_CLASS_PREFIX = 'mw-changeslist-';
52
53 protected $watchlist = false;
54 protected $lastdate;
55 protected $message;
56 protected $rc_cache;
57 protected $rcCacheIndex;
58 protected $rclistOpen;
59 protected $rcMoveIndex;
60
63
65 protected $watchMsgCache;
66
70 protected $linkRenderer;
71
76
81
85 protected $filterGroups;
86
90 protected $tagsCache;
91
95 protected $userLinkCache;
96
101 public function __construct( $context, array $filterGroups = [] ) {
102 $this->setContext( $context );
103 $this->preCacheMessages();
104 $this->watchMsgCache = new MapCacheLRU( 50 );
105 $this->filterGroups = $filterGroups;
106
107 $services = MediaWikiServices::getInstance();
108 $this->linkRenderer = $services->getLinkRenderer();
109 $this->commentFormatter = $services->getRowCommentFormatter();
110 $this->tagsCache = new MapCacheLRU( 50 );
111 $this->userLinkCache = new MapCacheLRU( 50 );
112 }
113
122 public static function newFromContext( IContextSource $context, array $groups = [] ) {
123 $user = $context->getUser();
124 $sk = $context->getSkin();
125 $services = MediaWikiServices::getInstance();
126 $list = null;
127 if ( ( new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
128 $userOptionsLookup = $services->getUserOptionsLookup();
129 $new = $context->getRequest()->getBool(
130 'enhanced',
131 $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
132 );
133
134 return $new ?
135 new EnhancedChangesList( $context, $groups ) :
136 new OldChangesList( $context, $groups );
137 } else {
138 return $list;
139 }
140 }
141
153 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
154 throw new RuntimeException( 'recentChangesLine should be implemented' );
155 }
156
163 protected function getHighlightsContainerDiv() {
164 $highlightColorDivs = '';
165 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
166 $highlightColorDivs .= Html::rawElement(
167 'div',
168 [
169 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
170 'data-color' => $color
171 ]
172 );
173 }
174
175 return Html::rawElement(
176 'div',
177 [ 'class' => 'mw-rcfilters-ui-highlights' ],
178 $highlightColorDivs
179 );
180 }
181
186 public function setWatchlistDivs( $value = true ) {
187 $this->watchlist = $value;
188 }
189
194 public function isWatchlist() {
195 return (bool)$this->watchlist;
196 }
197
202 private function preCacheMessages() {
203 if ( !isset( $this->message ) ) {
204 $this->message = [];
205 foreach ( [
206 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
207 'semicolon-separator', 'pipe-separator', 'word-separator' ] as $msg
208 ) {
209 $this->message[$msg] = $this->msg( $msg )->escaped();
210 }
211 }
212 }
213
220 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
221 $f = '';
222 foreach (
223 $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) as $flag => $_
224 ) {
225 $f .= isset( $flags[$flag] ) && $flags[$flag]
226 ? self::flag( $flag, $this->getContext() )
227 : $nothing;
228 }
229
230 return $f;
231 }
232
241 protected function getHTMLClasses( $rc, $watched ) {
242 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
243 $logType = $rc->mAttribs['rc_log_type'];
244
245 if ( $logType ) {
246 $classes[] = self::CSS_CLASS_PREFIX . 'log';
247 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
248 } else {
249 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
250 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
251 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
252 }
253
254 // Indicate watched status on the line to allow for more
255 // comprehensive styling.
256 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
257 ? self::CSS_CLASS_PREFIX . 'line-watched'
258 : self::CSS_CLASS_PREFIX . 'line-not-watched';
259
260 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
261
262 return $classes;
263 }
264
272 protected function getHTMLClassesForFilters( $rc ) {
273 $classes = [];
274
275 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
276 $rc->mAttribs['rc_namespace'] );
277
278 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
279 $classes[] = Sanitizer::escapeClass(
280 self::CSS_CLASS_PREFIX .
281 'ns-' .
282 ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
283 );
284
285 foreach ( $this->filterGroups as $filterGroup ) {
286 foreach ( $filterGroup->getFilters() as $filter ) {
287 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
288 }
289 }
290
291 return $classes;
292 }
293
304 public static function flag( $flag, IContextSource $context = null ) {
305 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
306 static $flagInfos = null;
307
308 if ( $flagInfos === null ) {
309 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
310 ->get( MainConfigNames::RecentChangesFlags );
311 $flagInfos = [];
312 foreach ( $recentChangesFlags as $key => $value ) {
313 $flagInfos[$key]['letter'] = $value['letter'];
314 $flagInfos[$key]['title'] = $value['title'];
315 // Allow customized class name, fall back to flag name
316 $flagInfos[$key]['class'] = $value['class'] ?? $key;
317 }
318 }
319
320 $context = $context ?: RequestContext::getMain();
321
322 // Inconsistent naming, kept for b/c
323 if ( isset( $map[$flag] ) ) {
324 $flag = $map[$flag];
325 }
326
327 $info = $flagInfos[$flag];
328 return Html::element( 'abbr', [
329 'class' => $info['class'],
330 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
331 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
332 }
333
338 public function beginRecentChangesList() {
339 $this->rc_cache = [];
340 $this->rcMoveIndex = 0;
341 $this->rcCacheIndex = 0;
342 $this->lastdate = '';
343 $this->rclistOpen = false;
344 $this->getOutput()->addModuleStyles( [
345 'mediawiki.interface.helpers.styles',
346 'mediawiki.special.changeslist'
347 ] );
348
349 return '<div class="mw-changeslist">';
350 }
351
355 public function initChangesListRows( $rows ) {
356 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
357 $this->formattedComments = $this->commentFormatter->createBatch()
358 ->comments(
359 $this->commentFormatter->rows( $rows )
360 ->commentKey( 'rc_comment' )
361 ->namespaceField( 'rc_namespace' )
362 ->titleField( 'rc_title' )
363 ->indexField( 'rc_id' )
364 )
365 ->useBlock()
366 ->execute();
367 }
368
379 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
380 if ( !$context ) {
381 $context = RequestContext::getMain();
382 }
383
384 $new = (int)$new;
385 $old = (int)$old;
386 $szdiff = $new - $old;
387
388 $lang = $context->getLanguage();
389 $config = $context->getConfig();
390 $code = $lang->getCode();
391 static $fastCharDiff = [];
392 if ( !isset( $fastCharDiff[$code] ) ) {
393 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
394 || $context->msg( 'rc-change-size' )->plain() === '$1';
395 }
396
397 $formattedSize = $lang->formatNum( $szdiff );
398
399 if ( !$fastCharDiff[$code] ) {
400 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
401 }
402
403 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
404 $tag = 'strong';
405 } else {
406 $tag = 'span';
407 }
408
409 if ( $szdiff === 0 ) {
410 $formattedSizeClass = 'mw-plusminus-null';
411 } elseif ( $szdiff > 0 ) {
412 $formattedSize = '+' . $formattedSize;
413 $formattedSizeClass = 'mw-plusminus-pos';
414 } else {
415 $formattedSizeClass = 'mw-plusminus-neg';
416 }
417 $formattedSizeClass .= ' mw-diff-bytes';
418
419 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
420
421 return Html::element( $tag,
422 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
423 $formattedSize ) . $lang->getDirMark();
424 }
425
433 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
434 $oldlen = $old->mAttribs['rc_old_len'];
435
436 if ( $new ) {
437 $newlen = $new->mAttribs['rc_new_len'];
438 } else {
439 $newlen = $old->mAttribs['rc_new_len'];
440 }
441
442 if ( $oldlen === null || $newlen === null ) {
443 return '';
444 }
445
446 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
447 }
448
453 public function endRecentChangesList() {
454 $out = $this->rclistOpen ? "</ul>\n" : '';
455 $out .= '</div>';
456
457 return $out;
458 }
459
473 public static function revDateLink(
474 RevisionRecord $rev,
475 Authority $performer,
476 Language $lang,
477 $title = null,
478 $className = ''
479 ) {
480 $ts = $rev->getTimestamp();
481 $time = $lang->userTime( $ts, $performer->getUser() );
482 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
483 $class = trim( 'mw-changeslist-date ' . $className );
484 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
485 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
486 $title ?? $rev->getPageAsLinkTarget(),
487 $date,
488 [ 'class' => $class ],
489 [ 'oldid' => $rev->getId() ]
490 );
491 } else {
492 $link = htmlspecialchars( $date );
493 }
494 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
495 $class = Linker::getRevisionDeletedClass( $rev ) . " $class";
496 $link = "<span class=\"$class\">$link</span>";
497 }
498 return Html::element( 'span', [
499 'class' => 'mw-changeslist-time'
500 ], $time ) . $link;
501 }
502
507 public function insertDateHeader( &$s, $rc_timestamp ) {
508 # Make date header if necessary
509 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
510 if ( $date != $this->lastdate ) {
511 if ( $this->lastdate != '' ) {
512 $s .= "</ul>\n";
513 }
514 $s .= Html::element( 'h4', [], $date ) . "\n<ul class=\"special\">";
515 $this->lastdate = $date;
516 $this->rclistOpen = true;
517 }
518 }
519
526 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
527 $page = new LogPage( $logtype );
528 $logname = $page->getName()->setContext( $this->getContext() )->text();
529 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
530 'class' => $useParentheses ? '' : 'mw-changeslist-links'
531 ] );
532 if ( $useParentheses ) {
533 $s .= $this->msg( 'parentheses' )->rawParams(
534 $link
535 )->escaped();
536 } else {
537 $s .= $link;
538 }
539 }
540
546 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
547 # Diff link
548 if (
549 $rc->mAttribs['rc_type'] == RC_NEW ||
550 $rc->mAttribs['rc_type'] == RC_LOG ||
551 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
552 ) {
553 $diffLink = $this->message['diff'];
554 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
555 $diffLink = $this->message['diff'];
556 } else {
557 $query = [
558 'curid' => $rc->mAttribs['rc_cur_id'],
559 'diff' => $rc->mAttribs['rc_this_oldid'],
560 'oldid' => $rc->mAttribs['rc_last_oldid']
561 ];
562
563 $diffLink = $this->linkRenderer->makeKnownLink(
564 $rc->getTitle(),
565 new HtmlArmor( $this->message['diff'] ),
566 [ 'class' => 'mw-changeslist-diff' ],
567 $query
568 );
569 }
570 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
571 $histLink = $this->message['hist'];
572 } else {
573 $histLink = $this->linkRenderer->makeKnownLink(
574 $rc->getTitle(),
575 new HtmlArmor( $this->message['hist'] ),
576 [ 'class' => 'mw-changeslist-history' ],
577 [
578 'curid' => $rc->mAttribs['rc_cur_id'],
579 'action' => 'history'
580 ]
581 );
582 }
583
584 $s .= Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
585 Html::rawElement( 'span', [], $diffLink ) .
586 Html::rawElement( 'span', [], $histLink )
587 ) .
588 ' <span class="mw-changeslist-separator"></span> ';
589 }
590
601 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
602 $params = [];
603 if ( $rc->getTitle()->isRedirect() ) {
604 $params = [ 'redirect' => 'no' ];
605 }
606
607 $articlelink = $this->linkRenderer->makeLink(
608 $rc->getTitle(),
609 null,
610 [ 'class' => 'mw-changeslist-title' ],
611 $params
612 );
613 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
614 $class = 'history-deleted';
615 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
616 $class .= ' mw-history-suppressed';
617 }
618 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
619 }
620 # To allow for boldening pages watched by this user
621 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
622 # RTL/LTR marker
623 $articlelink .= $this->getLanguage()->getDirMark();
624
625 # TODO: Deprecate the $s argument, it seems happily unused.
626 $s = '';
627 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
628 $s, $rc, $unpatrolled, $watched );
629
630 // Watchlist expiry icon.
631 $watchlistExpiry = '';
632 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
633 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
634 }
635
636 return "{$s} {$articlelink}{$watchlistExpiry}";
637 }
638
645 public function getWatchlistExpiry( RecentChange $recentChange ): string {
646 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
647 // Guard against expired items, even though they shouldn't come here.
648 if ( $item->isExpired() ) {
649 return '';
650 }
651 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
652 // Matching widget is also created in ChangesListSpecialPage, for the legend.
653 $widget = new IconWidget( [
654 'icon' => 'clock',
655 'title' => $daysLeftText,
656 'classes' => [ 'mw-changesList-watchlistExpiry' ],
657 ] );
658 $widget->setAttributes( [
659 // Add labels for assistive technologies.
660 'role' => 'img',
661 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
662 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
663 'data-days-left' => $item->getExpiryInDays(),
664 ] );
665 // Add spaces around the widget (the page title is to one side,
666 // and a semicolon or opening-parenthesis to the other).
667 return " $widget ";
668 }
669
678 public function getTimestamp( $rc ) {
679 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
680 // because in that case the timestamp is preceded by a clock icon.
681 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
682 // that whatever comes before it is distinguishable.
683 // (Otherwise your have the text of titles pushing up against the timestamp)
684 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
685 // as the `.mw-changeslist-date` class is used in a variety
686 // of other places with a different position and the information proceeding getTimestamp can vary.
687 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
688 // contain the full date (month, year) and adds consistency with Special:Contributions
689 // and other pages.
690 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
691 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
692 '<span class="mw-changeslist-date mw-changeslist-time">' .
693 htmlspecialchars( $this->getLanguage()->userTime(
694 $rc->mAttribs['rc_timestamp'],
695 $this->getUser()
696 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
697 }
698
705 public function insertTimestamp( &$s, $rc ) {
706 $s .= $this->getTimestamp( $rc );
707 }
708
715 public function insertUserRelatedLinks( &$s, &$rc ) {
716 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
717 $deletedClass = 'history-deleted';
718 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
719 $deletedClass .= ' mw-history-suppressed';
720 }
721 $s .= ' <span class="' . $deletedClass . '">' .
722 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
723 } else {
724 $s .= $this->getLanguage()->getDirMark();
725 $s .= $this->userLinkCache->getWithSetCallback(
726 $this->userLinkCache->makeKey(
727 $rc->mAttribs['rc_user_text'],
728 $this->getUser()->getName(),
729 $this->getLanguage()->getCode()
730 ),
731 static function () use ( $rc ) {
732 return Linker::userLink(
733 $rc->mAttribs['rc_user'],
734 $rc->mAttribs['rc_user_text']
735 ) . Linker::userToolLinks(
736 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
737 false, 0, null,
738 // The text content of tools is not wrapped with parentheses or "piped".
739 // This will be handled in CSS (T205581).
740 false
741 );
742 }
743 );
744 }
745 }
746
753 public function insertLogEntry( $rc ) {
754 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
755 $formatter->setContext( $this->getContext() );
756 $formatter->setShowUserToolLinks( true );
757 $mark = $this->getLanguage()->getDirMark();
758
759 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
760 . $formatter->getActionText()
761 . " $mark"
762 . $formatter->getComment()
763 . $this->message['word-separator']
764 . $formatter->getActionLinks()
765 . Html::closeElement( 'span' );
766 }
767
773 public function insertComment( $rc ) {
774 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
775 $deletedClass = 'history-deleted';
776 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
777 $deletedClass .= ' mw-history-suppressed';
778 }
779 return ' <span class="' . $deletedClass . ' comment">' .
780 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
781 } elseif ( isset( $rc->mAttribs['rc_id'] )
782 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
783 ) {
784 return $this->formattedComments[$rc->mAttribs['rc_id']];
785 } else {
786 return $this->commentFormatter->formatBlock(
787 $rc->mAttribs['rc_comment'],
788 $rc->getTitle(),
789 // Whether section links should refer to local page (using default false)
790 false,
791 // wikid to generate links for (using default null) */
792 null,
793 // whether parentheses should be rendered as part of the message
794 false
795 );
796 }
797 }
798
804 protected function numberofWatchingusers( $count ) {
805 if ( $count <= 0 ) {
806 return '';
807 }
808
809 return $this->watchMsgCache->getWithSetCallback(
810 $this->watchMsgCache->makeKey(
811 'watching-users-msg',
812 strval( $count ),
813 $this->getUser()->getName(),
814 $this->getLanguage()->getCode()
815 ),
816 function () use ( $count ) {
817 return $this->msg( 'number-of-watching-users-for-recent-changes' )
818 ->numParams( $count )->escaped();
819 }
820 );
821 }
822
829 public static function isDeleted( $rc, $field ) {
830 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
831 }
832
842 public static function userCan( $rc, $field, Authority $performer = null ) {
843 $performer ??= RequestContext::getMain()->getAuthority();
844
845 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
846 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
847 }
848
849 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
850 }
851
857 protected function maybeWatchedLink( $link, $watched = false ) {
858 if ( $watched ) {
859 return '<strong class="mw-watched">' . $link . '</strong>';
860 } else {
861 return '<span class="mw-rc-unwatched">' . $link . '</span>';
862 }
863 }
864
871 public function insertRollback( &$s, &$rc ) {
872 $this->insertPageTools( $s, $rc );
873 }
874
883 private function insertPageTools( &$s, &$rc ) {
884 // FIXME Some page tools (e.g. thanks) might make sense for log entries.
885 if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
886 // FIXME When would either of these not exist when type is RC_EDIT? Document.
887 || !$rc->mAttribs['rc_this_oldid']
888 || !$rc->mAttribs['rc_cur_id']
889 ) {
890 return;
891 }
892
893 // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
894 $title = $rc->getTitle();
895 $revRecord = new MutableRevisionRecord( $title );
896 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
897 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
898 $user = new UserIdentityValue(
899 (int)$rc->mAttribs['rc_user'],
900 $rc->mAttribs['rc_user_text']
901 );
902 $revRecord->setUser( $user );
903
904 $tools = new PagerTools(
905 $revRecord,
906 null,
907 // only show a rollback link on the top-most revision
908 $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
909 && $rc->mAttribs['rc_type'] != RC_NEW,
910 $this->getHookRunner(),
911 $title,
912 $this->getContext(),
913 // @todo: Inject
914 MediaWikiServices::getInstance()->getLinkRenderer()
915 );
916
917 $s .= $tools->toHTML();
918 }
919
925 public function getRollback( RecentChange $rc ) {
926 $s = '';
927 $this->insertRollback( $s, $rc );
928 return $s;
929 }
930
936 public function insertTags( &$s, &$rc, &$classes ) {
937 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
938 return;
939 }
940
946 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
947 $this->tagsCache->makeKey(
948 $rc->mAttribs['ts_tags'],
949 $this->getUser()->getName(),
950 $this->getLanguage()->getCode()
951 ),
953 $rc->mAttribs['ts_tags'],
954 'changeslist',
955 $this->getContext()
956 )
957 );
958 $classes = array_merge( $classes, $newClasses );
959 $s .= ' ' . $tagSummary;
960 }
961
968 public function getTags( RecentChange $rc, array &$classes ) {
969 $s = '';
970 $this->insertTags( $s, $rc, $classes );
971 return $s;
972 }
973
974 public function insertExtra( &$s, &$rc, &$classes ) {
975 // Empty, used for subclasses to add anything special.
976 }
977
978 protected function showAsUnpatrolled( RecentChange $rc ) {
979 return self::isUnpatrolled( $rc, $this->getUser() );
980 }
981
987 public static function isUnpatrolled( $rc, User $user ) {
988 if ( $rc instanceof RecentChange ) {
989 $isPatrolled = $rc->mAttribs['rc_patrolled'];
990 $rcType = $rc->mAttribs['rc_type'];
991 $rcLogType = $rc->mAttribs['rc_log_type'];
992 } else {
993 $isPatrolled = $rc->rc_patrolled;
994 $rcType = $rc->rc_type;
995 $rcLogType = $rc->rc_log_type;
996 }
997
998 if ( $isPatrolled ) {
999 return false;
1000 }
1001
1002 return $user->useRCPatrol() ||
1003 ( $rcType == RC_NEW && $user->useNPPatrol() ) ||
1004 ( $rcLogType === 'upload' && $user->useFilePatrol() );
1005 }
1006
1016 protected function isCategorizationWithoutRevision( $rcObj ) {
1017 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
1018 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
1019 }
1020
1026 protected function getDataAttributes( RecentChange $rc ) {
1027 $attrs = [];
1028
1029 $type = $rc->getAttribute( 'rc_source' );
1030 switch ( $type ) {
1031 case RecentChange::SRC_EDIT:
1032 case RecentChange::SRC_CATEGORIZE:
1033 case RecentChange::SRC_NEW:
1034 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1035 break;
1036 case RecentChange::SRC_LOG:
1037 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
1038 $attrs['data-mw-logaction'] =
1039 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
1040 break;
1041 }
1042
1043 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1044
1045 return $attrs;
1046 }
1047
1055 public function setChangeLinePrefixer( callable $prefixer ) {
1056 $this->changeLinePrefixer = $prefixer;
1057 }
1058}
getUser()
getAuthority()
getWatchlistExpiry(WatchedItemStoreInterface $store, PageIdentity $page, UserIdentity $user)
Get existing expiry from the database.
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.
getContext()
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)
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
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.
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)
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
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
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)
ChangesListFilterGroup[] $filterGroups
string[] $formattedComments
Comments indexed by rc_id.
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,...
MapCacheLRU $tagsCache
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.
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
Base class for language-specific code.
Definition Language.php:66
userTime( $ts, UserIdentity $user, array $options=[])
Get the formatted time for the given timestamp and formatted for the given user.
userTimeAndDate( $ts, UserIdentity $user, array $options=[])
Get the formatted date and time for the given timestamp and formatted for the given user.
Class to simplify the use of log pages.
Definition LogPage.php:45
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()
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:56
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:79
Value object representing a user's identity.
internal since 1.36
Definition User.php:93
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition User.php:2198
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition User.php:2223
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition User.php:2208
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.
Utility class for creating new RC entries.
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.