27use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
45 use ProtectedHookAccessorTrait;
97 public function __construct( $context, array $filterGroups = [] ) {
99 $this->preCacheMessages();
101 $this->filterGroups = $filterGroups;
103 $services = MediaWikiServices::getInstance();
104 $this->linkRenderer = $services->getLinkRenderer();
105 $this->commentFormatter = $services->getRowCommentFormatter();
121 $services = MediaWikiServices::getInstance();
123 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
124 $userOptionsLookup = $services->getUserOptionsLookup();
127 $userOptionsLookup->getBoolOption( $user,
'usenewrc' )
150 throw new RuntimeException(
'recentChangesLine should be implemented' );
160 $highlightColorDivs =
'';
161 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
162 $highlightColorDivs .= Html::rawElement(
165 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
166 'data-color' => $color
171 return Html::rawElement(
173 [
'class' =>
'mw-rcfilters-ui-highlights' ],
183 $this->watchlist = $value;
191 return (
bool)$this->watchlist;
198 private function preCacheMessages() {
199 if ( !isset( $this->message ) ) {
202 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
203 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
205 $this->message[$msg] = $this->msg( $msg )->escaped();
219 $this->
getConfig()->
get( MainConfigNames::RecentChangesFlags ) as $flag => $_
221 $f .= isset( $flags[$flag] ) && $flags[$flag]
238 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
239 $logType = $rc->mAttribs[
'rc_log_type'];
242 $classes[] = self::CSS_CLASS_PREFIX .
'log';
243 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
245 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
246 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
247 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
252 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
253 ? self::CSS_CLASS_PREFIX .
'line-watched'
254 : self::CSS_CLASS_PREFIX .
'line-not-watched';
271 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
272 $rc->mAttribs[
'rc_namespace'] );
274 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
275 $classes[] = Sanitizer::escapeClass(
276 self::CSS_CLASS_PREFIX .
278 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
281 foreach ( $this->filterGroups as $filterGroup ) {
282 foreach ( $filterGroup->getFilters() as $filter ) {
283 $filter->applyCssClassIfNeeded( $this, $rc, $classes );
301 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
302 static $flagInfos =
null;
304 if ( $flagInfos ===
null ) {
305 $recentChangesFlags = MediaWikiServices::getInstance()->getMainConfig()
306 ->get( MainConfigNames::RecentChangesFlags );
308 foreach ( $recentChangesFlags as $key => $value ) {
309 $flagInfos[$key][
'letter'] = $value[
'letter'];
310 $flagInfos[$key][
'title'] = $value[
'title'];
312 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
316 $context = $context ?: RequestContext::getMain();
319 if ( isset( $map[$flag] ) ) {
323 $info = $flagInfos[$flag];
324 return Html::element(
'abbr', [
325 'class' => $info[
'class'],
335 $this->rc_cache = [];
336 $this->rcMoveIndex = 0;
337 $this->rcCacheIndex = 0;
338 $this->lastdate =
'';
339 $this->rclistOpen =
false;
341 'mediawiki.interface.helpers.styles',
342 'mediawiki.special.changeslist'
345 return '<div class="mw-changeslist">';
352 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
353 $this->formattedComments = $this->commentFormatter->createBatch()
355 $this->commentFormatter->rows( $rows )
356 ->commentKey(
'rc_comment' )
357 ->namespaceField(
'rc_namespace' )
358 ->titleField(
'rc_title' )
359 ->indexField(
'rc_id' )
377 $context = RequestContext::getMain();
382 $szdiff = $new - $old;
384 $lang = $context->getLanguage();
385 $config = $context->getConfig();
386 $code = $lang->getCode();
387 static $fastCharDiff = [];
388 if ( !isset( $fastCharDiff[$code] ) ) {
389 $fastCharDiff[$code] = $config->get( MainConfigNames::MiserMode )
390 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
393 $formattedSize = $lang->formatNum( $szdiff );
395 if ( !$fastCharDiff[$code] ) {
396 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
399 if ( abs( $szdiff ) > abs( $config->get( MainConfigNames::RCChangedSizeThreshold ) ) ) {
405 if ( $szdiff === 0 ) {
406 $formattedSizeClass =
'mw-plusminus-null';
407 } elseif ( $szdiff > 0 ) {
408 $formattedSize =
'+' . $formattedSize;
409 $formattedSizeClass =
'mw-plusminus-pos';
411 $formattedSizeClass =
'mw-plusminus-neg';
413 $formattedSizeClass .=
' mw-diff-bytes';
415 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
417 return Html::element( $tag,
418 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
419 $formattedSize ) . $lang->getDirMark();
430 $oldlen = $old->mAttribs[
'rc_old_len'];
433 $newlen = $new->mAttribs[
'rc_new_len'];
435 $newlen = $old->mAttribs[
'rc_new_len'];
438 if ( $oldlen ===
null || $newlen ===
null ) {
442 return self::showCharacterDifference( $oldlen, $newlen, $this->
getContext() );
450 $out = $this->rclistOpen ?
"</ul>\n" :
'';
476 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
477 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
480 [
'class' =>
'mw-changeslist-date' ],
481 [
'oldid' => $rev->
getId() ]
484 $link = htmlspecialchars( $date );
486 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
487 $deletedClass = Linker::getRevisionDeletedClass( $rev );
488 $link =
"<span class=\"$deletedClass mw-changeslist-date\">$link</span>";
490 return Html::element(
'span', [
491 'class' =>
'mw-changeslist-time'
500 # Make date header if necessary
502 if ( $date != $this->lastdate ) {
503 if ( $this->lastdate !=
'' ) {
506 $s .= Xml::element(
'h4',
null, $date ) .
"\n<ul class=\"special\">";
507 $this->lastdate = $date;
508 $this->rclistOpen =
true;
518 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
519 $page =
new LogPage( $logtype );
520 $logname = $page->getName()->setContext( $this->
getContext() )->text();
521 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
522 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
524 if ( $useParentheses ) {
525 $s .= $this->
msg(
'parentheses' )->rawParams(
541 $rc->mAttribs[
'rc_type'] ==
RC_NEW ||
542 $rc->mAttribs[
'rc_type'] ==
RC_LOG ||
545 $diffLink = $this->message[
'diff'];
546 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
547 $diffLink = $this->message[
'diff'];
550 'curid' => $rc->mAttribs[
'rc_cur_id'],
551 'diff' => $rc->mAttribs[
'rc_this_oldid'],
552 'oldid' => $rc->mAttribs[
'rc_last_oldid']
555 $diffLink = $this->linkRenderer->makeKnownLink(
558 [
'class' =>
'mw-changeslist-diff' ],
563 $histLink = $this->message[
'hist'];
565 $histLink = $this->linkRenderer->makeKnownLink(
568 [
'class' =>
'mw-changeslist-history' ],
570 'curid' => $rc->mAttribs[
'rc_cur_id'],
571 'action' =>
'history'
576 $s .= Html::rawElement(
'div', [
'class' =>
'mw-changeslist-links' ],
577 Html::rawElement(
'span', [], $diffLink ) .
578 Html::rawElement(
'span', [], $histLink )
580 ' <span class="mw-changeslist-separator"></span> ';
595 if ( $rc->getTitle()->isRedirect() ) {
596 $params = [
'redirect' =>
'no' ];
599 $articlelink = $this->linkRenderer->makeLink(
602 [
'class' =>
'mw-changeslist-title' ],
605 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
606 $class =
'history-deleted';
607 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
608 $class .=
' mw-history-suppressed';
610 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
612 # To allow for boldening pages watched by this user
613 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
615 $articlelink .= $this->
getLanguage()->getDirMark();
617 # TODO: Deprecate the $s argument, it seems happily unused.
619 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
620 $s, $rc, $unpatrolled, $watched );
623 $watchlistExpiry =
'';
624 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
628 return "{$s} {$articlelink}{$watchlistExpiry}";
640 if ( $item->isExpired() ) {
645 $widget =
new IconWidget( [
647 'title' => $daysLeftText,
648 'classes' => [
'mw-changesList-watchlistExpiry' ],
650 $widget->setAttributes( [
653 'aria-label' => $this->msg(
'watchlist-expires-in-aria-label' )->text(),
655 'data-days-left' => $item->getExpiryInDays(),
682 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
683 return Html::element(
'span', [
'class' => $separatorClass ] ) .
' ' .
684 '<span class="mw-changeslist-date mw-changeslist-time">' .
685 htmlspecialchars( $this->getLanguage()->userTime(
686 $rc->mAttribs[
'rc_timestamp'],
688 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
708 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
709 $deletedClass =
'history-deleted';
710 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
711 $deletedClass .=
' mw-history-suppressed';
713 $s .=
' <span class="' . $deletedClass .
'">' .
714 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
716 $s .= $this->getLanguage()->getDirMark();
717 $s .= $this->userLinkCache->getWithSetCallback(
718 $this->userLinkCache->makeKey(
719 $rc->mAttribs[
'rc_user_text'],
720 $this->getUser()->getName(),
721 $this->getLanguage()->getCode()
723 static function () use ( $rc ) {
724 return Linker::userLink(
725 $rc->mAttribs[
'rc_user'],
726 $rc->mAttribs[
'rc_user_text']
727 ) . Linker::userToolLinks(
728 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
746 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
747 $formatter->setContext( $this->
getContext() );
748 $formatter->setShowUserToolLinks(
true );
749 $mark = $this->getLanguage()->getDirMark();
751 return Html::openElement(
'span', [
'class' =>
'mw-changeslist-log-entry' ] )
752 . $formatter->getActionText()
754 . $formatter->getComment()
755 . $this->message[
'word-separator']
756 . $formatter->getActionLinks()
757 . Html::closeElement(
'span' );
766 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
767 $deletedClass =
'history-deleted';
768 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
769 $deletedClass .=
' mw-history-suppressed';
771 return ' <span class="' . $deletedClass .
' comment">' .
772 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
773 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
774 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
776 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
778 return $this->commentFormatter->formatBlock(
779 $rc->mAttribs[
'rc_comment'],
801 return $this->watchMsgCache->getWithSetCallback(
802 $this->watchMsgCache->makeKey(
803 'watching-users-msg',
806 $this->getLanguage()->getCode()
808 function () use ( $count ) {
809 return $this->msg(
'number-of-watching-users-for-recent-changes' )
810 ->numParams( $count )->escaped();
822 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
835 $performer ??= RequestContext::getMain()->getAuthority();
837 if ( $rc->mAttribs[
'rc_type'] ==
RC_LOG ) {
838 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
841 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
851 return '<strong class="mw-watched">' . $link .
'</strong>';
853 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
864 $this->insertPageTools( $s, $rc );
875 private function insertPageTools( &$s, &$rc ) {
877 if ( !in_array( $rc->mAttribs[
'rc_type'], [
RC_EDIT,
RC_NEW ] )
879 || !$rc->mAttribs[
'rc_this_oldid']
880 || !$rc->mAttribs[
'rc_cur_id']
886 $title = $rc->getTitle();
888 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
889 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
891 (
int)$rc->mAttribs[
'rc_user'],
892 $rc->mAttribs[
'rc_user_text']
894 $revRecord->setUser( $user );
900 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
901 && $rc->mAttribs[
'rc_type'] !=
RC_NEW,
902 $this->getHookRunner(),
906 MediaWikiServices::getInstance()->getLinkRenderer()
909 $s .= $tools->toHTML();
919 $this->insertRollback( $s, $rc );
929 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
938 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
939 $this->tagsCache->makeKey(
940 $rc->mAttribs[
'ts_tags'],
941 $this->getUser()->getName(),
942 $this->getLanguage()->getCode()
945 $rc->mAttribs[
'ts_tags'],
950 $classes = array_merge( $classes, $newClasses );
951 $s .=
' ' . $tagSummary;
962 $this->insertTags( $s, $rc, $classes );
971 return self::isUnpatrolled( $rc, $this->
getUser() );
981 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
982 $rcType = $rc->mAttribs[
'rc_type'];
983 $rcLogType = $rc->mAttribs[
'rc_log_type'];
985 $isPatrolled = $rc->rc_patrolled;
986 $rcType = $rc->rc_type;
987 $rcLogType = $rc->rc_log_type;
990 if ( $isPatrolled ) {
1009 return intval( $rcObj->getAttribute(
'rc_type' ) ) ===
RC_CATEGORIZE
1010 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1023 case RecentChange::SRC_EDIT:
1024 case RecentChange::SRC_NEW:
1025 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1027 case RecentChange::SRC_LOG:
1028 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1029 $attrs[
'data-mw-logaction'] =
1030 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1032 case RecentChange::SRC_CATEGORIZE:
1033 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1037 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1050 $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.
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.
static revDateLink(RevisionRecord $rev, Authority $performer, Language $lang, $title=null)
Render the date and time of a revision in the current user language based on whether the user is able...
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.
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.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
setContext(IContextSource $context)
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.
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.