30use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
48 use ProtectedHookAccessorTrait;
100 public function __construct( $context, array $filterGroups = [] ) {
102 $this->preCacheMessages();
104 $this->filterGroups = $filterGroups;
106 $services = MediaWikiServices::getInstance();
107 $this->linkRenderer = $services->getLinkRenderer();
108 $this->commentFormatter = $services->getRowCommentFormatter();
124 $services = MediaWikiServices::getInstance();
126 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
127 $userOptionsLookup = $services->getUserOptionsLookup();
130 $userOptionsLookup->getBoolOption( $user,
'usenewrc' )
153 throw new RuntimeException(
'recentChangesLine should be implemented' );
163 $highlightColorDivs =
'';
164 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
165 $highlightColorDivs .= Html::rawElement(
168 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
169 'data-color' => $color
174 return Html::rawElement(
176 [
'class' =>
'mw-rcfilters-ui-highlights' ],
186 $this->watchlist = $value;
194 return (
bool)$this->watchlist;
201 private function preCacheMessages() {
202 if ( !isset( $this->message ) ) {
205 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
206 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
208 $this->message[$msg] = $this->msg( $msg )->escaped();
222 $this->
getConfig()->
get( MainConfigNames::RecentChangesFlags ) as $flag => $_
224 $f .= isset( $flags[$flag] ) && $flags[$flag]
241 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
242 $logType = $rc->mAttribs[
'rc_log_type'];
245 $classes[] = self::CSS_CLASS_PREFIX .
'log';
246 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
248 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
249 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
250 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
255 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
256 ? self::CSS_CLASS_PREFIX .
'line-watched'
257 : self::CSS_CLASS_PREFIX .
'line-not-watched';
274 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
275 $rc->mAttribs[
'rc_namespace'] );
277 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
278 $classes[] = Sanitizer::escapeClass(
279 self::CSS_CLASS_PREFIX .
281 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
284 foreach ( $this->filterGroups as $filterGroup ) {
285 foreach ( $filterGroup->getFilters() as $filter ) {
286 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
304 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
305 static $flagInfos =
null;
307 if ( $flagInfos ===
null ) {
308 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
309 ->get( MainConfigNames::RecentChangesFlags );
311 foreach ( $recentChangesFlags as $key => $value ) {
312 $flagInfos[$key][
'letter'] = $value[
'letter'];
313 $flagInfos[$key][
'title'] = $value[
'title'];
315 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
319 $context = $context ?: RequestContext::getMain();
322 if ( isset( $map[$flag] ) ) {
326 $info = $flagInfos[$flag];
327 return Html::element(
'abbr', [
328 'class' => $info[
'class'],
338 $this->rc_cache = [];
339 $this->rcMoveIndex = 0;
340 $this->rcCacheIndex = 0;
341 $this->lastdate =
'';
342 $this->rclistOpen =
false;
344 'mediawiki.interface.helpers.styles',
345 'mediawiki.special.changeslist'
348 return '<div class="mw-changeslist">';
355 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
356 $this->formattedComments = $this->commentFormatter->createBatch()
358 $this->commentFormatter->rows( $rows )
359 ->commentKey(
'rc_comment' )
360 ->namespaceField(
'rc_namespace' )
361 ->titleField(
'rc_title' )
362 ->indexField(
'rc_id' )
380 $context = RequestContext::getMain();
385 $szdiff = $new - $old;
387 $lang = $context->getLanguage();
388 $config = $context->getConfig();
389 $code = $lang->getCode();
390 static $fastCharDiff = [];
391 if ( !isset( $fastCharDiff[$code] ) ) {
392 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
393 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
396 $formattedSize = $lang->formatNum( $szdiff );
398 if ( !$fastCharDiff[$code] ) {
399 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
402 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
408 if ( $szdiff === 0 ) {
409 $formattedSizeClass =
'mw-plusminus-null';
410 } elseif ( $szdiff > 0 ) {
411 $formattedSize =
'+' . $formattedSize;
412 $formattedSizeClass =
'mw-plusminus-pos';
414 $formattedSizeClass =
'mw-plusminus-neg';
416 $formattedSizeClass .=
' mw-diff-bytes';
418 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
420 return Html::element( $tag,
421 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
422 $formattedSize ) . $lang->getDirMark();
433 $oldlen = $old->mAttribs[
'rc_old_len'];
436 $newlen = $new->mAttribs[
'rc_new_len'];
438 $newlen = $old->mAttribs[
'rc_new_len'];
441 if ( $oldlen ===
null || $newlen ===
null ) {
445 return self::showCharacterDifference( $oldlen, $newlen, $this->
getContext() );
453 $out = $this->rclistOpen ?
"</ul>\n" :
'';
482 $class = trim(
'mw-changeslist-date ' . $className );
483 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
484 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
487 [
'class' => $class ],
488 [
'oldid' => $rev->
getId() ]
491 $link = htmlspecialchars( $date );
493 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
494 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
495 $link =
"<span class=\"$class\">$link</span>";
497 return Html::element(
'span', [
498 'class' =>
'mw-changeslist-time'
507 # Make date header if necessary
509 if ( $date != $this->lastdate ) {
510 if ( $this->lastdate !=
'' ) {
513 $s .= Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
514 $this->lastdate = $date;
515 $this->rclistOpen =
true;
525 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
526 $page =
new LogPage( $logtype );
527 $logname = $page->getName()->setContext( $this->
getContext() )->text();
528 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
529 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
531 if ( $useParentheses ) {
532 $s .= $this->
msg(
'parentheses' )->rawParams(
548 $rc->mAttribs[
'rc_type'] ==
RC_NEW ||
549 $rc->mAttribs[
'rc_type'] ==
RC_LOG ||
552 $diffLink = $this->message[
'diff'];
553 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
554 $diffLink = $this->message[
'diff'];
557 'curid' => $rc->mAttribs[
'rc_cur_id'],
558 'diff' => $rc->mAttribs[
'rc_this_oldid'],
559 'oldid' => $rc->mAttribs[
'rc_last_oldid']
562 $diffLink = $this->linkRenderer->makeKnownLink(
565 [
'class' =>
'mw-changeslist-diff' ],
570 $histLink = $this->message[
'hist'];
572 $histLink = $this->linkRenderer->makeKnownLink(
575 [
'class' =>
'mw-changeslist-history' ],
577 'curid' => $rc->mAttribs[
'rc_cur_id'],
578 'action' =>
'history'
583 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
584 Html::rawElement(
'span', [], $diffLink ) .
585 Html::rawElement(
'span', [], $histLink )
587 ' <span class="mw-changeslist-separator"></span> ';
602 if ( $rc->getTitle()->isRedirect() ) {
603 $params = [
'redirect' =>
'no' ];
606 $articlelink = $this->linkRenderer->makeLink(
609 [
'class' =>
'mw-changeslist-title' ],
612 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
613 $class =
'history-deleted';
614 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
615 $class .=
' mw-history-suppressed';
617 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
619 # To allow for boldening pages watched by this user
620 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
622 $articlelink .= $this->
getLanguage()->getDirMark();
624 # TODO: Deprecate the $s argument, it seems happily unused.
626 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
627 $s, $rc, $unpatrolled, $watched );
630 $watchlistExpiry =
'';
631 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
635 return "{$s} {$articlelink}{$watchlistExpiry}";
647 if ( $item->isExpired() ) {
652 $widget =
new IconWidget( [
654 'title' => $daysLeftText,
655 'classes' => [
'mw-changesList-watchlistExpiry' ],
657 $widget->setAttributes( [
660 'aria-label' => $this->msg(
'watchlist-expires-in-aria-label' )->text(),
662 'data-days-left' => $item->getExpiryInDays(),
689 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
690 return Html::element(
'span', [
'class' => $separatorClass ] ) .
' ' .
691 '<span class="mw-changeslist-date mw-changeslist-time">' .
692 htmlspecialchars( $this->getLanguage()->userTime(
693 $rc->mAttribs[
'rc_timestamp'],
695 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
715 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
716 $deletedClass =
'history-deleted';
717 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
718 $deletedClass .=
' mw-history-suppressed';
720 $s .=
' <span class="' . $deletedClass .
'">' .
721 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
723 $s .= $this->getLanguage()->getDirMark();
724 $s .= $this->userLinkCache->getWithSetCallback(
725 $this->userLinkCache->makeKey(
726 $rc->mAttribs[
'rc_user_text'],
727 $this->getUser()->getName(),
728 $this->getLanguage()->getCode()
730 static function () use ( $rc ) {
731 return Linker::userLink(
732 $rc->mAttribs[
'rc_user'],
733 $rc->mAttribs[
'rc_user_text']
734 ) . Linker::userToolLinks(
735 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
753 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
754 $formatter->setContext( $this->
getContext() );
755 $formatter->setShowUserToolLinks(
true );
756 $mark = $this->getLanguage()->getDirMark();
758 return Html::openElement(
'span', [
'class' =>
'mw-changeslist-log-entry' ] )
759 . $formatter->getActionText()
761 . $formatter->getComment()
762 . $this->message[
'word-separator']
763 . $formatter->getActionLinks()
764 . Html::closeElement(
'span' );
773 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
774 $deletedClass =
'history-deleted';
775 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
776 $deletedClass .=
' mw-history-suppressed';
778 return ' <span class="' . $deletedClass .
' comment">' .
779 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
780 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
781 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
783 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
785 return $this->commentFormatter->formatBlock(
786 $rc->mAttribs[
'rc_comment'],
808 return $this->watchMsgCache->getWithSetCallback(
809 $this->watchMsgCache->makeKey(
810 'watching-users-msg',
813 $this->getLanguage()->getCode()
815 function () use ( $count ) {
816 return $this->msg(
'number-of-watching-users-for-recent-changes' )
817 ->numParams( $count )->escaped();
829 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
842 $performer ??= RequestContext::getMain()->getAuthority();
844 if ( $rc->mAttribs[
'rc_type'] ==
RC_LOG ) {
845 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
848 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
858 return '<strong class="mw-watched">' . $link .
'</strong>';
860 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
871 $this->insertPageTools( $s, $rc );
882 private function insertPageTools( &$s, &$rc ) {
884 if ( !in_array( $rc->mAttribs[
'rc_type'], [
RC_EDIT,
RC_NEW ] )
886 || !$rc->mAttribs[
'rc_this_oldid']
887 || !$rc->mAttribs[
'rc_cur_id']
893 $title = $rc->getTitle();
895 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
896 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
898 (
int)$rc->mAttribs[
'rc_user'],
899 $rc->mAttribs[
'rc_user_text']
901 $revRecord->setUser( $user );
907 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
908 && $rc->mAttribs[
'rc_type'] !=
RC_NEW,
909 $this->getHookRunner(),
913 MediaWikiServices::getInstance()->getLinkRenderer()
916 $s .= $tools->toHTML();
926 $this->insertRollback( $s, $rc );
936 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
945 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
946 $this->tagsCache->makeKey(
947 $rc->mAttribs[
'ts_tags'],
948 $this->getUser()->getName(),
949 $this->getLanguage()->getCode()
952 $rc->mAttribs[
'ts_tags'],
957 $classes = array_merge( $classes, $newClasses );
958 $s .=
' ' . $tagSummary;
969 $this->insertTags( $s, $rc, $classes );
978 return self::isUnpatrolled( $rc, $this->
getUser() );
988 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
989 $rcType = $rc->mAttribs[
'rc_type'];
990 $rcLogType = $rc->mAttribs[
'rc_log_type'];
992 $isPatrolled = $rc->rc_patrolled;
993 $rcType = $rc->rc_type;
994 $rcLogType = $rc->rc_log_type;
997 if ( $isPatrolled ) {
1016 return intval( $rcObj->getAttribute(
'rc_type' ) ) ===
RC_CATEGORIZE
1017 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1030 case RecentChange::SRC_EDIT:
1031 case RecentChange::SRC_CATEGORIZE:
1032 case RecentChange::SRC_NEW:
1033 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1035 case RecentChange::SRC_LOG:
1036 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1037 $attrs[
'data-mw-logaction'] =
1038 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1042 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1055 $this->changeLinePrefixer = $prefixer;
getWatchlistExpiry(WatchedItemStoreInterface $store, Title $title, 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.
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.