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 ) {
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 );
117 * Put accumulated information into the cache, for later display.
118 * Page moves go on their own line.
120 * @param RCCacheEntry $cacheEntry
122 protected function addCacheEntry( RCCacheEntry
$cacheEntry ) {
123 $cacheGroupingKey = $this->makeCacheGroupingKey( $cacheEntry );
125 if ( !isset( $this->rc_cache
[$cacheGroupingKey] ) ) {
126 $this->rc_cache
[$cacheGroupingKey] = array();
129 array_push( $this->rc_cache
[$cacheGroupingKey], $cacheEntry );
133 * @todo use rc_source to group, if set; fallback to rc_type
135 * @param RCCacheEntry $cacheEntry
139 protected function makeCacheGroupingKey( RCCacheEntry
$cacheEntry ) {
140 $title = $cacheEntry->getTitle();
141 $cacheGroupingKey = $title->getPrefixedDBkey();
143 $type = $cacheEntry->mAttribs
['rc_type'];
145 if ( $type == RC_LOG
) {
147 $cacheGroupingKey = SpecialPage
::getTitleFor(
149 $cacheEntry->mAttribs
['rc_log_type']
150 )->getPrefixedDBkey();
153 return $cacheGroupingKey;
158 * @param RCCacheEntry[] $block
161 protected function recentChangesBlockGroup( $block ) {
163 # Add the namespace and title of the block as part of the class
164 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
165 if ( $block[0]->mAttribs
['rc_log_type'] ) {
167 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
168 . $block[0]->mAttribs
['rc_log_type'] );
170 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
171 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
173 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
174 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
175 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
176 Html
::openElement( 'tr' );
178 # Collate list of users
179 $userlinks = array();
181 $unpatrolled = false;
185 $curId = $currentRevision = 0;
186 # Some catalyst variables...
190 $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
191 foreach ( $block as $rcObj ) {
192 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
193 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
196 // If all log actions to this page were hidden, then don't
197 // give the name of the affected page for this block!
198 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
201 $u = $rcObj->userlink
;
202 if ( !isset( $userlinks[$u] ) ) {
205 if ( $rcObj->unpatrolled
) {
208 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
211 # Get the latest entry with a page_id and oldid
212 # since logs may not have these.
213 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
214 $curId = $rcObj->mAttribs
['rc_cur_id'];
216 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
217 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
220 if ( !$rcObj->mAttribs
['rc_bot'] ) {
223 if ( !$rcObj->mAttribs
['rc_minor'] ) {
230 # Sort the list and convert to text
231 krsort( $userlinks );
234 foreach ( $userlinks as $userlink => $count ) {
236 $text .= $this->getLanguage()->getDirMark();
238 // @todo FIXME: Hardcoded '×'. Should be a message.
239 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
240 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
242 array_push( $users, $text );
245 $users = ' <span class="changedby">'
246 . $this->msg( 'brackets' )->rawParams(
247 implode( $this->message
['semicolon-separator'], $users )
248 )->escaped() . '</span>';
250 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
251 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
252 $r .= "<td>$tl</td>";
255 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
256 'newpage' => $isnew, # show, when one have this flag
257 'minor' => $allMinors, # show only, when all have this flag
258 'unpatrolled' => $unpatrolled, # show, when one have this flag
259 'bot' => $allBots, # show only, when all have this flag
263 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
267 $r .= ' <span class="history-deleted">' .
268 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
269 } elseif ( $allLogs ) {
270 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
272 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
275 $r .= $this->getLanguage()->getDirMark();
277 $queryParams['curid'] = $curId;
280 static $nchanges = array();
281 static $sinceLastVisitMsg = array();
283 $n = count( $block );
284 if ( !isset( $nchanges[$n] ) ) {
285 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
289 $unvisitedOldid = null;
290 /** @var $rcObj RCCacheEntry */
291 foreach ( $block as $rcObj ) {
292 // Same logic as below inside main foreach
293 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
295 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
298 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
299 $sinceLastVisitMsg[$sinceLast] =
300 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
306 /** @var $block0 RecentChange */
309 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
310 $logtext .= $nchanges[$n];
311 } elseif ( $isnew ) {
312 $logtext .= $nchanges[$n];
314 $logtext .= Linker
::link(
318 $queryParams +
array(
319 'diff' => $currentRevision,
322 array( 'known', 'noclasses' )
324 if ( $sinceLast > 0 && $sinceLast < $n ) {
325 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
327 $sinceLastVisitMsg[$sinceLast],
329 $queryParams +
array(
330 'diff' => $currentRevision,
331 'oldid' => $unvisitedOldid,
333 array( 'known', 'noclasses' )
341 // don't show history link for logs
342 } elseif ( $namehidden ||
!$block0->getTitle()->exists() ) {
343 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
345 $params = $queryParams;
346 $params['action'] = 'history';
348 $logtext .= $this->message
['pipe-separator'] .
351 $this->message
['enhancedrc-history'],
357 if ( $logtext !== '' ) {
358 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
361 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
363 # Character difference (does not apply if only log items)
364 if ( $RCShowChangedSize && !$allLogs ) {
366 $first = count( $block ) - 1;
367 # Some events (like logs) have an "empty" size, so we need to skip those...
368 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
371 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
375 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
377 if ( $chardiff == '' ) {
380 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
385 $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers
);
389 foreach ( $block as $rcObj ) {
390 # Classes to apply -- TODO implement
392 $type = $rcObj->mAttribs
['rc_type'];
394 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
395 ?
' class="mw-enhanced-watched"' : '';
397 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
398 $r .= $this->recentChangesFlags( array(
399 'newpage' => $type == RC_NEW
,
400 'minor' => $rcObj->mAttribs
['rc_minor'],
401 'unpatrolled' => $rcObj->unpatrolled
,
402 'bot' => $rcObj->mAttribs
['rc_bot'],
404 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
406 $params = $queryParams;
408 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
409 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
413 if ( $type == RC_LOG
) {
414 $link = $rcObj->timestamp
;
416 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
417 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
420 $link = Linker
::linkKnown(
426 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
427 $link = '<span class="history-deleted">' . $link . '</span> ';
430 $r .= $link . '</span>';
432 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
433 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
435 $this->message
['pipe-separator'] .
439 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
442 if ( $RCShowChangedSize ) {
443 $cd = $this->formatCharacterDifference( $rcObj );
445 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
449 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
450 $r .= $this->insertLogEntry( $rcObj );
453 $r .= $rcObj->userlink
;
454 $r .= $rcObj->usertalklink
;
455 $r .= $this->insertComment( $rcObj );
459 $this->insertRollback( $r, $rcObj );
461 $this->insertTags( $r, $rcObj, $classes );
463 $r .= "</td></tr>\n";
467 $this->rcCacheIndex++
;
474 * Enhanced RC ungrouped line.
476 * @param RecentChange|RCCacheEntry $rcObj
477 * @return string A HTML formatted line (generated using $r)
479 protected function recentChangesBlockLine( $rcObj ) {
480 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
482 $type = $rcObj->mAttribs
['rc_type'];
483 $logType = $rcObj->mAttribs
['rc_log_type'];
484 $classes = array( 'mw-enhanced-rc' );
487 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType );
489 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
490 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
492 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
493 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
494 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
495 Html
::openElement( 'tr' );
497 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
499 $r .= $this->recentChangesFlags( array(
500 'newpage' => $type == RC_NEW
,
501 'minor' => $rcObj->mAttribs
['rc_minor'],
502 'unpatrolled' => $rcObj->unpatrolled
,
503 'bot' => $rcObj->mAttribs
['rc_bot'],
505 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
506 # Article or log link
508 $logPage = new LogPage( $logType );
509 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
510 $logName = $logPage->getName()->escaped();
511 $r .= $this->msg( 'parentheses' )
512 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
514 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
516 # Diff and hist links
517 if ( $type != RC_LOG
) {
518 $query['action'] = 'history';
519 $r .= ' ' . $this->msg( 'parentheses' )
520 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
522 $this->message
['hist'],
527 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
529 if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
530 $cd = $this->formatCharacterDifference( $rcObj );
532 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
536 if ( $type == RC_LOG
) {
537 $r .= $this->insertLogEntry( $rcObj );
539 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
540 $r .= $this->insertComment( $rcObj );
541 $this->insertRollback( $r, $rcObj );
545 $this->insertTags( $r, $rcObj, $classes );
546 # Show how many people are watching this if enabled
547 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
549 $r .= "</td></tr></table>\n";
556 * If enhanced RC is in use, this function takes the previously cached
557 * RC lines, arranges them, and outputs the HTML
561 protected function recentChangesBlock() {
562 if ( count( $this->rc_cache
) == 0 ) {
568 foreach ( $this->rc_cache
as $block ) {
569 if ( count( $block ) < 2 ) {
570 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
572 $blockOut .= $this->recentChangesBlockGroup( $block );
577 return '<div>' . $blockOut . '</div>';
581 * Returns text for the end of RC
582 * If enhanced RC is in use, returns pretty much all the text
585 public function endRecentChangesList() {
586 return $this->recentChangesBlock() . '</div>';