MediaWiki REL1_41
ChangesList.php
Go to the documentation of this file.
1<?php
27use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
41use OOUI\IconWidget;
43
45 use ProtectedHookAccessorTrait;
46
47 public const CSS_CLASS_PREFIX = 'mw-changeslist-';
48
49 protected $watchlist = false;
50 protected $lastdate;
51 protected $message;
52 protected $rc_cache;
53 protected $rcCacheIndex;
54 protected $rclistOpen;
55 protected $rcMoveIndex;
56
59
61 protected $watchMsgCache;
62
66 protected $linkRenderer;
67
72
77
81 protected $filterGroups;
82
86 protected $tagsCache;
87
91 protected $userLinkCache;
92
97 public function __construct( $context, array $filterGroups = [] ) {
98 $this->setContext( $context );
99 $this->preCacheMessages();
100 $this->watchMsgCache = new MapCacheLRU( 50 );
101 $this->filterGroups = $filterGroups;
102
103 $services = MediaWikiServices::getInstance();
104 $this->linkRenderer = $services->getLinkRenderer();
105 $this->commentFormatter = $services->getRowCommentFormatter();
106 $this->tagsCache = new MapCacheLRU( 50 );
107 $this->userLinkCache = new MapCacheLRU( 50 );
108 }
109
118 public static function newFromContext( IContextSource $context, array $groups = [] ) {
119 $user = $context->getUser();
120 $sk = $context->getSkin();
121 $services = MediaWikiServices::getInstance();
122 $list = null;
123 if ( ( new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
124 $userOptionsLookup = $services->getUserOptionsLookup();
125 $new = $context->getRequest()->getBool(
126 'enhanced',
127 $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
128 );
129
130 return $new ?
131 new EnhancedChangesList( $context, $groups ) :
132 new OldChangesList( $context, $groups );
133 } else {
134 return $list;
135 }
136 }
137
149 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
150 throw new RuntimeException( 'recentChangesLine should be implemented' );
151 }
152
159 protected function getHighlightsContainerDiv() {
160 $highlightColorDivs = '';
161 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
162 $highlightColorDivs .= Html::rawElement(
163 'div',
164 [
165 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
166 'data-color' => $color
167 ]
168 );
169 }
170
171 return Html::rawElement(
172 'div',
173 [ 'class' => 'mw-rcfilters-ui-highlights' ],
174 $highlightColorDivs
175 );
176 }
177
182 public function setWatchlistDivs( $value = true ) {
183 $this->watchlist = $value;
184 }
185
190 public function isWatchlist() {
191 return (bool)$this->watchlist;
192 }
193
198 private function preCacheMessages() {
199 if ( !isset( $this->message ) ) {
200 $this->message = [];
201 foreach ( [
202 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
203 'semicolon-separator', 'pipe-separator', 'word-separator' ] as $msg
204 ) {
205 $this->message[$msg] = $this->msg( $msg )->escaped();
206 }
207 }
208 }
209
216 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
217 $f = '';
218 foreach (
219 $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) as $flag => $_
220 ) {
221 $f .= isset( $flags[$flag] ) && $flags[$flag]
222 ? self::flag( $flag, $this->getContext() )
223 : $nothing;
224 }
225
226 return $f;
227 }
228
237 protected function getHTMLClasses( $rc, $watched ) {
238 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
239 $logType = $rc->mAttribs['rc_log_type'];
240
241 if ( $logType ) {
242 $classes[] = self::CSS_CLASS_PREFIX . 'log';
243 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
244 } else {
245 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
246 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
247 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
248 }
249
250 // Indicate watched status on the line to allow for more
251 // comprehensive styling.
252 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
253 ? self::CSS_CLASS_PREFIX . 'line-watched'
254 : self::CSS_CLASS_PREFIX . 'line-not-watched';
255
256 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
257
258 return $classes;
259 }
260
268 protected function getHTMLClassesForFilters( $rc ) {
269 $classes = [];
270
271 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
272 $rc->mAttribs['rc_namespace'] );
273
274 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
275 $classes[] = Sanitizer::escapeClass(
276 self::CSS_CLASS_PREFIX .
277 'ns-' .
278 ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
279 );
280
281 foreach ( $this->filterGroups as $filterGroup ) {
282 foreach ( $filterGroup->getFilters() as $filter ) {
283 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
284 }
285 }
286
287 return $classes;
288 }
289
300 public static function flag( $flag, IContextSource $context = null ) {
301 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
302 static $flagInfos = null;
303
304 if ( $flagInfos === null ) {
305 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
306 ->get( MainConfigNames::RecentChangesFlags );
307 $flagInfos = [];
308 foreach ( $recentChangesFlags as $key => $value ) {
309 $flagInfos[$key]['letter'] = $value['letter'];
310 $flagInfos[$key]['title'] = $value['title'];
311 // Allow customized class name, fall back to flag name
312 $flagInfos[$key]['class'] = $value['class'] ?? $key;
313 }
314 }
315
316 $context = $context ?: RequestContext::getMain();
317
318 // Inconsistent naming, kept for b/c
319 if ( isset( $map[$flag] ) ) {
320 $flag = $map[$flag];
321 }
322
323 $info = $flagInfos[$flag];
324 return Html::element( 'abbr', [
325 'class' => $info['class'],
326 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
327 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
328 }
329
334 public function beginRecentChangesList() {
335 $this->rc_cache = [];
336 $this->rcMoveIndex = 0;
337 $this->rcCacheIndex = 0;
338 $this->lastdate = '';
339 $this->rclistOpen = false;
340 $this->getOutput()->addModuleStyles( [
341 'mediawiki.interface.helpers.styles',
342 'mediawiki.special.changeslist'
343 ] );
344
345 return '<div class="mw-changeslist">';
346 }
347
351 public function initChangesListRows( $rows ) {
352 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
353 $this->formattedComments = $this->commentFormatter->createBatch()
354 ->comments(
355 $this->commentFormatter->rows( $rows )
356 ->commentKey( 'rc_comment' )
357 ->namespaceField( 'rc_namespace' )
358 ->titleField( 'rc_title' )
359 ->indexField( 'rc_id' )
360 )
361 ->useBlock()
362 ->execute();
363 }
364
375 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
376 if ( !$context ) {
377 $context = RequestContext::getMain();
378 }
379
380 $new = (int)$new;
381 $old = (int)$old;
382 $szdiff = $new - $old;
383
384 $lang = $context->getLanguage();
385 $config = $context->getConfig();
386 $code = $lang->getCode();
387 static $fastCharDiff = [];
388 if ( !isset( $fastCharDiff[$code] ) ) {
389 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
390 || $context->msg( 'rc-change-size' )->plain() === '$1';
391 }
392
393 $formattedSize = $lang->formatNum( $szdiff );
394
395 if ( !$fastCharDiff[$code] ) {
396 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
397 }
398
399 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
400 $tag = 'strong';
401 } else {
402 $tag = 'span';
403 }
404
405 if ( $szdiff === 0 ) {
406 $formattedSizeClass = 'mw-plusminus-null';
407 } elseif ( $szdiff > 0 ) {
408 $formattedSize = '+' . $formattedSize;
409 $formattedSizeClass = 'mw-plusminus-pos';
410 } else {
411 $formattedSizeClass = 'mw-plusminus-neg';
412 }
413 $formattedSizeClass .= ' mw-diff-bytes';
414
415 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
416
417 return Html::element( $tag,
418 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
419 $formattedSize ) . $lang->getDirMark();
420 }
421
429 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
430 $oldlen = $old->mAttribs['rc_old_len'];
431
432 if ( $new ) {
433 $newlen = $new->mAttribs['rc_new_len'];
434 } else {
435 $newlen = $old->mAttribs['rc_new_len'];
436 }
437
438 if ( $oldlen === null || $newlen === null ) {
439 return '';
440 }
441
442 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
443 }
444
449 public function endRecentChangesList() {
450 $out = $this->rclistOpen ? "</ul>\n" : '';
451 $out .= '</div>';
452
453 return $out;
454 }
455
467 public static function revDateLink(
468 RevisionRecord $rev,
469 Authority $performer,
470 Language $lang,
471 $title = null
472 ) {
473 $ts = $rev->getTimestamp();
474 $time = $lang->userTime( $ts, $performer->getUser() );
475 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
476 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
477 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
478 $title ?? $rev->getPageAsLinkTarget(),
479 $date,
480 [ 'class' => 'mw-changeslist-date' ],
481 [ 'oldid' => $rev->getId() ]
482 );
483 } else {
484 $link = htmlspecialchars( $date );
485 }
486 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
487 $deletedClass = Linker::getRevisionDeletedClass( $rev );
488 $link = "<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
489 }
490 return Html::element( 'span', [
491 'class' => 'mw-changeslist-time'
492 ], $time ) . $link;
493 }
494
499 public function insertDateHeader( &$s, $rc_timestamp ) {
500 # Make date header if necessary
501 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
502 if ( $date != $this->lastdate ) {
503 if ( $this->lastdate != '' ) {
504 $s .= "</ul>\n";
505 }
506 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
507 $this->lastdate = $date;
508 $this->rclistOpen = true;
509 }
510 }
511
518 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
519 $page = new LogPage( $logtype );
520 $logname = $page->getName()->setContext( $this->getContext() )->text();
521 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
522 'class' => $useParentheses ? '' : 'mw-changeslist-links'
523 ] );
524 if ( $useParentheses ) {
525 $s .= $this->msg( 'parentheses' )->rawParams(
526 $link
527 )->escaped();
528 } else {
529 $s .= $link;
530 }
531 }
532
538 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
539 # Diff link
540 if (
541 $rc->mAttribs['rc_type'] == RC_NEW ||
542 $rc->mAttribs['rc_type'] == RC_LOG ||
543 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
544 ) {
545 $diffLink = $this->message['diff'];
546 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
547 $diffLink = $this->message['diff'];
548 } else {
549 $query = [
550 'curid' => $rc->mAttribs['rc_cur_id'],
551 'diff' => $rc->mAttribs['rc_this_oldid'],
552 'oldid' => $rc->mAttribs['rc_last_oldid']
553 ];
554
555 $diffLink = $this->linkRenderer->makeKnownLink(
556 $rc->getTitle(),
557 new HtmlArmor( $this->message['diff'] ),
558 [ 'class' => 'mw-changeslist-diff' ],
559 $query
560 );
561 }
562 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
563 $histLink = $this->message['hist'];
564 } else {
565 $histLink = $this->linkRenderer->makeKnownLink(
566 $rc->getTitle(),
567 new HtmlArmor( $this->message['hist'] ),
568 [ 'class' => 'mw-changeslist-history' ],
569 [
570 'curid' => $rc->mAttribs['rc_cur_id'],
571 'action' => 'history'
572 ]
573 );
574 }
575
576 $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
577 Html::rawElement( 'span', [], $diffLink ) .
578 Html::rawElement( 'span', [], $histLink )
579 ) .
580 ' <span class="mw-changeslist-separator"></span> ';
581 }
582
593 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
594 $params = [];
595 if ( $rc->getTitle()->isRedirect() ) {
596 $params = [ 'redirect' => 'no' ];
597 }
598
599 $articlelink = $this->linkRenderer->makeLink(
600 $rc->getTitle(),
601 null,
602 [ 'class' => 'mw-changeslist-title' ],
603 $params
604 );
605 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
606 $class = 'history-deleted';
607 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
608 $class .= ' mw-history-suppressed';
609 }
610 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
611 }
612 # To allow for boldening pages watched by this user
613 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
614 # RTL/LTR marker
615 $articlelink .= $this->getLanguage()->getDirMark();
616
617 # TODO: Deprecate the $s argument, it seems happily unused.
618 $s = '';
619 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
620 $s, $rc, $unpatrolled, $watched );
621
622 // Watchlist expiry icon.
623 $watchlistExpiry = '';
624 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
625 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
626 }
627
628 return "{$s} {$articlelink}{$watchlistExpiry}";
629 }
630
637 public function getWatchlistExpiry( RecentChange $recentChange ): string {
638 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
639 // Guard against expired items, even though they shouldn't come here.
640 if ( $item->isExpired() ) {
641 return '';
642 }
643 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
644 // Matching widget is also created in ChangesListSpecialPage, for the legend.
645 $widget = new IconWidget( [
646 'icon' => 'clock',
647 'title' => $daysLeftText,
648 'classes' => [ 'mw-changesList-watchlistExpiry' ],
649 ] );
650 $widget->setAttributes( [
651 // Add labels for assistive technologies.
652 'role' => 'img',
653 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
654 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
655 'data-days-left' => $item->getExpiryInDays(),
656 ] );
657 // Add spaces around the widget (the page title is to one side,
658 // and a semicolon or opening-parenthesis to the other).
659 return " $widget ";
660 }
661
670 public function getTimestamp( $rc ) {
671 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
672 // because in that case the timestamp is preceded by a clock icon.
673 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
674 // that whatever comes before it is distinguishable.
675 // (Otherwise your have the text of titles pushing up against the timestamp)
676 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
677 // as the `.mw-changeslist-date` class is used in a variety
678 // of other places with a different position and the information proceeding getTimestamp can vary.
679 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
680 // contain the full date (month, year) and adds consistency with Special:Contributions
681 // and other pages.
682 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
683 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
684 '<span class="mw-changeslist-date mw-changeslist-time">' .
685 htmlspecialchars( $this->getLanguage()->userTime(
686 $rc->mAttribs['rc_timestamp'],
687 $this->getUser()
688 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
689 }
690
697 public function insertTimestamp( &$s, $rc ) {
698 $s .= $this->getTimestamp( $rc );
699 }
700
707 public function insertUserRelatedLinks( &$s, &$rc ) {
708 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
709 $deletedClass = 'history-deleted';
710 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
711 $deletedClass .= ' mw-history-suppressed';
712 }
713 $s .= ' <span class="' . $deletedClass . '">' .
714 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
715 } else {
716 $s .= $this->getLanguage()->getDirMark();
717 $s .= $this->userLinkCache->getWithSetCallback(
718 $this->userLinkCache->makeKey(
719 $rc->mAttribs['rc_user_text'],
720 $this->getUser()->getName(),
721 $this->getLanguage()->getCode()
722 ),
723 static function () use ( $rc ) {
724 return Linker::userLink(
725 $rc->mAttribs['rc_user'],
726 $rc->mAttribs['rc_user_text']
727 ) . Linker::userToolLinks(
728 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
729 false, 0, null,
730 // The text content of tools is not wrapped with parentheses or "piped".
731 // This will be handled in CSS (T205581).
732 false
733 );
734 }
735 );
736 }
737 }
738
745 public function insertLogEntry( $rc ) {
746 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
747 $formatter->setContext( $this->getContext() );
748 $formatter->setShowUserToolLinks( true );
749 $mark = $this->getLanguage()->getDirMark();
750
751 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
752 . $formatter->getActionText()
753 . " $mark"
754 . $formatter->getComment()
755 . $this->message['word-separator']
756 . $formatter->getActionLinks()
757 . Html::closeElement( 'span' );
758 }
759
765 public function insertComment( $rc ) {
766 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
767 $deletedClass = 'history-deleted';
768 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
769 $deletedClass .= ' mw-history-suppressed';
770 }
771 return ' <span class="' . $deletedClass . ' comment">' .
772 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
773 } elseif ( isset( $rc->mAttribs['rc_id'] )
774 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
775 ) {
776 return $this->formattedComments[$rc->mAttribs['rc_id']];
777 } else {
778 return $this->commentFormatter->formatBlock(
779 $rc->mAttribs['rc_comment'],
780 $rc->getTitle(),
781 // Whether section links should refer to local page (using default false)
782 false,
783 // wikid to generate links for (using default null) */
784 null,
785 // whether parentheses should be rendered as part of the message
786 false
787 );
788 }
789 }
790
796 protected function numberofWatchingusers( $count ) {
797 if ( $count <= 0 ) {
798 return '';
799 }
800
801 return $this->watchMsgCache->getWithSetCallback(
802 $this->watchMsgCache->makeKey(
803 'watching-users-msg',
804 strval( $count ),
805 $this->getUser()->getName(),
806 $this->getLanguage()->getCode()
807 ),
808 function () use ( $count ) {
809 return $this->msg( 'number-of-watching-users-for-recent-changes' )
810 ->numParams( $count )->escaped();
811 }
812 );
813 }
814
821 public static function isDeleted( $rc, $field ) {
822 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
823 }
824
834 public static function userCan( $rc, $field, Authority $performer = null ) {
835 $performer ??= RequestContext::getMain()->getAuthority();
836
837 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
838 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
839 }
840
841 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
842 }
843
849 protected function maybeWatchedLink( $link, $watched = false ) {
850 if ( $watched ) {
851 return '<strong class="mw-watched">' . $link . '</strong>';
852 } else {
853 return '<span class="mw-rc-unwatched">' . $link . '</span>';
854 }
855 }
856
863 public function insertRollback( &$s, &$rc ) {
864 $this->insertPageTools( $s, $rc );
865 }
866
875 private function insertPageTools( &$s, &$rc ) {
876 // FIXME Some page tools (e.g. thanks) might make sense for log entries.
877 if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
878 // FIXME When would either of these not exist when type is RC_EDIT? Document.
879 || !$rc->mAttribs['rc_this_oldid']
880 || !$rc->mAttribs['rc_cur_id']
881 ) {
882 return;
883 }
884
885 // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
886 $title = $rc->getTitle();
887 $revRecord = new MutableRevisionRecord( $title );
888 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
889 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
890 $user = new UserIdentityValue(
891 (int)$rc->mAttribs['rc_user'],
892 $rc->mAttribs['rc_user_text']
893 );
894 $revRecord->setUser( $user );
895
896 $tools = new PagerTools(
897 $revRecord,
898 null,
899 // only show a rollback link on the top-most revision
900 $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
901 && $rc->mAttribs['rc_type'] != RC_NEW,
902 $this->getHookRunner(),
903 $title,
904 $this->getContext(),
905 // @todo: Inject
906 MediaWikiServices::getInstance()->getLinkRenderer()
907 );
908
909 $s .= $tools->toHTML();
910 }
911
917 public function getRollback( RecentChange $rc ) {
918 $s = '';
919 $this->insertRollback( $s, $rc );
920 return $s;
921 }
922
928 public function insertTags( &$s, &$rc, &$classes ) {
929 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
930 return;
931 }
932
938 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
939 $this->tagsCache->makeKey(
940 $rc->mAttribs['ts_tags'],
941 $this->getUser()->getName(),
942 $this->getLanguage()->getCode()
943 ),
945 $rc->mAttribs['ts_tags'],
946 'changeslist',
947 $this->getContext()
948 )
949 );
950 $classes = array_merge( $classes, $newClasses );
951 $s .= ' ' . $tagSummary;
952 }
953
960 public function getTags( RecentChange $rc, array &$classes ) {
961 $s = '';
962 $this->insertTags( $s, $rc, $classes );
963 return $s;
964 }
965
966 public function insertExtra( &$s, &$rc, &$classes ) {
967 // Empty, used for subclasses to add anything special.
968 }
969
970 protected function showAsUnpatrolled( RecentChange $rc ) {
971 return self::isUnpatrolled( $rc, $this->getUser() );
972 }
973
979 public static function isUnpatrolled( $rc, User $user ) {
980 if ( $rc instanceof RecentChange ) {
981 $isPatrolled = $rc->mAttribs['rc_patrolled'];
982 $rcType = $rc->mAttribs['rc_type'];
983 $rcLogType = $rc->mAttribs['rc_log_type'];
984 } else {
985 $isPatrolled = $rc->rc_patrolled;
986 $rcType = $rc->rc_type;
987 $rcLogType = $rc->rc_log_type;
988 }
989
990 if ( $isPatrolled ) {
991 return false;
992 }
993
994 return $user->useRCPatrol() ||
995 ( $rcType == RC_NEW && $user->useNPPatrol() ) ||
996 ( $rcLogType === 'upload' && $user->useFilePatrol() );
997 }
998
1008 protected function isCategorizationWithoutRevision( $rcObj ) {
1009 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
1010 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
1011 }
1012
1018 protected function getDataAttributes( RecentChange $rc ) {
1019 $attrs = [];
1020
1021 $type = $rc->getAttribute( 'rc_source' );
1022 switch ( $type ) {
1023 case RecentChange::SRC_EDIT:
1024 case RecentChange::SRC_NEW:
1025 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1026 break;
1027 case RecentChange::SRC_LOG:
1028 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
1029 $attrs['data-mw-logaction'] =
1030 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
1031 break;
1032 case RecentChange::SRC_CATEGORIZE:
1033 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
1034 break;
1035 }
1036
1037 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1038
1039 return $attrs;
1040 }
1041
1049 public function setChangeLinePrefixer( callable $prefixer ) {
1050 $this->changeLinePrefixer = $prefixer;
1051 }
1052}
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()
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.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
setContext(IContextSource $context)
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:43
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 ...
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
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:76
Value object representing a user's identity.
internal since 1.36
Definition User.php:98
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition User.php:2361
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition User.php:2386
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition User.php:2371
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 the current execution context, such as a web reque...
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.