15use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
27use MediaWiki\Pager\PagerTools;
52 use ProtectedHookAccessorTrait;
117 $this->preCacheMessages();
122 $this->linkRenderer = $services->getLinkRenderer();
123 $this->commentFormatter = $services->getRowCommentFormatter();
124 $this->logFormatterFactory = $services->getLogFormatterFactory();
125 $this->userLinkRenderer = $services->getUserLinkRenderer();
147 if ( (
new HookRunner( $services->getHookContainer() ) )->onFetchChangesList( $user, $sk, $list, $groups ) ) {
148 $userOptionsLookup = $services->getUserOptionsLookup();
174 throw new RuntimeException(
'recentChangesLine should be implemented' );
184 $highlightColorDivs =
'';
185 foreach ( [
'none',
'c1',
'c2',
'c3',
'c4',
'c5' ] as $color ) {
186 $highlightColorDivs .= Html::rawElement(
189 'class' =>
'mw-rcfilters-ui-highlights-color-' . $color,
190 'data-color' => $color
195 return Html::rawElement(
197 [
'class' =>
'mw-rcfilters-ui-highlights' ],
207 $this->watchlist = $value;
222 private function preCacheMessages() {
224 if ( !isset( $this->message ) ) {
227 'cur',
'diff',
'hist',
'enhancedrc-history',
'last',
'blocklink',
'history',
228 'semicolon-separator',
'pipe-separator',
'word-separator' ] as $msg
230 $this->message[$msg] = $this->
msg( $msg )->escaped();
246 $f .= isset( $flags[$flag] ) && $flags[$flag]
263 $classes = [ self::CSS_CLASS_PREFIX .
'line' ];
264 $logType = $rc->mAttribs[
'rc_log_type'];
267 $classes[] = self::CSS_CLASS_PREFIX .
'log';
268 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'log-' . $logType );
270 $classes[] = self::CSS_CLASS_PREFIX .
'edit';
271 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns' .
272 $rc->mAttribs[
'rc_namespace'] .
'-' . $rc->mAttribs[
'rc_title'] );
277 $classes[] = $watched && $rc->mAttribs[
'rc_timestamp'] >= $watched
278 ? self::CSS_CLASS_PREFIX .
'line-watched'
279 : self::CSS_CLASS_PREFIX .
'line-not-watched';
296 $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX .
'ns-' .
297 $rc->mAttribs[
'rc_namespace'] );
300 $classes[] = Sanitizer::escapeClass(
301 self::CSS_CLASS_PREFIX .
303 ( $nsInfo->isTalk( $rc->mAttribs[
'rc_namespace'] ) ?
'talk' :
'subject' )
306 $this->filterGroups->applyCssClassIfNeeded( $this->
getContext(), $rc, $classes );
322 static $map = [
'minoredit' =>
'minor',
'botedit' =>
'bot' ];
323 static $flagInfos =
null;
325 if ( $flagInfos ===
null ) {
329 foreach ( $recentChangesFlags as $key => $value ) {
330 $flagInfos[$key][
'letter'] = $value[
'letter'];
331 $flagInfos[$key][
'title'] = $value[
'title'];
333 $flagInfos[$key][
'class'] = $value[
'class'] ?? $key;
337 $context = $context ?: RequestContext::getMain();
340 if ( isset( $map[$flag] ) ) {
344 $info = $flagInfos[$flag];
346 'class' => $info[
'class'],
356 $this->rc_cache = [];
357 $this->rcMoveIndex = 0;
358 $this->rcCacheIndex = 0;
359 $this->lastdate =
'';
360 $this->rclistOpen =
false;
362 'mediawiki.interface.helpers.styles',
363 'mediawiki.special.changeslist'
366 return '<div class="mw-changeslist">';
373 $this->getHookRunner()->onChangesListInitRows( $this, $rows );
374 $this->formattedComments = $this->commentFormatter->createBatch()
376 $this->commentFormatter->rows( $rows )
377 ->commentKey(
'rc_comment' )
378 ->namespaceField(
'rc_namespace' )
379 ->titleField(
'rc_title' )
380 ->indexField(
'rc_id' )
398 $context = RequestContext::getMain();
403 $szdiff = $new - $old;
405 $lang = $context->getLanguage();
406 $config = $context->getConfig();
407 $code = $lang->getCode();
408 static $fastCharDiff = [];
409 if ( !isset( $fastCharDiff[$code] ) ) {
411 || $context->msg(
'rc-change-size' )->plain() ===
'$1';
414 $formattedSize = $lang->formatNum( $szdiff );
416 if ( !$fastCharDiff[$code] ) {
417 $formattedSize = $context->msg(
'rc-change-size', $formattedSize )->text();
426 if ( $szdiff === 0 ) {
427 $formattedSizeClass =
'mw-plusminus-null';
428 } elseif ( $szdiff > 0 ) {
429 $formattedSize =
'+' . $formattedSize;
430 $formattedSizeClass =
'mw-plusminus-pos';
432 $formattedSizeClass =
'mw-plusminus-neg';
434 $formattedSizeClass .=
' mw-diff-bytes';
436 $formattedTotalSize = $context->msg(
'rc-change-size-new' )->numParams( $new )->text();
439 [
'dir' =>
'ltr',
'class' => $formattedSizeClass,
'title' => $formattedTotalSize ],
451 $oldlen = $old->mAttribs[
'rc_old_len'];
454 $newlen = $new->mAttribs[
'rc_new_len'];
456 $newlen = $old->mAttribs[
'rc_new_len'];
459 if ( $oldlen ===
null || $newlen ===
null ) {
471 $out = $this->rclistOpen ?
"</ul>\n" :
'';
500 $class = trim(
'mw-changeslist-date ' . $className );
501 if ( $rev->
userCan( RevisionRecord::DELETED_TEXT, $performer ) ) {
502 $link = Html::rawElement(
'bdi', [
'dir' => $lang->
getDir() ],
506 [
'class' => $class ],
507 [
'oldid' => $rev->
getId() ]
511 $link = htmlspecialchars( $date );
513 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
514 $class = Linker::getRevisionDeletedClass( $rev ) .
" $class";
515 $link =
"<span class=\"$class\">$link</span>";
518 'class' =>
'mw-changeslist-time'
527 # Make date header if necessary
529 if ( $date != $this->lastdate ) {
530 if ( $this->lastdate !=
'' ) {
533 $s .=
Html::element(
'h4', [], $date ) .
"\n<ul class=\"special\">";
534 $this->lastdate = $date;
535 $this->rclistOpen =
true;
545 public function insertLog( &$s, $title, $logtype, $useParentheses =
true ) {
546 $page =
new LogPage( $logtype );
547 $logname = $page->getName()->setContext( $this->
getContext() )->text();
548 $link = $this->linkRenderer->makeKnownLink( $title, $logname, [
549 'class' => $useParentheses ?
'' :
'mw-changeslist-links'
551 if ( $useParentheses ) {
552 $s .= $this->
msg(
'parentheses' )->rawParams(
571 $diffLink = $this->message[
'diff'];
572 } elseif ( !self::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->
getAuthority() ) ) {
573 $diffLink = $this->message[
'diff'];
576 'curid' => $rc->mAttribs[
'rc_cur_id'],
577 'diff' => $rc->mAttribs[
'rc_this_oldid'],
578 'oldid' => $rc->mAttribs[
'rc_last_oldid']
581 $diffLink = $this->linkRenderer->makeKnownLink(
584 [
'class' =>
'mw-changeslist-diff' ],
588 $histLink = $this->linkRenderer->makeKnownLink(
591 [
'class' =>
'mw-changeslist-history' ],
593 'curid' => $rc->mAttribs[
'rc_cur_id'],
594 'action' =>
'history'
598 $s .= Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
599 Html::rawElement(
'span', [], $diffLink ) .
600 Html::rawElement(
'span', [], $histLink )
602 ' <span class="mw-changeslist-separator"></span> ';
617 if ( $rc->getTitle()->isRedirect() ) {
618 $params = [
'redirect' =>
'no' ];
621 $articlelink = $this->linkRenderer->makeLink(
624 [
'class' =>
'mw-changeslist-title' ],
627 if ( static::isDeleted( $rc, RevisionRecord::DELETED_TEXT ) ) {
628 $class =
'history-deleted';
629 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
630 $class .=
' mw-history-suppressed';
632 $articlelink =
'<span class="' . $class .
'">' . $articlelink .
'</span>';
635 $articlelink = Html::rawElement(
'bdi', [
'dir' => $dir ], $articlelink );
636 # To allow for boldening pages watched by this user
637 # Don't wrap result of this with another tag, see T376814
638 $articlelink =
"<span class=\"mw-title\">{$articlelink}</span>";
640 # TODO: Deprecate the $s argument, it seems happily unused.
642 $this->getHookRunner()->onChangesListInsertArticleLink( $this, $articlelink,
643 $s, $rc, $unpatrolled, $watched );
646 $watchlistExpiry =
'';
648 if ( isset( $rc->watchlistExpiry ) && $rc->watchlistExpiry ) {
652 return "{$s} {$articlelink}{$watchlistExpiry}";
664 if ( $item->isExpired() ) {
669 $widget =
new IconWidget( [
671 'title' => $daysLeftText,
672 'classes' => [
'mw-changesList-watchlistExpiry' ],
674 $widget->setAttributes( [
677 'aria-label' => $this->
msg(
'watchlist-expires-in-aria-label' )->text(),
679 'data-days-left' => $item->getExpiryInDays(),
706 $separatorClass = $rc->watchlistExpiry ?
'mw-changeslist-separator' :
'mw-changeslist-separator--semicolon';
707 return Html::element(
'span', [
'class' => $separatorClass ] ) . $this->message[
'word-separator'] .
708 '<span class="mw-changeslist-date mw-changeslist-time">' .
709 htmlspecialchars( $this->getLanguage()->userTime(
710 $rc->mAttribs[
'rc_timestamp'],
712 ) ) .
'</span> <span class="mw-changeslist-separator"></span> ';
722 $s .= $this->getTimestamp( $rc );
732 if ( static::isDeleted( $rc, RevisionRecord::DELETED_USER ) ) {
733 $deletedClass =
'history-deleted';
734 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
735 $deletedClass .=
' mw-history-suppressed';
737 $s .=
' <span class="' . $deletedClass .
'">' .
738 $this->msg(
'rev-deleted-user' )->escaped() .
'</span>';
740 $s .= $this->linkRenderer->makeUserLink(
741 $rc->getPerformerIdentity(),
744 # Don't wrap result of this with another tag, see T376814
745 $s .= $this->userLinkCache->getWithSetCallback(
746 $this->userLinkCache->makeKey(
747 $rc->mAttribs[
'rc_user_text'],
748 $this->getUser()->getName(),
749 $this->getLanguage()->getCode()
753 static fn () => Linker::userToolLinks(
754 $rc->mAttribs[
'rc_user'], $rc->mAttribs[
'rc_user_text'],
769 $entry = DatabaseLogEntry::newFromRow( $rc->mAttribs );
770 $formatter = $this->logFormatterFactory->newFromEntry( $entry );
771 $formatter->setContext( $this->getContext() );
772 $formatter->setShowUserToolLinks(
true );
774 $comment = $formatter->getComment();
775 if ( $comment !==
'' ) {
776 $dir = $this->getLanguage()->getDir();
777 $comment = Html::rawElement(
'bdi', [
'dir' => $dir ], $comment );
780 $html = $formatter->getActionText() . $this->message[
'word-separator'] . $comment .
781 $this->message[
'word-separator'] . $formatter->getActionLinks();
782 $classes = [
'mw-changeslist-log-entry' ];
786 $this->getHookRunner()->onChangesListInsertLogEntry( $entry, $this->getContext(), $html, $classes, $attribs );
787 $attribs = array_filter( $attribs,
788 Sanitizer::isReservedDataAttribute( ... ),
791 $attribs[
'class'] = $classes;
793 return Html::openElement(
'span', $attribs ) . $html . Html::closeElement(
'span' );
802 if ( static::isDeleted( $rc, RevisionRecord::DELETED_COMMENT ) ) {
803 $deletedClass =
'history-deleted';
804 if ( static::isDeleted( $rc, RevisionRecord::DELETED_RESTRICTED ) ) {
805 $deletedClass .=
' mw-history-suppressed';
807 return ' <span class="' . $deletedClass .
' comment">' .
808 $this->msg(
'rev-deleted-comment' )->escaped() .
'</span>';
809 } elseif ( isset( $rc->mAttribs[
'rc_id'] )
810 && isset( $this->formattedComments[$rc->mAttribs[
'rc_id']] )
812 return $this->formattedComments[$rc->mAttribs[
'rc_id']];
814 return $this->commentFormatter->formatBlock(
815 $rc->mAttribs[
'rc_comment'],
837 return $this->watchMsgCache->getWithSetCallback(
838 $this->watchMsgCache->makeKey(
839 'watching-users-msg',
841 $this->getUser()->getName(),
842 $this->getLanguage()->getCode()
844 function () use ( $count ) {
845 return $this->msg(
'number-of-watching-users-for-recent-changes' )
846 ->numParams( $count )->escaped();
858 return ( $rc->mAttribs[
'rc_deleted'] & $field ) == $field;
871 $performer ??= RequestContext::getMain()->getAuthority();
874 return LogEventsList::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
877 return RevisionRecord::userCanBitfield( $rc->mAttribs[
'rc_deleted'], $field, $performer );
887 return '<strong class="mw-watched">' . $link .
'</strong>';
889 return '<span class="mw-rc-unwatched">' . $link .
'</span>';
900 $this->insertPageTools( $s, $rc );
910 private function insertPageTools( &$s, &$rc ) {
914 || !$rc->mAttribs[
'rc_this_oldid']
915 || !$rc->mAttribs[
'rc_cur_id']
921 $title = $rc->getTitle();
922 $revRecord =
new MutableRevisionRecord( $title );
923 $revRecord->setId( (
int)$rc->mAttribs[
'rc_this_oldid'] );
924 $revRecord->setVisibility( (
int)$rc->mAttribs[
'rc_deleted'] );
925 $user =
new UserIdentityValue(
926 (
int)$rc->mAttribs[
'rc_user'],
927 $rc->mAttribs[
'rc_user_text']
929 $revRecord->setUser( $user );
931 $tools =
new PagerTools(
935 $rc->getAttribute(
'page_latest' ) == $rc->mAttribs[
'rc_this_oldid']
937 $this->getHookRunner(),
944 $s .= $tools->toHTML();
954 $this->insertRollback( $s, $rc );
964 if ( empty( $rc->mAttribs[
'ts_tags'] ) ) {
973 [ $tagSummary, $newClasses ] = $this->tagsCache->getWithSetCallback(
974 $this->tagsCache->makeKey(
975 $rc->mAttribs[
'ts_tags'],
976 $this->getUser()->getName(),
977 $this->getLanguage()->getCode()
979 fn () => ChangeTags::formatSummaryRow(
980 $rc->mAttribs[
'ts_tags'],
985 $classes = array_merge( $classes, $newClasses );
986 $s .= $this->message[
'word-separator'] . $tagSummary;
997 $this->insertTags( $s, $rc, $classes );
1014 return self::isUnpatrolled( $rc, $this->getUser() );
1024 $isPatrolled = $rc->mAttribs[
'rc_patrolled'];
1025 $rcSource = $rc->mAttribs[
'rc_source'];
1026 $rcLogType = $rc->mAttribs[
'rc_log_type'];
1028 $isPatrolled = $rc->rc_patrolled;
1029 $rcSource = $rc->rc_source;
1030 $rcLogType = $rc->rc_log_type;
1033 if ( $isPatrolled ) {
1053 && intval( $rcObj->getAttribute(
'rc_this_oldid' ) ) === 0;
1069 $attrs[
'data-mw-revid'] = $rc->mAttribs[
'rc_this_oldid'];
1072 $attrs[
'data-mw-logid'] = $rc->mAttribs[
'rc_logid'];
1073 $attrs[
'data-mw-logaction'] =
1074 $rc->mAttribs[
'rc_log_type'] .
'/' . $rc->mAttribs[
'rc_log_action'];
1078 $attrs[
'data-mw-ts' ] = $rc->
getAttribute(
'rc_timestamp' );
1091 $this->changeLinePrefixer = $prefixer;
1096class_alias( ChangesList::class,
'ChangesList' );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
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 value class to process existing log entries.
Class to simplify the use of log pages.
A class containing constants representing the names of configuration variables.
const RecentChangesFlags
Name constant for the RecentChangesFlags setting, for use with Config::get()
const RCChangedSizeThreshold
Name constant for the RCChangedSizeThreshold setting, for use with Config::get()
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()
Interface for objects which can provide a MediaWiki context on request.