56 $this->userLinkRenderer
67 'mediawiki.special.changeslist.enhanced',
70 parent::beginRecentChangesList();
71 return '<div class="mw-changeslist" aria-live="polite">';
85 $rc->mAttribs[
'rc_timestamp'],
88 if ( $this->lastdate ===
'' ) {
89 $this->lastdate = $date;
94 # If it's a new day, flush the cache and update $this->lastdate
95 if ( $date !== $this->lastdate ) {
96 # Process current cache (uses $this->lastdate to generate a heading)
99 $this->lastdate = $date;
102 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
114 $this->rc_cache[$cacheGroupingKey][] = $cacheEntry;
124 $cacheGroupingKey = $title->getPrefixedDBkey();
126 $source = $cacheEntry->mAttribs[
'rc_source'];
132 $cacheEntry->mAttribs[
'rc_log_type']
133 )->getPrefixedDBkey();
136 return $cacheGroupingKey;
147 # Add the namespace and title of the block as part of the class
148 $tableClasses = [
'mw-enhanced-rc',
'mw-changeslist-line' ];
149 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
151 $tableClasses[] =
'mw-changeslist-log';
152 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
153 . $block[0]->mAttribs[
'rc_log_type'] );
155 $tableClasses[] =
'mw-changeslist-edit';
156 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
157 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
159 if ( $block[0]->watched ) {
160 $tableClasses[] =
'mw-changeslist-line-watched';
162 $tableClasses[] =
'mw-changeslist-line-not-watched';
165 # Collate list of users
168 # Some catalyst variables...
173 # Default values for RC flags
174 $collectedRcFlags = [];
175 foreach ( $recentChangesFlags as $key => $value ) {
176 $flagGrouping = $value[
'grouping'] ??
'any';
177 switch ( $flagGrouping ) {
179 $collectedRcFlags[$key] =
true;
182 $collectedRcFlags[$key] =
false;
185 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
188 foreach ( $block as $rcObj ) {
191 if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
194 $username = $rcObj->getPerformerIdentity()->getName();
195 $userlink = $rcObj->userlink;
198 if ( static::isDeleted( $rcObj, LogPage::DELETED_USER ) ) {
202 if ( !isset( $usercounts[$username] ) ) {
203 $usercounts[$username] = 0;
204 $userlinks[$username] = $userlink;
210 $usercounts[$username]++;
213 # Sort the list and convert to text
214 krsort( $usercounts );
215 asort( $usercounts );
217 foreach ( $usercounts as $username => $count ) {
218 $text = (string)$userlinks[$username];
220 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
221 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
223 $users[] = Html::rawElement(
225 [
'class' =>
'mw-changeslist-user-in-group' ],
232 $revDeletedMsg =
false;
234 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
235 } elseif ( $allLogs ) {
236 $articleLink = $this->
maybeWatchedLink( $block[0]->link, $block[0]->watched );
239 $block[0], $block[0]->unpatrolled, $block[0]->watched );
245 foreach ( $block as $i => $rcObj ) {
246 $line = $this->
getLineData( $block, $rcObj, [],
false );
254 foreach ( $line[
'recentChangesFlagsRaw'] as $key => $value ) {
255 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
256 switch ( $flagGrouping ) {
259 $collectedRcFlags[$key] =
false;
264 $collectedRcFlags[$key] =
true;
268 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
275 $this->
getTags( $rcObj, $filterClasses );
276 $filterClasses = array_unique( $filterClasses );
283 $block = array_values( $block );
284 $filterClasses = array_values( $filterClasses );
286 if ( !$block || !$lines ) {
292 if ( $labels ===
'' ) {
293 foreach ( $block as $i => $rcObj ) {
295 $lineLabels = $this->
getLabels( $rcObj, $lineClasses );
296 if ( $lineLabels !==
'' ) {
297 $lines[$i][
'data'][] = $lineLabels;
302 $logText = $this->
getLogText( $block, [], $allLogs,
303 $collectedRcFlags[
'newpage'], $namehidden
306 # Character difference (does not apply if only log items)
307 $charDifference =
false;
308 if ( $RCShowChangedSize && !$allLogs ) {
310 $first = count( $block ) - 1;
311 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
312 while ( $last < $first && $block[$last]->mAttribs[
'rc_new_len'] ===
null ) {
315 while ( $last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
323 $usersList = $this->
msg(
'brackets' )->rawParams(
324 implode( $this->message[
'semicolon-separator'], $users )
328 if ( is_callable( $this->changeLinePrefixer ) ) {
333 'checkboxId' =>
'mw-checkbox-' . base64_encode( random_bytes( 3 ) ),
334 'articleLink' => $articleLink,
335 'charDifference' => $charDifference,
337 'filterClasses' => $filterClasses,
340 'logText' => $logText,
341 'numberofWatchingusers' => $numberofWatchingusers,
343 'rev-deleted-event' => $revDeletedMsg,
344 'tableClasses' => $tableClasses,
345 'timestamp' => $block[0]->timestamp,
346 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
347 'users' => $usersList,
350 $this->rcCacheIndex++;
352 return $this->templateParser->processTemplate(
353 'EnhancedChangesListGroup',
368 array $queryParams = [],
369 bool $includeLabels =
true
373 $source = $rcObj->mAttribs[
'rc_source'];
377 $titleText = $this->
msg(
'rev-deleted-event' );
379 $lineParams = [
'targetTitle' => $titleText ];
381 $classes = [
'mw-enhanced-rc' ];
382 if ( $rcObj->watched ) {
383 $classes[] =
'mw-enhanced-watched';
385 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
387 $separator =
' <span class="mw-changeslist-separator"></span> ';
389 $data[
'recentChangesFlags'] = [
391 'minor' => $rcObj->mAttribs[
'rc_minor'],
392 'unpatrolled' => $rcObj->unpatrolled,
393 'bot' => $rcObj->mAttribs[
'rc_bot'],
398 $link = htmlspecialchars( $rcObj->timestamp );
401 $link =
Html::element(
'span', [
'class' =>
'history-deleted' ], $rcObj->timestamp );
404 $params[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
405 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
406 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
411 $link = $this->linkRenderer->makeKnownLink(
415 $params + $queryParams
417 if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
418 $link =
'<span class="history-deleted">' . $link .
'</span> ';
421 $data[
'timestampLink'] = $link;
423 $currentAndLastLinks =
'';
425 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
427 $this->message[
'pipe-separator'] .
431 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
432 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
435 if ( $RCShowChangedSize ) {
438 $data[
'characterDiff'] = $cd;
439 $data[
'separatorAfterCharacterDiff'] = $separator;
449 $data[
'userLink'] = $rcObj->userlink;
450 $data[
'userTalkLink'] = $rcObj->usertalklink;
455 # Rollback, thanks etc...
460 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
463 $labels = $this->
getLabels( $rcObj, $classes );
464 if ( $includeLabels ) {
465 $data[
'labels'] = $labels;
471 $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
472 $this, $data, $block, $rcObj, $classes, $attribs );
477 $attribs = array_filter( $attribs,
478 Sanitizer::isReservedDataAttribute( ... ),
482 $lineParams[
'recentChangesFlagsRaw'] = [];
483 if ( isset( $data[
'recentChangesFlags'] ) ) {
484 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
485 # FIXME: This is used by logic, don't return it in the template params.
486 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
487 unset( $data[
'recentChangesFlags'] );
490 if ( isset( $data[
'timestampLink'] ) ) {
491 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
492 unset( $data[
'timestampLink'] );
495 $lineParams[
'classes'] = array_values( $classes );
496 $lineParams[
'attribs'] = Html::expandAttributes( $attribs );
499 $lineParams[
'data'] = array_values( $data );
514 $firstLabelIds = (string)( $block[0]->mAttribs[WatchlistLabelCondition::LABEL_IDS] ??
'' );
515 if ( $firstLabelIds ===
'' ) {
519 foreach ( $block as $rcObj ) {
520 $labelIds = (string)( $rcObj->mAttribs[WatchlistLabelCondition::LABEL_IDS] ??
'' );
521 if ( $labelIds !== $firstLabelIds ) {
526 return $this->
getLabels( $block[0], $classes );
539 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
545 static $nchanges = [];
546 static $sinceLastVisitMsg = [];
548 $n = count( $block );
549 if ( !isset( $nchanges[$n] ) ) {
550 $nchanges[$n] = $this->msg(
'nchanges' )->numParams( $n )->escaped();
554 $unvisitedOldid =
null;
555 $currentRevision = 0;
556 $previousRevision = 0;
558 $allCategorization =
true;
560 foreach ( $block as $rcObj ) {
567 $allCategorization =
false;
568 $previousRevision = $rcObj->mAttribs[
'rc_last_oldid'];
570 if ( $rcObj->watched ) {
572 $unvisitedOldid = $previousRevision;
574 if ( !$currentRevision ) {
575 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
578 $curId = $rcObj->mAttribs[
'rc_cur_id'];
584 $title = $block[0]->getTitle();
588 if ( $isnew || $allCategorization ) {
589 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
591 $links[
'total-changes'] = Html::rawElement(
'span', [],
592 $this->linkRenderer->makeKnownLink(
595 [
'class' =>
'mw-changeslist-groupdiff' ],
598 'diff' => $currentRevision,
599 'oldid' => $previousRevision,
606 !$allCategorization &&
610 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
611 $sinceLastVisitMsg[$sinceLast] =
612 $this->msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
614 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
615 $this->linkRenderer->makeKnownLink(
617 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
618 [
'class' =>
'mw-changeslist-groupdiff' ],
621 'diff' => $currentRevision,
622 'oldid' => $unvisitedOldid,
630 if ( $allLogs || $allCategorization ) {
632 } elseif ( $namehidden || !$title->exists() ) {
633 $links[
'history'] = Html::rawElement(
'span', [], $this->message[
'enhancedrc-history'] );
635 $links[
'history'] = Html::rawElement(
'span', [],
636 $this->linkRenderer->makeKnownLink(
638 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
639 [
'class' =>
'mw-changeslist-history' ],
642 'action' =>
'history',
649 $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
655 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
656 implode(
' ', $links ) );
657 return ' ' . $logtext;
669 $source = $rcObj->mAttribs[
'rc_source'];
670 $logType = $rcObj->mAttribs[
'rc_log_type'];
671 $classes = $this->getHTMLClasses( $rcObj, $rcObj->watched );
672 $classes[] =
'mw-enhanced-rc';
676 $classes[] =
'mw-changeslist-log';
677 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
679 $classes[] =
'mw-changeslist-edit';
680 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
681 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
685 $data[
'recentChangesFlags'] = [
687 'minor' => $rcObj->mAttribs[
'rc_minor'],
688 'unpatrolled' => $rcObj->unpatrolled,
689 'bot' => $rcObj->mAttribs[
'rc_bot'],
693 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
695 # Article or log link
697 $logPage =
new LogPage( $logType );
699 $logName = $logPage->getName()->text();
700 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
701 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
704 $data[
'articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
707 # Diff and hist links
709 $data[
'historyLink'] = $this->getDiffHistLinks( $rcObj,
false );
711 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
715 $cd = $this->formatCharacterDifference( $rcObj );
717 $data[
'characterDiff'] = $cd;
718 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
723 $data[
'logEntry'] = $this->insertLogEntry( $rcObj );
724 } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
725 $data[
'comment'] = $this->insertComment( $rcObj );
727 $data[
'userLink'] = $rcObj->userlink;
728 $data[
'userTalkLink'] = $rcObj->usertalklink;
729 $data[
'comment'] = $this->insertComment( $rcObj );
731 $data[
'historyLink'] = $this->getDiffHistLinks( $rcObj,
false );
733 $data[
'rollback'] = $this->getRollback( $rcObj );
737 $data[
'tags'] = $this->getTags( $rcObj, $classes );
740 $data[
'labels'] = $this->getLabels( $rcObj, $classes );
742 # Show how many people are watching this if enabled
743 $data[
'watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
745 $data[
'attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [
'class' => $classes ] );
748 $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
749 $this, $data, $rcObj );
754 $attribs = $data[
'attribs'];
755 unset( $data[
'attribs'] );
756 $attribs = array_filter( $attribs,
static function ( $key ) {
757 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
758 }, ARRAY_FILTER_USE_KEY );
761 if ( is_callable( $this->changeLinePrefixer ) ) {
762 $prefix = ( $this->changeLinePrefixer )( $rcObj, $this,
false );
765 $line = Html::openElement(
'table', $attribs ) . Html::openElement(
'tr' );
767 $line .= Html::rawElement(
'td', [],
768 $this->getHighlightsContainerDiv()
771 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
772 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
773 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
775 if ( isset( $data[
'recentChangesFlags'] ) ) {
776 $line .= $this->recentChangesFlags( $data[
'recentChangesFlags'] );
777 unset( $data[
'recentChangesFlags'] );
780 if ( isset( $data[
'timestampLink'] ) ) {
781 $line .=
"\u{00A0}" . $data[
'timestampLink'];
782 unset( $data[
'timestampLink'] );
785 $titleText = $rcObj->getTitle();
787 $titleText = $this->msg(
'rev-deleted-event' )->escaped();
789 $line .=
"\u{00A0}</td>";
790 $line .= Html::openElement(
'td', [
791 'class' =>
'mw-changeslist-line-inner',
793 'data-target-page' => $titleText,
797 foreach ( $data as $key => $dataItem ) {
798 $line .= Html::rawElement(
'span', [
799 'class' =>
'mw-changeslist-line-inner-' . $key,
803 $line .=
"</td></tr></table>\n";
820 if ( is_bool( $query ) ) {
821 $useParentheses = $query;
822 } elseif ( $query !==
null ) {
823 wfDeprecated( __METHOD__ .
' with $query parameter',
'1.36' );
828 $pageTitle = Title::newFromID( $rc->
getAttribute(
'rc_cur_id' ) );
836 $histLink = $this->linkRenderer->makeKnownLink(
839 [
'class' =>
'mw-changeslist-history' ],
842 'action' =>
'history'
845 if ( $useParentheses !==
false ) {
846 $retVal = $this->msg(
'parentheses' )
847 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
848 . $histLink )->escaped();
850 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
851 Html::rawElement(
'span', [], $rc->difflink ) .
852 Html::rawElement(
'span', [], $histLink )
855 return ' ' . $retVal;
865 if ( count( $this->rc_cache ) == 0 ) {
870 foreach ( $this->rc_cache as $block ) {
871 if ( count( $block ) < 2 ) {
872 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
874 $blockOut .= $this->recentChangesBlockGroup( $block );
878 if ( $blockOut ===
'' ) {
882 return Html::element(
'h4', [], $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';
891 return $this->recentChangesBlock() .
'</div>';
896class_alias( EnhancedChangesList::class,
'EnhancedChangesList' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
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 RCShowChangedSize
Name constant for the RCShowChangedSize setting, for use with Config::get()
Create a RCCacheEntry from a RecentChange to use in EnhancedChangesList.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Interface for objects which can provide a MediaWiki context on request.