MediaWiki 1.40.4
ChangesList.php
Go to the documentation of this file.
1<?php
26use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
37use OOUI\IconWidget;
39
41 use ProtectedHookAccessorTrait;
42
43 public const CSS_CLASS_PREFIX = 'mw-changeslist-';
44
45 protected $watchlist = false;
46 protected $lastdate;
47 protected $message;
48 protected $rc_cache;
49 protected $rcCacheIndex;
50 protected $rclistOpen;
51 protected $rcMoveIndex;
52
55
57 protected $watchMsgCache;
58
62 protected $linkRenderer;
63
68
73
77 protected $filterGroups;
78
83 public function __construct( $context, array $filterGroups = [] ) {
84 $this->setContext( $context );
85 $this->preCacheMessages();
86 $this->watchMsgCache = new MapCacheLRU( 50 );
87 $this->filterGroups = $filterGroups;
88
89 $services = MediaWikiServices::getInstance();
90 $this->linkRenderer = $services->getLinkRenderer();
91 $this->commentFormatter = $services->getRowCommentFormatter();
92 }
93
102 public static function newFromContext( IContextSource $context, array $groups = [] ) {
103 $user = $context->getUser();
104 $sk = $context->getSkin();
105 $list = null;
106 if ( Hooks::runner()->onFetchChangesList( $user, $sk, $list, $groups ) ) {
107 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
108 $new = $context->getRequest()->getBool(
109 'enhanced',
110 $userOptionsLookup->getBoolOption( $user, 'usenewrc' )
111 );
112
113 return $new ?
114 new EnhancedChangesList( $context, $groups ) :
115 new OldChangesList( $context, $groups );
116 } else {
117 return $list;
118 }
119 }
120
132 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
133 throw new RuntimeException( 'recentChangesLine should be implemented' );
134 }
135
142 protected function getHighlightsContainerDiv() {
143 $highlightColorDivs = '';
144 foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
145 $highlightColorDivs .= Html::rawElement(
146 'div',
147 [
148 'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
149 'data-color' => $color
150 ]
151 );
152 }
153
154 return Html::rawElement(
155 'div',
156 [ 'class' => 'mw-rcfilters-ui-highlights' ],
157 $highlightColorDivs
158 );
159 }
160
165 public function setWatchlistDivs( $value = true ) {
166 $this->watchlist = $value;
167 }
168
173 public function isWatchlist() {
174 return (bool)$this->watchlist;
175 }
176
181 private function preCacheMessages() {
182 if ( !isset( $this->message ) ) {
183 $this->message = [];
184 foreach ( [
185 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
186 'semicolon-separator', 'pipe-separator' ] as $msg
187 ) {
188 $this->message[$msg] = $this->msg( $msg )->escaped();
189 }
190 }
191 }
192
199 public function recentChangesFlags( $flags, $nothing = "\u{00A0}" ) {
200 $f = '';
201 foreach (
202 array_keys( $this->getConfig()->get( MainConfigNames::RecentChangesFlags ) ) as $flag
203 ) {
204 $f .= isset( $flags[$flag] ) && $flags[$flag]
205 ? self::flag( $flag, $this->getContext() )
206 : $nothing;
207 }
208
209 return $f;
210 }
211
220 protected function getHTMLClasses( $rc, $watched ) {
221 $classes = [ self::CSS_CLASS_PREFIX . 'line' ];
222 $logType = $rc->mAttribs['rc_log_type'];
223
224 if ( $logType ) {
225 $classes[] = self::CSS_CLASS_PREFIX . 'log';
226 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'log-' . $logType );
227 } else {
228 $classes[] = self::CSS_CLASS_PREFIX . 'edit';
229 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
230 $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
231 }
232
233 // Indicate watched status on the line to allow for more
234 // comprehensive styling.
235 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
236 ? self::CSS_CLASS_PREFIX . 'line-watched'
237 : self::CSS_CLASS_PREFIX . 'line-not-watched';
238
239 $classes = array_merge( $classes, $this->getHTMLClassesForFilters( $rc ) );
240
241 return $classes;
242 }
243
251 protected function getHTMLClassesForFilters( $rc ) {
252 $classes = [];
253
254 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
255 $rc->mAttribs['rc_namespace'] );
256
257 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
258 $classes[] = Sanitizer::escapeClass(
259 self::CSS_CLASS_PREFIX .
260 'ns-' .
261 ( $nsInfo->isTalk( $rc->mAttribs['rc_namespace'] ) ? 'talk' : 'subject' )
262 );
263
264 foreach ( $this->filterGroups as $filterGroup ) {
265 foreach ( $filterGroup->getFilters() as $filter ) {
266 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
267 }
268 }
269
270 return $classes;
271 }
272
283 public static function flag( $flag, IContextSource $context = null ) {
284 static $map = [ 'minoredit' => 'minor', 'botedit' => 'bot' ];
285 static $flagInfos = null;
286
287 if ( $flagInfos === null ) {
288 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
289 ->get( MainConfigNames::RecentChangesFlags );
290 $flagInfos = [];
291 foreach ( $recentChangesFlags as $key => $value ) {
292 $flagInfos[$key]['letter'] = $value['letter'];
293 $flagInfos[$key]['title'] = $value['title'];
294 // Allow customized class name, fall back to flag name
295 $flagInfos[$key]['class'] = $value['class'] ?? $key;
296 }
297 }
298
299 $context = $context ?: RequestContext::getMain();
300
301 // Inconsistent naming, kept for b/c
302 if ( isset( $map[$flag] ) ) {
303 $flag = $map[$flag];
304 }
305
306 $info = $flagInfos[$flag];
307 return Html::element( 'abbr', [
308 'class' => $info['class'],
309 'title' => wfMessage( $info['title'] )->setContext( $context )->text(),
310 ], wfMessage( $info['letter'] )->setContext( $context )->text() );
311 }
312
317 public function beginRecentChangesList() {
318 $this->rc_cache = [];
319 $this->rcMoveIndex = 0;
320 $this->rcCacheIndex = 0;
321 $this->lastdate = '';
322 $this->rclistOpen = false;
323 $this->getOutput()->addModuleStyles( [
324 'mediawiki.interface.helpers.styles',
325 'mediawiki.special.changeslist'
326 ] );
327
328 return '<div class="mw-changeslist">';
329 }
330
334 public function initChangesListRows( $rows ) {
335 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
336 $this->formattedComments = $this->commentFormatter->createBatch()
337 ->comments(
338 $this->commentFormatter->rows( $rows )
339 ->commentKey( 'rc_comment' )
340 ->namespaceField( 'rc_namespace' )
341 ->titleField( 'rc_title' )
342 ->indexField( 'rc_id' )
343 )
344 ->useBlock()
345 ->execute();
346 }
347
358 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
359 if ( !$context ) {
360 $context = RequestContext::getMain();
361 }
362
363 $new = (int)$new;
364 $old = (int)$old;
365 $szdiff = $new - $old;
366
367 $lang = $context->getLanguage();
368 $config = $context->getConfig();
369 $code = $lang->getCode();
370 static $fastCharDiff = [];
371 if ( !isset( $fastCharDiff[$code] ) ) {
372 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
373 || $context->msg( 'rc-change-size' )->plain() === '$1';
374 }
375
376 $formattedSize = $lang->formatNum( $szdiff );
377
378 if ( !$fastCharDiff[$code] ) {
379 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
380 }
381
382 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
383 $tag = 'strong';
384 } else {
385 $tag = 'span';
386 }
387
388 if ( $szdiff === 0 ) {
389 $formattedSizeClass = 'mw-plusminus-null';
390 } elseif ( $szdiff > 0 ) {
391 $formattedSize = '+' . $formattedSize;
392 $formattedSizeClass = 'mw-plusminus-pos';
393 } else {
394 $formattedSizeClass = 'mw-plusminus-neg';
395 }
396 $formattedSizeClass .= ' mw-diff-bytes';
397
398 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
399
400 return Html::element( $tag,
401 [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
402 $formattedSize ) . $lang->getDirMark();
403 }
404
412 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
413 $oldlen = $old->mAttribs['rc_old_len'];
414
415 if ( $new ) {
416 $newlen = $new->mAttribs['rc_new_len'];
417 } else {
418 $newlen = $old->mAttribs['rc_new_len'];
419 }
420
421 if ( $oldlen === null || $newlen === null ) {
422 return '';
423 }
424
425 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
426 }
427
432 public function endRecentChangesList() {
433 $out = $this->rclistOpen ? "</ul>\n" : '';
434 $out .= '</div>';
435
436 return $out;
437 }
438
450 public static function revDateLink(
451 RevisionRecord $rev,
452 Authority $performer,
454 $title = null
455 ) {
456 $ts = $rev->getTimestamp();
457 $time = $lang->userTime( $ts, $performer->getUser() );
458 $date = $lang->userTimeAndDate( $ts, $performer->getUser() );
459 if ( $rev->userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
460 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
461 $title ?? $rev->getPageAsLinkTarget(),
462 $date,
463 [ 'class' => 'mw-changeslist-date' ],
464 [ 'oldid' => $rev->getId() ]
465 );
466 } else {
467 $link = htmlspecialchars( $date );
468 }
469 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
470 $deletedClass = Linker::getRevisionDeletedClass( $rev );
471 $link = "<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
472 }
473 return Html::element( 'span', [
474 'class' => 'mw-changeslist-time'
475 ], $time ) . $link;
476 }
477
482 public function insertDateHeader( &$s, $rc_timestamp ) {
483 # Make date header if necessary
484 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
485 if ( $date != $this->lastdate ) {
486 if ( $this->lastdate != '' ) {
487 $s .= "</ul>\n";
488 }
489 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
490 $this->lastdate = $date;
491 $this->rclistOpen = true;
492 }
493 }
494
501 public function insertLog( &$s, $title, $logtype, $useParentheses = true ) {
502 $page = new LogPage( $logtype );
503 $logname = $page->getName()->setContext( $this->getContext() )->text();
504 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
505 'class' => $useParentheses ? '' : 'mw-changeslist-links'
506 ] );
507 if ( $useParentheses ) {
508 $s .= $this->msg( 'parentheses' )->rawParams(
509 $link
510 )->escaped();
511 } else {
512 $s .= $link;
513 }
514 }
515
521 public function insertDiffHist( &$s, &$rc, $unpatrolled = null ) {
522 # Diff link
523 if (
524 $rc->mAttribs['rc_type'] == RC_NEW ||
525 $rc->mAttribs['rc_type'] == RC_LOG ||
526 $rc->mAttribs['rc_type'] == RC_CATEGORIZE
527 ) {
528 $diffLink = $this->message['diff'];
529 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
530 $diffLink = $this->message['diff'];
531 } else {
532 $query = [
533 'curid' => $rc->mAttribs['rc_cur_id'],
534 'diff' => $rc->mAttribs['rc_this_oldid'],
535 'oldid' => $rc->mAttribs['rc_last_oldid']
536 ];
537
538 $diffLink = $this->linkRenderer->makeKnownLink(
539 $rc->getTitle(),
540 new HtmlArmor( $this->message['diff'] ),
541 [ 'class' => 'mw-changeslist-diff' ],
542 $query
543 );
544 }
545 if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
546 $histLink = $this->message['hist'];
547 } else {
548 $histLink = $this->linkRenderer->makeKnownLink(
549 $rc->getTitle(),
550 new HtmlArmor( $this->message['hist'] ),
551 [ 'class' => 'mw-changeslist-history' ],
552 [
553 'curid' => $rc->mAttribs['rc_cur_id'],
554 'action' => 'history'
555 ]
556 );
557 }
558
559 $s .= Html::rawElement( 'div', [ 'class' => 'mw-changeslist-links' ],
560 Html::rawElement( 'span', [], $diffLink ) .
561 Html::rawElement( 'span', [], $histLink )
562 ) .
563 ' <span class="mw-changeslist-separator"></span> ';
564 }
565
576 public function getArticleLink( &$rc, $unpatrolled, $watched ) {
577 $params = [];
578 if ( $rc->getTitle()->isRedirect() ) {
579 $params = [ 'redirect' => 'no' ];
580 }
581
582 $articlelink = $this->linkRenderer->makeLink(
583 $rc->getTitle(),
584 null,
585 [ 'class' => 'mw-changeslist-title' ],
586 $params
587 );
588 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
589 $class = 'history-deleted';
590 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
591 $class .= ' mw-history-suppressed';
592 }
593 $articlelink = '<span class="' . $class . '">' . $articlelink . '</span>';
594 }
595 # To allow for boldening pages watched by this user
596 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
597 # RTL/LTR marker
598 $articlelink .= $this->getLanguage()->getDirMark();
599
600 # TODO: Deprecate the $s argument, it seems happily unused.
601 $s = '';
602 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
603 $s, $rc, $unpatrolled, $watched );
604
605 // Watchlist expiry icon.
606 $watchlistExpiry = '';
607 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
608 $watchlistExpiry = $this->getWatchlistExpiry( $rc );
609 }
610
611 return "{$s} {$articlelink}{$watchlistExpiry}";
612 }
613
620 public function getWatchlistExpiry( RecentChange $recentChange ): string {
621 $item = WatchedItem::newFromRecentChange( $recentChange, $this->getUser() );
622 // Guard against expired items, even though they shouldn't come here.
623 if ( $item->isExpired() ) {
624 return '';
625 }
626 $daysLeftText = $item->getExpiryInDaysText( $this->getContext() );
627 // Matching widget is also created in ChangesListSpecialPage, for the legend.
628 $widget = new IconWidget( [
629 'icon' => 'clock',
630 'title' => $daysLeftText,
631 'classes' => [ 'mw-changesList-watchlistExpiry' ],
632 ] );
633 $widget->setAttributes( [
634 // Add labels for assistive technologies.
635 'role' => 'img',
636 'aria-label' => $this->msg( 'watchlist-expires-in-aria-label' )->text(),
637 // Days-left is used in resources/src/mediawiki.special.changeslist.watchlistexpiry/watchlistexpiry.js
638 'data-days-left' => $item->getExpiryInDays(),
639 ] );
640 // Add spaces around the widget (the page title is to one side,
641 // and a semicolon or opening-parenthesis to the other).
642 return " $widget ";
643 }
644
653 public function getTimestamp( $rc ) {
654 // This uses the semi-colon separator unless there's a watchlist expiry date for the entry,
655 // because in that case the timestamp is preceded by a clock icon.
656 // A space is important after `.mw-changeslist-separator--semicolon` to make sure
657 // that whatever comes before it is distinguishable.
658 // (Otherwise your have the text of titles pushing up against the timestamp)
659 // A specific element is used for this purpose rather than styling `.mw-changeslist-date`
660 // as the `.mw-changeslist-date` class is used in a variety
661 // of other places with a different position and the information proceeding getTimestamp can vary.
662 // The `.mw-changeslist-time` class allows us to distinguish from `.mw-changeslist-date` elements that
663 // contain the full date (month, year) and adds consistency with Special:Contributions
664 // and other pages.
665 $separatorClass = $rc->watchlistExpiry ? 'mw-changeslist-separator' : 'mw-changeslist-separator--semicolon';
666 return Html::element( 'span', [ 'class' => $separatorClass ] ) . ' ' .
667 '<span class="mw-changeslist-date mw-changeslist-time">' .
668 htmlspecialchars( $this->getLanguage()->userTime(
669 $rc->mAttribs['rc_timestamp'],
670 $this->getUser()
671 ) ) . '</span> <span class="mw-changeslist-separator"></span> ';
672 }
673
680 public function insertTimestamp( &$s, $rc ) {
681 $s .= $this->getTimestamp( $rc );
682 }
683
690 public function insertUserRelatedLinks( &$s, &$rc ) {
691 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
692 $deletedClass = 'history-deleted';
693 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
694 $deletedClass .= ' mw-history-suppressed';
695 }
696 $s .= ' <span class="' . $deletedClass . '">' .
697 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
698 } else {
699 $s .= $this->getLanguage()->getDirMark() . Linker::userLink(
700 $rc->mAttribs['rc_user'],
701 $rc->mAttribs['rc_user_text'],
702 false,
703 [ 'data-mw-revid' => $rc->mAttribs['rc_this_oldid'] ]
704 );
705 $s .= Linker::userToolLinks(
706 $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'],
707 false, 0, null,
708 // The text content of tools is not wrapped with parentheses or "piped".
709 // This will be handled in CSS (T205581).
710 false
711 );
712 }
713 }
714
721 public function insertLogEntry( $rc ) {
722 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
723 $formatter->setContext( $this->getContext() );
724 $formatter->setShowUserToolLinks( true );
725 $mark = $this->getLanguage()->getDirMark();
726
727 return Html::openElement( 'span', [ 'class' => 'mw-changeslist-log-entry' ] )
728 . $formatter->getActionText()
729 . " $mark"
730 . $formatter->getComment()
731 . $this->msg( 'word-separator' )->escaped()
732 . $formatter->getActionLinks()
733 . Html::closeElement( 'span' );
734 }
735
741 public function insertComment( $rc ) {
742 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
743 $deletedClass = 'history-deleted';
744 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
745 $deletedClass .= ' mw-history-suppressed';
746 }
747 return ' <span class="' . $deletedClass . ' comment">' .
748 $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
749 } elseif ( isset( $rc->mAttribs['rc_id'] )
750 && isset( $this->formattedComments[$rc->mAttribs['rc_id']] )
751 ) {
752 return $this->formattedComments[$rc->mAttribs['rc_id']];
753 } else {
754 return $this->commentFormatter->formatBlock(
755 $rc->mAttribs['rc_comment'],
756 $rc->getTitle(),
757 // Whether section links should refer to local page (using default false)
758 false,
759 // wikid to generate links for (using default null) */
760 null,
761 // whether parentheses should be rendered as part of the message
762 false
763 );
764 }
765 }
766
772 protected function numberofWatchingusers( $count ) {
773 if ( $count <= 0 ) {
774 return '';
775 }
776
777 return $this->watchMsgCache->getWithSetCallback(
778 "watching-users-msg:$count",
779 function () use ( $count ) {
780 return $this->msg( 'number-of-watching-users-for-recent-changes' )
781 ->numParams( $count )->escaped();
782 }
783 );
784 }
785
792 public static function isDeleted( $rc, $field ) {
793 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
794 }
795
805 public static function userCan( $rc, $field, Authority $performer = null ) {
806 $performer ??= RequestContext::getMain()->getAuthority();
807
808 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
809 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
810 }
811
812 return RevisionRecord::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $performer );
813 }
814
820 protected function maybeWatchedLink( $link, $watched = false ) {
821 if ( $watched ) {
822 return '<strong class="mw-watched">' . $link . '</strong>';
823 } else {
824 return '<span class="mw-rc-unwatched">' . $link . '</span>';
825 }
826 }
827
834 public function insertRollback( &$s, &$rc ) {
835 $this->insertPageTools( $s, $rc );
836 }
837
846 private function insertPageTools( &$s, &$rc ) {
847 // FIXME Some page tools (e.g. thanks) might make sense for log entries.
848 if ( !in_array( $rc->mAttribs['rc_type'], [ RC_EDIT, RC_NEW ] )
849 // FIXME When would either of these not exist when type is RC_EDIT? Document.
850 || !$rc->mAttribs['rc_this_oldid']
851 || !$rc->mAttribs['rc_cur_id']
852 ) {
853 return;
854 }
855
856 // Construct a fake revision for PagerTools. FIXME can't we just obtain the real one?
857 $title = $rc->getTitle();
858 $revRecord = new MutableRevisionRecord( $title );
859 $revRecord->setId( (int)$rc->mAttribs['rc_this_oldid'] );
860 $revRecord->setVisibility( (int)$rc->mAttribs['rc_deleted'] );
861 $user = new UserIdentityValue(
862 (int)$rc->mAttribs['rc_user'],
863 $rc->mAttribs['rc_user_text']
864 );
865 $revRecord->setUser( $user );
866
867 $tools = new PagerTools(
868 $revRecord,
869 null,
870 // only show a rollback link on the top-most revision
871 $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
872 && $rc->mAttribs['rc_type'] != RC_NEW,
873 $this->getHookRunner(),
874 $title,
875 $this->getContext(),
876 // @todo: Inject
877 MediaWikiServices::getInstance()->getLinkRenderer()
878 );
879
880 $s .= $tools->toHTML();
881 }
882
888 public function getRollback( RecentChange $rc ) {
889 $s = '';
890 $this->insertRollback( $s, $rc );
891 return $s;
892 }
893
899 public function insertTags( &$s, &$rc, &$classes ) {
900 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
901 return;
902 }
903
904 [ $tagSummary, $newClasses ] = ChangeTags::formatSummaryRow(
905 $rc->mAttribs['ts_tags'],
906 'changeslist',
907 $this->getContext()
908 );
909 $classes = array_merge( $classes, $newClasses );
910 $s .= ' ' . $tagSummary;
911 }
912
919 public function getTags( RecentChange $rc, array &$classes ) {
920 $s = '';
921 $this->insertTags( $s, $rc, $classes );
922 return $s;
923 }
924
925 public function insertExtra( &$s, &$rc, &$classes ) {
926 // Empty, used for subclasses to add anything special.
927 }
928
929 protected function showAsUnpatrolled( RecentChange $rc ) {
930 return self::isUnpatrolled( $rc, $this->getUser() );
931 }
932
938 public static function isUnpatrolled( $rc, User $user ) {
939 if ( $rc instanceof RecentChange ) {
940 $isPatrolled = $rc->mAttribs['rc_patrolled'];
941 $rcType = $rc->mAttribs['rc_type'];
942 $rcLogType = $rc->mAttribs['rc_log_type'];
943 } else {
944 $isPatrolled = $rc->rc_patrolled;
945 $rcType = $rc->rc_type;
946 $rcLogType = $rc->rc_log_type;
947 }
948
949 if ( !$isPatrolled ) {
950 if ( $user->useRCPatrol() ) {
951 return true;
952 }
953 if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
954 return true;
955 }
956 if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
957 return true;
958 }
959 }
960
961 return false;
962 }
963
973 protected function isCategorizationWithoutRevision( $rcObj ) {
974 return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
975 && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
976 }
977
983 protected function getDataAttributes( RecentChange $rc ) {
984 $attrs = [];
985
986 $type = $rc->getAttribute( 'rc_source' );
987 switch ( $type ) {
988 case RecentChange::SRC_EDIT:
989 case RecentChange::SRC_NEW:
990 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
991 break;
992 case RecentChange::SRC_LOG:
993 $attrs['data-mw-logid'] = $rc->mAttribs['rc_logid'];
994 $attrs['data-mw-logaction'] =
995 $rc->mAttribs['rc_log_type'] . '/' . $rc->mAttribs['rc_log_action'];
996 break;
997 case RecentChange::SRC_CATEGORIZE:
998 $attrs['data-mw-revid'] = $rc->mAttribs['rc_this_oldid'];
999 break;
1000 }
1001
1002 $attrs[ 'data-mw-ts' ] = $rc->getAttribute( 'rc_timestamp' );
1003
1004 return $attrs;
1005 }
1006
1014 public function setChangeLinePrefixer( callable $prefixer ) {
1015 $this->changeLinePrefixer = $prefixer;
1016 }
1017}
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.
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:56
Class to simplify the use of log pages.
Definition LogPage.php:41
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 ...
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:67
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.
Represents a title within MediaWiki.
Definition Title.php:82
Value object representing a user's identity.
Generate a set of tools for a revision.
Utility class for creating new RC entries.
getAttribute( $name)
Get an attribute value.
internal since 1.36
Definition User.php:71
useFilePatrol()
Check whether to enable new files patrol features for this user.
Definition User.php:2400
useNPPatrol()
Check whether to enable new pages patrol features for this user.
Definition User.php:2385
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
Definition User.php:2375
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.
if(!isset( $args[0])) $lang