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">';
103 $rc->mAttribs[
'rc_timestamp'],
109 # If it's a new day, add the headline and flush the cache
110 if ( $date != $this->lastdate ) {
111 # Process current cache
113 $this->rc_cache = [];
115 $this->lastdate = $date;
118 $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
133 if ( !isset( $this->rc_cache[$cacheGroupingKey] ) ) {
134 $this->rc_cache[$cacheGroupingKey] = [];
137 array_push( $this->rc_cache[$cacheGroupingKey], $cacheEntry );
149 $cacheGroupingKey =
$title->getPrefixedDBkey();
151 $type = $cacheEntry->mAttribs[
'rc_type'];
157 $cacheEntry->mAttribs[
'rc_log_type']
158 )->getPrefixedDBkey();
161 return $cacheGroupingKey;
171 $recentChangesFlags = $this->
getConfig()->get(
'RecentChangesFlags' );
173 # Add the namespace and title of the block as part of the class
174 $tableClasses = [
'mw-collapsible',
'mw-collapsed',
'mw-enhanced-rc' ];
175 if ( $block[0]->mAttribs[
'rc_log_type'] ) {
177 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-log-'
178 . $block[0]->mAttribs[
'rc_log_type'] );
180 $tableClasses[] = Sanitizer::escapeClass(
'mw-changeslist-ns'
181 . $block[0]->mAttribs[
'rc_namespace'] .
'-' . $block[0]->mAttribs[
'rc_title'] );
183 if ( $block[0]->watched
184 && $block[0]->mAttribs[
'rc_timestamp'] >= $block[0]->watched
186 $tableClasses[] =
'mw-changeslist-line-watched';
188 $tableClasses[] =
'mw-changeslist-line-not-watched';
191 # Collate list of users
195 # Some catalyst variables...
198 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
200 # Default values for RC flags
201 $collectedRcFlags = [];
202 foreach ( $recentChangesFlags
as $key =>
$value ) {
203 $flagGrouping = ( isset( $recentChangesFlags[$key][
'grouping'] ) ?
204 $recentChangesFlags[$key][
'grouping'] :
'any' );
205 switch ( $flagGrouping ) {
207 $collectedRcFlags[$key] =
true;
210 $collectedRcFlags[$key] =
false;
213 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
216 foreach ( $block
as $rcObj ) {
222 $u = $rcObj->userlink;
223 if ( !isset( $userlinks[$u] ) ) {
226 if ( $rcObj->mAttribs[
'rc_type'] !=
RC_LOG ) {
229 # Get the latest entry with a page_id and oldid
230 # since logs may not have these.
231 if ( !$curId && $rcObj->mAttribs[
'rc_cur_id'] ) {
232 $curId = $rcObj->mAttribs[
'rc_cur_id'];
238 # Sort the list and convert to text
239 krsort( $userlinks );
242 foreach ( $userlinks
as $userlink => $count ) {
247 $formattedCount = $this->
getLanguage()->formatNum( $count ) .
'×';
248 $text .=
' ' . $this->
msg(
'parentheses' )->rawParams( $formattedCount )->escaped();
250 array_push( $users, $text );
255 $revDeletedMsg =
false;
257 $revDeletedMsg = $this->
msg(
'rev-deleted-event' )->escaped();
258 } elseif ( $allLogs ) {
261 $articleLink = $this->
getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched );
264 $queryParams[
'curid'] = $curId;
268 foreach ( $block
as $i => $rcObj ) {
277 foreach (
$line[
'recentChangesFlagsRaw']
as $key =>
$value ) {
278 $flagGrouping = ( isset( $recentChangesFlags[$key][
'grouping'] ) ?
279 $recentChangesFlags[$key][
'grouping'] :
'any' );
280 switch ( $flagGrouping ) {
283 $collectedRcFlags[$key] =
false;
288 $collectedRcFlags[$key] =
true;
292 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
301 $block = array_values( $block );
303 if ( empty( $block ) || !
$lines ) {
308 $logText = $this->
getLogText( $block, $queryParams, $allLogs,
309 $collectedRcFlags[
'newpage'], $namehidden
312 # Character difference (does not apply if only log items)
313 $charDifference =
false;
314 if ( $RCShowChangedSize && !$allLogs ) {
316 $first =
count( $block ) - 1;
317 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
318 while (
$last < $first && $block[
$last]->mAttribs[
'rc_new_len'] ===
null ) {
321 while (
$last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
329 $usersList = $this->
msg(
'brackets' )->rawParams(
330 implode( $this->
message[
'semicolon-separator'], $users )
334 'articleLink' => $articleLink,
335 'charDifference' => $charDifference,
337 'languageDirMark' => $this->
getLanguage()->getDirMark(),
339 'logText' => $logText,
340 'numberofWatchingusers' => $numberofWatchingusers,
341 'rev-deleted-event' => $revDeletedMsg,
342 'tableClasses' => $tableClasses,
343 'timestamp' => $block[0]->timestamp,
344 'users' => $usersList,
347 $this->rcCacheIndex++;
349 return $this->templateParser->processTemplate(
350 'EnhancedChangesListGroup',
365 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
367 $type = $rcObj->mAttribs[
'rc_type'];
371 $classes = [
'mw-enhanced-rc' ];
373 && $rcObj->mAttribs[
'rc_timestamp'] >= $rcObj->watched
375 $classes[] =
'mw-enhanced-watched';
379 $separator =
' <span class="mw-changeslist-separator">. .</span> ';
381 $data[
'recentChangesFlags'] = [
383 'minor' => $rcObj->mAttribs[
'rc_minor'],
384 'unpatrolled' => $rcObj->unpatrolled,
385 'bot' => $rcObj->mAttribs[
'rc_bot'],
390 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
391 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
396 $link = $rcObj->timestamp;
399 $link =
'<span class="history-deleted">' . $rcObj->timestamp .
'</span> ';
401 $link = $this->linkRenderer->makeKnownLink(
408 $link =
'<span class="history-deleted">' .
$link .
'</span> ';
411 $data[
'timestampLink'] =
$link;
413 $currentAndLastLinks =
'';
415 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
417 $this->message[
'pipe-separator'] .
421 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
422 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
425 if ( $RCShowChangedSize ) {
428 $data[
'characterDiff'] = $cd;
429 $data[
'separatorAfterCharacterDiff'] = $separator;
433 if ( $rcObj->mAttribs[
'rc_type'] ==
RC_LOG ) {
439 $data[
'userLink'] = $rcObj->userlink;
440 $data[
'userTalkLink'] = $rcObj->usertalklink;
448 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
452 [ $this, &$data, $block, $rcObj, &$classes ] );
458 $lineParams[
'recentChangesFlagsRaw'] = [];
459 if ( isset( $data[
'recentChangesFlags'] ) ) {
460 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
461 # FIXME: This is used by logic, don't return it in the template params.
462 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
463 unset( $data[
'recentChangesFlags'] );
466 if ( isset( $data[
'timestampLink'] ) ) {
467 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
468 unset( $data[
'timestampLink'] );
471 $lineParams[
'classes'] = array_values( $classes );
474 $lineParams[
'data'] = array_values( $data );
489 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
490 if ( empty( $block ) ) {
495 static $nchanges = [];
496 static $sinceLastVisitMsg = [];
498 $n =
count( $block );
499 if ( !isset( $nchanges[$n] ) ) {
500 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
504 $unvisitedOldid =
null;
506 foreach ( $block
as $rcObj ) {
508 if ( $rcObj->watched && $rcObj->mAttribs[
'rc_timestamp'] >= $rcObj->watched ) {
510 $unvisitedOldid = $rcObj->mAttribs[
'rc_last_oldid'];
513 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
514 $sinceLastVisitMsg[$sinceLast] =
515 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
518 $currentRevision = 0;
519 foreach ( $block
as $rcObj ) {
520 if ( !$currentRevision ) {
521 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
535 $links[
'total-changes'] = $nchanges[$n];
537 $links[
'total-changes'] = $this->linkRenderer->makeKnownLink(
540 [
'class' =>
'mw-changeslist-groupdiff' ],
542 'diff' => $currentRevision,
543 'oldid' =>
$last->mAttribs[
'rc_last_oldid'],
546 if ( $sinceLast > 0 && $sinceLast < $n ) {
547 $links[
'total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
549 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
550 [
'class' =>
'mw-changeslist-groupdiff' ],
552 'diff' => $currentRevision,
553 'oldid' => $unvisitedOldid,
561 if ( $allLogs || $rcObj->mAttribs[
'rc_type'] ==
RC_CATEGORIZE ) {
563 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
564 $links[
'history'] = $this->
message[
'enhancedrc-history'];
569 $links[
'history'] = $this->linkRenderer->makeKnownLink(
572 [
'class' =>
'mw-changeslist-history' ],
577 # Allow others to alter, remove or add to these links
578 Hooks::run(
'EnhancedChangesList::getLogText',
579 [ $this, &$links, $block ] );
585 $logtext = implode( $this->
message[
'pipe-separator'], $links );
586 $logtext = $this->
msg(
'parentheses' )->rawParams( $logtext )->escaped();
587 return ' ' . $logtext;
599 $query[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
601 $type = $rcObj->mAttribs[
'rc_type'];
602 $logType = $rcObj->mAttribs[
'rc_log_type'];
604 $classes[] =
'mw-enhanced-rc';
608 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
610 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
611 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
615 $data[
'recentChangesFlags'] = [
617 'minor' => $rcObj->mAttribs[
'rc_minor'],
618 'unpatrolled' => $rcObj->unpatrolled,
619 'bot' => $rcObj->mAttribs[
'rc_bot'],
623 $data[
'timestampLink'] = $rcObj->timestamp;
625 # Article or log link
627 $logPage =
new LogPage( $logType );
629 $logName = $logPage->getName()->text();
630 $data[
'logLink'] = $this->
msg(
'parentheses' )
632 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
635 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
638 # Diff and hist links
640 $query[
'action'] =
'history';
643 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator">. .</span> ';
646 if ( $this->
getConfig()->
get(
'RCShowChangedSize' ) ) {
649 $data[
'characterDiff'] = $cd;
650 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator">. .</span> ';
659 $data[
'userLink'] = $rcObj->userlink;
660 $data[
'userTalkLink'] = $rcObj->usertalklink;
669 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
671 # Show how many people are watching this if enabled
676 [ $this, &$data, $rcObj ] );
684 $line .=
'<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
686 if ( isset( $data[
'recentChangesFlags'] ) ) {
688 unset( $data[
'recentChangesFlags'] );
691 if ( isset( $data[
'timestampLink'] ) ) {
692 $line .=
' ' . $data[
'timestampLink'];
693 unset( $data[
'timestampLink'] );
695 $line .=
' </td><td>';
698 $line .= implode(
'', $data );
700 $line .=
"</td></tr></table>\n";
722 $retVal =
' ' . $this->
msg(
'parentheses' )
723 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
724 . $this->linkRenderer->makeKnownLink(
727 [
'class' =>
'mw-changeslist-history' ],
740 if (
count( $this->rc_cache ) == 0 ) {
745 foreach ( $this->rc_cache
as $block ) {
746 if (
count( $block ) < 2 ) {
753 return '<div>' . $blockOut .
'</div>';