55 $this->userLinkRenderer
66 'mediawiki.special.changeslist.enhanced',
69 parent::beginRecentChangesList();
70 return '<div class="mw-changeslist" aria-live="polite">';
84 $rc->mAttribs[
'rc_timestamp'],
87 if ( $this->lastdate ===
'' ) {
88 $this->lastdate = $date;
93 # If it's a new day, flush the cache and update $this->lastdate
94 if ( $date !== $this->lastdate ) {
95 # Process current cache (uses $this->lastdate to generate a heading)
98 $this->lastdate = $date;
101 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
113 $this->rc_cache[$cacheGroupingKey][] = $cacheEntry;
123 $cacheGroupingKey = $title->getPrefixedDBkey();
125 $source = $cacheEntry->mAttribs[
'rc_source'];
131 $cacheEntry->mAttribs[
'rc_log_type']
132 )->getPrefixedDBkey();
135 return $cacheGroupingKey;
146 # Add the namespace and title of the block as part of the class
147 $tableClasses = [
'mw-enhanced-rc',
'mw-changeslist-line' ];
148 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
150 $tableClasses[] =
'mw-changeslist-log';
151 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
152 . $block[0]->mAttribs[
'rc_log_type'] );
154 $tableClasses[] =
'mw-changeslist-edit';
155 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
156 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
158 if ( $block[0]->watched ) {
159 $tableClasses[] =
'mw-changeslist-line-watched';
161 $tableClasses[] =
'mw-changeslist-line-not-watched';
164 # Collate list of users
167 # Some catalyst variables...
172 # Default values for RC flags
173 $collectedRcFlags = [];
174 foreach ( $recentChangesFlags as $key => $value ) {
175 $flagGrouping = $value[
'grouping'] ??
'any';
176 switch ( $flagGrouping ) {
178 $collectedRcFlags[$key] =
true;
181 $collectedRcFlags[$key] =
false;
184 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
187 foreach ( $block as $rcObj ) {
190 if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
193 $username = $rcObj->getPerformerIdentity()->getName();
194 $userlink = $rcObj->userlink;
197 if ( static::isDeleted( $rcObj, LogPage::DELETED_USER ) ) {
201 if ( !isset( $usercounts[$username] ) ) {
202 $usercounts[$username] = 0;
203 $userlinks[$username] = $userlink;
209 $usercounts[$username]++;
212 # Sort the list and convert to text
213 krsort( $usercounts );
214 asort( $usercounts );
216 foreach ( $usercounts as $username => $count ) {
217 $text = (string)$userlinks[$username];
219 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
220 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
222 $users[] = Html::rawElement(
224 [
'class' =>
'mw-changeslist-user-in-group' ],
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 ) {
245 $line = $this->
getLineData( $block, $rcObj, [],
false );
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 $labels = $this->
getLabels( $block[0], $tableClasses );
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 ) ) {
323 'checkboxId' =>
'mw-checkbox-' . base64_encode( random_bytes( 3 ) ),
324 'articleLink' => $articleLink,
325 'charDifference' => $charDifference,
327 'filterClasses' => $filterClasses,
330 'logText' => $logText,
331 'numberofWatchingusers' => $numberofWatchingusers,
333 'rev-deleted-event' => $revDeletedMsg,
334 'tableClasses' => $tableClasses,
335 'timestamp' => $block[0]->timestamp,
336 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
337 'users' => $usersList,
340 $this->rcCacheIndex++;
342 return $this->templateParser->processTemplate(
343 'EnhancedChangesListGroup',
358 array $queryParams = [],
359 bool $includeLabels =
true
363 $source = $rcObj->mAttribs[
'rc_source'];
365 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
367 $classes = [
'mw-enhanced-rc' ];
368 if ( $rcObj->watched ) {
369 $classes[] =
'mw-enhanced-watched';
371 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
373 $separator =
' <span class="mw-changeslist-separator"></span> ';
375 $data[
'recentChangesFlags'] = [
377 'minor' => $rcObj->mAttribs[
'rc_minor'],
378 'unpatrolled' => $rcObj->unpatrolled,
379 'bot' => $rcObj->mAttribs[
'rc_bot'],
384 $link = htmlspecialchars( $rcObj->timestamp );
387 $link =
Html::element(
'span', [
'class' =>
'history-deleted' ], $rcObj->timestamp );
390 $params[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
391 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
392 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
397 $link = $this->linkRenderer->makeKnownLink(
401 $params + $queryParams
403 if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
404 $link =
'<span class="history-deleted">' . $link .
'</span> ';
407 $data[
'timestampLink'] = $link;
409 $currentAndLastLinks =
'';
411 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
413 $this->message[
'pipe-separator'] .
417 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
418 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
421 if ( $RCShowChangedSize ) {
424 $data[
'characterDiff'] = $cd;
425 $data[
'separatorAfterCharacterDiff'] = $separator;
435 $data[
'userLink'] = $rcObj->userlink;
436 $data[
'userTalkLink'] = $rcObj->usertalklink;
441 # Rollback, thanks etc...
446 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
449 $labels = $this->
getLabels( $rcObj, $classes );
450 if ( $includeLabels ) {
451 $data[
'labels'] = $labels;
457 $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
458 $this, $data, $block, $rcObj, $classes, $attribs );
463 $attribs = array_filter( $attribs,
464 Sanitizer::isReservedDataAttribute( ... ),
468 $lineParams[
'recentChangesFlagsRaw'] = [];
469 if ( isset( $data[
'recentChangesFlags'] ) ) {
470 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
471 # FIXME: This is used by logic, don't return it in the template params.
472 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
473 unset( $data[
'recentChangesFlags'] );
476 if ( isset( $data[
'timestampLink'] ) ) {
477 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
478 unset( $data[
'timestampLink'] );
481 $lineParams[
'classes'] = array_values( $classes );
482 $lineParams[
'attribs'] = Html::expandAttributes( $attribs );
485 $lineParams[
'data'] = array_values( $data );
500 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
506 static $nchanges = [];
507 static $sinceLastVisitMsg = [];
509 $n = count( $block );
510 if ( !isset( $nchanges[$n] ) ) {
511 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
515 $unvisitedOldid =
null;
516 $currentRevision = 0;
517 $previousRevision = 0;
519 $allCategorization =
true;
521 foreach ( $block as $rcObj ) {
528 $allCategorization =
false;
529 $previousRevision = $rcObj->mAttribs[
'rc_last_oldid'];
531 if ( $rcObj->watched ) {
533 $unvisitedOldid = $previousRevision;
535 if ( !$currentRevision ) {
536 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
539 $curId = $rcObj->mAttribs[
'rc_cur_id'];
545 $title = $block[0]->getTitle();
549 if ( $isnew || $allCategorization ) {
550 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
552 $links[
'total-changes'] = Html::rawElement(
'span', [],
553 $this->linkRenderer->makeKnownLink(
556 [
'class' =>
'mw-changeslist-groupdiff' ],
559 'diff' => $currentRevision,
560 'oldid' => $previousRevision,
567 !$allCategorization &&
571 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
572 $sinceLastVisitMsg[$sinceLast] =
573 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
575 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
576 $this->linkRenderer->makeKnownLink(
578 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
579 [
'class' =>
'mw-changeslist-groupdiff' ],
582 'diff' => $currentRevision,
583 'oldid' => $unvisitedOldid,
591 if ( $allLogs || $allCategorization ) {
593 } elseif ( $namehidden || !$title->exists() ) {
594 $links[
'history'] = Html::rawElement(
'span', [], $this->message[
'enhancedrc-history'] );
596 $links[
'history'] = Html::rawElement(
'span', [],
597 $this->linkRenderer->makeKnownLink(
599 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
600 [
'class' =>
'mw-changeslist-history' ],
603 'action' =>
'history',
610 $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
616 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
617 implode(
' ', $links ) );
618 return ' ' . $logtext;
630 $source = $rcObj->mAttribs[
'rc_source'];
631 $logType = $rcObj->mAttribs[
'rc_log_type'];
633 $classes[] =
'mw-enhanced-rc';
637 $classes[] =
'mw-changeslist-log';
638 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
640 $classes[] =
'mw-changeslist-edit';
641 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
642 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
646 $data[
'recentChangesFlags'] = [
648 'minor' => $rcObj->mAttribs[
'rc_minor'],
649 'unpatrolled' => $rcObj->unpatrolled,
650 'bot' => $rcObj->mAttribs[
'rc_bot'],
654 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
656 # Article or log link
658 $logPage =
new LogPage( $logType );
660 $logName = $logPage->getName()->text();
661 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
662 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
665 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
668 # Diff and hist links
672 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
678 $data[
'characterDiff'] = $cd;
679 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
688 $data[
'userLink'] = $rcObj->userlink;
689 $data[
'userTalkLink'] = $rcObj->usertalklink;
698 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
701 $data[
'labels'] = $this->
getLabels( $rcObj, $classes );
703 # Show how many people are watching this if enabled
706 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
709 $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
710 $this, $data, $rcObj );
715 $attribs = $data[
'attribs'];
716 unset( $data[
'attribs'] );
717 $attribs = array_filter( $attribs,
static function ( $key ) {
718 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
719 }, ARRAY_FILTER_USE_KEY );
722 if ( is_callable( $this->changeLinePrefixer ) ) {
726 $line = Html::openElement(
'table', $attribs ) . Html::openElement(
'tr' );
728 $line .= Html::rawElement(
'td', [],
732 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
733 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
734 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
736 if ( isset( $data[
'recentChangesFlags'] ) ) {
738 unset( $data[
'recentChangesFlags'] );
741 if ( isset( $data[
'timestampLink'] ) ) {
742 $line .=
"\u{00A0}" . $data[
'timestampLink'];
743 unset( $data[
'timestampLink'] );
745 $line .=
"\u{00A0}</td>";
746 $line .= Html::openElement(
'td', [
747 'class' =>
'mw-changeslist-line-inner',
749 'data-target-page' => $rcObj->getTitle(),
753 foreach ( $data as $key => $dataItem ) {
754 $line .= Html::rawElement(
'span', [
755 'class' =>
'mw-changeslist-line-inner-' . $key,
759 $line .=
"</td></tr></table>\n";
776 if ( is_bool( $query ) ) {
777 $useParentheses = $query;
778 } elseif ( $query !==
null ) {
779 wfDeprecated( __METHOD__ .
' with $query parameter',
'1.36' );
784 $pageTitle = Title::newFromID( $rc->
getAttribute(
'rc_cur_id' ) );
792 $histLink = $this->linkRenderer->makeKnownLink(
795 [
'class' =>
'mw-changeslist-history' ],
798 'action' =>
'history'
801 if ( $useParentheses !==
false ) {
802 $retVal = $this->
msg(
'parentheses' )
803 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
804 . $histLink )->escaped();
806 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
807 Html::rawElement(
'span', [], $rc->difflink ) .
808 Html::rawElement(
'span', [], $histLink )
811 return ' ' . $retVal;
821 if ( count( $this->rc_cache ) == 0 ) {
826 foreach ( $this->rc_cache as $block ) {
827 if ( count( $block ) < 2 ) {
834 if ( $blockOut ===
'' ) {
838 return Html::element(
'h4', [], $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';
852class_alias( EnhancedChangesList::class,
'EnhancedChangesList' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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.