26use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
53 use ProtectedHookAccessorTrait;
107 public function __construct( $context, array $filterGroups = [] ) {
109 $this->preCacheMessages();
111 $this->filterGroups = $filterGroups;
113 $services = MediaWikiServices::getInstance();
114 $this->linkRenderer = $services->getLinkRenderer();
115 $this->commentFormatter = $services->getRowCommentFormatter();
116 $this->logFormatterFactory = $services->getLogFormatterFactory();
132 $services = MediaWikiServices::getInstance();
134 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
135 $userOptionsLookup = $services->getUserOptionsLookup();
138 $userOptionsLookup->getBoolOption( $user,
'usenewrc' )
161 throw new RuntimeException(
'recentChangesLine should be implemented' );
171 $highlightColorDivs =
'';
172 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
173 $highlightColorDivs .= Html::rawElement(
176 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
177 'data-color' => $color
182 return Html::rawElement(
184 [
'class' =>
'mw-rcfilters-ui-highlights' ],
194 $this->watchlist = $value;
202 return (
bool)$this->watchlist;
209 private function preCacheMessages() {
210 if ( !isset( $this->message ) ) {
213 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
214 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
216 $this->message[$msg] = $this->msg( $msg )->escaped();
230 $this->
getConfig()->
get( MainConfigNames::RecentChangesFlags ) as $flag => $_
232 $f .= isset( $flags[$flag] ) && $flags[$flag]
249 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
250 $logType = $rc->mAttribs[
'rc_log_type'];
253 $classes[] = self::CSS_CLASS_PREFIX .
'log';
254 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
256 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
257 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
258 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
263 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
264 ? self::CSS_CLASS_PREFIX .
'line-watched'
265 : self::CSS_CLASS_PREFIX .
'line-not-watched';
282 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
283 $rc->mAttribs[
'rc_namespace'] );
285 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
286 $classes[] = Sanitizer::escapeClass(
287 self::CSS_CLASS_PREFIX .
289 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
292 foreach ( $this->filterGroups as $filterGroup ) {
293 foreach ( $filterGroup->getFilters() as $filter ) {
294 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
312 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
313 static $flagInfos =
null;
315 if ( $flagInfos ===
null ) {
316 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
317 ->get( MainConfigNames::RecentChangesFlags );
319 foreach ( $recentChangesFlags as $key => $value ) {
320 $flagInfos[$key][
'letter'] = $value[
'letter'];
321 $flagInfos[$key][
'title'] = $value[
'title'];
323 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
327 $context = $context ?: RequestContext::getMain();
330 if ( isset( $map[$flag] ) ) {
334 $info = $flagInfos[$flag];
335 return Html::element(
'abbr', [
336 'class' => $info[
'class'],
346 $this->rc_cache = [];
347 $this->rcMoveIndex = 0;
348 $this->rcCacheIndex = 0;
349 $this->lastdate =
'';
350 $this->rclistOpen =
false;
352 'mediawiki.interface.helpers.styles',
353 'mediawiki.special.changeslist'
356 return '<div class="mw-changeslist">';
363 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
364 $this->formattedComments = $this->commentFormatter->createBatch()
366 $this->commentFormatter->rows( $rows )
367 ->commentKey(
'rc_comment' )
368 ->namespaceField(
'rc_namespace' )
369 ->titleField(
'rc_title' )
370 ->indexField(
'rc_id' )
388 $context = RequestContext::getMain();
393 $szdiff = $new - $old;
395 $lang = $context->getLanguage();
396 $config = $context->getConfig();
397 $code = $lang->getCode();
398 static $fastCharDiff = [];
399 if ( !isset( $fastCharDiff[$code] ) ) {
400 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
401 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
404 $formattedSize = $lang->formatNum( $szdiff );
406 if ( !$fastCharDiff[$code] ) {
407 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
410 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
416 if ( $szdiff === 0 ) {
417 $formattedSizeClass =
'mw-plusminus-null';
418 } elseif ( $szdiff > 0 ) {
419 $formattedSize =
'+' . $formattedSize;
420 $formattedSizeClass =
'mw-plusminus-pos';
422 $formattedSizeClass =
'mw-plusminus-neg';
424 $formattedSizeClass .=
' mw-diff-bytes';
426 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
428 return Html::element( $tag,
429 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
430 $formattedSize ) . $lang->getDirMark();
441 $oldlen = $old->mAttribs[
'rc_old_len'];
444 $newlen = $new->mAttribs[
'rc_new_len'];
446 $newlen = $old->mAttribs[
'rc_new_len'];
449 if ( $oldlen ===
null || $newlen ===
null ) {
453 return self::showCharacterDifference( $oldlen, $newlen, $this->
getContext() );
461 $out = $this->rclistOpen ?
"</ul>\n" :
'';
488 $time = $lang->userTime( $ts, $performer->
getUser() );
489 $date = $lang->userTimeAndDate( $ts, $performer->
getUser() );
490 $class = trim(
'mw-changeslist-date ' . $className );
491 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
492 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
495 [
'class' => $class ],
496 [
'oldid' => $rev->
getId() ]
499 $link = htmlspecialchars( $date );
501 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
502 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
503 $link =
"<span class=\"$class\">$link</span>";
505 return Html::element(
'span', [
506 'class' =>
'mw-changeslist-time'
515 # Make date header if necessary
517 if ( $date != $this->lastdate ) {
518 if ( $this->lastdate !=
'' ) {
521 $s .= Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
522 $this->lastdate = $date;
523 $this->rclistOpen =
true;
533 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
534 $page =
new LogPage( $logtype );
535 $logname = $page->getName()->setContext( $this->
getContext() )->text();
536 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
537 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
539 if ( $useParentheses ) {
540 $s .= $this->
msg(
'parentheses' )->rawParams(
556 $rc->mAttribs[
'rc_type'] ==
RC_NEW ||
557 $rc->mAttribs[
'rc_type'] ==
RC_LOG ||
560 $diffLink = $this->message[
'diff'];
561 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
562 $diffLink = $this->message[
'diff'];
565 'curid' => $rc->mAttribs[
'rc_cur_id'],
566 'diff' => $rc->mAttribs[
'rc_this_oldid'],
567 'oldid' => $rc->mAttribs[
'rc_last_oldid']
570 $diffLink = $this->linkRenderer->makeKnownLink(
573 [
'class' =>
'mw-changeslist-diff' ],
578 $histLink = $this->message[
'hist'];
580 $histLink = $this->linkRenderer->makeKnownLink(
583 [
'class' =>
'mw-changeslist-history' ],
585 'curid' => $rc->mAttribs[
'rc_cur_id'],
586 'action' =>
'history'
591 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
592 Html::rawElement(
'span', [], $diffLink ) .
593 Html::rawElement(
'span', [], $histLink )
595 ' <span class="mw-changeslist-separator"></span> ';
610 if ( $rc->getTitle()->isRedirect() ) {
611 $params = [
'redirect' =>
'no' ];
614 $articlelink = $this->linkRenderer->makeLink(
617 [
'class' =>
'mw-changeslist-title' ],
620 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
621 $class =
'history-deleted';
622 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
623 $class .=
' mw-history-suppressed';
625 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
627 # To allow for boldening pages watched by this user
628 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
630 $articlelink .= $this->
getLanguage()->getDirMark();
632 # TODO: Deprecate the $s argument, it seems happily unused.
634 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
635 $s, $rc, $unpatrolled, $watched );
638 $watchlistExpiry =
'';
639 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
643 return "{$s} {$articlelink}{$watchlistExpiry}";
655 if ( $item->isExpired() ) {
660 $widget =
new IconWidget( [
662 'title' => $daysLeftText,
663 'classes' => [
'mw-changesList-watchlistExpiry' ],
665 $widget->setAttributes( [
668 'aria-label' => $this->msg(
'watchlist-expires-in-aria-label' )->text(),
670 'data-days-left' => $item->getExpiryInDays(),
697 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
698 return Html::element(
'span', [
'class' => $separatorClass ] ) .
' ' .
699 '<span class="mw-changeslist-date mw-changeslist-time">' .
700 htmlspecialchars( $this->getLanguage()->userTime(
701 $rc->mAttribs[
'rc_timestamp'],
703 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
723 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
724 $deletedClass =
'history-deleted';
725 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
726 $deletedClass .=
' mw-history-suppressed';
728 $s .=
' <span class="' . $deletedClass .
'">' .
729 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
731 $s .= $this->getLanguage()->getDirMark();
732 $s .= $this->userLinkCache->getWithSetCallback(
733 $this->userLinkCache->makeKey(
734 $rc->mAttribs[
'rc_user_text'],
735 $this->getUser()->getName(),
736 $this->getLanguage()->getCode()
738 static function () use ( $rc ) {
739 return Linker::userLink(
740 $rc->mAttribs[
'rc_user'],
741 $rc->mAttribs[
'rc_user_text']
742 ) . Linker::userToolLinks(
743 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
761 $formatter = $this->logFormatterFactory->newFromRow( $rc->mAttribs );
762 $formatter->setContext( $this->
getContext() );
763 $formatter->setShowUserToolLinks(
true );
764 $mark = $this->getLanguage()->getDirMark();
766 return Html::openElement(
'span', [
'class' =>
'mw-changeslist-log-entry' ] )
767 . $formatter->getActionText()
769 . $formatter->getComment()
770 . $this->message[
'word-separator']
771 . $formatter->getActionLinks()
772 . Html::closeElement(
'span' );
781 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
782 $deletedClass =
'history-deleted';
783 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
784 $deletedClass .=
' mw-history-suppressed';
786 return ' <span class="' . $deletedClass .
' comment">' .
787 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
788 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
789 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
791 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
793 return $this->commentFormatter->formatBlock(
794 $rc->mAttribs[
'rc_comment'],
816 return $this->watchMsgCache->getWithSetCallback(
817 $this->watchMsgCache->makeKey(
818 'watching-users-msg',
821 $this->getLanguage()->getCode()
823 function () use ( $count ) {
824 return $this->msg(
'number-of-watching-users-for-recent-changes' )
825 ->numParams( $count )->escaped();
837 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
850 $performer ??= RequestContext::getMain()->getAuthority();
852 if ( $rc->mAttribs[
'rc_type'] ==
RC_LOG ) {
853 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
856 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
866 return '<strong class="mw-watched">' . $link .
'</strong>';
868 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
879 $this->insertPageTools( $s, $rc );
890 private function insertPageTools( &$s, &$rc ) {
892 if ( !in_array( $rc->mAttribs[
'rc_type'], [
RC_EDIT,
RC_NEW ] )
894 || !$rc->mAttribs[
'rc_this_oldid']
895 || !$rc->mAttribs[
'rc_cur_id']
901 $title = $rc->getTitle();
903 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
904 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
906 (
int)$rc->mAttribs[
'rc_user'],
907 $rc->mAttribs[
'rc_user_text']
909 $revRecord->setUser( $user );
915 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
916 && $rc->mAttribs[
'rc_type'] !=
RC_NEW,
917 $this->getHookRunner(),
921 MediaWikiServices::getInstance()->getLinkRenderer()
924 $s .= $tools->toHTML();
934 $this->insertRollback( $s, $rc );
944 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
953 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
954 $this->tagsCache->makeKey(
955 $rc->mAttribs[
'ts_tags'],
956 $this->getUser()->getName(),
957 $this->getLanguage()->getCode()
960 $rc->mAttribs[
'ts_tags'],
965 $classes = array_merge( $classes, $newClasses );
966 $s .=
' ' . $tagSummary;
977 $this->insertTags( $s, $rc, $classes );
986 return self::isUnpatrolled( $rc, $this->
getUser() );
996 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
997 $rcType = $rc->mAttribs[
'rc_type'];
998 $rcLogType = $rc->mAttribs[
'rc_log_type'];
1000 $isPatrolled = $rc->rc_patrolled;
1001 $rcType = $rc->rc_type;
1002 $rcLogType = $rc->rc_log_type;
1005 if ( $isPatrolled ) {
1024 return intval( $rcObj->getAttribute(
'rc_type' ) ) ===
RC_CATEGORIZE
1025 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1038 case RecentChange::SRC_EDIT:
1039 case RecentChange::SRC_CATEGORIZE:
1040 case RecentChange::SRC_NEW:
1041 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1043 case RecentChange::SRC_LOG:
1044 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1045 $attrs[
'data-mw-logaction'] =
1046 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1050 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1063 $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)
Base class for lists of recent changes shown on special pages.
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.
Generate a list of changes using an Enhanced system (uses javascript).
Marks HTML that shouldn't be escaped.
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.
Generate a list of changes using the good old system (no javascript).
Utility class for creating and reading rows in the recentchanges table.
getAttribute( $name)
Get an attribute value.
Interface for objects which can provide a MediaWiki context on request.