30use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
49 use ProtectedHookAccessorTrait;
101 public function __construct( $context, array $filterGroups = [] ) {
103 $this->preCacheMessages();
105 $this->filterGroups = $filterGroups;
107 $services = MediaWikiServices::getInstance();
108 $this->linkRenderer = $services->getLinkRenderer();
109 $this->commentFormatter = $services->getRowCommentFormatter();
125 $services = MediaWikiServices::getInstance();
127 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
128 $userOptionsLookup = $services->getUserOptionsLookup();
131 $userOptionsLookup->getBoolOption( $user,
'usenewrc' )
154 throw new RuntimeException(
'recentChangesLine should be implemented' );
164 $highlightColorDivs =
'';
165 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
166 $highlightColorDivs .= Html::rawElement(
169 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
170 'data-color' => $color
175 return Html::rawElement(
177 [
'class' =>
'mw-rcfilters-ui-highlights' ],
187 $this->watchlist = $value;
195 return (
bool)$this->watchlist;
202 private function preCacheMessages() {
203 if ( !isset( $this->message ) ) {
206 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
207 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
209 $this->message[$msg] = $this->msg( $msg )->escaped();
223 $this->
getConfig()->
get( MainConfigNames::RecentChangesFlags ) as $flag => $_
225 $f .= isset( $flags[$flag] ) && $flags[$flag]
242 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
243 $logType = $rc->mAttribs[
'rc_log_type'];
246 $classes[] = self::CSS_CLASS_PREFIX .
'log';
247 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
249 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
250 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
251 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
256 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
257 ? self::CSS_CLASS_PREFIX .
'line-watched'
258 : self::CSS_CLASS_PREFIX .
'line-not-watched';
275 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
276 $rc->mAttribs[
'rc_namespace'] );
278 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
279 $classes[] = Sanitizer::escapeClass(
280 self::CSS_CLASS_PREFIX .
282 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
285 foreach ( $this->filterGroups as $filterGroup ) {
286 foreach ( $filterGroup->getFilters() as $filter ) {
287 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
305 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
306 static $flagInfos =
null;
308 if ( $flagInfos ===
null ) {
309 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
310 ->get( MainConfigNames::RecentChangesFlags );
312 foreach ( $recentChangesFlags as $key => $value ) {
313 $flagInfos[$key][
'letter'] = $value[
'letter'];
314 $flagInfos[$key][
'title'] = $value[
'title'];
316 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
320 $context = $context ?: RequestContext::getMain();
323 if ( isset( $map[$flag] ) ) {
327 $info = $flagInfos[$flag];
328 return Html::element(
'abbr', [
329 'class' => $info[
'class'],
339 $this->rc_cache = [];
340 $this->rcMoveIndex = 0;
341 $this->rcCacheIndex = 0;
342 $this->lastdate =
'';
343 $this->rclistOpen =
false;
345 'mediawiki.interface.helpers.styles',
346 'mediawiki.special.changeslist'
349 return '<div class="mw-changeslist">';
356 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
357 $this->formattedComments = $this->commentFormatter->createBatch()
359 $this->commentFormatter->rows( $rows )
360 ->commentKey(
'rc_comment' )
361 ->namespaceField(
'rc_namespace' )
362 ->titleField(
'rc_title' )
363 ->indexField(
'rc_id' )
381 $context = RequestContext::getMain();
386 $szdiff = $new - $old;
388 $lang = $context->getLanguage();
389 $config = $context->getConfig();
390 $code = $lang->getCode();
391 static $fastCharDiff = [];
392 if ( !isset( $fastCharDiff[$code] ) ) {
393 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
394 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
397 $formattedSize = $lang->formatNum( $szdiff );
399 if ( !$fastCharDiff[$code] ) {
400 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
403 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
409 if ( $szdiff === 0 ) {
410 $formattedSizeClass =
'mw-plusminus-null';
411 } elseif ( $szdiff > 0 ) {
412 $formattedSize =
'+' . $formattedSize;
413 $formattedSizeClass =
'mw-plusminus-pos';
415 $formattedSizeClass =
'mw-plusminus-neg';
417 $formattedSizeClass .=
' mw-diff-bytes';
419 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
421 return Html::element( $tag,
422 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
423 $formattedSize ) . $lang->getDirMark();
434 $oldlen = $old->mAttribs[
'rc_old_len'];
437 $newlen = $new->mAttribs[
'rc_new_len'];
439 $newlen = $old->mAttribs[
'rc_new_len'];
442 if ( $oldlen ===
null || $newlen ===
null ) {
446 return self::showCharacterDifference( $oldlen, $newlen, $this->
getContext() );
454 $out = $this->rclistOpen ?
"</ul>\n" :
'';
483 $class = trim(
'mw-changeslist-date ' . $className );
484 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
485 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
488 [
'class' => $class ],
489 [
'oldid' => $rev->
getId() ]
492 $link = htmlspecialchars( $date );
494 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
495 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
496 $link =
"<span class=\"$class\">$link</span>";
498 return Html::element(
'span', [
499 'class' =>
'mw-changeslist-time'
508 # Make date header if necessary
510 if ( $date != $this->lastdate ) {
511 if ( $this->lastdate !=
'' ) {
514 $s .= Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
515 $this->lastdate = $date;
516 $this->rclistOpen =
true;
526 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
527 $page =
new LogPage( $logtype );
528 $logname = $page->getName()->setContext( $this->
getContext() )->text();
529 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
530 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
532 if ( $useParentheses ) {
533 $s .= $this->
msg(
'parentheses' )->rawParams(
549 $rc->mAttribs[
'rc_type'] ==
RC_NEW ||
550 $rc->mAttribs[
'rc_type'] ==
RC_LOG ||
553 $diffLink = $this->message[
'diff'];
554 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
555 $diffLink = $this->message[
'diff'];
558 'curid' => $rc->mAttribs[
'rc_cur_id'],
559 'diff' => $rc->mAttribs[
'rc_this_oldid'],
560 'oldid' => $rc->mAttribs[
'rc_last_oldid']
563 $diffLink = $this->linkRenderer->makeKnownLink(
566 [
'class' =>
'mw-changeslist-diff' ],
571 $histLink = $this->message[
'hist'];
573 $histLink = $this->linkRenderer->makeKnownLink(
576 [
'class' =>
'mw-changeslist-history' ],
578 'curid' => $rc->mAttribs[
'rc_cur_id'],
579 'action' =>
'history'
584 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
585 Html::rawElement(
'span', [], $diffLink ) .
586 Html::rawElement(
'span', [], $histLink )
588 ' <span class="mw-changeslist-separator"></span> ';
603 if ( $rc->getTitle()->isRedirect() ) {
604 $params = [
'redirect' =>
'no' ];
607 $articlelink = $this->linkRenderer->makeLink(
610 [
'class' =>
'mw-changeslist-title' ],
613 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
614 $class =
'history-deleted';
615 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
616 $class .=
' mw-history-suppressed';
618 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
620 # To allow for boldening pages watched by this user
621 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
623 $articlelink .= $this->
getLanguage()->getDirMark();
625 # TODO: Deprecate the $s argument, it seems happily unused.
627 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
628 $s, $rc, $unpatrolled, $watched );
631 $watchlistExpiry =
'';
632 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
636 return "{$s} {$articlelink}{$watchlistExpiry}";
648 if ( $item->isExpired() ) {
653 $widget =
new IconWidget( [
655 'title' => $daysLeftText,
656 'classes' => [
'mw-changesList-watchlistExpiry' ],
658 $widget->setAttributes( [
661 'aria-label' => $this->msg(
'watchlist-expires-in-aria-label' )->text(),
663 'data-days-left' => $item->getExpiryInDays(),
690 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
691 return Html::element(
'span', [
'class' => $separatorClass ] ) .
' ' .
692 '<span class="mw-changeslist-date mw-changeslist-time">' .
693 htmlspecialchars( $this->getLanguage()->userTime(
694 $rc->mAttribs[
'rc_timestamp'],
696 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
716 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
717 $deletedClass =
'history-deleted';
718 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
719 $deletedClass .=
' mw-history-suppressed';
721 $s .=
' <span class="' . $deletedClass .
'">' .
722 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
724 $s .= $this->getLanguage()->getDirMark();
725 $s .= $this->userLinkCache->getWithSetCallback(
726 $this->userLinkCache->makeKey(
727 $rc->mAttribs[
'rc_user_text'],
728 $this->getUser()->getName(),
729 $this->getLanguage()->getCode()
731 static function () use ( $rc ) {
732 return Linker::userLink(
733 $rc->mAttribs[
'rc_user'],
734 $rc->mAttribs[
'rc_user_text']
735 ) . Linker::userToolLinks(
736 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
754 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
755 $formatter->setContext( $this->
getContext() );
756 $formatter->setShowUserToolLinks(
true );
757 $mark = $this->getLanguage()->getDirMark();
759 return Html::openElement(
'span', [
'class' =>
'mw-changeslist-log-entry' ] )
760 . $formatter->getActionText()
762 . $formatter->getComment()
763 . $this->message[
'word-separator']
764 . $formatter->getActionLinks()
765 . Html::closeElement(
'span' );
774 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
775 $deletedClass =
'history-deleted';
776 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
777 $deletedClass .=
' mw-history-suppressed';
779 return ' <span class="' . $deletedClass .
' comment">' .
780 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
781 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
782 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
784 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
786 return $this->commentFormatter->formatBlock(
787 $rc->mAttribs[
'rc_comment'],
809 return $this->watchMsgCache->getWithSetCallback(
810 $this->watchMsgCache->makeKey(
811 'watching-users-msg',
814 $this->getLanguage()->getCode()
816 function () use ( $count ) {
817 return $this->msg(
'number-of-watching-users-for-recent-changes' )
818 ->numParams( $count )->escaped();
830 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
843 $performer ??= RequestContext::getMain()->getAuthority();
845 if ( $rc->mAttribs[
'rc_type'] ==
RC_LOG ) {
846 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
849 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
859 return '<strong class="mw-watched">' . $link .
'</strong>';
861 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
872 $this->insertPageTools( $s, $rc );
883 private function insertPageTools( &$s, &$rc ) {
885 if ( !in_array( $rc->mAttribs[
'rc_type'], [
RC_EDIT,
RC_NEW ] )
887 || !$rc->mAttribs[
'rc_this_oldid']
888 || !$rc->mAttribs[
'rc_cur_id']
894 $title = $rc->getTitle();
896 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
897 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
899 (
int)$rc->mAttribs[
'rc_user'],
900 $rc->mAttribs[
'rc_user_text']
902 $revRecord->setUser( $user );
908 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
909 && $rc->mAttribs[
'rc_type'] !=
RC_NEW,
910 $this->getHookRunner(),
914 MediaWikiServices::getInstance()->getLinkRenderer()
917 $s .= $tools->toHTML();
927 $this->insertRollback( $s, $rc );
937 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
946 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
947 $this->tagsCache->makeKey(
948 $rc->mAttribs[
'ts_tags'],
949 $this->getUser()->getName(),
950 $this->getLanguage()->getCode()
953 $rc->mAttribs[
'ts_tags'],
958 $classes = array_merge( $classes, $newClasses );
959 $s .=
' ' . $tagSummary;
970 $this->insertTags( $s, $rc, $classes );
979 return self::isUnpatrolled( $rc, $this->
getUser() );
989 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
990 $rcType = $rc->mAttribs[
'rc_type'];
991 $rcLogType = $rc->mAttribs[
'rc_log_type'];
993 $isPatrolled = $rc->rc_patrolled;
994 $rcType = $rc->rc_type;
995 $rcLogType = $rc->rc_log_type;
998 if ( $isPatrolled ) {
1017 return intval( $rcObj->getAttribute(
'rc_type' ) ) ===
RC_CATEGORIZE
1018 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1031 case RecentChange::SRC_EDIT:
1032 case RecentChange::SRC_CATEGORIZE:
1033 case RecentChange::SRC_NEW:
1034 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1036 case RecentChange::SRC_LOG:
1037 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1038 $attrs[
'data-mw-logaction'] =
1039 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1043 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1056 $this->changeLinePrefixer = $prefixer;
getWatchlistExpiry(WatchedItemStoreInterface $store, PageIdentity $page, UserIdentity $user)
Get existing expiry from the database.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
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.
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.
static revDateLink(RevisionRecord $rev, Authority $performer, Language $lang, $title=null, $className='')
Render the date and time of a revision in the current user language based on whether the user is able...
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.
Marks HTML that shouldn't be escaped.
Base class for language-specific code.
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.
Store key-value entries in a size-limited in-memory LRU cache.
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()
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
Utility class for creating new RC entries.
getAttribute( $name)
Get an attribute value.
Interface for objects which can provide a MediaWiki context on request.