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
39 public function __construct( $obj ) {
40 if ( $obj instanceof Skin
) {
41 // @todo: deprecate constructing with Skin
42 $context = $obj->getContext();
44 if ( !$obj instanceof IContextSource
) {
45 throw new MWException( 'EnhancedChangesList must be constructed with a '
46 . 'context source or skin.' );
52 parent
::__construct( $context );
54 // message is set by the parent ChangesList class
55 $this->cacheEntryFactory
= new RCCacheEntryFactory(
62 * Add the JavaScript file for enhanced changeslist
65 public function beginRecentChangesList() {
66 $this->rc_cache
= array();
67 $this->rcMoveIndex
= 0;
68 $this->rcCacheIndex
= 0;
70 $this->rclistOpen
= false;
71 $this->getOutput()->addModuleStyles( array(
72 'mediawiki.special.changeslist',
73 'mediawiki.special.changeslist.enhanced',
75 $this->getOutput()->addModules( array(
76 'jquery.makeCollapsible',
80 return '<div class="mw-changeslist">';
84 * Format a line for enhanced recentchange (aka with javascript and block of lines).
86 * @param RecentChange $baseRC
87 * @param bool $watched
91 public function recentChangesLine( &$baseRC, $watched = false ) {
92 wfProfileIn( __METHOD__
);
94 $date = $this->getLanguage()->userDate(
95 $baseRC->mAttribs
['rc_timestamp'],
101 # If it's a new day, add the headline and flush the cache
102 if ( $date != $this->lastdate
) {
103 # Process current cache
104 $ret = $this->recentChangesBlock();
105 $this->rc_cache
= array();
106 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
107 $this->lastdate
= $date;
110 $cacheEntry = $this->cacheEntryFactory
->newFromRecentChange( $baseRC, $watched );
111 $this->addCacheEntry( $cacheEntry );
113 wfProfileOut( __METHOD__
);
119 * Put accumulated information into the cache, for later display.
120 * Page moves go on their own line.
122 * @param RCCacheEntry $cacheEntry
124 protected function addCacheEntry( RCCacheEntry
$cacheEntry ) {
125 $cacheGroupingKey = $this->makeCacheGroupingKey( $cacheEntry );
127 if ( !isset( $this->rc_cache
[$cacheGroupingKey] ) ) {
128 $this->rc_cache
[$cacheGroupingKey] = array();
131 array_push( $this->rc_cache
[$cacheGroupingKey], $cacheEntry );
135 * @todo use rc_source to group, if set; fallback to rc_type
137 * @param RCCacheEntry $cacheEntry
141 protected function makeCacheGroupingKey( RCCacheEntry
$cacheEntry ) {
142 $title = $cacheEntry->getTitle();
143 $cacheGroupingKey = $title->getPrefixedDBkey();
145 $type = $cacheEntry->mAttribs
['rc_type'];
147 if ( $type == RC_LOG
) {
149 $cacheGroupingKey = SpecialPage
::getTitleFor(
151 $cacheEntry->mAttribs
['rc_log_type']
152 )->getPrefixedDBkey();
155 return $cacheGroupingKey;
160 * @param RCCacheEntry[] $block
163 protected function recentChangesBlockGroup( $block ) {
164 wfProfileIn( __METHOD__
);
166 # Add the namespace and title of the block as part of the class
167 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
168 if ( $block[0]->mAttribs
['rc_log_type'] ) {
170 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
171 . $block[0]->mAttribs
['rc_log_type'] );
173 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
174 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
176 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
177 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
178 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
179 Html
::openElement( 'tr' );
181 # Collate list of users
182 $userlinks = array();
184 $unpatrolled = false;
188 $curId = $currentRevision = 0;
189 # Some catalyst variables...
193 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
194 foreach ( $block as $rcObj ) {
195 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
196 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
199 // If all log actions to this page were hidden, then don't
200 // give the name of the affected page for this block!
201 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
204 $u = $rcObj->userlink
;
205 if ( !isset( $userlinks[$u] ) ) {
208 if ( $rcObj->unpatrolled
) {
211 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
214 # Get the latest entry with a page_id and oldid
215 # since logs may not have these.
216 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
217 $curId = $rcObj->mAttribs
['rc_cur_id'];
219 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
220 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
223 if ( !$rcObj->mAttribs
['rc_bot'] ) {
226 if ( !$rcObj->mAttribs
['rc_minor'] ) {
233 # Sort the list and convert to text
234 krsort( $userlinks );
237 foreach ( $userlinks as $userlink => $count ) {
239 $text .= $this->getLanguage()->getDirMark();
241 // @todo FIXME: Hardcoded '×'. Should be a message.
242 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
243 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
245 array_push( $users, $text );
248 $users = ' <span class="changedby">'
249 . $this->msg( 'brackets' )->rawParams(
250 implode( $this->message
['semicolon-separator'], $users )
251 )->escaped() . '</span>';
253 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
254 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
255 $r .= "<td>$tl</td>";
258 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
259 'newpage' => $isnew, # show, when one have this flag
260 'minor' => $allMinors, # show only, when all have this flag
261 'unpatrolled' => $unpatrolled, # show, when one have this flag
262 'bot' => $allBots, # show only, when all have this flag
266 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
270 $r .= ' <span class="history-deleted">' .
271 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
272 } elseif ( $allLogs ) {
273 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
275 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
278 $r .= $this->getLanguage()->getDirMark();
280 $queryParams['curid'] = $curId;
283 static $nchanges = array();
284 static $sinceLastVisitMsg = array();
286 $n = count( $block );
287 if ( !isset( $nchanges[$n] ) ) {
288 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
292 $unvisitedOldid = null;
293 /** @var $rcObj RCCacheEntry */
294 foreach ( $block as $rcObj ) {
295 // Same logic as below inside main foreach
296 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
298 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
301 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
302 $sinceLastVisitMsg[$sinceLast] =
303 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
309 /** @var $block0 RecentChange */
312 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
313 $logtext .= $nchanges[$n];
314 } elseif ( $isnew ) {
315 $logtext .= $nchanges[$n];
317 $logtext .= Linker
::link(
321 $queryParams +
array(
322 'diff' => $currentRevision,
325 array( 'known', 'noclasses' )
327 if ( $sinceLast > 0 && $sinceLast < $n ) {
328 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
330 $sinceLastVisitMsg[$sinceLast],
332 $queryParams +
array(
333 'diff' => $currentRevision,
334 'oldid' => $unvisitedOldid,
336 array( 'known', 'noclasses' )
344 // don't show history link for logs
345 } elseif ( $namehidden ||
!$block0->getTitle()->exists() ) {
346 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
348 $params = $queryParams;
349 $params['action'] = 'history';
351 $logtext .= $this->message
['pipe-separator'] .
354 $this->message
['enhancedrc-history'],
360 if ( $logtext !== '' ) {
361 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
364 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
366 # Character difference (does not apply if only log items)
367 if ( $RCShowChangedSize && !$allLogs ) {
369 $first = count( $block ) - 1;
370 # Some events (like logs) have an "empty" size, so we need to skip those...
371 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
374 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
378 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
380 if ( $chardiff == '' ) {
383 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
388 $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers
);
392 foreach ( $block as $rcObj ) {
393 # Classes to apply -- TODO implement
395 $type = $rcObj->mAttribs
['rc_type'];
397 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
398 ?
' class="mw-enhanced-watched"' : '';
400 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
401 $r .= $this->recentChangesFlags( array(
402 'newpage' => $type == RC_NEW
,
403 'minor' => $rcObj->mAttribs
['rc_minor'],
404 'unpatrolled' => $rcObj->unpatrolled
,
405 'bot' => $rcObj->mAttribs
['rc_bot'],
407 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
409 $params = $queryParams;
411 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
412 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
416 if ( $type == RC_LOG
) {
417 $link = $rcObj->timestamp
;
419 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
420 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
423 $link = Linker
::linkKnown(
429 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
430 $link = '<span class="history-deleted">' . $link . '</span> ';
433 $r .= $link . '</span>';
435 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
436 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
438 $this->message
['pipe-separator'] .
442 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
445 if ( $RCShowChangedSize ) {
446 $cd = $this->formatCharacterDifference( $rcObj );
448 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
452 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
453 $r .= $this->insertLogEntry( $rcObj );
456 $r .= $rcObj->userlink
;
457 $r .= $rcObj->usertalklink
;
458 $r .= $this->insertComment( $rcObj );
462 $this->insertRollback( $r, $rcObj );
464 $this->insertTags( $r, $rcObj, $classes );
466 $r .= "</td></tr>\n";
470 $this->rcCacheIndex++
;
472 wfProfileOut( __METHOD__
);
478 * Enhanced RC ungrouped line.
480 * @param RecentChange|RCCacheEntry $rcObj
481 * @return string A HTML formatted line (generated using $r)
483 protected function recentChangesBlockLine( $rcObj ) {
484 wfProfileIn( __METHOD__
);
485 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
487 $type = $rcObj->mAttribs
['rc_type'];
488 $logType = $rcObj->mAttribs
['rc_log_type'];
489 $classes = array( 'mw-enhanced-rc' );
492 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType );
494 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
495 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
497 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
498 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
499 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
500 Html
::openElement( 'tr' );
502 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
504 $r .= $this->recentChangesFlags( array(
505 'newpage' => $type == RC_NEW
,
506 'minor' => $rcObj->mAttribs
['rc_minor'],
507 'unpatrolled' => $rcObj->unpatrolled
,
508 'bot' => $rcObj->mAttribs
['rc_bot'],
510 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
511 # Article or log link
513 $logPage = new LogPage( $logType );
514 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
515 $logName = $logPage->getName()->escaped();
516 $r .= $this->msg( 'parentheses' )
517 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
519 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
521 # Diff and hist links
522 if ( $type != RC_LOG
) {
523 $query['action'] = 'history';
524 $r .= ' ' . $this->msg( 'parentheses' )
525 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
527 $this->message
['hist'],
532 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
534 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
535 $cd = $this->formatCharacterDifference( $rcObj );
537 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
541 if ( $type == RC_LOG
) {
542 $r .= $this->insertLogEntry( $rcObj );
544 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
545 $r .= $this->insertComment( $rcObj );
546 $this->insertRollback( $r, $rcObj );
550 $this->insertTags( $r, $rcObj, $classes );
551 # Show how many people are watching this if enabled
552 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
554 $r .= "</td></tr></table>\n";
556 wfProfileOut( __METHOD__
);
562 * If enhanced RC is in use, this function takes the previously cached
563 * RC lines, arranges them, and outputs the HTML
567 protected function recentChangesBlock() {
568 if ( count( $this->rc_cache
) == 0 ) {
572 wfProfileIn( __METHOD__
);
575 foreach ( $this->rc_cache
as $block ) {
576 if ( count( $block ) < 2 ) {
577 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
579 $blockOut .= $this->recentChangesBlockGroup( $block );
583 wfProfileOut( __METHOD__
);
585 return '<div>' . $blockOut . '</div>';
589 * Returns text for the end of RC
590 * If enhanced RC is in use, returns pretty much all the text
593 public function endRecentChangesList() {
594 return $this->recentChangesBlock() . '</div>';