26use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
54 use ProtectedHookAccessorTrait;
59 protected $watchlist =
false;
115 public function __construct( $context, array $filterGroups = [] ) {
117 $this->preCacheMessages();
119 $this->filterGroups = $filterGroups;
121 $services = MediaWikiServices::getInstance();
122 $this->linkRenderer = $services->getLinkRenderer();
123 $this->commentFormatter = $services->getRowCommentFormatter();
124 $this->logFormatterFactory = $services->getLogFormatterFactory();
140 $services = MediaWikiServices::getInstance();
142 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
143 $userOptionsLookup = $services->getUserOptionsLookup();
169 throw new RuntimeException(
'recentChangesLine should be implemented' );
179 $highlightColorDivs =
'';
180 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
181 $highlightColorDivs .= Html::rawElement(
184 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
185 'data-color' => $color
190 return Html::rawElement(
192 [
'class' =>
'mw-rcfilters-ui-highlights' ],
202 $this->watchlist = $value;
210 return (
bool)$this->watchlist;
217 private function preCacheMessages() {
218 if ( !isset( $this->message ) ) {
221 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
222 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
224 $this->message[$msg] = $this->msg( $msg )->escaped();
238 $this->
getConfig()->
get( MainConfigNames::RecentChangesFlags ) as $flag => $_
240 $f .= isset( $flags[$flag] ) && $flags[$flag]
257 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
258 $logType = $rc->mAttribs[
'rc_log_type'];
261 $classes[] = self::CSS_CLASS_PREFIX .
'log';
262 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
264 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
265 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
266 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
271 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
272 ? self::CSS_CLASS_PREFIX .
'line-watched'
273 : self::CSS_CLASS_PREFIX .
'line-not-watched';
290 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
291 $rc->mAttribs[
'rc_namespace'] );
293 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
294 $classes[] = Sanitizer::escapeClass(
295 self::CSS_CLASS_PREFIX .
297 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
300 foreach ( $this->filterGroups as $filterGroup ) {
301 foreach ( $filterGroup->getFilters() as $filter ) {
302 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
320 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
321 static $flagInfos =
null;
323 if ( $flagInfos ===
null ) {
324 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
325 ->get( MainConfigNames::RecentChangesFlags );
327 foreach ( $recentChangesFlags as $key => $value ) {
328 $flagInfos[$key][
'letter'] = $value[
'letter'];
329 $flagInfos[$key][
'title'] = $value[
'title'];
331 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
335 $context = $context ?: RequestContext::getMain();
338 if ( isset( $map[$flag] ) ) {
342 $info = $flagInfos[$flag];
343 return Html::element(
'abbr', [
344 'class' => $info[
'class'],
354 $this->rc_cache = [];
355 $this->rcMoveIndex = 0;
356 $this->rcCacheIndex = 0;
357 $this->lastdate =
'';
358 $this->rclistOpen =
false;
360 'mediawiki.interface.helpers.styles',
361 'mediawiki.special.changeslist'
364 return '<div class="mw-changeslist">';
371 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
372 $this->formattedComments = $this->commentFormatter->createBatch()
374 $this->commentFormatter->rows( $rows )
375 ->commentKey(
'rc_comment' )
376 ->namespaceField(
'rc_namespace' )
377 ->titleField(
'rc_title' )
378 ->indexField(
'rc_id' )
396 $context = RequestContext::getMain();
401 $szdiff = $new - $old;
403 $lang = $context->getLanguage();
404 $config = $context->getConfig();
405 $code = $lang->getCode();
406 static $fastCharDiff = [];
407 if ( !isset( $fastCharDiff[$code] ) ) {
408 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
409 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
412 $formattedSize = $lang->formatNum( $szdiff );
414 if ( !$fastCharDiff[$code] ) {
415 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
418 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
424 if ( $szdiff === 0 ) {
425 $formattedSizeClass =
'mw-plusminus-null';
426 } elseif ( $szdiff > 0 ) {
427 $formattedSize =
'+' . $formattedSize;
428 $formattedSizeClass =
'mw-plusminus-pos';
430 $formattedSizeClass =
'mw-plusminus-neg';
432 $formattedSizeClass .=
' mw-diff-bytes';
434 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
436 return Html::element( $tag,
437 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
449 $oldlen = $old->mAttribs[
'rc_old_len'];
452 $newlen = $new->mAttribs[
'rc_new_len'];
454 $newlen = $old->mAttribs[
'rc_new_len'];
457 if ( $oldlen ===
null || $newlen ===
null ) {
461 return self::showCharacterDifference( $oldlen, $newlen, $this->
getContext() );
469 $out = $this->rclistOpen ?
"</ul>\n" :
'';
498 $class = trim(
'mw-changeslist-date ' . $className );
499 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
500 $link = Html::rawElement(
'bdi', [
'dir' => $lang->
getDir() ],
501 MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
504 [
'class' => $class ],
505 [
'oldid' => $rev->
getId() ]
509 $link = htmlspecialchars( $date );
511 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
512 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
513 $link =
"<span class=\"$class\">$link</span>";
515 return Html::element(
'span', [
516 'class' =>
'mw-changeslist-time'
525 # Make date header if necessary
527 if ( $date != $this->lastdate ) {
528 if ( $this->lastdate !=
'' ) {
531 $s .= Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
532 $this->lastdate = $date;
533 $this->rclistOpen =
true;
543 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
544 $page =
new LogPage( $logtype );
545 $logname = $page->getName()->setContext( $this->
getContext() )->text();
546 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
547 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
549 if ( $useParentheses ) {
550 $s .= $this->
msg(
'parentheses' )->rawParams(
566 $rc->mAttribs[
'rc_type'] ==
RC_NEW ||
567 $rc->mAttribs[
'rc_type'] ==
RC_LOG ||
570 $diffLink = $this->message[
'diff'];
571 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
572 $diffLink = $this->message[
'diff'];
575 'curid' => $rc->mAttribs[
'rc_cur_id'],
576 'diff' => $rc->mAttribs[
'rc_this_oldid'],
577 'oldid' => $rc->mAttribs[
'rc_last_oldid']
580 $diffLink = $this->linkRenderer->makeKnownLink(
583 [
'class' =>
'mw-changeslist-diff' ],
588 $histLink = $this->message[
'hist'];
590 $histLink = $this->linkRenderer->makeKnownLink(
593 [
'class' =>
'mw-changeslist-history' ],
595 'curid' => $rc->mAttribs[
'rc_cur_id'],
596 'action' =>
'history'
601 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
602 Html::rawElement(
'span', [], $diffLink ) .
603 Html::rawElement(
'span', [], $histLink )
605 ' <span class="mw-changeslist-separator"></span> ';
620 if ( $rc->getTitle()->isRedirect() ) {
621 $params = [
'redirect' =>
'no' ];
624 $articlelink = $this->linkRenderer->makeLink(
627 [
'class' =>
'mw-changeslist-title' ],
630 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
631 $class =
'history-deleted';
632 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
633 $class .=
' mw-history-suppressed';
635 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
638 $articlelink = Html::rawElement(
'bdi', [
'dir' => $dir ], $articlelink );
639 # To allow for boldening pages watched by this user
640 # Don't wrap result of this with another tag, see T376814
641 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
643 # TODO: Deprecate the $s argument, it seems happily unused.
645 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
646 $s, $rc, $unpatrolled, $watched );
649 $watchlistExpiry =
'';
650 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
654 return "{$s} {$articlelink}{$watchlistExpiry}";
666 if ( $item->isExpired() ) {
671 $widget =
new IconWidget( [
673 'title' => $daysLeftText,
674 'classes' => [
'mw-changesList-watchlistExpiry' ],
676 $widget->setAttributes( [
679 'aria-label' => $this->msg(
'watchlist-expires-in-aria-label' )->text(),
681 'data-days-left' => $item->getExpiryInDays(),
708 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
709 return Html::element(
'span', [
'class' => $separatorClass ] ) .
' ' .
710 '<span class="mw-changeslist-date mw-changeslist-time">' .
711 htmlspecialchars( $this->getLanguage()->userTime(
712 $rc->mAttribs[
'rc_timestamp'],
714 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
734 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
735 $deletedClass =
'history-deleted';
736 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
737 $deletedClass .=
' mw-history-suppressed';
739 $s .=
' <span class="' . $deletedClass .
'">' .
740 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
742 # Don't wrap result of this with another tag, see T376814
743 $s .= $this->userLinkCache->getWithSetCallback(
744 $this->userLinkCache->makeKey(
745 $rc->mAttribs[
'rc_user_text'],
746 $this->getUser()->getName(),
747 $this->getLanguage()->getCode()
749 static function () use ( $rc ) {
750 return Linker::userLink(
751 $rc->mAttribs[
'rc_user'],
752 $rc->mAttribs[
'rc_user_text']
753 ) . Linker::userToolLinks(
754 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
772 $formatter = $this->logFormatterFactory->newFromRow( $rc->mAttribs );
773 $formatter->setContext( $this->getContext() );
774 $formatter->setShowUserToolLinks(
true );
776 $comment = $formatter->getComment();
777 if ( $comment !==
'' ) {
778 $dir = $this->getLanguage()->getDir();
779 $comment = Html::rawElement(
'bdi', [
'dir' => $dir ], $comment );
782 return Html::openElement(
'span', [
'class' =>
'mw-changeslist-log-entry' ] )
783 . $formatter->getActionText()
786 . $this->message[
'word-separator']
787 . $formatter->getActionLinks()
788 . Html::closeElement(
'span' );
797 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
798 $deletedClass =
'history-deleted';
799 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
800 $deletedClass .=
' mw-history-suppressed';
802 return ' <span class="' . $deletedClass .
' comment">' .
803 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
804 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
805 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
807 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
809 return $this->commentFormatter->formatBlock(
810 $rc->mAttribs[
'rc_comment'],
832 return $this->watchMsgCache->getWithSetCallback(
833 $this->watchMsgCache->makeKey(
834 'watching-users-msg',
836 $this->getUser()->getName(),
837 $this->getLanguage()->getCode()
839 function () use ( $count ) {
840 return $this->msg(
'number-of-watching-users-for-recent-changes' )
841 ->numParams( $count )->escaped();
853 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
866 $performer ??= RequestContext::getMain()->getAuthority();
868 if ( $rc->mAttribs[
'rc_type'] ==
RC_LOG ) {
869 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
872 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
882 return '<strong class="mw-watched">' . $link .
'</strong>';
884 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
895 $this->insertPageTools( $s, $rc );
906 private function insertPageTools( &$s, &$rc ) {
908 if ( !in_array( $rc->mAttribs[
'rc_type'], [
RC_EDIT,
RC_NEW ] )
910 || !$rc->mAttribs[
'rc_this_oldid']
911 || !$rc->mAttribs[
'rc_cur_id']
917 $title = $rc->getTitle();
919 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
920 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
922 (
int)$rc->mAttribs[
'rc_user'],
923 $rc->mAttribs[
'rc_user_text']
925 $revRecord->setUser( $user );
931 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
932 && $rc->mAttribs[
'rc_type'] !=
RC_NEW,
933 $this->getHookRunner(),
937 MediaWikiServices::getInstance()->getLinkRenderer()
940 $s .= $tools->toHTML();
950 $this->insertRollback( $s, $rc );
960 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
969 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
970 $this->tagsCache->makeKey(
971 $rc->mAttribs[
'ts_tags'],
972 $this->getUser()->getName(),
973 $this->getLanguage()->getCode()
976 $rc->mAttribs[
'ts_tags'],
981 $classes = array_merge( $classes, $newClasses );
982 $s .=
' ' . $tagSummary;
993 $this->insertTags( $s, $rc, $classes );
1002 return self::isUnpatrolled( $rc, $this->getUser() );
1012 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
1013 $rcType = $rc->mAttribs[
'rc_type'];
1014 $rcLogType = $rc->mAttribs[
'rc_log_type'];
1016 $isPatrolled = $rc->rc_patrolled;
1017 $rcType = $rc->rc_type;
1018 $rcLogType = $rc->rc_log_type;
1021 if ( $isPatrolled ) {
1040 return intval( $rcObj->getAttribute(
'rc_type' ) ) ===
RC_CATEGORIZE
1041 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1054 case RecentChange::SRC_EDIT:
1055 case RecentChange::SRC_CATEGORIZE:
1056 case RecentChange::SRC_NEW:
1057 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1059 case RecentChange::SRC_LOG:
1060 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1061 $attrs[
'data-mw-logaction'] =
1062 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1066 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1079 $this->changeLinePrefixer = $prefixer;
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 showCharacterDifference( $old, $new, ?IContextSource $context=null)
Show formatted char difference.
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.
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)
formatCharacterDifference(RecentChange $old, ?RecentChange $new=null)
Format the character difference of one or several changes.
static userCan( $rc, $field, ?Authority $performer=null)
Determine if the current user is allowed to view a particular field of this revision,...
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.
getRollback(RecentChange $rc)
MapCacheLRU $watchMsgCache
endRecentChangesList()
Returns text for the end of RC.
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.
insertExtra(&$s, &$rc, &$classes)
static flag( $flag, ?IContextSource $context=null)
Make an "<abbr>" element for a given change flag.
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()
getContext()
Get the base IContextSource object.
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.