3 * Generates a list of changes using an Enhanced system (uses javascript).
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 class EnhancedChangesList
extends ChangesList
{
26 * @var RCCacheEntryFactory
28 protected $cacheEntryFactory;
31 * @var array Array of array of RCCacheEntry
36 * @param IContextSource|Skin $obj
38 public function __construct( $obj ) {
39 if ( $obj instanceof Skin
) {
40 // @todo: deprecate constructing with Skin
41 $context = $obj->getContext();
43 if ( !$obj instanceof IContextSource
) {
44 throw new MWException( 'EnhancedChangesList must be constructed with a '
45 . 'context source or skin.' );
51 parent
::__construct( $context );
53 // message is set by the parent ChangesList class
54 $this->cacheEntryFactory
= new RCCacheEntryFactory(
61 * Add the JavaScript file for enhanced changeslist
64 public function beginRecentChangesList() {
65 $this->rc_cache
= array();
66 $this->rcMoveIndex
= 0;
67 $this->rcCacheIndex
= 0;
69 $this->rclistOpen
= false;
70 $this->getOutput()->addModuleStyles( array(
71 'mediawiki.special.changeslist',
72 'mediawiki.special.changeslist.enhanced',
74 $this->getOutput()->addModules( array(
75 'jquery.makeCollapsible',
79 return '<div class="mw-changeslist">';
83 * Format a line for enhanced recentchange (aka with javascript and block of lines).
85 * @param RecentChange $baseRC
86 * @param bool $watched
90 public function recentChangesLine( &$baseRC, $watched = false ) {
91 wfProfileIn( __METHOD__
);
93 $date = $this->getLanguage()->userDate(
94 $baseRC->mAttribs
['rc_timestamp'],
100 # If it's a new day, add the headline and flush the cache
101 if ( $date != $this->lastdate
) {
102 # Process current cache
103 $ret = $this->recentChangesBlock();
104 $this->rc_cache
= array();
105 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
106 $this->lastdate
= $date;
109 $cacheEntry = $this->cacheEntryFactory
->newFromRecentChange( $baseRC, $watched );
110 $this->addCacheEntry( $cacheEntry );
112 wfProfileOut( __METHOD__
);
118 * Put accumulated information into the cache, for later display.
119 * Page moves go on their own line.
121 * @param RCCacheEntry $cacheEntry
123 protected function addCacheEntry( RCCacheEntry
$cacheEntry ) {
124 $cacheGroupingKey = $this->makeCacheGroupingKey( $cacheEntry );
126 if ( !isset( $this->rc_cache
[$cacheGroupingKey] ) ) {
127 $this->rc_cache
[$cacheGroupingKey] = array();
130 array_push( $this->rc_cache
[$cacheGroupingKey], $cacheEntry );
134 * @todo use rc_source to group, if set; fallback to rc_type
136 * @param RCCacheEntry $cacheEntry
140 protected function makeCacheGroupingKey( RCCacheEntry
$cacheEntry ) {
141 $title = $cacheEntry->getTitle();
142 $cacheGroupingKey = $title->getPrefixedDBkey();
144 $type = $cacheEntry->mAttribs
['rc_type'];
146 if ( $type == RC_LOG
) {
148 $cacheGroupingKey = SpecialPage
::getTitleFor(
150 $cacheEntry->mAttribs
['rc_log_type']
151 )->getPrefixedDBkey();
154 return $cacheGroupingKey;
159 * @param RCCacheEntry[] $block
162 protected function recentChangesBlockGroup( $block ) {
163 wfProfileIn( __METHOD__
);
165 # Add the namespace and title of the block as part of the class
166 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
167 if ( $block[0]->mAttribs
['rc_log_type'] ) {
169 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
170 . $block[0]->mAttribs
['rc_log_type'] );
172 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
173 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
175 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
176 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
177 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
178 Html
::openElement( 'tr' );
180 # Collate list of users
181 $userlinks = array();
183 $unpatrolled = false;
187 $curId = $currentRevision = 0;
188 # Some catalyst variables...
192 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
193 foreach ( $block as $rcObj ) {
194 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
195 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
198 // If all log actions to this page were hidden, then don't
199 // give the name of the affected page for this block!
200 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
203 $u = $rcObj->userlink
;
204 if ( !isset( $userlinks[$u] ) ) {
207 if ( $rcObj->unpatrolled
) {
210 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
213 # Get the latest entry with a page_id and oldid
214 # since logs may not have these.
215 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
216 $curId = $rcObj->mAttribs
['rc_cur_id'];
218 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
219 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
222 if ( !$rcObj->mAttribs
['rc_bot'] ) {
225 if ( !$rcObj->mAttribs
['rc_minor'] ) {
232 # Sort the list and convert to text
233 krsort( $userlinks );
236 foreach ( $userlinks as $userlink => $count ) {
238 $text .= $this->getLanguage()->getDirMark();
240 // @todo FIXME: Hardcoded '×'. Should be a message.
241 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
242 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
244 array_push( $users, $text );
247 $users = ' <span class="changedby">'
248 . $this->msg( 'brackets' )->rawParams(
249 implode( $this->message
['semicolon-separator'], $users )
250 )->escaped() . '</span>';
252 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
253 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
254 $r .= "<td>$tl</td>";
257 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
258 'newpage' => $isnew, # show, when one have this flag
259 'minor' => $allMinors, # show only, when all have this flag
260 'unpatrolled' => $unpatrolled, # show, when one have this flag
261 'bot' => $allBots, # show only, when all have this flag
265 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
269 $r .= ' <span class="history-deleted">' .
270 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
271 } elseif ( $allLogs ) {
272 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
274 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
277 $r .= $this->getLanguage()->getDirMark();
279 $queryParams['curid'] = $curId;
282 static $nchanges = array();
283 static $sinceLastVisitMsg = array();
285 $n = count( $block );
286 if ( !isset( $nchanges[$n] ) ) {
287 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
291 $unvisitedOldid = null;
292 /** @var $rcObj RCCacheEntry */
293 foreach ( $block as $rcObj ) {
294 // Same logic as below inside main foreach
295 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
297 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
300 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
301 $sinceLastVisitMsg[$sinceLast] =
302 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
308 /** @var $block0 RecentChange */
311 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
312 $logtext .= $nchanges[$n];
313 } elseif ( $isnew ) {
314 $logtext .= $nchanges[$n];
316 $logtext .= Linker
::link(
320 $queryParams +
array(
321 'diff' => $currentRevision,
324 array( 'known', 'noclasses' )
326 if ( $sinceLast > 0 && $sinceLast < $n ) {
327 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
329 $sinceLastVisitMsg[$sinceLast],
331 $queryParams +
array(
332 'diff' => $currentRevision,
333 'oldid' => $unvisitedOldid,
335 array( 'known', 'noclasses' )
343 // don't show history link for logs
344 } elseif ( $namehidden ||
!$block0->getTitle()->exists() ) {
345 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
347 $params = $queryParams;
348 $params['action'] = 'history';
350 $logtext .= $this->message
['pipe-separator'] .
353 $this->message
['enhancedrc-history'],
359 if ( $logtext !== '' ) {
360 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
363 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
365 # Character difference (does not apply if only log items)
366 if ( $RCShowChangedSize && !$allLogs ) {
368 $first = count( $block ) - 1;
369 # Some events (like logs) have an "empty" size, so we need to skip those...
370 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
373 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
377 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
379 if ( $chardiff == '' ) {
382 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
387 $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers
);
391 foreach ( $block as $rcObj ) {
392 # Classes to apply -- TODO implement
394 $type = $rcObj->mAttribs
['rc_type'];
396 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
397 ?
' class="mw-enhanced-watched"' : '';
399 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
400 $r .= $this->recentChangesFlags( array(
401 'newpage' => $type == RC_NEW
,
402 'minor' => $rcObj->mAttribs
['rc_minor'],
403 'unpatrolled' => $rcObj->unpatrolled
,
404 'bot' => $rcObj->mAttribs
['rc_bot'],
406 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
408 $params = $queryParams;
410 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
411 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
415 if ( $type == RC_LOG
) {
416 $link = $rcObj->timestamp
;
418 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
419 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
422 $link = Linker
::linkKnown(
428 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
429 $link = '<span class="history-deleted">' . $link . '</span> ';
432 $r .= $link . '</span>';
434 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
435 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
437 $this->message
['pipe-separator'] .
441 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
444 if ( $RCShowChangedSize ) {
445 $cd = $this->formatCharacterDifference( $rcObj );
447 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
451 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
452 $r .= $this->insertLogEntry( $rcObj );
455 $r .= $rcObj->userlink
;
456 $r .= $rcObj->usertalklink
;
457 $r .= $this->insertComment( $rcObj );
461 $this->insertRollback( $r, $rcObj );
463 $this->insertTags( $r, $rcObj, $classes );
465 $r .= "</td></tr>\n";
469 $this->rcCacheIndex++
;
471 wfProfileOut( __METHOD__
);
477 * Enhanced RC ungrouped line.
479 * @param RecentChange|RCCacheEntry $rcObj
480 * @return string A HTML formatted line (generated using $r)
482 protected function recentChangesBlockLine( $rcObj ) {
483 wfProfileIn( __METHOD__
);
484 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
486 $type = $rcObj->mAttribs
['rc_type'];
487 $logType = $rcObj->mAttribs
['rc_log_type'];
488 $classes = array( 'mw-enhanced-rc' );
491 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType );
493 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
494 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
496 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
497 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
498 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
499 Html
::openElement( 'tr' );
501 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
503 $r .= $this->recentChangesFlags( array(
504 'newpage' => $type == RC_NEW
,
505 'minor' => $rcObj->mAttribs
['rc_minor'],
506 'unpatrolled' => $rcObj->unpatrolled
,
507 'bot' => $rcObj->mAttribs
['rc_bot'],
509 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
510 # Article or log link
512 $logPage = new LogPage( $logType );
513 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
514 $logName = $logPage->getName()->escaped();
515 $r .= $this->msg( 'parentheses' )
516 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
518 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
520 # Diff and hist links
521 if ( $type != RC_LOG
) {
522 $query['action'] = 'history';
523 $r .= ' ' . $this->msg( 'parentheses' )
524 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
526 $this->message
['hist'],
531 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
533 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
534 $cd = $this->formatCharacterDifference( $rcObj );
536 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
540 if ( $type == RC_LOG
) {
541 $r .= $this->insertLogEntry( $rcObj );
543 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
544 $r .= $this->insertComment( $rcObj );
545 $this->insertRollback( $r, $rcObj );
549 $this->insertTags( $r, $rcObj, $classes );
550 # Show how many people are watching this if enabled
551 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
553 $r .= "</td></tr></table>\n";
555 wfProfileOut( __METHOD__
);
561 * If enhanced RC is in use, this function takes the previously cached
562 * RC lines, arranges them, and outputs the HTML
566 protected function recentChangesBlock() {
567 if ( count( $this->rc_cache
) == 0 ) {
571 wfProfileIn( __METHOD__
);
574 foreach ( $this->rc_cache
as $block ) {
575 if ( count( $block ) < 2 ) {
576 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
578 $blockOut .= $this->recentChangesBlockGroup( $block );
582 wfProfileOut( __METHOD__
);
584 return '<div>' . $blockOut . '</div>';
588 * Returns text for the end of RC
589 * If enhanced RC is in use, returns pretty much all the text
592 public function endRecentChangesList() {
593 return $this->recentChangesBlock() . '</div>';