7namespace MediaWiki\RecentChanges;
9use MediaWiki\ChangeTags\ChangeTagsFormatter;
10use MediaWiki\CommentFormatter\RowCommentFormatter;
11use MediaWiki\Context\ContextSource;
12use MediaWiki\Context\IContextSource;
13use MediaWiki\HookContainer\HookRunner;
14use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
15use MediaWiki\Html\Html;
16use MediaWiki\Language\Language;
17use MediaWiki\Linker\Linker;
18use MediaWiki\Linker\LinkRenderer;
19use MediaWiki\Linker\UserLinkRenderer;
20use MediaWiki\Logging\DatabaseLogEntry;
21use MediaWiki\Logging\LogEventsList;
22use MediaWiki\Logging\LogFormatterFactory;
23use MediaWiki\Logging\LogPage;
24use MediaWiki\MainConfigNames;
25use MediaWiki\MediaWikiServices;
26use MediaWiki\Parser\Sanitizer;
27use MediaWiki\Permissions\Authority;
28use MediaWiki\RecentChanges\ChangesListQuery\WatchlistLabelCondition;
29use MediaWiki\RecentChanges\ChangeTools\ChangeToolsFactory;
30use MediaWiki\Revision\MutableRevisionRecord;
31use MediaWiki\Revision\RevisionRecord;
32use MediaWiki\Specials\SpecialWatchlist;
33use MediaWiki\Title\Title;
34use MediaWiki\User\User;
35use MediaWiki\User\UserIdentityValue;
36use MediaWiki\Watchlist\WatchedItem;
37use MediaWiki\Watchlist\WatchlistLabel;
41use Wikimedia\HtmlArmor\HtmlArmor;
42use Wikimedia\ObjectCache\MapCacheLRU;
43use Wikimedia\Rdbms\IResultWrapper;
54 use ProtectedHookAccessorTrait;
131 $this->preCacheMessages();
136 $this->linkRenderer = $services->getLinkRenderer();
137 $this->commentFormatter = $services->getRowCommentFormatter();
138 $this->logFormatterFactory = $services->getLogFormatterFactory();
139 $this->userLinkRenderer = $services->getUserLinkRenderer();
140 $this->changeToolsFactory = $changeToolsFactory ?? $services->getChangeToolsFactory();
141 $this->changeTagsFormatter = $changeTagsFormatter ?? $services->getChangeTagsFormatter();
158 $user = $context->getUser();
159 $sk = $context->getSkin();
163 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
164 $userOptionsLookup = $services->getUserOptionsLookup();
165 $new = $context->getRequest()->getBool(
190 throw new RuntimeException(
'recentChangesLine should be implemented' );
200 $highlightColorDivs =
'';
201 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
202 $highlightColorDivs .= Html::rawElement(
205 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
206 'data-color' => $color
211 return Html::rawElement(
213 [
'class' =>
'mw-rcfilters-ui-highlights' ],
223 $this->watchlist = $value;
238 private function preCacheMessages() {
240 if ( !isset( $this->message ) ) {
243 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
244 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
246 $this->message[$msg] = $this->
msg( $msg )->escaped();
262 $f .= isset( $flags[$flag] ) && $flags[$flag]
279 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
280 $logType = $rc->mAttribs[
'rc_log_type'];
283 $classes[] = self::CSS_CLASS_PREFIX .
'log';
284 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
286 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
287 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
288 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
293 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
294 ? self::CSS_CLASS_PREFIX .
'line-watched'
295 : self::CSS_CLASS_PREFIX .
'line-not-watched';
312 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
313 $rc->mAttribs[
'rc_namespace'] );
316 $classes[] = Sanitizer::escapeClass(
317 self::CSS_CLASS_PREFIX .
319 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
322 $this->filterGroups->applyCssClassIfNeeded( $this->
getContext(), $rc, $classes );
338 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
339 static $flagInfos =
null;
341 if ( $flagInfos ===
null ) {
345 foreach ( $recentChangesFlags as $key => $value ) {
346 $flagInfos[$key][
'letter'] = $value[
'letter'];
347 $flagInfos[$key][
'title'] = $value[
'title'];
349 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
354 if ( isset( $map[$flag] ) ) {
358 $info = $flagInfos[$flag];
360 'class' => $info[
'class'],
370 $this->rc_cache = [];
371 $this->rcMoveIndex = 0;
372 $this->rcCacheIndex = 0;
373 $this->lastdate =
'';
374 $this->rclistOpen =
false;
376 'mediawiki.interface.helpers.styles',
377 'mediawiki.special.changeslist'
380 return '<div class="mw-changeslist">';
387 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
388 $this->formattedComments = $this->commentFormatter->createBatch()
390 $this->commentFormatter->rows( $rows )
391 ->commentKey(
'rc_comment' )
392 ->namespaceField(
'rc_namespace' )
393 ->titleField(
'rc_title' )
394 ->indexField(
'rc_id' )
413 $szdiff = $new - $old;
415 $lang = $context->getLanguage();
416 $config = $context->getConfig();
417 $code = $lang->getCode();
418 static $fastCharDiff = [];
419 if ( !isset( $fastCharDiff[$code] ) ) {
421 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
424 $formattedSize = $lang->formatNum( $szdiff );
426 if ( !$fastCharDiff[$code] ) {
427 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
436 if ( $szdiff === 0 ) {
437 $formattedSizeClass =
'mw-plusminus-null';
438 } elseif ( $szdiff > 0 ) {
439 $formattedSize =
'+' . $formattedSize;
440 $formattedSizeClass =
'mw-plusminus-pos';
442 $formattedSizeClass =
'mw-plusminus-neg';
444 $formattedSizeClass .=
' mw-diff-bytes';
446 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
449 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
461 $oldlen = $old->mAttribs[
'rc_old_len'];
464 $newlen = $new->mAttribs[
'rc_new_len'];
466 $newlen = $old->mAttribs[
'rc_new_len'];
469 if ( $oldlen ===
null || $newlen ===
null ) {
481 $out = $this->rclistOpen ?
"</ul>\n" :
'';
510 $class = trim(
'mw-changeslist-date ' . $className );
511 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
512 $link = Html::rawElement(
'bdi', [
'dir' => $lang->
getDir() ],
516 [
'class' => $class ],
517 [
'oldid' => $rev->
getId() ]
521 $link = htmlspecialchars( $date );
523 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
524 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
525 $link =
"<span class=\"$class\">$link</span>";
528 'class' =>
'mw-changeslist-time'
537 # Make date header if necessary
539 if ( $date != $this->lastdate ) {
540 if ( $this->lastdate !=
'' ) {
543 $s .=
Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
544 $this->lastdate = $date;
545 $this->rclistOpen =
true;
555 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
556 $page =
new LogPage( $logtype );
557 $logname = $page->getName()->setContext( $this->
getContext() )->text();
558 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
559 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
561 if ( $useParentheses ) {
562 $s .= $this->
msg(
'parentheses' )->rawParams(
581 $diffLink = $this->message[
'diff'];
582 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
583 $diffLink = $this->message[
'diff'];
586 'curid' => $rc->mAttribs[
'rc_cur_id'],
587 'diff' => $rc->mAttribs[
'rc_this_oldid'],
588 'oldid' => $rc->mAttribs[
'rc_last_oldid']
591 $diffLink = $this->linkRenderer->makeKnownLink(
594 [
'class' =>
'mw-changeslist-diff' ],
598 $histLink = $this->linkRenderer->makeKnownLink(
601 [
'class' =>
'mw-changeslist-history' ],
603 'curid' => $rc->mAttribs[
'rc_cur_id'],
604 'action' =>
'history'
608 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
609 Html::rawElement(
'span', [], $diffLink ) .
610 Html::rawElement(
'span', [], $histLink )
612 ' <span class="mw-changeslist-separator"></span> ';
627 if ( $rc->getTitle()->isRedirect() ) {
628 $params = [
'redirect' =>
'no' ];
631 $articlelink = $this->linkRenderer->makeLink(
634 [
'class' =>
'mw-changeslist-title' ],
637 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
638 $class =
'history-deleted';
639 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
640 $class .=
' mw-history-suppressed';
642 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
645 $articlelink = Html::rawElement(
'bdi', [
'dir' => $dir ], $articlelink );
646 # To allow for boldening pages watched by this user
647 # Don't wrap result of this with another tag, see T376814
648 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
650 # TODO: Deprecate the $s argument, it seems happily unused.
652 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
653 $s, $rc, $unpatrolled, $watched );
656 $watchlistExpiry =
'';
658 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
662 return "{$s} {$articlelink}{$watchlistExpiry}";
674 if ( $item->isExpired() ) {
679 $widget =
new IconWidget( [
681 'title' => $daysLeftText,
682 'classes' => [
'mw-changesList-watchlistExpiry' ],
684 $widget->setAttributes( [
687 'aria-label' => $this->
msg(
'watchlist-expires-in-aria-label' )->text(),
689 'data-days-left' => $item->getExpiryInDays(),
716 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
717 return Html::element(
'span', [
'class' => $separatorClass ] ) . $this->message[
'word-separator'] .
718 '<span class="mw-changeslist-date mw-changeslist-time">' .
720 $rc->mAttribs[
'rc_timestamp'],
722 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
742 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
743 $deletedClass =
'history-deleted';
744 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
745 $deletedClass .=
' mw-history-suppressed';
747 $s .=
' <span class="' . $deletedClass .
'">' .
748 $this->
msg(
'rev-deleted-user' )->escaped() .
'</span>';
750 $s .= $this->linkRenderer->makeUserLink(
751 $rc->getPerformerIdentity(),
754 # Don't wrap result of this with another tag, see T376814
755 $s .= $this->userLinkCache->getWithSetCallback(
756 $this->userLinkCache->makeKey(
757 $rc->mAttribs[
'rc_user_text'],
758 $this->getUser()->getName(),
759 $this->getLanguage()->getCode()
763 static fn () => Linker::userToolLinks(
764 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
779 $entry = DatabaseLogEntry::newFromRow( $rc->mAttribs );
780 $formatter = $this->logFormatterFactory->newFromEntry( $entry );
781 $formatter->setContext( $this->
getContext() );
782 $formatter->setShowUserToolLinks(
true );
784 $comment = $formatter->getComment();
785 if ( $comment !==
'' ) {
787 $comment = Html::rawElement(
'bdi', [
'dir' => $dir ], $comment );
790 $html = $formatter->getActionText() . $this->message[
'word-separator'] . $comment .
791 $this->message[
'word-separator'] . $formatter->getActionLinks();
792 $classes = [
'mw-changeslist-log-entry' ];
796 $this->getHookRunner()->onChangesListInsertLogEntry( $entry, $this->
getContext(), $html, $classes, $attribs );
797 $attribs = array_filter( $attribs,
798 Sanitizer::isReservedDataAttribute( ... ),
801 $attribs[
'class'] = $classes;
803 return Html::rawElement(
'span', $attribs, $html );
812 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
813 $deletedClass =
'history-deleted';
814 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
815 $deletedClass .=
' mw-history-suppressed';
817 return ' <span class="' . $deletedClass .
' comment">' .
818 $this->
msg(
'rev-deleted-comment' )->escaped() .
'</span>';
819 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
820 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
822 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
824 return $this->commentFormatter->formatBlock(
825 $rc->mAttribs[
'rc_comment'],
847 return $this->watchMsgCache->getWithSetCallback(
848 $this->watchMsgCache->makeKey(
849 'watching-users-msg',
854 function () use ( $count ) {
855 return $this->
msg(
'number-of-watching-users-for-recent-changes' )
856 ->numParams( $count )->escaped();
868 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
881 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
884 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
894 return '<strong class="mw-watched">' . $link .
'</strong>';
896 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
907 $this->insertPageTools( $s, $rc );
917 private function insertPageTools( &$s, &$rc ) {
921 || !$rc->mAttribs[
'rc_this_oldid']
922 || !$rc->mAttribs[
'rc_cur_id']
928 $title = $rc->getTitle();
929 $revRecord =
new MutableRevisionRecord( $title );
930 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
931 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
932 $user =
new UserIdentityValue(
933 (
int)$rc->mAttribs[
'rc_user'],
934 $rc->mAttribs[
'rc_user_text']
936 $revRecord->setUser( $user );
938 $tools = $this->changeToolsFactory->buildChangeTools(
942 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
947 $s .= $tools->toHTML();
967 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
976 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
977 $this->tagsCache->makeKey(
978 $rc->mAttribs[
'ts_tags'],
979 $this->getUser()->getName(),
980 $this->getLanguage()->getCode()
982 fn () => $this->changeTagsFormatter->formatTagsAsSummaryList(
983 $rc->mAttribs[
'ts_tags'],
985 $this->getAuthority()
988 $classes = array_merge( $classes, $newClasses );
989 $s .= $this->message[
'word-separator'] . $tagSummary;
1014 if ( empty( $rc->mAttribs[ WatchlistLabelCondition::LABEL_IDS ] ) ) {
1017 $labelIds = explode(
',', $rc->mAttribs[ WatchlistLabelCondition::LABEL_IDS ] );
1019 foreach ( $labelIds as $labelId ) {
1021 if ( !isset( $this->userLabels[ $labelId ] ) ) {
1024 $classes[] = SpecialWatchlist::WATCHLIST_LABEL_CSS_CLASS_PREFIX . $labelId;
1025 $labelStrings[] =
wfEscapeWikiText( $this->userLabels[ $labelId ]->getName() );
1027 if ( !$labelStrings ) {
1030 $labelsList = $this->
msg(
'watchlistlabels-list-wrapper' )->params(
1033 return $this->message[
'word-separator'] .
1036 [
'class' =>
'mw-changeslist-watchlistlabels' ],
1037 $this->
msg(
'parentheses' )->rawParams( $labelsList )->escaped()
1047 $s .= $this->
getLabels( $rc, $classes );
1063 return self::isUnpatrolled( $rc, $this->
getUser() );
1073 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
1074 $rcSource = $rc->mAttribs[
'rc_source'];
1075 $rcLogType = $rc->mAttribs[
'rc_log_type'];
1077 $isPatrolled = $rc->rc_patrolled;
1078 $rcSource = $rc->rc_source;
1079 $rcLogType = $rc->rc_log_type;
1082 if ( $isPatrolled ) {
1102 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1118 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1121 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1122 $attrs[
'data-mw-logaction'] =
1123 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1127 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1140 $this->changeLinePrefixer = $prefixer;
1153class_alias( ChangesList::class,
'ChangesList' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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.
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.