56 public function __construct( $context, array $filterGroups = [] ) {
74 'mediawiki.special.changeslist.enhanced',
77 parent::beginRecentChangesList();
78 return '<div class="mw-changeslist" aria-live="polite">';
92 $rc->mAttribs[
'rc_timestamp'],
95 if ( $this->lastdate ===
'' ) {
96 $this->lastdate = $date;
101 # If it's a new day, flush the cache and update $this->lastdate
102 if ( $date !== $this->lastdate ) {
103 # Process current cache (uses $this->lastdate to generate a heading)
105 $this->rc_cache = [];
106 $this->lastdate = $date;
109 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
123 $this->rc_cache[$cacheGroupingKey][] = $cacheEntry;
135 $cacheGroupingKey = $title->getPrefixedDBkey();
137 $type = $cacheEntry->mAttribs[
'rc_type'];
141 $cacheGroupingKey = SpecialPage::getTitleFor(
143 $cacheEntry->mAttribs[
'rc_log_type']
144 )->getPrefixedDBkey();
147 return $cacheGroupingKey;
156 $recentChangesFlags = $this->
getConfig()->get( MainConfigNames::RecentChangesFlags );
158 # Add the namespace and title of the block as part of the class
159 $tableClasses = [
'mw-enhanced-rc',
'mw-changeslist-line' ];
160 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
162 $tableClasses[] =
'mw-changeslist-log';
163 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
164 . $block[0]->mAttribs[
'rc_log_type'] );
166 $tableClasses[] =
'mw-changeslist-edit';
167 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
168 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
170 if ( $block[0]->watched ) {
171 $tableClasses[] =
'mw-changeslist-line-watched';
173 $tableClasses[] =
'mw-changeslist-line-not-watched';
176 # Collate list of users
179 # Some catalyst variables...
182 $RCShowChangedSize = $this->
getConfig()->get( MainConfigNames::RCShowChangedSize );
184 # Default values for RC flags
185 $collectedRcFlags = [];
186 foreach ( $recentChangesFlags as $key => $value ) {
187 $flagGrouping = $value[
'grouping'] ??
'any';
188 switch ( $flagGrouping ) {
190 $collectedRcFlags[$key] =
true;
193 $collectedRcFlags[$key] =
false;
196 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
199 foreach ( $block as $rcObj ) {
202 if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
205 $username = $rcObj->getPerformerIdentity()->getName();
206 $userlink = $rcObj->userlink;
207 if ( !isset( $usercounts[$username] ) ) {
208 $usercounts[$username] = 0;
209 $userlinks[$username] = $userlink;
211 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
215 $usercounts[$username]++;
218 # Sort the list and convert to text
219 krsort( $usercounts );
220 asort( $usercounts );
222 foreach ( $usercounts as $username => $count ) {
223 $text = (string)$userlinks[$username];
225 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
226 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
233 $revDeletedMsg =
false;
235 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
236 } elseif ( $allLogs ) {
237 $articleLink = $this->
maybeWatchedLink( $block[0]->link, $block[0]->watched );
240 $block[0], $block[0]->unpatrolled, $block[0]->watched );
246 foreach ( $block as $i => $rcObj ) {
255 foreach ( $line[
'recentChangesFlagsRaw'] as $key => $value ) {
256 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
257 switch ( $flagGrouping ) {
260 $collectedRcFlags[$key] =
false;
265 $collectedRcFlags[$key] =
true;
269 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
276 $this->
getTags( $rcObj, $filterClasses );
277 $filterClasses = array_unique( $filterClasses );
284 $block = array_values( $block );
285 $filterClasses = array_values( $filterClasses );
287 if ( !$block || !
$lines ) {
292 $logText = $this->
getLogText( $block, [], $allLogs,
293 $collectedRcFlags[
'newpage'], $namehidden
296 # Character difference (does not apply if only log items)
297 $charDifference =
false;
298 if ( $RCShowChangedSize && !$allLogs ) {
300 $first = count( $block ) - 1;
301 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
302 while ( $last < $first && $block[$last]->mAttribs[
'rc_new_len'] ===
null ) {
305 while ( $last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
313 $usersList = $this->
msg(
'brackets' )->rawParams(
314 implode( $this->message[
'semicolon-separator'], $users )
318 if ( is_callable( $this->changeLinePrefixer ) ) {
319 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this,
true );
323 'checkboxId' =>
'mw-checkbox-' . base64_encode( random_bytes( 3 ) ),
324 'articleLink' => $articleLink,
325 'charDifference' => $charDifference,
327 'filterClasses' => $filterClasses,
329 'logText' => $logText,
330 'numberofWatchingusers' => $numberofWatchingusers,
332 'rev-deleted-event' => $revDeletedMsg,
333 'tableClasses' => $tableClasses,
334 'timestamp' => $block[0]->timestamp,
335 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
336 'users' => $usersList,
339 $this->rcCacheIndex++;
341 return $this->templateParser->processTemplate(
342 'EnhancedChangesListGroup',
354 $RCShowChangedSize = $this->
getConfig()->get( MainConfigNames::RCShowChangedSize );
356 $type = $rcObj->mAttribs[
'rc_type'];
358 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
360 $classes = [
'mw-enhanced-rc' ];
361 if ( $rcObj->watched ) {
362 $classes[] =
'mw-enhanced-watched';
364 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
366 $separator =
' <span class="mw-changeslist-separator"></span> ';
368 $data[
'recentChangesFlags'] = [
369 'newpage' => $type ==
RC_NEW,
370 'minor' => $rcObj->mAttribs[
'rc_minor'],
371 'unpatrolled' => $rcObj->unpatrolled,
372 'bot' => $rcObj->mAttribs[
'rc_bot'],
377 $link = htmlspecialchars( $rcObj->timestamp );
380 $link = Html::element(
'span', [
'class' =>
'history-deleted' ], $rcObj->timestamp );
383 $params[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
384 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
385 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
390 $link = $this->linkRenderer->makeKnownLink(
396 if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
397 $link =
'<span class="history-deleted">' . $link .
'</span> ';
400 $data[
'timestampLink'] = $link;
402 $currentAndLastLinks =
'';
404 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
406 $this->message[
'pipe-separator'] .
410 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
411 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
414 if ( $RCShowChangedSize ) {
417 $data[
'characterDiff'] = $cd;
418 $data[
'separatorAfterCharacterDiff'] = $separator;
428 $data[
'userLink'] = $rcObj->userlink;
429 $data[
'userTalkLink'] = $rcObj->usertalklink;
434 # Rollback, thanks etc...
439 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
444 $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
445 $this, $data, $block, $rcObj, $classes, $attribs );
450 $attribs = array_filter( $attribs,
451 [ Sanitizer::class,
'isReservedDataAttribute' ],
455 $lineParams[
'recentChangesFlagsRaw'] = [];
456 if ( isset( $data[
'recentChangesFlags'] ) ) {
457 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
458 # FIXME: This is used by logic, don't return it in the template params.
459 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
460 unset( $data[
'recentChangesFlags'] );
463 if ( isset( $data[
'timestampLink'] ) ) {
464 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
465 unset( $data[
'timestampLink'] );
468 $lineParams[
'classes'] = array_values( $classes );
469 $lineParams[
'attribs'] = Html::expandAttributes( $attribs );
472 $lineParams[
'data'] = array_values( $data );
487 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
493 static $nchanges = [];
494 static $sinceLastVisitMsg = [];
496 $n = count( $block );
497 if ( !isset( $nchanges[$n] ) ) {
498 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
502 $unvisitedOldid =
null;
503 $currentRevision = 0;
504 $previousRevision = 0;
506 $allCategorization =
true;
508 foreach ( $block as $rcObj ) {
515 $allCategorization =
false;
516 $previousRevision = $rcObj->mAttribs[
'rc_last_oldid'];
518 if ( $rcObj->watched ) {
520 $unvisitedOldid = $previousRevision;
522 if ( !$currentRevision ) {
523 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
526 $curId = $rcObj->mAttribs[
'rc_cur_id'];
532 $title = $block[0]->getTitle();
536 if ( $isnew || $allCategorization ) {
537 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
539 $links[
'total-changes'] = Html::rawElement(
'span', [],
540 $this->linkRenderer->makeKnownLink(
543 [
'class' =>
'mw-changeslist-groupdiff' ],
546 'diff' => $currentRevision,
547 'oldid' => $previousRevision,
554 !$allCategorization &&
558 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
559 $sinceLastVisitMsg[$sinceLast] =
560 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
562 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
563 $this->linkRenderer->makeKnownLink(
565 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
566 [
'class' =>
'mw-changeslist-groupdiff' ],
569 'diff' => $currentRevision,
570 'oldid' => $unvisitedOldid,
578 if ( $allLogs || $allCategorization ) {
580 } elseif ( $namehidden || !$title->exists() ) {
581 $links[
'history'] = Html::rawElement(
'span', [], $this->message[
'enhancedrc-history'] );
583 $links[
'history'] = Html::rawElement(
'span', [],
584 $this->linkRenderer->makeKnownLink(
586 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
587 [
'class' =>
'mw-changeslist-history' ],
590 'action' =>
'history',
597 $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
603 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
604 implode(
' ', $links ) );
605 return ' ' . $logtext;
617 $type = $rcObj->mAttribs[
'rc_type'];
618 $logType = $rcObj->mAttribs[
'rc_log_type'];
620 $classes[] =
'mw-enhanced-rc';
624 $classes[] =
'mw-changeslist-log';
625 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
627 $classes[] =
'mw-changeslist-edit';
628 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
629 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
633 $data[
'recentChangesFlags'] = [
634 'newpage' => $type ==
RC_NEW,
635 'minor' => $rcObj->mAttribs[
'rc_minor'],
636 'unpatrolled' => $rcObj->unpatrolled,
637 'bot' => $rcObj->mAttribs[
'rc_bot'],
641 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
643 # Article or log link
645 $logPage =
new LogPage( $logType );
646 $logTitle = SpecialPage::getTitleFor(
'Log', $logType );
647 $logName = $logPage->getName()->text();
648 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
649 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
652 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
655 # Diff and hist links
659 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
662 if ( $this->
getConfig()->
get( MainConfigNames::RCShowChangedSize ) ) {
665 $data[
'characterDiff'] = $cd;
666 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
675 $data[
'userLink'] = $rcObj->userlink;
676 $data[
'userTalkLink'] = $rcObj->usertalklink;
685 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
687 # Show how many people are watching this if enabled
690 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
693 $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
694 $this, $data, $rcObj );
699 $attribs = $data[
'attribs'];
700 unset( $data[
'attribs'] );
701 $attribs = array_filter( $attribs,
static function ( $key ) {
702 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
703 }, ARRAY_FILTER_USE_KEY );
706 if ( is_callable( $this->changeLinePrefixer ) ) {
707 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this,
false );
710 $line = Html::openElement(
'table', $attribs ) . Html::openElement(
'tr' );
712 $line .= Html::rawElement(
'td', [],
716 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
717 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
718 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
720 if ( isset( $data[
'recentChangesFlags'] ) ) {
722 unset( $data[
'recentChangesFlags'] );
725 if ( isset( $data[
'timestampLink'] ) ) {
726 $line .=
"\u{00A0}" . $data[
'timestampLink'];
727 unset( $data[
'timestampLink'] );
729 $line .=
"\u{00A0}</td>";
730 $line .= Html::openElement(
'td', [
731 'class' =>
'mw-changeslist-line-inner',
733 'data-target-page' => $rcObj->getTitle(),
737 foreach ( $data as $key => $dataItem ) {
738 $line .= Html::rawElement(
'span', [
739 'class' =>
'mw-changeslist-line-inner-' . $key,
743 $line .=
"</td></tr></table>\n";
760 if ( is_bool( $query ) ) {
761 $useParentheses = $query;
762 } elseif ( $query !==
null ) {
763 wfDeprecated( __METHOD__ .
' with $query parameter',
'1.36' );
768 $pageTitle = Title::newFromID( $rc->
getAttribute(
'rc_cur_id' ) );
776 $histLink = $this->linkRenderer->makeKnownLink(
779 [
'class' =>
'mw-changeslist-history' ],
782 'action' =>
'history'
785 if ( $useParentheses !==
false ) {
786 $retVal = $this->
msg(
'parentheses' )
787 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
788 . $histLink )->escaped();
790 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
791 Html::rawElement(
'span', [], $rc->difflink ) .
792 Html::rawElement(
'span', [], $histLink )
795 return ' ' . $retVal;
805 if ( count( $this->rc_cache ) == 0 ) {
810 foreach ( $this->rc_cache as $block ) {
811 if ( count( $block ) < 2 ) {
818 if ( $blockOut ===
'' ) {
822 return Html::element(
'h4', [], $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
array $params
The job parameters.
Base class for lists of recent changes shown on special pages.
maybeWatchedLink( $link, $watched=false)
getHighlightsContainerDiv()
Get the container for highlights that are used in the new StructuredFilters system.
recentChangesFlags( $flags, $nothing="\u{00A0}")
Returns the appropriate flags for new page, minor change and patrolling.
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.
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...
getRollback(RecentChange $rc)
insertLogEntry( $rc)
Insert a formatted action.
ChangesListFilterGroup[] $filterGroups
insertComment( $rc)
Insert a formatted comment.
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.
Generate a list of changes using an Enhanced system (uses javascript).
RCCacheEntry[][] $rc_cache
TemplateParser $templateParser
recentChangesBlock()
If enhanced RC is in use, this function takes the previously cached RC lines, arranges them,...
getDiffHistLinks(RCCacheEntry $rc, $query=null, $useParentheses=null)
Returns value to be used in 'historyLink' element of $data param in EnhancedChangesListModifyBlockLin...
makeCacheGroupingKey(RCCacheEntry $cacheEntry)
beginRecentChangesList()
Add the JavaScript file for enhanced changeslist.
__construct( $context, array $filterGroups=[])
endRecentChangesList()
Returns text for the end of RC If enhanced RC is in use, returns pretty much all the text.
addCacheEntry(RCCacheEntry $cacheEntry)
Put accumulated information into the cache, for later display.
RCCacheEntryFactory $cacheEntryFactory
recentChangesBlockGroup( $block)
Enhanced RC group.
getLineData(array $block, RCCacheEntry $rcObj, array $queryParams=[])
recentChangesBlockLine( $rcObj)
Enhanced RC ungrouped line.
recentChangesLine(&$rc, $watched=false, $linenumber=null)
Format a line for enhanced recentchange (aka with javascript and block of lines).
getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden)
Generates amount of changes (linking to diff ) & link to history.
Marks HTML that shouldn't be escaped.
Class to simplify the use of log pages.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
A class containing constants representing the names of configuration variables.
Parent class for all special pages.
Create a RCCacheEntry from a RecentChange to use in EnhancedChangesList.
getAttribute( $name)
Get an attribute value.
Interface for objects which can provide a MediaWiki context on request.
if(!file_exists( $CREDITS)) $lines