46 if ( $obj instanceof
Skin ) {
51 throw new MWException(
'EnhancedChangesList must be constructed with a '
52 .
'context source or skin.' );
66 $this->templateParser =
new TemplateParser();
75 $this->rcMoveIndex = 0;
76 $this->rcCacheIndex = 0;
78 $this->rclistOpen =
false;
81 'mediawiki.interface.helpers.styles',
82 'mediawiki.special.changeslist',
83 'mediawiki.special.changeslist.enhanced',
86 'jquery.makeCollapsible',
89 return '<div class="mw-changeslist">';
103 $rc->mAttribs[
'rc_timestamp'],
106 if ( $this->lastdate ===
'' ) {
107 $this->lastdate = $date;
112 # If it's a new day, flush the cache and update $this->lastdate
113 if ( $date !== $this->lastdate ) {
114 # Process current cache (uses $this->lastdate to generate a heading)
116 $this->rc_cache = [];
117 $this->lastdate = $date;
120 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
135 if ( !isset( $this->rc_cache[$cacheGroupingKey] ) ) {
136 $this->rc_cache[$cacheGroupingKey] = [];
139 array_push( $this->rc_cache[$cacheGroupingKey], $cacheEntry );
151 $cacheGroupingKey =
$title->getPrefixedDBkey();
153 $type = $cacheEntry->mAttribs[
'rc_type'];
159 $cacheEntry->mAttribs[
'rc_log_type']
160 )->getPrefixedDBkey();
163 return $cacheGroupingKey;
173 $recentChangesFlags = $this->
getConfig()->get(
'RecentChangesFlags' );
175 # Add the namespace and title of the block as part of the class
176 $tableClasses = [
'mw-collapsible',
'mw-collapsed',
'mw-enhanced-rc',
'mw-changeslist-line' ];
177 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
179 $tableClasses[] =
'mw-changeslist-log';
180 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
181 . $block[0]->mAttribs[
'rc_log_type'] );
183 $tableClasses[] =
'mw-changeslist-edit';
184 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
185 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
187 if ( $block[0]->watched
188 && $block[0]->mAttribs[
'rc_timestamp'] >= $block[0]->watched
190 $tableClasses[] =
'mw-changeslist-line-watched';
192 $tableClasses[] =
'mw-changeslist-line-not-watched';
195 # Collate list of users
199 # Some catalyst variables...
202 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
204 # Default values for RC flags
205 $collectedRcFlags = [];
206 foreach ( $recentChangesFlags
as $key =>
$value ) {
207 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
208 switch ( $flagGrouping ) {
210 $collectedRcFlags[$key] =
true;
213 $collectedRcFlags[$key] =
false;
216 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
219 foreach ( $block
as $rcObj ) {
225 $u = $rcObj->userlink;
226 if ( !isset( $userlinks[$u] ) ) {
229 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
232 # Get the latest entry with a page_id and oldid
233 # since logs may not have these.
234 if ( !$curId && $rcObj->mAttribs[
'rc_cur_id'] ) {
235 $curId = $rcObj->mAttribs[
'rc_cur_id'];
241 # Sort the list and convert to text
242 krsort( $userlinks );
245 foreach ( $userlinks
as $userlink => $count ) {
249 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
250 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
252 array_push( $users, $text );
257 $revDeletedMsg =
false;
259 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
260 } elseif ( $allLogs ) {
263 $articleLink = $this->
getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched );
266 $queryParams[
'curid'] = $curId;
271 foreach ( $block
as $i => $rcObj ) {
280 foreach (
$line[
'recentChangesFlagsRaw']
as $key =>
$value ) {
281 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
282 switch ( $flagGrouping ) {
285 $collectedRcFlags[$key] =
false;
290 $collectedRcFlags[$key] =
true;
294 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
301 $this->
getTags( $rcObj, $filterClasses );
302 $filterClasses = array_unique( $filterClasses );
309 $block = array_values( $block );
310 $filterClasses = array_values( $filterClasses );
312 if ( empty( $block ) || !
$lines ) {
317 $logText = $this->
getLogText( $block, $queryParams, $allLogs,
318 $collectedRcFlags[
'newpage'], $namehidden
321 # Character difference (does not apply if only log items)
322 $charDifference =
false;
323 if ( $RCShowChangedSize && !$allLogs ) {
325 $first =
count( $block ) - 1;
326 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
327 while (
$last < $first && $block[
$last]->mAttribs[
'rc_new_len'] ===
null ) {
330 while (
$last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
338 $usersList = $this->
msg(
'brackets' )->rawParams(
339 implode( $this->
message[
'semicolon-separator'], $users )
343 if ( is_callable( $this->changeLinePrefixer ) ) {
344 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this,
true );
348 'articleLink' => $articleLink,
349 'charDifference' => $charDifference,
351 'filterClasses' => $filterClasses,
352 'languageDirMark' => $this->
getLanguage()->getDirMark(),
354 'logText' => $logText,
355 'numberofWatchingusers' => $numberofWatchingusers,
357 'rev-deleted-event' => $revDeletedMsg,
358 'tableClasses' => $tableClasses,
359 'timestamp' => $block[0]->timestamp,
360 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
361 'users' => $usersList,
364 $this->rcCacheIndex++;
366 return $this->templateParser->processTemplate(
367 'EnhancedChangesListGroup',
382 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
384 $type = $rcObj->mAttribs[
'rc_type'];
386 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
388 $classes = [
'mw-enhanced-rc' ];
390 && $rcObj->mAttribs[
'rc_timestamp'] >= $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'],
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(
425 $link =
'<span class="history-deleted">' .
$link .
'</span> ';
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;
481 $lineParams[
'recentChangesFlagsRaw'] = [];
482 if ( isset(
$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 && $rcObj->mAttribs[
'rc_timestamp'] >= $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'];
559 $links[
'total-changes'] = Html::rawElement(
'span', [], $nchanges[$n] );
561 $links[
'total-changes'] = Html::rawElement(
'span', [],
562 $this->linkRenderer->makeKnownLink(
565 [
'class' =>
'mw-changeslist-groupdiff' ],
567 'diff' => $currentRevision,
568 'oldid' =>
$last->mAttribs[
'rc_last_oldid'],
572 if ( $sinceLast > 0 && $sinceLast < $n ) {
573 $links[
'total-changes-since-last'] = Html::rawElement(
'span', [],
574 $this->linkRenderer->makeKnownLink(
576 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
577 [
'class' =>
'mw-changeslist-groupdiff' ],
579 'diff' => $currentRevision,
580 'oldid' => $unvisitedOldid,
589 if ( $allLogs || $rcObj->mAttribs[
'rc_type'] ==
RC_CATEGORIZE ) {
591 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
592 $links[
'history'] = Html::rawElement(
'span', [], $this->
message[
'enhancedrc-history'] );
597 $links[
'history'] = Html::rawElement(
'span', [],
598 $this->linkRenderer->makeKnownLink(
601 [
'class' =>
'mw-changeslist-history' ],
607 # Allow others to alter, remove or add to these links
608 Hooks::run(
'EnhancedChangesList::getLogText',
609 [ $this, &$links, $block ] );
615 $logtext = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
616 implode(
' ', $links ) );
617 return ' ' . $logtext;
629 $query[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
631 $type = $rcObj->mAttribs[
'rc_type'];
632 $logType = $rcObj->mAttribs[
'rc_log_type'];
634 $classes[] =
'mw-enhanced-rc';
638 $classes[] =
'mw-changeslist-log';
639 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
641 $classes[] =
'mw-changeslist-edit';
642 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
643 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
647 $data[
'recentChangesFlags'] = [
649 'minor' => $rcObj->mAttribs[
'rc_minor'],
650 'unpatrolled' => $rcObj->unpatrolled,
651 'bot' => $rcObj->mAttribs[
'rc_bot'],
655 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
657 # Article or log link
659 $logPage =
new LogPage( $logType );
661 $logName = $logPage->getName()->text();
662 $data[
'logLink'] = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
663 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
666 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
669 # Diff and hist links
671 $query[
'action'] =
'history';
674 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator"></span> ';
677 if ( $this->
getConfig()->
get(
'RCShowChangedSize' ) ) {
680 $data[
'characterDiff'] = $cd;
681 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator"></span> ';
690 $data[
'userLink'] = $rcObj->userlink;
691 $data[
'userTalkLink'] = $rcObj->usertalklink;
702 # Show how many people are watching this if enabled
709 [ $this, &
$data, $rcObj ] );
715 unset(
$data[
'attribs'] );
717 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
718 }, ARRAY_FILTER_USE_KEY );
721 if ( is_callable( $this->changeLinePrefixer ) ) {
722 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this,
false );
725 $line = Html::openElement(
'table',
$attribs ) . Html::openElement(
'tr' );
727 $line .= Html::rawElement(
'td', [],
731 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
732 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
733 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
735 if ( isset(
$data[
'recentChangesFlags'] ) ) {
737 unset(
$data[
'recentChangesFlags'] );
740 if ( isset(
$data[
'timestampLink'] ) ) {
742 unset(
$data[
'timestampLink'] );
744 $line .=
"\u{00A0}</td>";
745 $line .= Html::openElement(
'td', [
746 'class' =>
'mw-changeslist-line-inner',
748 'data-target-page' => $rcObj->getTitle(),
752 foreach (
$data as $key => $dataItem ) {
753 $line .= Html::rawElement(
'span', [
754 'class' =>
'mw-changeslist-line-inner-' . $key,
758 $line .=
"</td></tr></table>\n";
786 $histLink = $this->linkRenderer->makeKnownLink(
789 [
'class' =>
'mw-changeslist-history' ],
792 if ( $useParentheses ) {
793 $retVal = $this->
msg(
'parentheses' )
794 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
795 . $histLink )->escaped();
797 $retVal = Html::rawElement(
'span', [
'class' =>
'mw-changeslist-links' ],
798 Html::rawElement(
'span', [], $rc->difflink ) .
799 Html::rawElement(
'span', [], $histLink )
802 return ' ' . $retVal;
812 if (
count( $this->rc_cache ) == 0 ) {
817 foreach ( $this->rc_cache
as $block ) {
818 if (
count( $block ) < 2 ) {
825 if ( $blockOut ===
'' ) {
829 return Xml::element(
'h4',
null, $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';