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