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 );
149 $title = $cacheEntry->getTitle();
150 $cacheGroupingKey = $title->getPrefixedDBkey();
152 $type = $cacheEntry->mAttribs[
'rc_type'];
156 $cacheGroupingKey = SpecialPage::getTitleFor(
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 = ( isset( $recentChangesFlags[$key][
'grouping'] ) ?
207 $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;
270 foreach ( $block as $i => $rcObj ) {
279 foreach (
$line[
'recentChangesFlagsRaw'] as $key =>
$value ) {
280 $flagGrouping = ( isset( $recentChangesFlags[$key][
'grouping'] ) ?
281 $recentChangesFlags[$key][
'grouping'] :
'any' );
282 switch ( $flagGrouping ) {
285 $collectedRcFlags[$key] =
false;
290 $collectedRcFlags[$key] =
true;
294 throw new DomainException(
"Unknown grouping type \"{$flagGrouping}\"" );
303 $block = array_values( $block );
305 if ( empty( $block ) || !
$lines ) {
310 $logText = $this->
getLogText( $block, $queryParams, $allLogs,
311 $collectedRcFlags[
'newpage'], $namehidden
314 # Character difference (does not apply if only log items)
315 $charDifference =
false;
316 if ( $RCShowChangedSize && !$allLogs ) {
318 $first = count( $block ) - 1;
319 # Some events (like logs and category changes) have an "empty" size, so we need to skip those...
320 while (
$last < $first && $block[
$last]->mAttribs[
'rc_new_len'] ===
null ) {
323 while (
$last < $first && $block[$first]->mAttribs[
'rc_old_len'] ===
null ) {
331 $usersList = $this->
msg(
'brackets' )->rawParams(
332 implode( $this->message[
'semicolon-separator'], $users )
336 if ( is_callable( $this->changeLinePrefixer ) ) {
337 $prefix = call_user_func( $this->changeLinePrefixer, $block[0], $this,
true );
341 'articleLink' => $articleLink,
342 'charDifference' => $charDifference,
344 'languageDirMark' => $this->
getLanguage()->getDirMark(),
346 'logText' => $logText,
347 'numberofWatchingusers' => $numberofWatchingusers,
349 'rev-deleted-event' => $revDeletedMsg,
350 'tableClasses' => $tableClasses,
351 'timestamp' => $block[0]->timestamp,
352 'fullTimestamp' => $block[0]->getAttribute(
'rc_timestamp' ),
353 'users' => $usersList,
356 $this->rcCacheIndex++;
358 return $this->templateParser->processTemplate(
359 'EnhancedChangesListGroup',
374 $RCShowChangedSize = $this->
getConfig()->get(
'RCShowChangedSize' );
376 $type = $rcObj->mAttribs[
'rc_type'];
378 $lineParams = [
'targetTitle' => $rcObj->getTitle() ];
380 $classes = [
'mw-enhanced-rc' ];
382 && $rcObj->mAttribs[
'rc_timestamp'] >= $rcObj->watched
384 $classes[] =
'mw-enhanced-watched';
386 $classes = array_merge( $classes, $this->
getHTMLClasses( $rcObj, $rcObj->watched ) );
388 $separator =
' <span class="mw-changeslist-separator">. .</span> ';
390 $data[
'recentChangesFlags'] = [
392 'minor' => $rcObj->mAttribs[
'rc_minor'],
393 'unpatrolled' => $rcObj->unpatrolled,
394 'bot' => $rcObj->mAttribs[
'rc_bot'],
399 if ( $rcObj->mAttribs[
'rc_this_oldid'] != 0 ) {
400 $params[
'oldid'] = $rcObj->mAttribs[
'rc_this_oldid'];
405 $link = $rcObj->timestamp;
408 $link =
'<span class="history-deleted">' . $rcObj->timestamp .
'</span> ';
410 $link = $this->linkRenderer->makeKnownLink(
416 if ( $this->
isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
417 $link =
'<span class="history-deleted">' .
$link .
'</span> ';
420 $data[
'timestampLink'] =
$link;
422 $currentAndLastLinks =
'';
424 $currentAndLastLinks .=
' ' . $this->
msg(
'parentheses' )->rawParams(
426 $this->message[
'pipe-separator'] .
430 $data[
'currentAndLastLinks'] = $currentAndLastLinks;
431 $data[
'separatorAfterCurrentAndLastLinks'] = $separator;
434 if ( $RCShowChangedSize ) {
437 $data[
'characterDiff'] = $cd;
438 $data[
'separatorAfterCharacterDiff'] = $separator;
442 if ( $rcObj->mAttribs[
'rc_type'] ==
RC_LOG ) {
448 $data[
'userLink'] = $rcObj->userlink;
449 $data[
'userTalkLink'] = $rcObj->usertalklink;
457 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
462 $success = Hooks::run(
'EnhancedChangesListModifyLineData',
463 [ $this, &$data, $block, $rcObj, &$classes, &
$attribs ] );
470 $lineParams[
'recentChangesFlagsRaw'] = [];
471 if ( isset( $data[
'recentChangesFlags'] ) ) {
472 $lineParams[
'recentChangesFlags'] = $this->
recentChangesFlags( $data[
'recentChangesFlags'] );
473 # FIXME: This is used by logic, don't return it in the template params.
474 $lineParams[
'recentChangesFlagsRaw'] = $data[
'recentChangesFlags'];
475 unset( $data[
'recentChangesFlags'] );
478 if ( isset( $data[
'timestampLink'] ) ) {
479 $lineParams[
'timestampLink'] = $data[
'timestampLink'];
480 unset( $data[
'timestampLink'] );
483 $lineParams[
'classes'] = array_values( $classes );
484 $lineParams[
'attribs'] = Html::expandAttributes(
$attribs );
487 $lineParams[
'data'] = array_values( $data );
502 protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) {
503 if ( empty( $block ) ) {
508 static $nchanges = [];
509 static $sinceLastVisitMsg = [];
511 $n = count( $block );
512 if ( !isset( $nchanges[$n] ) ) {
513 $nchanges[$n] = $this->
msg(
'nchanges' )->numParams( $n )->escaped();
517 $unvisitedOldid =
null;
519 foreach ( $block as $rcObj ) {
521 if ( $rcObj->watched && $rcObj->mAttribs[
'rc_timestamp'] >= $rcObj->watched ) {
523 $unvisitedOldid = $rcObj->mAttribs[
'rc_last_oldid'];
526 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
527 $sinceLastVisitMsg[$sinceLast] =
528 $this->
msg(
'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
531 $currentRevision = 0;
532 foreach ( $block as $rcObj ) {
533 if ( !$currentRevision ) {
534 $currentRevision = $rcObj->mAttribs[
'rc_this_oldid'];
542 $last = $block[count( $block ) - 1];
548 $links[
'total-changes'] = $nchanges[$n];
550 $links[
'total-changes'] = $this->linkRenderer->makeKnownLink(
553 [
'class' =>
'mw-changeslist-groupdiff' ],
555 'diff' => $currentRevision,
556 'oldid' =>
$last->mAttribs[
'rc_last_oldid'],
559 if ( $sinceLast > 0 && $sinceLast < $n ) {
560 $links[
'total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
562 new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
563 [
'class' =>
'mw-changeslist-groupdiff' ],
565 'diff' => $currentRevision,
566 'oldid' => $unvisitedOldid,
574 if ( $allLogs || $rcObj->mAttribs[
'rc_type'] ==
RC_CATEGORIZE ) {
576 } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
577 $links[
'history'] = $this->message[
'enhancedrc-history'];
582 $links[
'history'] = $this->linkRenderer->makeKnownLink(
584 new HtmlArmor( $this->message[
'enhancedrc-history'] ),
585 [
'class' =>
'mw-changeslist-history' ],
590 # Allow others to alter, remove or add to these links
591 Hooks::run(
'EnhancedChangesList::getLogText',
592 [ $this, &$links, $block ] );
598 $logtext = implode( $this->message[
'pipe-separator'], $links );
599 $logtext = $this->
msg(
'parentheses' )->rawParams( $logtext )->escaped();
600 return ' ' . $logtext;
612 $query[
'curid'] = $rcObj->mAttribs[
'rc_cur_id'];
614 $type = $rcObj->mAttribs[
'rc_type'];
615 $logType = $rcObj->mAttribs[
'rc_log_type'];
617 $classes[] =
'mw-enhanced-rc';
621 $classes[] =
'mw-changeslist-log';
622 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-log-' . $logType );
624 $classes[] =
'mw-changeslist-edit';
625 $classes[] = Sanitizer::escapeClass(
'mw-changeslist-ns' .
626 $rcObj->mAttribs[
'rc_namespace'] .
'-' . $rcObj->mAttribs[
'rc_title'] );
630 $data[
'recentChangesFlags'] = [
632 'minor' => $rcObj->mAttribs[
'rc_minor'],
633 'unpatrolled' => $rcObj->unpatrolled,
634 'bot' => $rcObj->mAttribs[
'rc_bot'],
638 $data[
'timestampLink'] = $rcObj->timestamp;
640 # Article or log link
642 $logPage =
new LogPage( $logType );
643 $logTitle = SpecialPage::getTitleFor(
'Log', $logType );
644 $logName = $logPage->getName()->text();
645 $data[
'logLink'] = $this->
msg(
'parentheses' )
647 $this->linkRenderer->makeKnownLink( $logTitle, $logName )
650 $data[
'articleLink'] = $this->
getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
653 # Diff and hist links
655 $query[
'action'] =
'history';
658 $data[
'separatorAfterLinks'] =
' <span class="mw-changeslist-separator">. .</span> ';
661 if ( $this->
getConfig()->
get(
'RCShowChangedSize' ) ) {
664 $data[
'characterDiff'] = $cd;
665 $data[
'separatorAftercharacterDiff'] =
' <span class="mw-changeslist-separator">. .</span> ';
674 $data[
'userLink'] = $rcObj->userlink;
675 $data[
'userTalkLink'] = $rcObj->usertalklink;
684 $data[
'tags'] = $this->
getTags( $rcObj, $classes );
686 # Show how many people are watching this if enabled
689 $data[
'attribs'] = array_merge( $this->
getDataAttributes( $rcObj ), [
'class' => $classes ] );
692 $success = Hooks::run(
'EnhancedChangesListModifyBlockLineData',
693 [ $this, &$data, $rcObj ] );
699 unset( $data[
'attribs'] );
701 return $key ===
'class' || Sanitizer::isReservedDataAttribute( $key );
705 if ( is_callable( $this->changeLinePrefixer ) ) {
706 $prefix = call_user_func( $this->changeLinePrefixer, $rcObj, $this,
false );
709 $line = Html::openElement(
'table',
$attribs ) . Html::openElement(
'tr' );
710 $line .= Html::rawElement(
'td', [],
'<span class="mw-enhancedchanges-arrow-space"></span>' );
711 $line .= Html::rawElement(
'td', [
'class' =>
'mw-changeslist-line-prefix' ], $prefix );
712 $line .=
'<td class="mw-enhanced-rc">';
714 if ( isset( $data[
'recentChangesFlags'] ) ) {
716 unset( $data[
'recentChangesFlags'] );
719 if ( isset( $data[
'timestampLink'] ) ) {
720 $line .=
' ' . $data[
'timestampLink'];
721 unset( $data[
'timestampLink'] );
723 $line .=
' </td>';
724 $line .= Html::openElement(
'td', [
725 'class' =>
'mw-changeslist-line-inner',
727 'data-target-page' => $rcObj->getTitle(),
731 $line .= implode(
'', $data );
733 $line .=
"</td></tr></table>\n";
749 $pageTitle = $rc->getTitle();
752 $pageTitle = Title::newFromID( $rc->getAttribute(
'rc_cur_id' ) );
760 $retVal =
' ' . $this->
msg(
'parentheses' )
761 ->rawParams( $rc->difflink . $this->message[
'pipe-separator']
762 . $this->linkRenderer->makeKnownLink(
765 [
'class' =>
'mw-changeslist-history' ],
778 if ( count( $this->rc_cache ) == 0 ) {
783 foreach ( $this->rc_cache as $block ) {
784 if ( count( $block ) < 2 ) {
791 if ( $blockOut ===
'' ) {
795 return Xml::element(
'h4',
null, $this->lastdate ) .
"\n<div>" . $blockOut .
'</div>';
wfArrayFilterByKey(array $arr, callable $callback)
Like array_filter with ARRAY_FILTER_USE_KEY, but works pre-5.6.
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,...
recentChangesFlags( $flags, $nothing=' ')
Returns the appropriate flags for new page, minor change and patrolling.
formatCharacterDifference(RecentChange $old, RecentChange $new=null)
Format the character difference of one or several changes.
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)
getRollback(RecentChange $rc)
insertLogEntry( $rc)
Insert a formatted action.
static isDeleted( $rc, $field)
Determine if said field of a revision is hidden.
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...
msg( $key)
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.
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.
getDiffHistLinks(RCCacheEntry $rc, array $query)
Returns value to be used in 'historyLink' element of $data param in EnhancedChangesListModifyBlockLin...
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.
The main skin class which provides methods and properties for all other skins.
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template to be included in the link
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
usually copyright or history_copyright This message must be in HTML not wikitext & $link
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Interface for objects which can provide a MediaWiki context on request.