69 $this->userLinkRenderer
80 'mediawiki.special.changeslist.enhanced',
83 parent::beginRecentChangesList();
84 return '<div class="mw-changeslist" aria-live="polite">';
98 $rc->mAttribs[
'rc_timestamp'],
101 if ( $this->lastdate ===
'' ) {
102 $this->lastdate = $date;
107 # If it's a new day, flush the cache and update $this->lastdate
108 if ( $date !== $this->lastdate ) {
109 # Process current cache (uses $this->lastdate to generate a heading)
111 $this->rc_cache = [];
112 $this->lastdate = $date;
115 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
127 $this->rc_cache[$cacheGroupingKey][] = $cacheEntry;
139 $cacheGroupingKey = $title->getPrefixedDBkey();
141 $type = $cacheEntry->mAttribs[
'rc_type'];
147 $cacheEntry->mAttribs[
'rc_log_type']
148 )->getPrefixedDBkey();
151 return $cacheGroupingKey;
162 # Add the namespace and title of the block as part of the class
163 $tableClasses = [
'mw-enhanced-rc',
'mw-changeslist-line' ];
164 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
166 $tableClasses[] =
'mw-changeslist-log';
167 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
168 . $block[0]->mAttribs[
'rc_log_type'] );
170 $tableClasses[] =
'mw-changeslist-edit';
171 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
172 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
174 if ( $block[0]->watched ) {
175 $tableClasses[] =
'mw-changeslist-line-watched';
177 $tableClasses[] =
'mw-changeslist-line-not-watched';
180 # Collate list of users
183 # Some catalyst variables...
188 # Default values for RC flags
189 $collectedRcFlags = [];
190 foreach ( $recentChangesFlags as $key => $value ) {
191 $flagGrouping = $value[
'grouping'] ??
'any';
192 switch ( $flagGrouping ) {
194 $collectedRcFlags[$key] =
true;
197 $collectedRcFlags[$key] =
false;
200 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
203 foreach ( $block as $rcObj ) {
206 if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
209 $username = $rcObj->getPerformerIdentity()->getName();
210 $userlink = $rcObj->userlink;
211 if ( !isset( $usercounts[$username] ) ) {
212 $usercounts[$username] = 0;
213 $userlinks[$username] = $userlink;
215 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
219 $usercounts[$username]++;
222 # Sort the list and convert to text
223 krsort( $usercounts );
224 asort( $usercounts );
226 foreach ( $usercounts as $username => $count ) {
227 $text = (string)$userlinks[$username];
229 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
230 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
237 $revDeletedMsg =
false;
239 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
240 } elseif ( $allLogs ) {
241 $articleLink = $this->
maybeWatchedLink( $block[0]->link, $block[0]->watched );
244 $block[0], $block[0]->unpatrolled, $block[0]->watched );
250 foreach ( $block as $i => $rcObj ) {
259 foreach ( $line[
'recentChangesFlagsRaw'] as $key => $value ) {
260 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
261 switch ( $flagGrouping ) {
264 $collectedRcFlags[$key] =
false;
269 $collectedRcFlags[$key] =
true;
273 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
280 $this->
getTags( $rcObj, $filterClasses );
281 $filterClasses = array_unique( $filterClasses );
288 $block = array_values( $block );
289 $filterClasses = array_values( $filterClasses );
291 if ( !$block || !$lines ) {
296 $logText = $this->
getLogText( $block, [], $allLogs,
297 $collectedRcFlags[
'newpage'], $namehidden
300 # Character difference (does not apply if only log items)
301 $charDifference =
false;
302 if ( $RCShowChangedSize && !$allLogs ) {
304 $first = count( $block ) - 1;
305 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
306 while ( $last < $first && $block[$last]->mAttribs[
'rc_new_len'] ===
null ) {
309 while ( $last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
317 $usersList = $this->
msg(
'brackets' )->rawParams(
318 implode( $this->message[
'semicolon-separator'], $users )
322 if ( is_callable( $this->changeLinePrefixer ) ) {
327 'checkboxId' =>
'mw-checkbox-' . base64_encode( random_bytes( 3 ) ),
328 'articleLink' => $articleLink,
329 'charDifference' => $charDifference,
331 'filterClasses' => $filterClasses,
333 'logText' => $logText,
334 'numberofWatchingusers' => $numberofWatchingusers,
336 'rev-deleted-event' => $revDeletedMsg,
337 'tableClasses' => $tableClasses,
338 'timestamp' => $block[0]->timestamp,
339 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
340 'users' => $usersList,
343 $this->rcCacheIndex++;
345 return $this->templateParser->processTemplate(
346 'EnhancedChangesListGroup',
360 $type = $rcObj->mAttribs[
'rc_type'];
362 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
364 $classes = [
'mw-enhanced-rc' ];
365 if ( $rcObj->watched ) {
366 $classes[] =
'mw-enhanced-watched';
368 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
370 $separator =
' <span class="mw-changeslist-separator"></span> ';
372 $data[
'recentChangesFlags'] = [
373 'newpage' => $type ==
RC_NEW,
374 'minor' => $rcObj->mAttribs[
'rc_minor'],
375 'unpatrolled' => $rcObj->unpatrolled,
376 'bot' => $rcObj->mAttribs[
'rc_bot'],
381 $link = htmlspecialchars( $rcObj->timestamp );
384 $link =
Html::element(
'span', [
'class' =>
'history-deleted' ], $rcObj->timestamp );
387 $params[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
388 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
389 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
394 $link = $this->linkRenderer->makeKnownLink(
398 $params + $queryParams
400 if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
401 $link =
'<span class="history-deleted">' . $link .
'</span> ';
404 $data[
'timestampLink'] = $link;
406 $currentAndLastLinks =
'';
408 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
410 $this->message[
'pipe-separator'] .
414 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
415 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
418 if ( $RCShowChangedSize ) {
421 $data[
'characterDiff'] = $cd;
422 $data[
'separatorAfterCharacterDiff'] = $separator;
432 $data[
'userLink'] = $rcObj->userlink;
433 $data[
'userTalkLink'] = $rcObj->usertalklink;
438 # Rollback, thanks etc...
443 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
448 $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
449 $this, $data, $block, $rcObj, $classes, $attribs );
454 $attribs = array_filter( $attribs,
455 [ Sanitizer::class,
'isReservedDataAttribute' ],
459 $lineParams[
'recentChangesFlagsRaw'] = [];
460 if ( isset( $data[
'recentChangesFlags'] ) ) {
461 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
462 # FIXME: This is used by logic, don't return it in the template params.
463 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
464 unset( $data[
'recentChangesFlags'] );
467 if ( isset( $data[
'timestampLink'] ) ) {
468 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
469 unset( $data[
'timestampLink'] );
472 $lineParams[
'classes'] = array_values( $classes );
473 $lineParams[
'attribs'] = Html::expandAttributes( $attribs );
476 $lineParams[
'data'] = array_values( $data );
491 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
497 static $nchanges = [];
498 static $sinceLastVisitMsg = [];
500 $n = count( $block );
501 if ( !isset( $nchanges[$n] ) ) {
502 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
506 $unvisitedOldid =
null;
507 $currentRevision = 0;
508 $previousRevision = 0;
510 $allCategorization =
true;
512 foreach ( $block as $rcObj ) {
519 $allCategorization =
false;
520 $previousRevision = $rcObj->mAttribs[
'rc_last_oldid'];
522 if ( $rcObj->watched ) {
524 $unvisitedOldid = $previousRevision;
526 if ( !$currentRevision ) {
527 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
530 $curId = $rcObj->mAttribs[
'rc_cur_id'];
536 $title = $block[0]->getTitle();
540 if ( $isnew || $allCategorization ) {
541 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
543 $links[
'total-changes'] = Html::rawElement(
'span', [],
544 $this->linkRenderer->makeKnownLink(
547 [
'class' =>
'mw-changeslist-groupdiff' ],
550 'diff' => $currentRevision,
551 'oldid' => $previousRevision,
558 !$allCategorization &&
562 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
563 $sinceLastVisitMsg[$sinceLast] =
564 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
566 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
567 $this->linkRenderer->makeKnownLink(
569 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
570 [
'class' =>
'mw-changeslist-groupdiff' ],
573 'diff' => $currentRevision,
574 'oldid' => $unvisitedOldid,
582 if ( $allLogs || $allCategorization ) {
584 } elseif ( $namehidden || !$title->exists() ) {
585 $links[
'history'] = Html::rawElement(
'span', [], $this->message[
'enhancedrc-history'] );
587 $links[
'history'] = Html::rawElement(
'span', [],
588 $this->linkRenderer->makeKnownLink(
590 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
591 [
'class' =>
'mw-changeslist-history' ],
594 'action' =>
'history',
601 $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
607 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
608 implode(
' ', $links ) );
609 return ' ' . $logtext;
621 $type = $rcObj->mAttribs[
'rc_type'];
622 $logType = $rcObj->mAttribs[
'rc_log_type'];
624 $classes[] =
'mw-enhanced-rc';
628 $classes[] =
'mw-changeslist-log';
629 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
631 $classes[] =
'mw-changeslist-edit';
632 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
633 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
637 $data[
'recentChangesFlags'] = [
638 'newpage' => $type ==
RC_NEW,
639 'minor' => $rcObj->mAttribs[
'rc_minor'],
640 'unpatrolled' => $rcObj->unpatrolled,
641 'bot' => $rcObj->mAttribs[
'rc_bot'],
645 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
647 # Article or log link
649 $logPage =
new LogPage( $logType );
651 $logName = $logPage->getName()->text();
652 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
653 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
656 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
659 # Diff and hist links
663 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
669 $data[
'characterDiff'] = $cd;
670 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
679 $data[
'userLink'] = $rcObj->userlink;
680 $data[
'userTalkLink'] = $rcObj->usertalklink;
689 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
691 # Show how many people are watching this if enabled
694 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
697 $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
698 $this, $data, $rcObj );
703 $attribs = $data[
'attribs'];
704 unset( $data[
'attribs'] );
705 $attribs = array_filter( $attribs,
static function ( $key ) {
706 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
707 }, ARRAY_FILTER_USE_KEY );
710 if ( is_callable( $this->changeLinePrefixer ) ) {
714 $line = Html::openElement(
'table', $attribs ) . Html::openElement(
'tr' );
716 $line .= Html::rawElement(
'td', [],
720 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
721 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
722 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
724 if ( isset( $data[
'recentChangesFlags'] ) ) {
726 unset( $data[
'recentChangesFlags'] );
729 if ( isset( $data[
'timestampLink'] ) ) {
730 $line .=
"\u{00A0}" . $data[
'timestampLink'];
731 unset( $data[
'timestampLink'] );
733 $line .=
"\u{00A0}</td>";
734 $line .= Html::openElement(
'td', [
735 'class' =>
'mw-changeslist-line-inner',
737 'data-target-page' => $rcObj->getTitle(),
741 foreach ( $data as $key => $dataItem ) {
742 $line .= Html::rawElement(
'span', [
743 'class' =>
'mw-changeslist-line-inner-' . $key,
747 $line .=
"</td></tr></table>\n";
764 if ( is_bool( $query ) ) {
765 $useParentheses = $query;
766 } elseif ( $query !==
null ) {
767 wfDeprecated( __METHOD__ .
' with $query parameter',
'1.36' );
772 $pageTitle = Title::newFromID( $rc->
getAttribute(
'rc_cur_id' ) );
780 $histLink = $this->linkRenderer->makeKnownLink(
783 [
'class' =>
'mw-changeslist-history' ],
786 'action' =>
'history'
789 if ( $useParentheses !==
false ) {
790 $retVal = $this->
msg(
'parentheses' )
791 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
792 . $histLink )->escaped();
794 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
795 Html::rawElement(
'span', [], $rc->difflink ) .
796 Html::rawElement(
'span', [], $histLink )
799 return ' ' . $retVal;
809 if ( count( $this->rc_cache ) == 0 ) {
814 foreach ( $this->rc_cache as $block ) {
815 if ( count( $block ) < 2 ) {
822 if ( $blockOut ===
'' ) {
826 return Html::element(
'h4', [], $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';
840class_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.