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 ) {
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 ) ) {
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',
354 $source = $rcObj->mAttribs[
'rc_source'];
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'] = [
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(
392 $params + $queryParams
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::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 $source = $rcObj->mAttribs[
'rc_source'];
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'] = [
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 );
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> ';
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 ) ) {
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>';
834class_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.