48 public function __construct( $obj, array $filterGroups = [] ) {
49 if ( $obj instanceof
Skin ) {
54 throw new MWException(
'EnhancedChangesList must be constructed with a '
55 .
'context source or skin.' );
78 $this->rcMoveIndex = 0;
79 $this->rcCacheIndex = 0;
81 $this->rclistOpen =
false;
84 'mediawiki.interface.helpers.styles',
85 'mediawiki.special.changeslist',
86 'mediawiki.special.changeslist.enhanced',
89 'jquery.makeCollapsible',
92 return '<div class="mw-changeslist" aria-live="polite">';
106 $rc->mAttribs[
'rc_timestamp'],
109 if ( $this->lastdate ===
'' ) {
110 $this->lastdate = $date;
115 # If it's a new day, flush the cache and update $this->lastdate
116 if ( $date !== $this->lastdate ) {
117 # Process current cache (uses $this->lastdate to generate a heading)
119 $this->rc_cache = [];
120 $this->lastdate = $date;
123 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
138 if ( !isset( $this->rc_cache[$cacheGroupingKey] ) ) {
139 $this->rc_cache[$cacheGroupingKey] = [];
142 array_push( $this->rc_cache[$cacheGroupingKey], $cacheEntry );
154 $cacheGroupingKey =
$title->getPrefixedDBkey();
156 $type = $cacheEntry->mAttribs[
'rc_type'];
162 $cacheEntry->mAttribs[
'rc_log_type']
163 )->getPrefixedDBkey();
166 return $cacheGroupingKey;
176 $recentChangesFlags = $this->
getConfig()->get(
'RecentChangesFlags' );
178 # Add the namespace and title of the block as part of the class
179 $tableClasses = [
'mw-collapsible',
'mw-collapsed',
'mw-enhanced-rc',
'mw-changeslist-line' ];
180 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
182 $tableClasses[] =
'mw-changeslist-log';
183 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
184 . $block[0]->mAttribs[
'rc_log_type'] );
186 $tableClasses[] =
'mw-changeslist-edit';
187 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
188 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
190 if ( $block[0]->watched ) {
191 $tableClasses[] =
'mw-changeslist-line-watched';
193 $tableClasses[] =
'mw-changeslist-line-not-watched';
196 # Collate list of users
200 # Some catalyst variables...
203 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
205 # Default values for RC flags
206 $collectedRcFlags = [];
207 foreach ( $recentChangesFlags as $key => $value ) {
208 $flagGrouping = $value[
'grouping'] ??
'any';
209 switch ( $flagGrouping ) {
211 $collectedRcFlags[$key] =
true;
214 $collectedRcFlags[$key] =
false;
217 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
220 foreach ( $block as $rcObj ) {
226 $u = $rcObj->userlink;
227 if ( !isset( $userlinks[$u] ) ) {
230 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
233 # Get the latest entry with a page_id and oldid
234 # since logs may not have these.
235 if ( !$curId && $rcObj->mAttribs[
'rc_cur_id'] ) {
236 $curId = $rcObj->mAttribs[
'rc_cur_id'];
242 # Sort the list and convert to text
243 krsort( $userlinks );
246 foreach ( $userlinks as $userlink => $count ) {
250 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
251 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
253 array_push( $users, $text );
258 $revDeletedMsg =
false;
260 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
261 } elseif ( $allLogs ) {
262 $articleLink = $this->
maybeWatchedLink( $block[0]->link, $block[0]->watched );
265 $block[0], $block[0]->unpatrolled, $block[0]->watched );
268 $queryParams = [
'curid' => $curId ];
273 foreach ( $block as $i => $rcObj ) {
282 foreach (
$line[
'recentChangesFlagsRaw'] as $key => $value ) {
283 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
284 switch ( $flagGrouping ) {
287 $collectedRcFlags[$key] =
false;
292 $collectedRcFlags[$key] =
true;
296 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
303 $this->
getTags( $rcObj, $filterClasses );
304 $filterClasses = array_unique( $filterClasses );
311 $block = array_values( $block );
312 $filterClasses = array_values( $filterClasses );
314 if ( empty( $block ) || !
$lines ) {
319 $logText = $this->
getLogText( $block, $queryParams, $allLogs,
320 $collectedRcFlags[
'newpage'], $namehidden
323 # Character difference (does not apply if only log items)
324 $charDifference =
false;
325 if ( $RCShowChangedSize && !$allLogs ) {
327 $first = count( $block ) - 1;
328 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
329 while ( $last < $first && $block[$last]->mAttribs[
'rc_new_len'] ===
null ) {
332 while ( $last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
340 $usersList = $this->
msg(
'brackets' )->rawParams(
341 implode( $this->message[
'semicolon-separator'], $users )
345 if ( is_callable( $this->changeLinePrefixer ) ) {
346 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this,
true );
350 'articleLink' => $articleLink,
351 'charDifference' => $charDifference,
353 'filterClasses' => $filterClasses,
354 'languageDirMark' => $this->
getLanguage()->getDirMark(),
356 'logText' => $logText,
357 'numberofWatchingusers' => $numberofWatchingusers,
359 'rev-deleted-event' => $revDeletedMsg,
360 'tableClasses' => $tableClasses,
361 'timestamp' => $block[0]->timestamp,
362 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
363 'users' => $usersList,
366 $this->rcCacheIndex++;
368 return $this->templateParser->processTemplate(
369 'EnhancedChangesListGroup',
384 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
386 $type = $rcObj->mAttribs[
'rc_type'];
388 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
390 $classes = [
'mw-enhanced-rc' ];
391 if ( $rcObj->watched ) {
392 $classes[] =
'mw-enhanced-watched';
394 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
396 $separator =
' <span class="mw-changeslist-separator"></span> ';
398 $data[
'recentChangesFlags'] = [
400 'minor' => $rcObj->mAttribs[
'rc_minor'],
401 'unpatrolled' => $rcObj->unpatrolled,
402 'bot' => $rcObj->mAttribs[
'rc_bot'],
405 $params = $queryParams;
407 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
408 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
413 $link = htmlspecialchars( $rcObj->timestamp );
416 $link = Html::element(
'span', [
'class' =>
'history-deleted' ], $rcObj->timestamp );
418 $link = $this->linkRenderer->makeKnownLink(
424 if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
425 $link =
'<span class="history-deleted">' . $link .
'</span> ';
428 $data[
'timestampLink'] = $link;
430 $currentAndLastLinks =
'';
432 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
434 $this->message[
'pipe-separator'] .
438 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
439 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
442 if ( $RCShowChangedSize ) {
445 $data[
'characterDiff'] = $cd;
446 $data[
'separatorAfterCharacterDiff'] = $separator;
450 if ( $rcObj->mAttribs[
'rc_type'] ==
RC_LOG ) {
456 $data[
'userLink'] = $rcObj->userlink;
457 $data[
'userTalkLink'] = $rcObj->usertalklink;
465 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
470 $success = $this->getHookRunner()->onEnhancedChangesListModifyLineData(
471 $this, $data, $block, $rcObj, $classes, $attribs );
476 $attribs = array_filter( $attribs,
477 [ Sanitizer::class,
'isReservedDataAttribute' ],
481 $lineParams[
'recentChangesFlagsRaw'] = [];
482 if ( isset( $data[
'recentChangesFlags'] ) ) {
483 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
484 # FIXME: This is used by logic, don't return it in the template params.
485 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
486 unset( $data[
'recentChangesFlags'] );
489 if ( isset( $data[
'timestampLink'] ) ) {
490 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
491 unset( $data[
'timestampLink'] );
494 $lineParams[
'classes'] = array_values( $classes );
495 $lineParams[
'attribs'] = Html::expandAttributes( $attribs );
498 $lineParams[
'data'] = array_values( $data );
513 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
514 if ( empty( $block ) ) {
519 static $nchanges = [];
520 static $sinceLastVisitMsg = [];
522 $n = count( $block );
523 if ( !isset( $nchanges[$n] ) ) {
524 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
528 $unvisitedOldid =
null;
530 foreach ( $block as $rcObj ) {
532 if ( $rcObj->watched ) {
534 $unvisitedOldid = $rcObj->mAttribs[
'rc_last_oldid'];
537 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
538 $sinceLastVisitMsg[$sinceLast] =
539 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
542 $currentRevision = 0;
543 foreach ( $block as $rcObj ) {
544 if ( !$currentRevision ) {
545 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
553 $last = $block[count( $block ) - 1];
560 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
562 $links[
'total-changes'] = Html::rawElement(
'span', [],
563 $this->linkRenderer->makeKnownLink(
566 [
'class' =>
'mw-changeslist-groupdiff' ],
568 'diff' => $currentRevision,
569 'oldid' => $last->mAttribs[
'rc_last_oldid'],
580 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
581 $this->linkRenderer->makeKnownLink(
583 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
584 [
'class' =>
'mw-changeslist-groupdiff' ],
586 'diff' => $currentRevision,
587 'oldid' => $unvisitedOldid,
595 if ( $allLogs || $rcObj->mAttribs[
'rc_type'] ==
RC_CATEGORIZE ) {
597 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
598 $links[
'history'] = Html::rawElement(
'span', [], $this->message[
'enhancedrc-history'] );
600 $params = $queryParams;
601 $params[
'action'] =
'history';
603 $links[
'history'] = Html::rawElement(
'span', [],
604 $this->linkRenderer->makeKnownLink(
606 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
607 [
'class' =>
'mw-changeslist-history' ],
613 # Allow others to alter, remove or add to these links
614 $this->getHookRunner()->onEnhancedChangesList__getLogText( $this, $links, $block );
620 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
621 implode(
' ', $links ) );
622 return ' ' . $logtext;
634 $query = [
'curid' => $rcObj->mAttribs[
'rc_cur_id'] ];
636 $type = $rcObj->mAttribs[
'rc_type'];
637 $logType = $rcObj->mAttribs[
'rc_log_type'];
639 $classes[] =
'mw-enhanced-rc';
643 $classes[] =
'mw-changeslist-log';
644 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
646 $classes[] =
'mw-changeslist-edit';
647 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
648 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
652 $data[
'recentChangesFlags'] = [
654 'minor' => $rcObj->mAttribs[
'rc_minor'],
655 'unpatrolled' => $rcObj->unpatrolled,
656 'bot' => $rcObj->mAttribs[
'rc_bot'],
660 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
662 # Article or log link
664 $logPage =
new LogPage( $logType );
666 $logName = $logPage->getName()->text();
667 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
668 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
671 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
674 # Diff and hist links
676 $query[
'action'] =
'history';
679 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
682 if ( $this->
getConfig()->
get(
'RCShowChangedSize' ) ) {
685 $data[
'characterDiff'] = $cd;
686 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
695 $data[
'userLink'] = $rcObj->userlink;
696 $data[
'userTalkLink'] = $rcObj->usertalklink;
705 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
707 # Show how many people are watching this if enabled
710 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
713 $success = $this->getHookRunner()->onEnhancedChangesListModifyBlockLineData(
714 $this, $data, $rcObj );
719 $attribs = $data[
'attribs'];
720 unset( $data[
'attribs'] );
721 $attribs = array_filter( $attribs,
function ( $key ) {
722 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
723 }, ARRAY_FILTER_USE_KEY );
726 if ( is_callable( $this->changeLinePrefixer ) ) {
727 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this,
false );
730 $line = Html::openElement(
'table', $attribs ) . Html::openElement(
'tr' );
732 $line .= Html::rawElement(
'td', [],
736 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
737 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
738 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
740 if ( isset( $data[
'recentChangesFlags'] ) ) {
742 unset( $data[
'recentChangesFlags'] );
745 if ( isset( $data[
'timestampLink'] ) ) {
746 $line .=
"\u{00A0}" . $data[
'timestampLink'];
747 unset( $data[
'timestampLink'] );
749 $line .=
"\u{00A0}</td>";
750 $line .= Html::openElement(
'td', [
751 'class' =>
'mw-changeslist-line-inner',
753 'data-target-page' => $rcObj->getTitle(),
757 foreach ( $data as $key => $dataItem ) {
758 $line .= Html::rawElement(
'span', [
759 'class' =>
'mw-changeslist-line-inner-' . $key,
763 $line .=
"</td></tr></table>\n";
783 $pageTitle = Title::newFromID( $rc->
getAttribute(
'rc_cur_id' ) );
791 $histLink = $this->linkRenderer->makeKnownLink(
794 [
'class' =>
'mw-changeslist-history' ],
797 if ( $useParentheses ) {
798 $retVal = $this->
msg(
'parentheses' )
799 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
800 . $histLink )->escaped();
802 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
803 Html::rawElement(
'span', [], $rc->difflink ) .
804 Html::rawElement(
'span', [], $histLink )
807 return ' ' . $retVal;
817 if ( count( $this->rc_cache ) == 0 ) {
822 foreach ( $this->rc_cache as $block ) {
823 if ( count( $block ) < 2 ) {
830 if ( $blockOut ===
'' ) {
834 return Xml::element(
'h4',
null, $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';
maybeWatchedLink( $link, $watched=false)
static userCan( $rc, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
formatCharacterDifference(RecentChange $old, RecentChange $new=null)
Format the character difference of one or several changes.
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)
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.
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.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
TemplateParser $templateParser
recentChangesBlock()
If enhanced RC is in use, this function takes the previously cached RC lines, arranges them,...
makeCacheGroupingKey(RCCacheEntry $cacheEntry)
beginRecentChangesList()
Add the JavaScript file for enhanced changeslist.
endRecentChangesList()
Returns text for the end of RC If enhanced RC is in use, returns pretty much all the text.
getDiffHistLinks(RCCacheEntry $rc, array $query, $useParentheses=true)
Returns value to be used in 'historyLink' element of $data param in EnhancedChangesListModifyBlockLin...
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=[])
array $rc_cache
Array of array of RCCacheEntry.
recentChangesBlockLine( $rcObj)
Enhanced RC ungrouped line.
__construct( $obj, array $filterGroups=[])
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.
getAttribute( $name)
Get an attribute value.
The main skin class which provides methods and properties for all other skins.
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.
if(!file_exists( $CREDITS)) $lines