MediaWiki master
ChangesList.php
Go to the documentation of this file.
1<?php
26use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
41use OOUI\IconWidget;
43
53 use ProtectedHookAccessorTrait;
54
55 public const CSS_CLASS_PREFIX = 'mw-changeslist-';
56
57 protected $watchlist = false;
58 protected $lastdate;
59 protected $message;
60 protected $rc_cache;
61 protected $rcCacheIndex;
62 protected $rclistOpen;
63 protected $rcMoveIndex;
64
67
69 protected $watchMsgCache;
70
74 protected $linkRenderer;
75
80
85
89 protected $filterGroups;
90
94 protected $tagsCache;
95
99 protected $userLinkCache;
100
101 private LogFormatterFactory $logFormatterFactory;
102
107 public function __construct( $context, array $filterGroups = [] ) {
108 $this->setContext( $context );
109 $this->preCacheMessages();
110 $this->watchMsgCache = new MapCacheLRU( 50 );
111 $this->filterGroups = $filterGroups;
112
113 $services = MediaWikiServices::getInstance();
114 $this->linkRenderer = $services->getLinkRenderer();
115 $this->commentFormatter = $services->getRowCommentFormatter();
116 $this->logFormatterFactory = $services->getLogFormatterFactory();
117 $this->tagsCache = new MapCacheLRU( 50 );
118 $this->userLinkCache = new MapCacheLRU( 50 );
119 }
120
129 public static function newFromContext( IContextSource $context, array $groups = [] ) {
130 $user = $context->getUser();
131 $sk = $context->getSkin();
132 $services = MediaWikiServices::getInstance();
133 $list = null;
134 if ( ( new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
135 $userOptionsLookup = $services->getUserOptionsLookup();
136 $new = $context->getRequest()->getBool(
137 'enhanced',
138 $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
139 );
140
141 return $new ?
142 new EnhancedChangesList( $context, $groups ) :
143 new OldChangesList( $context, $groups );
144 } else {
145 return $list;
146 }
147 }
148
160 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
161 throw new RuntimeException( 'recentChangesLine should be implemented' );
162 }
163
170 protected function getHighlightsContainerDiv() {
171 $highlightColorDivs = '';
172 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
173 $highlightColorDivs .= Html::rawElement(
174 'div',
175 [
176 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
177 'data-color' => $color
178 ]
179 );
180 }
181
182 return Html::rawElement(
183 'div',
184 [ 'class' => 'mw-rcfilters-ui-highlights' ],
185 $highlightColorDivs
186 );
187 }
188
193 public function setWatchlistDivs( $value = true ) {
194 $this->watchlist = $value;
195 }
196
201 public function isWatchlist() {
202 return (bool)$this->watchlist;
203 }
204
209 private function preCacheMessages() {
210 if ( !isset( $this->message ) ) {
211 $this->message = [];
212 foreach ( [
213 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
214 'semicolon-separator', 'pipe-separator', 'word-separator' ] as $msg
215 ) {
216 $this->message[$msg] = $this->msg( $msg )->escaped();
217 }
218 }
219 }
220
227 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
228 $f = '';
229 foreach (
230 $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) as $flag => $_
231 ) {
232 $f .= isset( $flags[$flag] ) && $flags[$flag]
233 ? self::flag( $flag, $this->getContext() )
234 : $nothing;
235 }
236
237 return $f;
238 }
239
248 protected function getHTMLClasses( $rc, $watched ) {
249 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
250 $logType = $rc->mAttribs['rc_log_type'];
251
252 if ( $logType ) {
253 $classes[] = self::CSS_CLASS_PREFIX . 'log';
254 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
255 } else {
256 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
257 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
258 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
259 }
260
261 // Indicate watched status on the line to allow for more
262 // comprehensive styling.
263 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
264 ? self::CSS_CLASS_PREFIX . 'line-watched'
265 : self::CSS_CLASS_PREFIX . 'line-not-watched';
266
267 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
268
269 return $classes;
270 }
271
279 protected function getHTMLClassesForFilters( $rc ) {
280 $classes = [];
281
282 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
283 $rc->mAttribs['rc_namespace'] );
284
285 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
286 $classes[] = Sanitizer::escapeClass(
287 self::CSS_CLASS_PREFIX .
288 'ns-' .
289 ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
290 );
291
292 foreach ( $this->filterGroups as $filterGroup ) {
293 foreach ( $filterGroup->getFilters() as $filter ) {
294 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
295 }
296 }
297
298 return $classes;
299 }
300
311 public static function flag( $flag, IContextSource $context = null ) {
312 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
313 static $flagInfos = null;
314
315 if ( $flagInfos === null ) {
316 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
317 ->get( MainConfigNames::RecentChangesFlags );
318 $flagInfos = [];
319 foreach ( $recentChangesFlags as $key => $value ) {
320 $flagInfos[$key]['letter'] = $value['letter'];
321 $flagInfos[$key]['title'] = $value['title'];
322 // Allow customized class name, fall back to flag name
323 $flagInfos[$key]['class'] = $value['class'] ?? $key;
324 }
325 }
326
327 $context = $context ?: RequestContext::getMain();
328
329 // Inconsistent naming, kept for b/c
330 if ( isset( $map[$flag] ) ) {
331 $flag = $map[$flag];
332 }
333
334 $info = $flagInfos[$flag];
335 return Html::element( 'abbr', [
336 'class' => $info['class'],
337 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
338 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
339 }
340
345 public function beginRecentChangesList() {
346 $this->rc_cache = [];
347 $this->rcMoveIndex = 0;
348 $this->rcCacheIndex = 0;
349 $this->lastdate = '';
350 $this->rclistOpen = false;
351 $this->getOutput()->addModuleStyles( [
352 'mediawiki.interface.helpers.styles',
353 'mediawiki.special.changeslist'
354 ] );
355
356 return '<div class="mw-changeslist">';
357 }
358
362 public function initChangesListRows( $rows ) {
363 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
364 $this->formattedComments = $this->commentFormatter->createBatch()
365 ->comments(
366 $this->commentFormatter->rows( $rows )
367 ->commentKey( 'rc_comment' )
368 ->namespaceField( 'rc_namespace' )
369 ->titleField( 'rc_title' )
370 ->indexField( 'rc_id' )
371 )
372 ->useBlock()
373 ->execute();
374 }
375
386 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
387 if ( !$context ) {
388 $context = RequestContext::getMain();
389 }
390
391 $new = (int)$new;
392 $old = (int)$old;
393 $szdiff = $new - $old;
394
395 $lang = $context->getLanguage();
396 $config = $context->getConfig();
397 $code = $lang->getCode();
398 static $fastCharDiff = [];
399 if ( !isset( $fastCharDiff[$code] ) ) {
400 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
401 || $context->msg( 'rc-change-size' )->plain() === '$1';
402 }
403
404 $formattedSize = $lang->formatNum( $szdiff );
405
406 if ( !$fastCharDiff[$code] ) {
407 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
408 }
409
410 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
411 $tag = 'strong';
412 } else {
413 $tag = 'span';
414 }
415
416 if ( $szdiff === 0 ) {
417 $formattedSizeClass = 'mw-plusminus-null';
418 } elseif ( $szdiff > 0 ) {
419 $formattedSize = '+' . $formattedSize;
420 $formattedSizeClass = 'mw-plusminus-pos';
421 } else {
422 $formattedSizeClass = 'mw-plusminus-neg';
423 }
424 $formattedSizeClass .= ' mw-diff-bytes';
425
426 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
427
428 return Html::element( $tag,
429 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
430 $formattedSize ) . $lang->getDirMark();
431 }
432
440 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
441 $oldlen = $old->mAttribs['rc_old_len'];
442
443 if ( $new ) {
444 $newlen = $new->mAttribs['rc_new_len'];
445 } else {
446 $newlen = $old->mAttribs['rc_new_len'];
447 }
448
449 if ( $oldlen === null || $newlen === null ) {
450 return '';
451 }
452
453 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
454 }
455
460 public function endRecentChangesList() {
461 $out = $this->rclistOpen ? "</ul>\n" : '';
462 $out .= '</div>';
463
464 return $out;
465 }
466
480 public static function revDateLink(
481 RevisionRecord $rev,
482 Authority $performer,
483 Language $lang,
484 $title = null,
485 $className = ''
486 ) {
487 $ts = $rev->getTimestamp();
488 $time = $lang->userTime( $ts, $performer->getUser() );
489 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
490 $class = trim( 'mw-changeslist-date ' . $className );
491 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
492 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
493 $title ?? $rev->getPageAsLinkTarget(),
494 $date,
495 [ 'class' => $class ],
496 [ 'oldid' => $rev->getId() ]
497 );
498 } else {
499 $link = htmlspecialchars( $date );
500 }
501 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
502 $class = Linker::getRevisionDeletedClass( $rev ) . " $class";
503 $link = "<span class=\"$class\">$link</span>";
504 }
505 return Html::element( 'span', [
506 'class' => 'mw-changeslist-time'
507 ], $time ) . $link;
508 }
509
514 public function insertDateHeader( &$s, $rc_timestamp ) {
515 # Make date header if necessary
516 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
517 if ( $date != $this->lastdate ) {
518 if ( $this->lastdate != '' ) {
519 $s .= "</ul>\n";
520 }
521 $s .= Html::element( 'h4', [], $date ) . "\n<ul class=\"special\">";
522 $this->lastdate = $date;
523 $this->rclistOpen = true;
524 }
525 }
526
533 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
534 $page = new LogPage( $logtype );
535 $logname = $page->getName()->setContext( $this->getContext() )->text();
536 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
537 'class' => $useParentheses ? '' : 'mw-changeslist-links'
538 ] );
539 if ( $useParentheses ) {
540 $s .= $this->msg( 'parentheses' )->rawParams(
541 $link
542 )->escaped();
543 } else {
544 $s .= $link;
545 }
546 }
547
553 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
554 # Diff link
555 if (
556 $rc->mAttribs['rc_type'] == RC_NEW ||
557 $rc->mAttribs['rc_type'] == RC_LOG ||
558 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
559 ) {
560 $diffLink = $this->message['diff'];
561 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
562 $diffLink = $this->message['diff'];
563 } else {
564 $query = [
565 'curid' => $rc->mAttribs['rc_cur_id'],
566 'diff' => $rc->mAttribs['rc_this_oldid'],
567 'oldid' => $rc->mAttribs['rc_last_oldid']
568 ];
569
570 $diffLink = $this->linkRenderer->makeKnownLink(
571 $rc->getTitle(),
572 new HtmlArmor( $this->message['diff'] ),
573 [ 'class' => 'mw-changeslist-diff' ],
574 $query
575 );
576 }
577 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
578 $histLink = $this->message['hist'];
579 } else {
580 $histLink = $this->linkRenderer->makeKnownLink(
581 $rc->getTitle(),
582 new HtmlArmor( $this->message['hist'] ),
583 [ 'class' => 'mw-changeslist-history' ],
584 [
585 'curid' => $rc->mAttribs['rc_cur_id'],
586 'action' => 'history'
587 ]
588 );
589 }
590
591 $s .= Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
592 Html::rawElement( 'span', [], $diffLink ) .
593 Html::rawElement( 'span', [], $histLink )
594 ) .
595 ' <span class="mw-changeslist-separator"></span> ';
596 }
597
608 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
609 $params = [];
610 if ( $rc->getTitle()->isRedirect() ) {
611 $params = [ 'redirect' => 'no' ];
612 }
613
614 $articlelink = $this->linkRenderer->makeLink(
615 $rc->getTitle(),
616 null,
617 [ 'class' => 'mw-changeslist-title' ],
618 $params
619 );
620 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
621 $class = 'history-deleted';
622 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
623 $class .= ' mw-history-suppressed';
624 }
625 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
626 }
627 # To allow for boldening pages watched by this user
628 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
629 # RTL/LTR marker
630 $articlelink .= $this->getLanguage()->getDirMark();
631
632 # TODO: Deprecate the $s argument, it seems happily unused.
633 $s = '';
634 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
635 $s, $rc, $unpatrolled, $watched );
636
637 // Watchlist expiry icon.
638 $watchlistExpiry = '';
639 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
640 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
641 }
642
643 return "{$s} {$articlelink}{$watchlistExpiry}";
644 }
645
652 public function getWatchlistExpiry( RecentChange $recentChange ): string {
653 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
654 // Guard against expired items, even though they shouldn't come here.
655 if ( $item->isExpired() ) {
656 return '';
657 }
658 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
659 // Matching widget is also created in ChangesListSpecialPage, for the legend.
660 $widget = new IconWidget( [
661 'icon' => 'clock',
662 'title' => $daysLeftText,
663 'classes' => [ 'mw-changesList-watchlistExpiry' ],
664 ] );
665 $widget->setAttributes( [
666 // Add labels for assistive technologies.
667 'role' => 'img',
668 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
669 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
670 'data-days-left' => $item->getExpiryInDays(),
671 ] );
672 // Add spaces around the widget (the page title is to one side,
673 // and a semicolon or opening-parenthesis to the other).
674 return " $widget ";
675 }
676
685 public function getTimestamp( $rc ) {
686 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
687 // because in that case the timestamp is preceded by a clock icon.
688 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
689 // that whatever comes before it is distinguishable.
690 // (Otherwise your have the text of titles pushing up against the timestamp)
691 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
692 // as the `.mw-changeslist-date` class is used in a variety
693 // of other places with a different position and the information proceeding getTimestamp can vary.
694 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
695 // contain the full date (month, year) and adds consistency with Special:Contributions
696 // and other pages.
697 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
698 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
699 '<span class="mw-changeslist-date mw-changeslist-time">' .
700 htmlspecialchars( $this->getLanguage()->userTime(
701 $rc->mAttribs['rc_timestamp'],
702 $this->getUser()
703 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
704 }
705
712 public function insertTimestamp( &$s, $rc ) {
713 $s .= $this->getTimestamp( $rc );
714 }
715
722 public function insertUserRelatedLinks( &$s, &$rc ) {
723 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
724 $deletedClass = 'history-deleted';
725 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
726 $deletedClass .= ' mw-history-suppressed';
727 }
728 $s .= ' <span class="' . $deletedClass . '">' .
729 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
730 } else {
731 $s .= $this->getLanguage()->getDirMark();
732 $s .= $this->userLinkCache->getWithSetCallback(
733 $this->userLinkCache->makeKey(
734 $rc->mAttribs['rc_user_text'],
735 $this->getUser()->getName(),
736 $this->getLanguage()->getCode()
737 ),
738 static function () use ( $rc ) {
739 return Linker::userLink(
740 $rc->mAttribs['rc_user'],
741 $rc->mAttribs['rc_user_text']
742 ) . Linker::userToolLinks(
743 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
744 false, 0, null,
745 // The text content of tools is not wrapped with parentheses or "piped".
746 // This will be handled in CSS (T205581).
747 false
748 );
749 }
750 );
751 }
752 }
753
760 public function insertLogEntry( $rc ) {
761 $formatter = $this->logFormatterFactory->newFromRow( $rc->mAttribs );
762 $formatter->setContext( $this->getContext() );
763 $formatter->setShowUserToolLinks( true );
764 $mark = $this->getLanguage()->getDirMark();
765
766 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
767 . $formatter->getActionText()
768 . " $mark"
769 . $formatter->getComment()
770 . $this->message['word-separator']
771 . $formatter->getActionLinks()
772 . Html::closeElement( 'span' );
773 }
774
780 public function insertComment( $rc ) {
781 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
782 $deletedClass = 'history-deleted';
783 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
784 $deletedClass .= ' mw-history-suppressed';
785 }
786 return ' <span class="' . $deletedClass . ' comment">' .
787 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
788 } elseif ( isset( $rc->mAttribs['rc_id'] )
789 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
790 ) {
791 return $this->formattedComments[$rc->mAttribs['rc_id']];
792 } else {
793 return $this->commentFormatter->formatBlock(
794 $rc->mAttribs['rc_comment'],
795 $rc->getTitle(),
796 // Whether section links should refer to local page (using default false)
797 false,
798 // wikid to generate links for (using default null) */
799 null,
800 // whether parentheses should be rendered as part of the message
801 false
802 );
803 }
804 }
805
811 protected function numberofWatchingusers( $count ) {
812 if ( $count <= 0 ) {
813 return '';
814 }
815
816 return $this->watchMsgCache->getWithSetCallback(
817 $this->watchMsgCache->makeKey(
818 'watching-users-msg',
819 strval( $count ),
820 $this->getUser()->getName(),
821 $this->getLanguage()->getCode()
822 ),
823 function () use ( $count ) {
824 return $this->msg( 'number-of-watching-users-for-recent-changes' )
825 ->numParams( $count )->escaped();
826 }
827 );
828 }
829
836 public static function isDeleted( $rc, $field ) {
837 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
838 }
839
849 public static function userCan( $rc, $field, Authority $performer = null ) {
850 $performer ??= RequestContext::getMain()->getAuthority();
851
852 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
853 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
854 }
855
856 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
857 }
858
864 protected function maybeWatchedLink( $link, $watched = false ) {
865 if ( $watched ) {
866 return '<strong class="mw-watched">' . $link . '</strong>';
867 } else {
868 return '<span class="mw-rc-unwatched">' . $link . '</span>';
869 }
870 }
871
878 public function insertRollback( &$s, &$rc ) {
879 $this->insertPageTools( $s, $rc );
880 }
881
890 private function insertPageTools( &$s, &$rc ) {
891 // FIXME Some page tools (e.g. thanks) might make sense for log entries.
892 if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
893 // FIXME When would either of these not exist when type is RC_EDIT? Document.
894 || !$rc->mAttribs['rc_this_oldid']
895 || !$rc->mAttribs['rc_cur_id']
896 ) {
897 return;
898 }
899
900 // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
901 $title = $rc->getTitle();
902 $revRecord = new MutableRevisionRecord( $title );
903 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
904 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
905 $user = new UserIdentityValue(
906 (int)$rc->mAttribs['rc_user'],
907 $rc->mAttribs['rc_user_text']
908 );
909 $revRecord->setUser( $user );
910
911 $tools = new PagerTools(
912 $revRecord,
913 null,
914 // only show a rollback link on the top-most revision
915 $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
916 && $rc->mAttribs['rc_type'] != RC_NEW,
917 $this->getHookRunner(),
918 $title,
919 $this->getContext(),
920 // @todo: Inject
921 MediaWikiServices::getInstance()->getLinkRenderer()
922 );
923
924 $s .= $tools->toHTML();
925 }
926
932 public function getRollback( RecentChange $rc ) {
933 $s = '';
934 $this->insertRollback( $s, $rc );
935 return $s;
936 }
937
943 public function insertTags( &$s, &$rc, &$classes ) {
944 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
945 return;
946 }
947
953 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
954 $this->tagsCache->makeKey(
955 $rc->mAttribs['ts_tags'],
956 $this->getUser()->getName(),
957 $this->getLanguage()->getCode()
958 ),
960 $rc->mAttribs['ts_tags'],
961 'changeslist',
962 $this->getContext()
963 )
964 );
965 $classes = array_merge( $classes, $newClasses );
966 $s .= ' ' . $tagSummary;
967 }
968
975 public function getTags( RecentChange $rc, array &$classes ) {
976 $s = '';
977 $this->insertTags( $s, $rc, $classes );
978 return $s;
979 }
980
981 public function insertExtra( &$s, &$rc, &$classes ) {
982 // Empty, used for subclasses to add anything special.
983 }
984
985 protected function showAsUnpatrolled( RecentChange $rc ) {
986 return self::isUnpatrolled( $rc, $this->getUser() );
987 }
988
994 public static function isUnpatrolled( $rc, User $user ) {
995 if ( $rc instanceof RecentChange ) {
996 $isPatrolled = $rc->mAttribs['rc_patrolled'];
997 $rcType = $rc->mAttribs['rc_type'];
998 $rcLogType = $rc->mAttribs['rc_log_type'];
999 } else {
1000 $isPatrolled = $rc->rc_patrolled;
1001 $rcType = $rc->rc_type;
1002 $rcLogType = $rc->rc_log_type;
1003 }
1004
1005 if ( $isPatrolled ) {
1006 return false;
1007 }
1008
1009 return $user->useRCPatrol() ||
1010 ( $rcType == RC_NEW && $user->useNPPatrol() ) ||
1011 ( $rcLogType === 'upload' && $user->useFilePatrol() );
1012 }
1013
1023 protected function isCategorizationWithoutRevision( $rcObj ) {
1024 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
1025 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
1026 }
1027
1033 protected function getDataAttributes( RecentChange $rc ) {
1034 $attrs = [];
1035
1036 $type = $rc->getAttribute( 'rc_source' );
1037 switch ( $type ) {
1038 case RecentChange::SRC_EDIT:
1039 case RecentChange::SRC_CATEGORIZE:
1040 case RecentChange::SRC_NEW:
1041 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1042 break;
1043 case RecentChange::SRC_LOG:
1044 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
1045 $attrs['data-mw-logaction'] =
1046 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
1047 break;
1048 }
1049
1050 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1051
1052 return $attrs;
1053 }
1054
1062 public function setChangeLinePrefixer( callable $prefixer ) {
1063 $this->changeLinePrefixer = $prefixer;
1064 }
1065}
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)
Base class for lists of recent changes shown on special pages.
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.
Generate a list of changes using an Enhanced system (uses javascript).
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
Class to simplify the use of log pages.
Definition LogPage.php: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: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: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.
Generate a list of changes using the good old system (no javascript).
Utility class for creating and reading rows in the recentchanges table.
getAttribute( $name)
Get an attribute value.
Interface for objects which can provide a MediaWiki context on request.
This interface represents the authority associated with the current execution context,...
Definition Authority.php:37
getUser()
Returns the performer of the actions associated with this authority.
Result wrapper for grabbing data queried from an IDatabase object.