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;
80 'mediawiki.special.changeslist',
81 'mediawiki.special.changeslist.enhanced',
84 'jquery.makeCollapsible',
88 return '<div class="mw-changeslist">';
102 $rc->mAttribs[
'rc_timestamp'],
105 if ( $this->lastdate ===
'' ) {
106 $this->lastdate = $date;
111 # If it's a new day, flush the cache and update $this->lastdate
112 if ( $date !== $this->lastdate ) {
113 # Process current cache (uses $this->lastdate to generate a heading)
115 $this->rc_cache = [];
116 $this->lastdate = $date;
119 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
134 if ( !isset( $this->rc_cache[$cacheGroupingKey] ) ) {
135 $this->rc_cache[$cacheGroupingKey] = [];
138 array_push( $this->rc_cache[$cacheGroupingKey], $cacheEntry );
150 $cacheGroupingKey =
$title->getPrefixedDBkey();
152 $type = $cacheEntry->mAttribs[
'rc_type'];
158 $cacheEntry->mAttribs[
'rc_log_type']
159 )->getPrefixedDBkey();
162 return $cacheGroupingKey;
172 $recentChangesFlags = $this->
getConfig()->get(
'RecentChangesFlags' );
174 # Add the namespace and title of the block as part of the class
175 $tableClasses = [
'mw-collapsible',
'mw-collapsed',
'mw-enhanced-rc',
'mw-changeslist-line' ];
176 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
178 $tableClasses[] =
'mw-changeslist-log';
179 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
180 . $block[0]->mAttribs[
'rc_log_type'] );
182 $tableClasses[] =
'mw-changeslist-edit';
183 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
184 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
186 if ( $block[0]->watched
187 && $block[0]->mAttribs[
'rc_timestamp'] >= $block[0]->watched
189 $tableClasses[] =
'mw-changeslist-line-watched';
191 $tableClasses[] =
'mw-changeslist-line-not-watched';
194 # Collate list of users
198 # Some catalyst variables...
201 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
203 # Default values for RC flags
204 $collectedRcFlags = [];
205 foreach ( $recentChangesFlags
as $key =>
$value ) {
206 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
207 switch ( $flagGrouping ) {
209 $collectedRcFlags[$key] =
true;
212 $collectedRcFlags[$key] =
false;
215 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
218 foreach ( $block
as $rcObj ) {
224 $u = $rcObj->userlink;
225 if ( !isset( $userlinks[$u] ) ) {
228 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
231 # Get the latest entry with a page_id and oldid
232 # since logs may not have these.
233 if ( !$curId && $rcObj->mAttribs[
'rc_cur_id'] ) {
234 $curId = $rcObj->mAttribs[
'rc_cur_id'];
240 # Sort the list and convert to text
241 krsort( $userlinks );
244 foreach ( $userlinks
as $userlink => $count ) {
248 $formattedCount = $this->
msg(
'ntimes' )->numParams( $count )->escaped();
249 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
251 array_push( $users, $text );
256 $revDeletedMsg =
false;
258 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
259 } elseif ( $allLogs ) {
262 $articleLink = $this->
getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched );
265 $queryParams[
'curid'] = $curId;
270 foreach ( $block
as $i => $rcObj ) {
279 foreach (
$line[
'recentChangesFlagsRaw']
as $key =>
$value ) {
280 $flagGrouping = ( $recentChangesFlags[$key][
'grouping'] ??
'any' );
281 switch ( $flagGrouping ) {
284 $collectedRcFlags[$key] =
false;
289 $collectedRcFlags[$key] =
true;
293 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
300 $this->
getTags( $rcObj, $filterClasses );
301 $filterClasses = array_unique( $filterClasses );
308 $block = array_values( $block );
309 $filterClasses = array_values( $filterClasses );
311 if ( empty( $block ) || !
$lines ) {
316 $logText = $this->
getLogText( $block, $queryParams, $allLogs,
317 $collectedRcFlags[
'newpage'], $namehidden
320 # Character difference (does not apply if only log items)
321 $charDifference =
false;
322 if ( $RCShowChangedSize && !$allLogs ) {
324 $first =
count( $block ) - 1;
325 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
326 while (
$last < $first && $block[
$last]->mAttribs[
'rc_new_len'] ===
null ) {
329 while (
$last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
337 $usersList = $this->
msg(
'brackets' )->rawParams(
338 implode( $this->
message[
'semicolon-separator'], $users )
342 if ( is_callable( $this->changeLinePrefixer ) ) {
343 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this,
true );
347 'articleLink' => $articleLink,
348 'charDifference' => $charDifference,
350 'filterClasses' => $filterClasses,
351 'languageDirMark' => $this->
getLanguage()->getDirMark(),
353 'logText' => $logText,
354 'numberofWatchingusers' => $numberofWatchingusers,
356 'rev-deleted-event' => $revDeletedMsg,
357 'tableClasses' => $tableClasses,
358 'timestamp' => $block[0]->timestamp,
359 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
360 'users' => $usersList,
363 $this->rcCacheIndex++;
365 return $this->templateParser->processTemplate(
366 'EnhancedChangesListGroup',
381 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
383 $type = $rcObj->mAttribs[
'rc_type'];
385 $lineParams = [
'targetTitle' => $rcObj->
getTitle() ];
387 $classes = [
'mw-enhanced-rc' ];
389 && $rcObj->mAttribs[
'rc_timestamp'] >= $rcObj->watched
391 $classes[] =
'mw-enhanced-watched';
393 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
395 $separator =
' <span class="mw-changeslist-separator">. .</span> ';
397 $data[
'recentChangesFlags'] = [
399 'minor' => $rcObj->mAttribs[
'rc_minor'],
400 'unpatrolled' => $rcObj->unpatrolled,
401 'bot' => $rcObj->mAttribs[
'rc_bot'],
406 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
407 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
412 $link = htmlspecialchars( $rcObj->timestamp );
417 $link = $this->linkRenderer->makeKnownLink(
424 $link =
'<span class="history-deleted">' .
$link .
'</span> ';
427 $data[
'timestampLink'] =
$link;
429 $currentAndLastLinks =
'';
431 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
433 $this->message[
'pipe-separator'] .
437 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
438 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
441 if ( $RCShowChangedSize ) {
444 $data[
'characterDiff'] = $cd;
445 $data[
'separatorAfterCharacterDiff'] = $separator;
449 if ( $rcObj->mAttribs[
'rc_type'] ==
RC_LOG ) {
455 $data[
'userLink'] = $rcObj->userlink;
456 $data[
'userTalkLink'] = $rcObj->usertalklink;
464 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
470 [ $this, &$data, $block, $rcObj, &$classes, &
$attribs ] );
480 $lineParams[
'recentChangesFlagsRaw'] = [];
481 if ( isset( $data[
'recentChangesFlags'] ) ) {
482 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
483 # FIXME: This is used by logic, don't return it in the template params.
484 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
485 unset( $data[
'recentChangesFlags'] );
488 if ( isset( $data[
'timestampLink'] ) ) {
489 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
490 unset( $data[
'timestampLink'] );
493 $lineParams[
'classes'] = array_values( $classes );
497 $lineParams[
'data'] = array_values( $data );
512 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
513 if ( empty( $block ) ) {
518 static $nchanges = [];
519 static $sinceLastVisitMsg = [];
521 $n =
count( $block );
522 if ( !isset( $nchanges[$n] ) ) {
523 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
527 $unvisitedOldid =
null;
529 foreach ( $block
as $rcObj ) {
531 if ( $rcObj->watched && $rcObj->mAttribs[
'rc_timestamp'] >= $rcObj->watched ) {
533 $unvisitedOldid = $rcObj->mAttribs[
'rc_last_oldid'];
536 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
537 $sinceLastVisitMsg[$sinceLast] =
538 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
541 $currentRevision = 0;
542 foreach ( $block
as $rcObj ) {
543 if ( !$currentRevision ) {
544 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
558 $links[
'total-changes'] = $nchanges[$n];
560 $links[
'total-changes'] = $this->linkRenderer->makeKnownLink(
563 [
'class' =>
'mw-changeslist-groupdiff' ],
565 'diff' => $currentRevision,
566 'oldid' =>
$last->mAttribs[
'rc_last_oldid'],
569 if ( $sinceLast > 0 && $sinceLast < $n ) {
570 $links[
'total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
572 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
573 [
'class' =>
'mw-changeslist-groupdiff' ],
575 'diff' => $currentRevision,
576 'oldid' => $unvisitedOldid,
584 if ( $allLogs || $rcObj->mAttribs[
'rc_type'] ==
RC_CATEGORIZE ) {
586 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
587 $links[
'history'] = $this->
message[
'enhancedrc-history'];
592 $links[
'history'] = $this->linkRenderer->makeKnownLink(
595 [
'class' =>
'mw-changeslist-history' ],
600 # Allow others to alter, remove or add to these links
601 Hooks::run(
'EnhancedChangesList::getLogText',
602 [ $this, &$links, $block ] );
608 $logtext = implode( $this->
message[
'pipe-separator'], $links );
609 $logtext = $this->
msg(
'parentheses' )->rawParams( $logtext )->escaped();
610 return ' ' . $logtext;
622 $query[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
624 $type = $rcObj->mAttribs[
'rc_type'];
625 $logType = $rcObj->mAttribs[
'rc_log_type'];
627 $classes[] =
'mw-enhanced-rc';
631 $classes[] =
'mw-changeslist-log';
632 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
634 $classes[] =
'mw-changeslist-edit';
635 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
636 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
640 $data[
'recentChangesFlags'] = [
642 'minor' => $rcObj->mAttribs[
'rc_minor'],
643 'unpatrolled' => $rcObj->unpatrolled,
644 'bot' => $rcObj->mAttribs[
'rc_bot'],
648 $data[
'timestampLink'] = htmlspecialchars( $rcObj->timestamp );
650 # Article or log link
652 $logPage =
new LogPage( $logType );
654 $logName = $logPage->getName()->text();
655 $data[
'logLink'] = $this->
msg(
'parentheses' )
657 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
660 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
663 # Diff and hist links
665 $query[
'action'] =
'history';
668 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator">. .</span> ';
671 if ( $this->
getConfig()->
get(
'RCShowChangedSize' ) ) {
674 $data[
'characterDiff'] = $cd;
675 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator">. .</span> ';
684 $data[
'userLink'] = $rcObj->userlink;
685 $data[
'userTalkLink'] = $rcObj->usertalklink;
694 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
696 # Show how many people are watching this if enabled
699 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
703 [ $this, &$data, $rcObj ] );
709 unset( $data[
'attribs'] );
711 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
712 }, ARRAY_FILTER_USE_KEY );
715 if ( is_callable( $this->changeLinePrefixer ) ) {
716 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this,
false );
727 $line .=
'<td class="mw-enhanced-rc" colspan="2">';
729 if ( isset( $data[
'recentChangesFlags'] ) ) {
731 unset( $data[
'recentChangesFlags'] );
734 if ( isset( $data[
'timestampLink'] ) ) {
735 $line .=
"\u{00A0}" . $data[
'timestampLink'];
736 unset( $data[
'timestampLink'] );
738 $line .=
"\u{00A0}</td>";
740 'class' =>
'mw-changeslist-line-inner',
742 'data-target-page' => $rcObj->getTitle(),
746 $line .= implode(
'', $data );
748 $line .=
"</td></tr></table>\n";
775 $retVal =
' ' . $this->
msg(
'parentheses' )
776 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
777 . $this->linkRenderer->makeKnownLink(
780 [
'class' =>
'mw-changeslist-history' ],
793 if (
count( $this->rc_cache ) == 0 ) {
798 foreach ( $this->rc_cache
as $block ) {
799 if (
count( $block ) < 2 ) {
806 if ( $blockOut ===
'' ) {
810 return Xml::element(
'h4',
null, $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';