15use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
27use MediaWiki\Pager\PagerTools;
43use Wikimedia\MapCacheLRU\MapCacheLRU;
55 use ProtectedHookAccessorTrait;
122 $this->preCacheMessages();
123 $this->watchMsgCache =
new MapCacheLRU( 50 );
127 $this->linkRenderer = $services->getLinkRenderer();
128 $this->commentFormatter = $services->getRowCommentFormatter();
129 $this->logFormatterFactory = $services->getLogFormatterFactory();
130 $this->userLinkRenderer = $services->getUserLinkRenderer();
131 $this->tagsCache =
new MapCacheLRU( 50 );
132 $this->userLinkCache =
new MapCacheLRU( 50 );
152 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
153 $userOptionsLookup = $services->getUserOptionsLookup();
179 throw new RuntimeException(
'recentChangesLine should be implemented' );
189 $highlightColorDivs =
'';
190 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
191 $highlightColorDivs .= Html::rawElement(
194 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
195 'data-color' => $color
200 return Html::rawElement(
202 [
'class' =>
'mw-rcfilters-ui-highlights' ],
212 $this->watchlist = $value;
227 private function preCacheMessages() {
229 if ( !isset( $this->message ) ) {
232 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
233 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
235 $this->message[$msg] = $this->
msg( $msg )->escaped();
251 $f .= isset( $flags[$flag] ) && $flags[$flag]
268 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
269 $logType = $rc->mAttribs[
'rc_log_type'];
272 $classes[] = self::CSS_CLASS_PREFIX .
'log';
273 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
275 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
276 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
277 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
282 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
283 ? self::CSS_CLASS_PREFIX .
'line-watched'
284 : self::CSS_CLASS_PREFIX .
'line-not-watched';
301 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
302 $rc->mAttribs[
'rc_namespace'] );
305 $classes[] = Sanitizer::escapeClass(
306 self::CSS_CLASS_PREFIX .
308 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
311 $this->filterGroups->applyCssClassIfNeeded( $this->
getContext(), $rc, $classes );
327 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
328 static $flagInfos =
null;
330 if ( $flagInfos ===
null ) {
334 foreach ( $recentChangesFlags as $key => $value ) {
335 $flagInfos[$key][
'letter'] = $value[
'letter'];
336 $flagInfos[$key][
'title'] = $value[
'title'];
338 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
344 'Calling ChangesList::flag without specifying a context is deprecated since 1.46',
347 $context = RequestContext::getMain();
351 if ( isset( $map[$flag] ) ) {
355 $info = $flagInfos[$flag];
357 'class' => $info[
'class'],
367 $this->rc_cache = [];
368 $this->rcMoveIndex = 0;
369 $this->rcCacheIndex = 0;
370 $this->lastdate =
'';
371 $this->rclistOpen =
false;
373 'mediawiki.interface.helpers.styles',
374 'mediawiki.special.changeslist'
377 return '<div class="mw-changeslist">';
384 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
385 $this->formattedComments = $this->commentFormatter->createBatch()
387 $this->commentFormatter->rows( $rows )
388 ->commentKey(
'rc_comment' )
389 ->namespaceField(
'rc_namespace' )
390 ->titleField(
'rc_title' )
391 ->indexField(
'rc_id' )
410 'Calling ChangesList::showCharacterDifference without specifying a context is deprecated since 1.46',
413 $context = RequestContext::getMain();
418 $szdiff = $new - $old;
420 $lang = $context->getLanguage();
421 $config = $context->getConfig();
422 $code = $lang->getCode();
423 static $fastCharDiff = [];
424 if ( !isset( $fastCharDiff[$code] ) ) {
426 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
429 $formattedSize = $lang->formatNum( $szdiff );
431 if ( !$fastCharDiff[$code] ) {
432 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
441 if ( $szdiff === 0 ) {
442 $formattedSizeClass =
'mw-plusminus-null';
443 } elseif ( $szdiff > 0 ) {
444 $formattedSize =
'+' . $formattedSize;
445 $formattedSizeClass =
'mw-plusminus-pos';
447 $formattedSizeClass =
'mw-plusminus-neg';
449 $formattedSizeClass .=
' mw-diff-bytes';
451 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
454 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
466 $oldlen = $old->mAttribs[
'rc_old_len'];
469 $newlen = $new->mAttribs[
'rc_new_len'];
471 $newlen = $old->mAttribs[
'rc_new_len'];
474 if ( $oldlen ===
null || $newlen ===
null ) {
486 $out = $this->rclistOpen ?
"</ul>\n" :
'';
515 $class = trim(
'mw-changeslist-date ' . $className );
516 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
517 $link = Html::rawElement(
'bdi', [
'dir' => $lang->
getDir() ],
521 [
'class' => $class ],
522 [
'oldid' => $rev->
getId() ]
526 $link = htmlspecialchars( $date );
528 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
529 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
530 $link =
"<span class=\"$class\">$link</span>";
533 'class' =>
'mw-changeslist-time'
542 # Make date header if necessary
544 if ( $date != $this->lastdate ) {
545 if ( $this->lastdate !=
'' ) {
548 $s .=
Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
549 $this->lastdate = $date;
550 $this->rclistOpen =
true;
560 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
561 $page =
new LogPage( $logtype );
562 $logname = $page->getName()->setContext( $this->
getContext() )->text();
563 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
564 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
566 if ( $useParentheses ) {
567 $s .= $this->
msg(
'parentheses' )->rawParams(
586 $diffLink = $this->message[
'diff'];
587 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
588 $diffLink = $this->message[
'diff'];
591 'curid' => $rc->mAttribs[
'rc_cur_id'],
592 'diff' => $rc->mAttribs[
'rc_this_oldid'],
593 'oldid' => $rc->mAttribs[
'rc_last_oldid']
596 $diffLink = $this->linkRenderer->makeKnownLink(
599 [
'class' =>
'mw-changeslist-diff' ],
603 $histLink = $this->linkRenderer->makeKnownLink(
606 [
'class' =>
'mw-changeslist-history' ],
608 'curid' => $rc->mAttribs[
'rc_cur_id'],
609 'action' =>
'history'
613 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
614 Html::rawElement(
'span', [], $diffLink ) .
615 Html::rawElement(
'span', [], $histLink )
617 ' <span class="mw-changeslist-separator"></span> ';
632 if ( $rc->getTitle()->isRedirect() ) {
633 $params = [
'redirect' =>
'no' ];
636 $articlelink = $this->linkRenderer->makeLink(
639 [
'class' =>
'mw-changeslist-title' ],
642 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
643 $class =
'history-deleted';
644 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
645 $class .=
' mw-history-suppressed';
647 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
650 $articlelink = Html::rawElement(
'bdi', [
'dir' => $dir ], $articlelink );
651 # To allow for boldening pages watched by this user
652 # Don't wrap result of this with another tag, see T376814
653 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
655 # TODO: Deprecate the $s argument, it seems happily unused.
657 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
658 $s, $rc, $unpatrolled, $watched );
661 $watchlistExpiry =
'';
663 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
667 return "{$s} {$articlelink}{$watchlistExpiry}";
679 if ( $item->isExpired() ) {
684 $widget =
new IconWidget( [
686 'title' => $daysLeftText,
687 'classes' => [
'mw-changesList-watchlistExpiry' ],
689 $widget->setAttributes( [
692 'aria-label' => $this->
msg(
'watchlist-expires-in-aria-label' )->text(),
694 'data-days-left' => $item->getExpiryInDays(),
721 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
722 return Html::element(
'span', [
'class' => $separatorClass ] ) . $this->message[
'word-separator'] .
723 '<span class="mw-changeslist-date mw-changeslist-time">' .
724 htmlspecialchars( $this->getLanguage()->userTime(
725 $rc->mAttribs[
'rc_timestamp'],
727 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
737 $s .= $this->getTimestamp( $rc );
747 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
748 $deletedClass =
'history-deleted';
749 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
750 $deletedClass .=
' mw-history-suppressed';
752 $s .=
' <span class="' . $deletedClass .
'">' .
753 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
755 $s .= $this->linkRenderer->makeUserLink(
756 $rc->getPerformerIdentity(),
759 # Don't wrap result of this with another tag, see T376814
760 $s .= $this->userLinkCache->getWithSetCallback(
761 $this->userLinkCache->makeKey(
762 $rc->mAttribs[
'rc_user_text'],
763 $this->getUser()->getName(),
764 $this->getLanguage()->getCode()
768 static fn () => Linker::userToolLinks(
769 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
784 $entry = DatabaseLogEntry::newFromRow( $rc->mAttribs );
785 $formatter = $this->logFormatterFactory->newFromEntry( $entry );
786 $formatter->setContext( $this->getContext() );
787 $formatter->setShowUserToolLinks(
true );
789 $comment = $formatter->getComment();
790 if ( $comment !==
'' ) {
791 $dir = $this->getLanguage()->getDir();
792 $comment = Html::rawElement(
'bdi', [
'dir' => $dir ], $comment );
795 $html = $formatter->getActionText() . $this->message[
'word-separator'] . $comment .
796 $this->message[
'word-separator'] . $formatter->getActionLinks();
797 $classes = [
'mw-changeslist-log-entry' ];
801 $this->getHookRunner()->onChangesListInsertLogEntry( $entry, $this->getContext(), $html, $classes, $attribs );
802 $attribs = array_filter( $attribs,
803 Sanitizer::isReservedDataAttribute( ... ),
806 $attribs[
'class'] = $classes;
808 return Html::rawElement(
'span', $attribs, $html );
817 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
818 $deletedClass =
'history-deleted';
819 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
820 $deletedClass .=
' mw-history-suppressed';
822 return ' <span class="' . $deletedClass .
' comment">' .
823 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
824 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
825 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
827 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
829 return $this->commentFormatter->formatBlock(
830 $rc->mAttribs[
'rc_comment'],
852 return $this->watchMsgCache->getWithSetCallback(
853 $this->watchMsgCache->makeKey(
854 'watching-users-msg',
856 $this->getUser()->getName(),
857 $this->getLanguage()->getCode()
859 function () use ( $count ) {
860 return $this->msg(
'number-of-watching-users-for-recent-changes' )
861 ->numParams( $count )->escaped();
873 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
888 'Calling ChangesList::userCan without specifying a performer is deprecated since 1.46',
891 $performer = RequestContext::getMain()->getAuthority();
895 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
898 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
908 return '<strong class="mw-watched">' . $link .
'</strong>';
910 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
921 $this->insertPageTools( $s, $rc );
931 private function insertPageTools( &$s, &$rc ) {
935 || !$rc->mAttribs[
'rc_this_oldid']
936 || !$rc->mAttribs[
'rc_cur_id']
942 $title = $rc->getTitle();
943 $revRecord =
new MutableRevisionRecord( $title );
944 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
945 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
946 $user =
new UserIdentityValue(
947 (
int)$rc->mAttribs[
'rc_user'],
948 $rc->mAttribs[
'rc_user_text']
950 $revRecord->setUser( $user );
952 $tools =
new PagerTools(
956 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
958 $this->getHookRunner(),
965 $s .= $tools->toHTML();
975 $this->insertRollback( $s, $rc );
985 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
994 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
995 $this->tagsCache->makeKey(
996 $rc->mAttribs[
'ts_tags'],
997 $this->getUser()->getName(),
998 $this->getLanguage()->getCode()
1000 fn () => ChangeTags::formatSummaryRow(
1001 $rc->mAttribs[
'ts_tags'],
1006 $classes = array_merge( $classes, $newClasses );
1007 $s .= $this->message[
'word-separator'] . $tagSummary;
1018 $this->insertTags( $s, $rc, $classes );
1032 if ( empty( $rc->mAttribs[ WatchlistLabelCondition::LABEL_IDS ] ) ) {
1035 $labelIds = explode(
',', $rc->mAttribs[ WatchlistLabelCondition::LABEL_IDS ] );
1037 foreach ( $labelIds as $labelId ) {
1038 $classes[] = SpecialWatchlist::WATCHLIST_LABEL_CSS_CLASS_PREFIX . $labelId;
1039 $labelStrings[] =
wfEscapeWikiText( $this->userLabels[ $labelId ]->getName() );
1041 $labelsList = $this->msg(
'watchlistlabels-list-wrapper' )->params(
1042 $this->getLanguage()->commaList( $labelStrings )
1044 return $this->message[
'word-separator'] .
1047 [
'class' =>
'mw-changeslist-watchlistlabels' ],
1048 $this->msg(
'parentheses' )->rawParams( $labelsList )->escaped()
1058 $s .= $this->getLabels( $rc, $classes );
1074 return self::isUnpatrolled( $rc, $this->getUser() );
1084 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
1085 $rcSource = $rc->mAttribs[
'rc_source'];
1086 $rcLogType = $rc->mAttribs[
'rc_log_type'];
1088 $isPatrolled = $rc->rc_patrolled;
1089 $rcSource = $rc->rc_source;
1090 $rcLogType = $rc->rc_log_type;
1093 if ( $isPatrolled ) {
1098 ( $rcSource === RecentChange::SRC_NEW && $user->
useNPPatrol() ) ||
1112 return $rcObj->getAttribute(
'rc_source' ) === RecentChange::SRC_CATEGORIZE
1113 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1126 case RecentChange::SRC_EDIT:
1127 case RecentChange::SRC_CATEGORIZE:
1128 case RecentChange::SRC_NEW:
1129 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1131 case RecentChange::SRC_LOG:
1132 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1133 $attrs[
'data-mw-logaction'] =
1134 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1138 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1151 $this->changeLinePrefixer = $prefixer;
1159 $this->userLabels = $userLabels;
1164class_alias( ChangesList::class,
'ChangesList' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
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()
getContext()
Get the base IContextSource object.
Group all the pieces relevant to the context of a request into one instance.
A value class to process existing log entries.
Class to simplify the use of log pages.
A class containing constants representing the names of configuration variables.
const RecentChangesFlags
Name constant for the RecentChangesFlags setting, for use with Config::get()
const RCChangedSizeThreshold
Name constant for the RCChangedSizeThreshold setting, for use with Config::get()
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()
Interface for objects which can provide a MediaWiki context on request.