MediaWiki REL1_39
ChangesList.php
Go to the documentation of this file.
1<?php
26use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
34use OOUI\IconWidget;
36
38 use ProtectedHookAccessorTrait;
39
40 public const CSS_CLASS_PREFIX = 'mw-changeslist-';
41
42 protected $watchlist = false;
43 protected $lastdate;
44 protected $message;
45 protected $rc_cache;
46 protected $rcCacheIndex;
47 protected $rclistOpen;
48 protected $rcMoveIndex;
49
52
54 protected $watchMsgCache;
55
59 protected $linkRenderer;
60
65
70
74 protected $filterGroups;
75
80 public function __construct( $context, array $filterGroups = [] ) {
81 $this->setContext( $context );
82 $this->preCacheMessages();
83 $this->watchMsgCache = new MapCacheLRU( 50 );
84 $this->filterGroups = $filterGroups;
85
86 $services = MediaWikiServices::getInstance();
87 $this->linkRenderer = $services->getLinkRenderer();
88 $this->commentFormatter = $services->getRowCommentFormatter();
89 }
90
99 public static function newFromContext( IContextSource $context, array $groups = [] ) {
100 $user = $context->getUser();
101 $sk = $context->getSkin();
102 $list = null;
103 if ( Hooks::runner()->onFetchChangesList( $user, $sk, $list, $groups ) ) {
104 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
105 $new = $context->getRequest()->getBool(
106 'enhanced',
107 $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
108 );
109
110 return $new ?
111 new EnhancedChangesList( $context, $groups ) :
112 new OldChangesList( $context, $groups );
113 } else {
114 return $list;
115 }
116 }
117
129 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
130 throw new RuntimeException( 'recentChangesLine should be implemented' );
131 }
132
139 protected function getHighlightsContainerDiv() {
140 $highlightColorDivs = '';
141 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
142 $highlightColorDivs .= Html::rawElement(
143 'div',
144 [
145 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
146 'data-color' => $color
147 ]
148 );
149 }
150
151 return Html::rawElement(
152 'div',
153 [ 'class' => 'mw-rcfilters-ui-highlights' ],
154 $highlightColorDivs
155 );
156 }
157
162 public function setWatchlistDivs( $value = true ) {
163 $this->watchlist = $value;
164 }
165
170 public function isWatchlist() {
171 return (bool)$this->watchlist;
172 }
173
178 private function preCacheMessages() {
179 if ( !isset( $this->message ) ) {
180 $this->message = [];
181 foreach ( [
182 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
183 'semicolon-separator', 'pipe-separator' ] as $msg
184 ) {
185 $this->message[$msg] = $this->msg( $msg )->escaped();
186 }
187 }
188 }
189
196 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
197 $f = '';
198 foreach (
199 array_keys( $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) ) as $flag
200 ) {
201 $f .= isset( $flags[$flag] ) && $flags[$flag]
202 ? self::flag( $flag, $this->getContext() )
203 : $nothing;
204 }
205
206 return $f;
207 }
208
217 protected function getHTMLClasses( $rc, $watched ) {
218 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
219 $logType = $rc->mAttribs['rc_log_type'];
220
221 if ( $logType ) {
222 $classes[] = self::CSS_CLASS_PREFIX . 'log';
223 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
224 } else {
225 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
226 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
227 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
228 }
229
230 // Indicate watched status on the line to allow for more
231 // comprehensive styling.
232 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
233 ? self::CSS_CLASS_PREFIX . 'line-watched'
234 : self::CSS_CLASS_PREFIX . 'line-not-watched';
235
236 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
237
238 return $classes;
239 }
240
248 protected function getHTMLClassesForFilters( $rc ) {
249 $classes = [];
250
251 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
252 $rc->mAttribs['rc_namespace'] );
253
254 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
255 $classes[] = Sanitizer::escapeClass(
256 self::CSS_CLASS_PREFIX .
257 'ns-' .
258 ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
259 );
260
261 foreach ( $this->filterGroups as $filterGroup ) {
262 foreach ( $filterGroup->getFilters() as $filter ) {
263 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
264 }
265 }
266
267 return $classes;
268 }
269
280 public static function flag( $flag, IContextSource $context = null ) {
281 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
282 static $flagInfos = null;
283
284 if ( $flagInfos === null ) {
285 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
286 ->get( MainConfigNames::RecentChangesFlags );
287 $flagInfos = [];
288 foreach ( $recentChangesFlags as $key => $value ) {
289 $flagInfos[$key]['letter'] = $value['letter'];
290 $flagInfos[$key]['title'] = $value['title'];
291 // Allow customized class name, fall back to flag name
292 $flagInfos[$key]['class'] = $value['class'] ?? $key;
293 }
294 }
295
296 $context = $context ?: RequestContext::getMain();
297
298 // Inconsistent naming, kept for b/c
299 if ( isset( $map[$flag] ) ) {
300 $flag = $map[$flag];
301 }
302
303 $info = $flagInfos[$flag];
304 return Html::element( 'abbr', [
305 'class' => $info['class'],
306 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
307 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
308 }
309
314 public function beginRecentChangesList() {
315 $this->rc_cache = [];
316 $this->rcMoveIndex = 0;
317 $this->rcCacheIndex = 0;
318 $this->lastdate = '';
319 $this->rclistOpen = false;
320 $this->getOutput()->addModuleStyles( [
321 'mediawiki.interface.helpers.styles',
322 'mediawiki.special.changeslist'
323 ] );
324
325 return '<div class="mw-changeslist">';
326 }
327
331 public function initChangesListRows( $rows ) {
332 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
333 $this->formattedComments = $this->commentFormatter->createBatch()
334 ->comments(
335 $this->commentFormatter->rows( $rows )
336 ->commentKey( 'rc_comment' )
337 ->namespaceField( 'rc_namespace' )
338 ->titleField( 'rc_title' )
339 ->indexField( 'rc_id' )
340 )
341 ->useBlock()
342 ->execute();
343 }
344
355 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
356 if ( !$context ) {
357 $context = RequestContext::getMain();
358 }
359
360 $new = (int)$new;
361 $old = (int)$old;
362 $szdiff = $new - $old;
363
364 $lang = $context->getLanguage();
365 $config = $context->getConfig();
366 $code = $lang->getCode();
367 static $fastCharDiff = [];
368 if ( !isset( $fastCharDiff[$code] ) ) {
369 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
370 || $context->msg( 'rc-change-size' )->plain() === '$1';
371 }
372
373 $formattedSize = $lang->formatNum( $szdiff );
374
375 if ( !$fastCharDiff[$code] ) {
376 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
377 }
378
379 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
380 $tag = 'strong';
381 } else {
382 $tag = 'span';
383 }
384
385 if ( $szdiff === 0 ) {
386 $formattedSizeClass = 'mw-plusminus-null';
387 } elseif ( $szdiff > 0 ) {
388 $formattedSize = '+' . $formattedSize;
389 $formattedSizeClass = 'mw-plusminus-pos';
390 } else {
391 $formattedSizeClass = 'mw-plusminus-neg';
392 }
393 $formattedSizeClass .= ' mw-diff-bytes';
394
395 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
396
397 return Html::element( $tag,
398 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
399 $formattedSize ) . $lang->getDirMark();
400 }
401
409 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
410 $oldlen = $old->mAttribs['rc_old_len'];
411
412 if ( $new ) {
413 $newlen = $new->mAttribs['rc_new_len'];
414 } else {
415 $newlen = $old->mAttribs['rc_new_len'];
416 }
417
418 if ( $oldlen === null || $newlen === null ) {
419 return '';
420 }
421
422 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
423 }
424
429 public function endRecentChangesList() {
430 $out = $this->rclistOpen ? "</ul>\n" : '';
431 $out .= '</div>';
432
433 return $out;
434 }
435
447 public static function revDateLink(
448 RevisionRecord $rev,
449 Authority $performer,
451 $title = null
452 ) {
453 $ts = $rev->getTimestamp();
454 $time = $lang->userTime( $ts, $performer->getUser() );
455 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
456 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
457 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
458 $title ?? $rev->getPageAsLinkTarget(),
459 $date,
460 [ 'class' => 'mw-changeslist-date' ],
461 [ 'oldid' => $rev->getId() ]
462 );
463 } else {
464 $link = htmlspecialchars( $date );
465 }
466 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
467 $deletedClass = Linker::getRevisionDeletedClass( $rev );
468 $link = "<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
469 }
470 return Html::element( 'span', [
471 'class' => 'mw-changeslist-time'
472 ], $time ) . $link;
473 }
474
479 public function insertDateHeader( &$s, $rc_timestamp ) {
480 # Make date header if necessary
481 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
482 if ( $date != $this->lastdate ) {
483 if ( $this->lastdate != '' ) {
484 $s .= "</ul>\n";
485 }
486 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
487 $this->lastdate = $date;
488 $this->rclistOpen = true;
489 }
490 }
491
498 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
499 $page = new LogPage( $logtype );
500 $logname = $page->getName()->setContext( $this->getContext() )->text();
501 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
502 'class' => $useParentheses ? '' : 'mw-changeslist-links'
503 ] );
504 if ( $useParentheses ) {
505 $s .= $this->msg( 'parentheses' )->rawParams(
506 $link
507 )->escaped();
508 } else {
509 $s .= $link;
510 }
511 }
512
518 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
519 # Diff link
520 if (
521 $rc->mAttribs['rc_type'] == RC_NEW ||
522 $rc->mAttribs['rc_type'] == RC_LOG ||
523 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
524 ) {
525 $diffLink = $this->message['diff'];
526 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
527 $diffLink = $this->message['diff'];
528 } else {
529 $query = [
530 'curid' => $rc->mAttribs['rc_cur_id'],
531 'diff' => $rc->mAttribs['rc_this_oldid'],
532 'oldid' => $rc->mAttribs['rc_last_oldid']
533 ];
534
535 $diffLink = $this->linkRenderer->makeKnownLink(
536 $rc->getTitle(),
537 new HtmlArmor( $this->message['diff'] ),
538 [ 'class' => 'mw-changeslist-diff' ],
539 $query
540 );
541 }
542 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
543 $histLink = $this->message['hist'];
544 } else {
545 $histLink = $this->linkRenderer->makeKnownLink(
546 $rc->getTitle(),
547 new HtmlArmor( $this->message['hist'] ),
548 [ 'class' => 'mw-changeslist-history' ],
549 [
550 'curid' => $rc->mAttribs['rc_cur_id'],
551 'action' => 'history'
552 ]
553 );
554 }
555
556 $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
557 Html::rawElement( 'span', [], $diffLink ) .
558 Html::rawElement( 'span', [], $histLink )
559 ) .
560 ' <span class="mw-changeslist-separator"></span> ';
561 }
562
573 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
574 $params = [];
575 if ( $rc->getTitle()->isRedirect() ) {
576 $params = [ 'redirect' => 'no' ];
577 }
578
579 $articlelink = $this->linkRenderer->makeLink(
580 $rc->getTitle(),
581 null,
582 [ 'class' => 'mw-changeslist-title' ],
583 $params
584 );
585 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
586 $class = 'history-deleted';
587 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
588 $class .= ' mw-history-suppressed';
589 }
590 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
591 }
592 # To allow for boldening pages watched by this user
593 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
594 # RTL/LTR marker
595 $articlelink .= $this->getLanguage()->getDirMark();
596
597 # TODO: Deprecate the $s argument, it seems happily unused.
598 $s = '';
599 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
600 $s, $rc, $unpatrolled, $watched );
601
602 // Watchlist expiry icon.
603 $watchlistExpiry = '';
604 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
605 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
606 }
607
608 return "{$s} {$articlelink}{$watchlistExpiry}";
609 }
610
617 public function getWatchlistExpiry( RecentChange $recentChange ): string {
618 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
619 // Guard against expired items, even though they shouldn't come here.
620 if ( $item->isExpired() ) {
621 return '';
622 }
623 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
624 // Matching widget is also created in ChangesListSpecialPage, for the legend.
625 $widget = new IconWidget( [
626 'icon' => 'clock',
627 'title' => $daysLeftText,
628 'classes' => [ 'mw-changesList-watchlistExpiry' ],
629 ] );
630 $widget->setAttributes( [
631 // Add labels for assistive technologies.
632 'role' => 'img',
633 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
634 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
635 'data-days-left' => $item->getExpiryInDays(),
636 ] );
637 // Add spaces around the widget (the page title is to one side,
638 // and a semicolon or opening-parenthesis to the other).
639 return " $widget ";
640 }
641
650 public function getTimestamp( $rc ) {
651 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
652 // because in that case the timestamp is preceded by a clock icon.
653 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
654 // that whatever comes before it is distinguishable.
655 // (Otherwise your have the text of titles pushing up against the timestamp)
656 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
657 // as the `.mw-changeslist-date` class is used in a variety
658 // of other places with a different position and the information proceeding getTimestamp can vary.
659 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
660 // contain the full date (month, year) and adds consistency with Special:Contributions
661 // and other pages.
662 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
663 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
664 '<span class="mw-changeslist-date mw-changeslist-time">' .
665 htmlspecialchars( $this->getLanguage()->userTime(
666 $rc->mAttribs['rc_timestamp'],
667 $this->getUser()
668 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
669 }
670
677 public function insertTimestamp( &$s, $rc ) {
678 $s .= $this->getTimestamp( $rc );
679 }
680
687 public function insertUserRelatedLinks( &$s, &$rc ) {
688 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
689 $deletedClass = 'history-deleted';
690 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
691 $deletedClass .= ' mw-history-suppressed';
692 }
693 $s .= ' <span class="' . $deletedClass . '">' .
694 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
695 } else {
696 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
697 $rc->mAttribs['rc_user_text'] );
699 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
700 false, 0, null,
701 // The text content of tools is not wrapped with parentheses or "piped".
702 // This will be handled in CSS (T205581).
703 false
704 );
705 }
706 }
707
714 public function insertLogEntry( $rc ) {
715 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
716 $formatter->setContext( $this->getContext() );
717 $formatter->setShowUserToolLinks( true );
718 $mark = $this->getLanguage()->getDirMark();
719
720 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
721 . $formatter->getActionText()
722 . " $mark"
723 . $formatter->getComment()
724 . $this->msg( 'word-separator' )->escaped()
725 . $formatter->getActionLinks()
726 . Html::closeElement( 'span' );
727 }
728
734 public function insertComment( $rc ) {
735 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
736 $deletedClass = 'history-deleted';
737 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
738 $deletedClass .= ' mw-history-suppressed';
739 }
740 return ' <span class="' . $deletedClass . ' comment">' .
741 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
742 } elseif ( isset( $rc->mAttribs['rc_id'] )
743 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
744 ) {
745 return $this->formattedComments[$rc->mAttribs['rc_id']];
746 } else {
747 return $this->commentFormatter->formatBlock(
748 $rc->mAttribs['rc_comment'],
749 $rc->getTitle(),
750 // Whether section links should refer to local page (using default false)
751 false,
752 // wikid to generate links for (using default null) */
753 null,
754 // whether parentheses should be rendered as part of the message
755 false
756 );
757 }
758 }
759
765 protected function numberofWatchingusers( $count ) {
766 if ( $count <= 0 ) {
767 return '';
768 }
769
770 return $this->watchMsgCache->getWithSetCallback(
771 "watching-users-msg:$count",
772 function () use ( $count ) {
773 return $this->msg( 'number-of-watching-users-for-recent-changes' )
774 ->numParams( $count )->escaped();
775 }
776 );
777 }
778
785 public static function isDeleted( $rc, $field ) {
786 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
787 }
788
798 public static function userCan( $rc, $field, Authority $performer = null ) {
799 if ( $performer === null ) {
800 $performer = RequestContext::getMain()->getAuthority();
801 }
802
803 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
804 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
805 }
806
807 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
808 }
809
815 protected function maybeWatchedLink( $link, $watched = false ) {
816 if ( $watched ) {
817 return '<strong class="mw-watched">' . $link . '</strong>';
818 } else {
819 return '<span class="mw-rc-unwatched">' . $link . '</span>';
820 }
821 }
822
829 public function insertRollback( &$s, &$rc ) {
830 if ( $rc->mAttribs['rc_type'] == RC_EDIT
831 && $rc->mAttribs['rc_this_oldid']
832 && $rc->mAttribs['rc_cur_id']
833 && $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
834 ) {
835 $title = $rc->getTitle();
839 if ( $this->getAuthority()->probablyCan( 'rollback', $title ) ) {
840 $revRecord = new MutableRevisionRecord( $title );
841 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
842 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
843 $user = new UserIdentityValue(
844 (int)$rc->mAttribs['rc_user'],
845 $rc->mAttribs['rc_user_text']
846 );
847 $revRecord->setUser( $user );
848
849 $s .= ' ';
851 $revRecord,
852 $this->getContext(),
853 [ 'noBrackets' ]
854 );
855 }
856 }
857 }
858
864 public function getRollback( RecentChange $rc ) {
865 $s = '';
866 $this->insertRollback( $s, $rc );
867 return $s;
868 }
869
875 public function insertTags( &$s, &$rc, &$classes ) {
876 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
877 return;
878 }
879
880 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
881 $rc->mAttribs['ts_tags'],
882 'changeslist',
883 $this->getContext()
884 );
885 $classes = array_merge( $classes, $newClasses );
886 $s .= ' ' . $tagSummary;
887 }
888
895 public function getTags( RecentChange $rc, array &$classes ) {
896 $s = '';
897 $this->insertTags( $s, $rc, $classes );
898 return $s;
899 }
900
901 public function insertExtra( &$s, &$rc, &$classes ) {
902 // Empty, used for subclasses to add anything special.
903 }
904
905 protected function showAsUnpatrolled( RecentChange $rc ) {
906 return self::isUnpatrolled( $rc, $this->getUser() );
907 }
908
914 public static function isUnpatrolled( $rc, User $user ) {
915 if ( $rc instanceof RecentChange ) {
916 $isPatrolled = $rc->mAttribs['rc_patrolled'];
917 $rcType = $rc->mAttribs['rc_type'];
918 $rcLogType = $rc->mAttribs['rc_log_type'];
919 } else {
920 $isPatrolled = $rc->rc_patrolled;
921 $rcType = $rc->rc_type;
922 $rcLogType = $rc->rc_log_type;
923 }
924
925 if ( !$isPatrolled ) {
926 if ( $user->useRCPatrol() ) {
927 return true;
928 }
929 if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
930 return true;
931 }
932 if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
933 return true;
934 }
935 }
936
937 return false;
938 }
939
949 protected function isCategorizationWithoutRevision( $rcObj ) {
950 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
951 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
952 }
953
959 protected function getDataAttributes( RecentChange $rc ) {
960 $attrs = [];
961
962 $type = $rc->getAttribute( 'rc_source' );
963 switch ( $type ) {
964 case RecentChange::SRC_EDIT:
965 case RecentChange::SRC_NEW:
966 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
967 break;
968 case RecentChange::SRC_LOG:
969 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
970 $attrs['data-mw-logaction'] =
971 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
972 break;
973 case RecentChange::SRC_CATEGORIZE:
974 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
975 break;
976 }
977
978 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
979
980 return $attrs;
981 }
982
990 public function setChangeLinePrefixer( callable $prefixer ) {
991 $this->changeLinePrefixer = $prefixer;
992 }
993}
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, $page, 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.
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,...
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:53
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition Linker.php:1114
static getRevisionDeletedClass(RevisionRecord $revisionRecord)
Returns css class of a deleted revision.
Definition Linker.php:1351
static generateRollback(RevisionRecord $revRecord, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition Linker.php:1834
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition Linker.php:1159
Class to simplify the use of log pages.
Definition LogPage.php:39
Handles a simple LRU key/value map with a maximum number of entries.
This is basically a CommentFormatter with a CommentStore dependency, allowing it to retrieve comment ...
Class that generates HTML anchor link elements for pages.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
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.
Value object representing a user's identity.
Utility class for creating new RC entries.
getAttribute( $name)
Get an attribute value.
internal since 1.36
Definition User.php:70
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition User.php:2399
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition User.php:2384
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition User.php:2374
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.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(!isset( $args[0])) $lang