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 );
121 $this->rc_cache[$cacheGroupingKey][] = $cacheEntry;
133 $cacheGroupingKey = $title->getPrefixedDBkey();
135 $type = $cacheEntry->mAttribs[
'rc_type'];
139 $cacheGroupingKey = SpecialPage::getTitleFor(
141 $cacheEntry->mAttribs[
'rc_log_type']
142 )->getPrefixedDBkey();
145 return $cacheGroupingKey;
154 $recentChangesFlags = $this->
getConfig()->get( MainConfigNames::RecentChangesFlags );
156 # Add the namespace and title of the block as part of the class
157 $tableClasses = [
'mw-enhanced-rc',
'mw-changeslist-line' ];
158 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
160 $tableClasses[] =
'mw-changeslist-log';
161 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
162 . $block[0]->mAttribs[
'rc_log_type'] );
164 $tableClasses[] =
'mw-changeslist-edit';
165 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
166 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
168 if ( $block[0]->watched ) {
169 $tableClasses[] =
'mw-changeslist-line-watched';
171 $tableClasses[] =
'mw-changeslist-line-not-watched';
174 # Collate list of users
177 # Some catalyst variables...
180 $RCShowChangedSize = $this->
getConfig()->get( MainConfigNames::RCShowChangedSize );
182 # Default values for RC flags
183 $collectedRcFlags = [];
184 foreach ( $recentChangesFlags as $key => $value ) {
185 $flagGrouping = $value[
'grouping'] ??
'any';
186 switch ( $flagGrouping ) {
188 $collectedRcFlags[$key] =
true;
191 $collectedRcFlags[$key] =
false;
194 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
197 foreach ( $block as $rcObj ) {
200 if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
203 $username = $rcObj->getPerformerIdentity()->getName();
204 $userlink = $rcObj->userlink;
205 if ( !isset( $usercounts[$username] ) ) {
206 $usercounts[$username] = 0;
207 $userlinks[$username] = $userlink;
209 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
213 $usercounts[$username]++;
216 # Sort the list and convert to text
217 krsort( $usercounts );
218 asort( $usercounts );
220 foreach ( $usercounts as $username => $count ) {
221 $text = (string)$userlinks[$username];
223 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
224 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
231 $revDeletedMsg =
false;
233 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
234 } elseif ( $allLogs ) {
235 $articleLink = $this->
maybeWatchedLink( $block[0]->link, $block[0]->watched );
238 $block[0], $block[0]->unpatrolled, $block[0]->watched );
244 foreach ( $block as $i => $rcObj ) {
253 foreach ( $line[
'recentChangesFlagsRaw'] as $key => $value ) {
254 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
255 switch ( $flagGrouping ) {
258 $collectedRcFlags[$key] =
false;
263 $collectedRcFlags[$key] =
true;
267 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
274 $this->
getTags( $rcObj, $filterClasses );
275 $filterClasses = array_unique( $filterClasses );
282 $block = array_values( $block );
283 $filterClasses = array_values( $filterClasses );
285 if ( !$block || !
$lines ) {
290 $logText = $this->
getLogText( $block, [], $allLogs,
291 $collectedRcFlags[
'newpage'], $namehidden
294 # Character difference (does not apply if only log items)
295 $charDifference =
false;
296 if ( $RCShowChangedSize && !$allLogs ) {
298 $first = count( $block ) - 1;
299 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
300 while ( $last < $first && $block[$last]->mAttribs[
'rc_new_len'] ===
null ) {
303 while ( $last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
311 $usersList = $this->
msg(
'brackets' )->rawParams(
312 implode( $this->message[
'semicolon-separator'], $users )
316 if ( is_callable( $this->changeLinePrefixer ) ) {
317 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this,
true );
321 'checkboxId' =>
'mw-checkbox-' . base64_encode( random_bytes( 3 ) ),
322 'articleLink' => $articleLink,
323 'charDifference' => $charDifference,
325 'filterClasses' => $filterClasses,
327 'logText' => $logText,
328 'numberofWatchingusers' => $numberofWatchingusers,
330 'rev-deleted-event' => $revDeletedMsg,
331 'tableClasses' => $tableClasses,
332 'timestamp' => $block[0]->timestamp,
333 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
334 'users' => $usersList,
337 $this->rcCacheIndex++;
339 return $this->templateParser->processTemplate(
340 'EnhancedChangesListGroup',
352 $RCShowChangedSize = $this->
getConfig()->get( MainConfigNames::RCShowChangedSize );
354 $type = $rcObj->mAttribs[
'rc_type'];
356 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
358 $classes = [
'mw-enhanced-rc' ];
359 if ( $rcObj->watched ) {
360 $classes[] =
'mw-enhanced-watched';
362 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
364 $separator =
' <span class="mw-changeslist-separator"></span> ';
366 $data[
'recentChangesFlags'] = [
367 'newpage' => $type ==
RC_NEW,
368 'minor' => $rcObj->mAttribs[
'rc_minor'],
369 'unpatrolled' => $rcObj->unpatrolled,
370 'bot' => $rcObj->mAttribs[
'rc_bot'],
375 $link = htmlspecialchars( $rcObj->timestamp );
378 $link = Html::element(
'span', [
'class' =>
'history-deleted' ], $rcObj->timestamp );
381 $params[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
382 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
383 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
388 $link = $this->linkRenderer->makeKnownLink(
394 if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
395 $link =
'<span class="history-deleted">' . $link .
'</span> ';
398 $data[
'timestampLink'] = $link;
400 $currentAndLastLinks =
'';
402 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
404 $this->message[
'pipe-separator'] .
408 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
409 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
412 if ( $RCShowChangedSize ) {
415 $data[
'characterDiff'] = $cd;
416 $data[
'separatorAfterCharacterDiff'] = $separator;
426 $data[
'userLink'] = $rcObj->userlink;
427 $data[
'userTalkLink'] = $rcObj->usertalklink;
432 # Rollback, thanks etc...
437 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
442 $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
443 $this, $data, $block, $rcObj, $classes, $attribs );
448 $attribs = array_filter( $attribs,
449 [ Sanitizer::class,
'isReservedDataAttribute' ],
453 $lineParams[
'recentChangesFlagsRaw'] = [];
454 if ( isset( $data[
'recentChangesFlags'] ) ) {
455 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
456 # FIXME: This is used by logic, don't return it in the template params.
457 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
458 unset( $data[
'recentChangesFlags'] );
461 if ( isset( $data[
'timestampLink'] ) ) {
462 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
463 unset( $data[
'timestampLink'] );
466 $lineParams[
'classes'] = array_values( $classes );
467 $lineParams[
'attribs'] = Html::expandAttributes( $attribs );
470 $lineParams[
'data'] = array_values( $data );
485 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
491 static $nchanges = [];
492 static $sinceLastVisitMsg = [];
494 $n = count( $block );
495 if ( !isset( $nchanges[$n] ) ) {
496 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
500 $unvisitedOldid =
null;
501 $currentRevision = 0;
502 $previousRevision = 0;
504 $allCategorization =
true;
506 foreach ( $block as $rcObj ) {
513 $allCategorization =
false;
514 $previousRevision = $rcObj->mAttribs[
'rc_last_oldid'];
516 if ( $rcObj->watched ) {
518 $unvisitedOldid = $previousRevision;
520 if ( !$currentRevision ) {
521 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
524 $curId = $rcObj->mAttribs[
'rc_cur_id'];
530 $title = $block[0]->getTitle();
534 if ( $isnew || $allCategorization ) {
535 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
537 $links[
'total-changes'] = Html::rawElement(
'span', [],
538 $this->linkRenderer->makeKnownLink(
541 [
'class' =>
'mw-changeslist-groupdiff' ],
544 'diff' => $currentRevision,
545 'oldid' => $previousRevision,
552 !$allCategorization &&
556 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
557 $sinceLastVisitMsg[$sinceLast] =
558 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
560 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
561 $this->linkRenderer->makeKnownLink(
563 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
564 [
'class' =>
'mw-changeslist-groupdiff' ],
567 'diff' => $currentRevision,
568 'oldid' => $unvisitedOldid,
576 if ( $allLogs || $allCategorization ) {
578 } elseif ( $namehidden || !$title->exists() ) {
579 $links[
'history'] = Html::rawElement(
'span', [], $this->message[
'enhancedrc-history'] );
581 $links[
'history'] = Html::rawElement(
'span', [],
582 $this->linkRenderer->makeKnownLink(
584 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
585 [
'class' =>
'mw-changeslist-history' ],
588 'action' =>
'history',
595 $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
601 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
602 implode(
' ', $links ) );
603 return ' ' . $logtext;
615 $type = $rcObj->mAttribs[
'rc_type'];
616 $logType = $rcObj->mAttribs[
'rc_log_type'];
618 $classes[] =
'mw-enhanced-rc';
622 $classes[] =
'mw-changeslist-log';
623 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
625 $classes[] =
'mw-changeslist-edit';
626 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
627 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
631 $data[
'recentChangesFlags'] = [
632 'newpage' => $type ==
RC_NEW,
633 'minor' => $rcObj->mAttribs[
'rc_minor'],
634 'unpatrolled' => $rcObj->unpatrolled,
635 'bot' => $rcObj->mAttribs[
'rc_bot'],
639 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
641 # Article or log link
643 $logPage =
new LogPage( $logType );
644 $logTitle = SpecialPage::getTitleFor(
'Log', $logType );
645 $logName = $logPage->getName()->text();
646 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
647 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
650 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
653 # Diff and hist links
657 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
660 if ( $this->
getConfig()->
get( MainConfigNames::RCShowChangedSize ) ) {
663 $data[
'characterDiff'] = $cd;
664 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
673 $data[
'userLink'] = $rcObj->userlink;
674 $data[
'userTalkLink'] = $rcObj->usertalklink;
683 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
685 # Show how many people are watching this if enabled
688 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
691 $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
692 $this, $data, $rcObj );
697 $attribs = $data[
'attribs'];
698 unset( $data[
'attribs'] );
699 $attribs = array_filter( $attribs,
static function ( $key ) {
700 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
701 }, ARRAY_FILTER_USE_KEY );
704 if ( is_callable( $this->changeLinePrefixer ) ) {
705 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this,
false );
708 $line = Html::openElement(
'table', $attribs ) . Html::openElement(
'tr' );
710 $line .= Html::rawElement(
'td', [],
714 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
715 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
716 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
718 if ( isset( $data[
'recentChangesFlags'] ) ) {
720 unset( $data[
'recentChangesFlags'] );
723 if ( isset( $data[
'timestampLink'] ) ) {
724 $line .=
"\u{00A0}" . $data[
'timestampLink'];
725 unset( $data[
'timestampLink'] );
727 $line .=
"\u{00A0}</td>";
728 $line .= Html::openElement(
'td', [
729 'class' =>
'mw-changeslist-line-inner',
731 'data-target-page' => $rcObj->getTitle(),
735 foreach ( $data as $key => $dataItem ) {
736 $line .= Html::rawElement(
'span', [
737 'class' =>
'mw-changeslist-line-inner-' . $key,
741 $line .=
"</td></tr></table>\n";
758 if ( is_bool( $query ) ) {
759 $useParentheses = $query;
760 } elseif ( $query !==
null ) {
761 wfDeprecated( __METHOD__ .
' with $query parameter',
'1.36' );
766 $pageTitle = Title::newFromID( $rc->
getAttribute(
'rc_cur_id' ) );
774 $histLink = $this->linkRenderer->makeKnownLink(
777 [
'class' =>
'mw-changeslist-history' ],
780 'action' =>
'history'
783 if ( $useParentheses !==
false ) {
784 $retVal = $this->
msg(
'parentheses' )
785 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
786 . $histLink )->escaped();
788 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
789 Html::rawElement(
'span', [], $rc->difflink ) .
790 Html::rawElement(
'span', [], $histLink )
793 return ' ' . $retVal;
803 if ( count( $this->rc_cache ) == 0 ) {
808 foreach ( $this->rc_cache as $block ) {
809 if ( count( $block ) < 2 ) {
816 if ( $blockOut ===
'' ) {
820 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