MediaWiki 1.42.1
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
470 public static function revDateLink(
471 RevisionRecord $rev,
472 Authority $performer,
473 Language $lang,
474 $title = null
475 ) {
476 $ts = $rev->getTimestamp();
477 $time = $lang->userTime( $ts, $performer->getUser() );
478 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
479 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
480 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
481 $title ?? $rev->getPageAsLinkTarget(),
482 $date,
483 [ 'class' => 'mw-changeslist-date' ],
484 [ 'oldid' => $rev->getId() ]
485 );
486 } else {
487 $link = htmlspecialchars( $date );
488 }
489 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
490 $deletedClass = Linker::getRevisionDeletedClass( $rev );
491 $link = "<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
492 }
493 return Html::element( 'span', [
494 'class' => 'mw-changeslist-time'
495 ], $time ) . $link;
496 }
497
502 public function insertDateHeader( &$s, $rc_timestamp ) {
503 # Make date header if necessary
504 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
505 if ( $date != $this->lastdate ) {
506 if ( $this->lastdate != '' ) {
507 $s .= "</ul>\n";
508 }
509 $s .= Html::element( 'h4', [], $date ) . "\n<ul class=\"special\">";
510 $this->lastdate = $date;
511 $this->rclistOpen = true;
512 }
513 }
514
521 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
522 $page = new LogPage( $logtype );
523 $logname = $page->getName()->setContext( $this->getContext() )->text();
524 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
525 'class' => $useParentheses ? '' : 'mw-changeslist-links'
526 ] );
527 if ( $useParentheses ) {
528 $s .= $this->msg( 'parentheses' )->rawParams(
529 $link
530 )->escaped();
531 } else {
532 $s .= $link;
533 }
534 }
535
541 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
542 # Diff link
543 if (
544 $rc->mAttribs['rc_type'] == RC_NEW ||
545 $rc->mAttribs['rc_type'] == RC_LOG ||
546 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
547 ) {
548 $diffLink = $this->message['diff'];
549 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
550 $diffLink = $this->message['diff'];
551 } else {
552 $query = [
553 'curid' => $rc->mAttribs['rc_cur_id'],
554 'diff' => $rc->mAttribs['rc_this_oldid'],
555 'oldid' => $rc->mAttribs['rc_last_oldid']
556 ];
557
558 $diffLink = $this->linkRenderer->makeKnownLink(
559 $rc->getTitle(),
560 new HtmlArmor( $this->message['diff'] ),
561 [ 'class' => 'mw-changeslist-diff' ],
562 $query
563 );
564 }
565 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
566 $histLink = $this->message['hist'];
567 } else {
568 $histLink = $this->linkRenderer->makeKnownLink(
569 $rc->getTitle(),
570 new HtmlArmor( $this->message['hist'] ),
571 [ 'class' => 'mw-changeslist-history' ],
572 [
573 'curid' => $rc->mAttribs['rc_cur_id'],
574 'action' => 'history'
575 ]
576 );
577 }
578
579 $s .= Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
580 Html::rawElement( 'span', [], $diffLink ) .
581 Html::rawElement( 'span', [], $histLink )
582 ) .
583 ' <span class="mw-changeslist-separator"></span> ';
584 }
585
596 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
597 $params = [];
598 if ( $rc->getTitle()->isRedirect() ) {
599 $params = [ 'redirect' => 'no' ];
600 }
601
602 $articlelink = $this->linkRenderer->makeLink(
603 $rc->getTitle(),
604 null,
605 [ 'class' => 'mw-changeslist-title' ],
606 $params
607 );
608 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
609 $class = 'history-deleted';
610 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
611 $class .= ' mw-history-suppressed';
612 }
613 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
614 }
615 # To allow for boldening pages watched by this user
616 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
617 # RTL/LTR marker
618 $articlelink .= $this->getLanguage()->getDirMark();
619
620 # TODO: Deprecate the $s argument, it seems happily unused.
621 $s = '';
622 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
623 $s, $rc, $unpatrolled, $watched );
624
625 // Watchlist expiry icon.
626 $watchlistExpiry = '';
627 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
628 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
629 }
630
631 return "{$s} {$articlelink}{$watchlistExpiry}";
632 }
633
640 public function getWatchlistExpiry( RecentChange $recentChange ): string {
641 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
642 // Guard against expired items, even though they shouldn't come here.
643 if ( $item->isExpired() ) {
644 return '';
645 }
646 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
647 // Matching widget is also created in ChangesListSpecialPage, for the legend.
648 $widget = new IconWidget( [
649 'icon' => 'clock',
650 'title' => $daysLeftText,
651 'classes' => [ 'mw-changesList-watchlistExpiry' ],
652 ] );
653 $widget->setAttributes( [
654 // Add labels for assistive technologies.
655 'role' => 'img',
656 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
657 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
658 'data-days-left' => $item->getExpiryInDays(),
659 ] );
660 // Add spaces around the widget (the page title is to one side,
661 // and a semicolon or opening-parenthesis to the other).
662 return " $widget ";
663 }
664
673 public function getTimestamp( $rc ) {
674 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
675 // because in that case the timestamp is preceded by a clock icon.
676 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
677 // that whatever comes before it is distinguishable.
678 // (Otherwise your have the text of titles pushing up against the timestamp)
679 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
680 // as the `.mw-changeslist-date` class is used in a variety
681 // of other places with a different position and the information proceeding getTimestamp can vary.
682 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
683 // contain the full date (month, year) and adds consistency with Special:Contributions
684 // and other pages.
685 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
686 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
687 '<span class="mw-changeslist-date mw-changeslist-time">' .
688 htmlspecialchars( $this->getLanguage()->userTime(
689 $rc->mAttribs['rc_timestamp'],
690 $this->getUser()
691 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
692 }
693
700 public function insertTimestamp( &$s, $rc ) {
701 $s .= $this->getTimestamp( $rc );
702 }
703
710 public function insertUserRelatedLinks( &$s, &$rc ) {
711 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
712 $deletedClass = 'history-deleted';
713 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
714 $deletedClass .= ' mw-history-suppressed';
715 }
716 $s .= ' <span class="' . $deletedClass . '">' .
717 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
718 } else {
719 $s .= $this->getLanguage()->getDirMark();
720 $s .= $this->userLinkCache->getWithSetCallback(
721 $this->userLinkCache->makeKey(
722 $rc->mAttribs['rc_user_text'],
723 $this->getUser()->getName(),
724 $this->getLanguage()->getCode()
725 ),
726 static function () use ( $rc ) {
727 return Linker::userLink(
728 $rc->mAttribs['rc_user'],
729 $rc->mAttribs['rc_user_text']
730 ) . Linker::userToolLinks(
731 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
732 false, 0, null,
733 // The text content of tools is not wrapped with parentheses or "piped".
734 // This will be handled in CSS (T205581).
735 false
736 );
737 }
738 );
739 }
740 }
741
748 public function insertLogEntry( $rc ) {
749 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
750 $formatter->setContext( $this->getContext() );
751 $formatter->setShowUserToolLinks( true );
752 $mark = $this->getLanguage()->getDirMark();
753
754 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
755 . $formatter->getActionText()
756 . " $mark"
757 . $formatter->getComment()
758 . $this->message['word-separator']
759 . $formatter->getActionLinks()
760 . Html::closeElement( 'span' );
761 }
762
768 public function insertComment( $rc ) {
769 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
770 $deletedClass = 'history-deleted';
771 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
772 $deletedClass .= ' mw-history-suppressed';
773 }
774 return ' <span class="' . $deletedClass . ' comment">' .
775 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
776 } elseif ( isset( $rc->mAttribs['rc_id'] )
777 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
778 ) {
779 return $this->formattedComments[$rc->mAttribs['rc_id']];
780 } else {
781 return $this->commentFormatter->formatBlock(
782 $rc->mAttribs['rc_comment'],
783 $rc->getTitle(),
784 // Whether section links should refer to local page (using default false)
785 false,
786 // wikid to generate links for (using default null) */
787 null,
788 // whether parentheses should be rendered as part of the message
789 false
790 );
791 }
792 }
793
799 protected function numberofWatchingusers( $count ) {
800 if ( $count <= 0 ) {
801 return '';
802 }
803
804 return $this->watchMsgCache->getWithSetCallback(
805 $this->watchMsgCache->makeKey(
806 'watching-users-msg',
807 strval( $count ),
808 $this->getUser()->getName(),
809 $this->getLanguage()->getCode()
810 ),
811 function () use ( $count ) {
812 return $this->msg( 'number-of-watching-users-for-recent-changes' )
813 ->numParams( $count )->escaped();
814 }
815 );
816 }
817
824 public static function isDeleted( $rc, $field ) {
825 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
826 }
827
837 public static function userCan( $rc, $field, Authority $performer = null ) {
838 $performer ??= RequestContext::getMain()->getAuthority();
839
840 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
841 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
842 }
843
844 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
845 }
846
852 protected function maybeWatchedLink( $link, $watched = false ) {
853 if ( $watched ) {
854 return '<strong class="mw-watched">' . $link . '</strong>';
855 } else {
856 return '<span class="mw-rc-unwatched">' . $link . '</span>';
857 }
858 }
859
866 public function insertRollback( &$s, &$rc ) {
867 $this->insertPageTools( $s, $rc );
868 }
869
878 private function insertPageTools( &$s, &$rc ) {
879 // FIXME Some page tools (e.g. thanks) might make sense for log entries.
880 if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
881 // FIXME When would either of these not exist when type is RC_EDIT? Document.
882 || !$rc->mAttribs['rc_this_oldid']
883 || !$rc->mAttribs['rc_cur_id']
884 ) {
885 return;
886 }
887
888 // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
889 $title = $rc->getTitle();
890 $revRecord = new MutableRevisionRecord( $title );
891 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
892 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
893 $user = new UserIdentityValue(
894 (int)$rc->mAttribs['rc_user'],
895 $rc->mAttribs['rc_user_text']
896 );
897 $revRecord->setUser( $user );
898
899 $tools = new PagerTools(
900 $revRecord,
901 null,
902 // only show a rollback link on the top-most revision
903 $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
904 && $rc->mAttribs['rc_type'] != RC_NEW,
905 $this->getHookRunner(),
906 $title,
907 $this->getContext(),
908 // @todo: Inject
909 MediaWikiServices::getInstance()->getLinkRenderer()
910 );
911
912 $s .= $tools->toHTML();
913 }
914
920 public function getRollback( RecentChange $rc ) {
921 $s = '';
922 $this->insertRollback( $s, $rc );
923 return $s;
924 }
925
931 public function insertTags( &$s, &$rc, &$classes ) {
932 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
933 return;
934 }
935
941 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
942 $this->tagsCache->makeKey(
943 $rc->mAttribs['ts_tags'],
944 $this->getUser()->getName(),
945 $this->getLanguage()->getCode()
946 ),
948 $rc->mAttribs['ts_tags'],
949 'changeslist',
950 $this->getContext()
951 )
952 );
953 $classes = array_merge( $classes, $newClasses );
954 $s .= ' ' . $tagSummary;
955 }
956
963 public function getTags( RecentChange $rc, array &$classes ) {
964 $s = '';
965 $this->insertTags( $s, $rc, $classes );
966 return $s;
967 }
968
969 public function insertExtra( &$s, &$rc, &$classes ) {
970 // Empty, used for subclasses to add anything special.
971 }
972
973 protected function showAsUnpatrolled( RecentChange $rc ) {
974 return self::isUnpatrolled( $rc, $this->getUser() );
975 }
976
982 public static function isUnpatrolled( $rc, User $user ) {
983 if ( $rc instanceof RecentChange ) {
984 $isPatrolled = $rc->mAttribs['rc_patrolled'];
985 $rcType = $rc->mAttribs['rc_type'];
986 $rcLogType = $rc->mAttribs['rc_log_type'];
987 } else {
988 $isPatrolled = $rc->rc_patrolled;
989 $rcType = $rc->rc_type;
990 $rcLogType = $rc->rc_log_type;
991 }
992
993 if ( $isPatrolled ) {
994 return false;
995 }
996
997 return $user->useRCPatrol() ||
998 ( $rcType == RC_NEW && $user->useNPPatrol() ) ||
999 ( $rcLogType === 'upload' && $user->useFilePatrol() );
1000 }
1001
1011 protected function isCategorizationWithoutRevision( $rcObj ) {
1012 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
1013 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
1014 }
1015
1021 protected function getDataAttributes( RecentChange $rc ) {
1022 $attrs = [];
1023
1024 $type = $rc->getAttribute( 'rc_source' );
1025 switch ( $type ) {
1026 case RecentChange::SRC_EDIT:
1027 case RecentChange::SRC_CATEGORIZE:
1028 case RecentChange::SRC_NEW:
1029 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1030 break;
1031 case RecentChange::SRC_LOG:
1032 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
1033 $attrs['data-mw-logaction'] =
1034 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
1035 break;
1036 }
1037
1038 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1039
1040 return $attrs;
1041 }
1042
1050 public function setChangeLinePrefixer( callable $prefixer ) {
1051 $this->changeLinePrefixer = $prefixer;
1052 }
1053}
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.
static revDateLink(RevisionRecord $rev, Authority $performer, Language $lang, $title=null)
Render the date and time of a revision in the current user language based on whether the user is able...
recentChangesLine(&$rc, $watched=false, $linenumber=null)
Format a line.
__construct( $context, array $filterGroups=[])
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
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.