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 # If it's a new day, add the headline and flush the cache
94 $date = $this->getLanguage()->userDate(
95 $baseRC->mAttribs
['rc_timestamp'],
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 );
111 # Put accumulated information into the cache, for later display
112 # Page moves go on their own line
113 $title = $cacheEntry->getTitle();
114 $secureName = $title->getPrefixedDBkey();
116 $type = $cacheEntry->mAttribs
['rc_type'];
118 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
119 # Use an @ character to prevent collision with page names
120 $this->rc_cache
['@@' . ( $this->rcMoveIndex++
)] = array( $cacheEntry );
122 # Logs are grouped by type
123 if ( $type == RC_LOG
) {
124 $secureName = SpecialPage
::getTitleFor(
126 $cacheEntry->mAttribs
['rc_log_type']
127 )->getPrefixedDBkey();
129 if ( !isset( $this->rc_cache
[$secureName] ) ) {
130 $this->rc_cache
[$secureName] = array();
133 array_push( $this->rc_cache
[$secureName], $cacheEntry );
136 wfProfileOut( __METHOD__
);
143 * @param RCCacheEntry[] $block
146 protected function recentChangesBlockGroup( $block ) {
147 global $wgRCShowChangedSize;
149 wfProfileIn( __METHOD__
);
151 # Add the namespace and title of the block as part of the class
152 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
153 if ( $block[0]->mAttribs
['rc_log_type'] ) {
155 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
156 . $block[0]->mAttribs
['rc_log_type'] );
158 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
159 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
161 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
162 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
163 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
164 Html
::openElement( 'tr' );
166 # Collate list of users
167 $userlinks = array();
169 $unpatrolled = false;
173 $curId = $currentRevision = 0;
174 # Some catalyst variables...
178 foreach ( $block as $rcObj ) {
179 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
180 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
183 // If all log actions to this page were hidden, then don't
184 // give the name of the affected page for this block!
185 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
188 $u = $rcObj->userlink
;
189 if ( !isset( $userlinks[$u] ) ) {
192 if ( $rcObj->unpatrolled
) {
195 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
198 # Get the latest entry with a page_id and oldid
199 # since logs may not have these.
200 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
201 $curId = $rcObj->mAttribs
['rc_cur_id'];
203 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
204 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
207 if ( !$rcObj->mAttribs
['rc_bot'] ) {
210 if ( !$rcObj->mAttribs
['rc_minor'] ) {
217 # Sort the list and convert to text
218 krsort( $userlinks );
221 foreach ( $userlinks as $userlink => $count ) {
223 $text .= $this->getLanguage()->getDirMark();
225 // @todo FIXME: Hardcoded '×'. Should be a message.
226 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
227 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
229 array_push( $users, $text );
232 $users = ' <span class="changedby">'
233 . $this->msg( 'brackets' )->rawParams(
234 implode( $this->message
['semicolon-separator'], $users )
235 )->escaped() . '</span>';
237 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
238 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
239 $r .= "<td>$tl</td>";
242 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
243 'newpage' => $isnew, # show, when one have this flag
244 'minor' => $allMinors, # show only, when all have this flag
245 'unpatrolled' => $unpatrolled, # show, when one have this flag
246 'bot' => $allBots, # show only, when all have this flag
250 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
254 $r .= ' <span class="history-deleted">' .
255 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
256 } elseif ( $allLogs ) {
257 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
259 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
262 $r .= $this->getLanguage()->getDirMark();
264 $queryParams['curid'] = $curId;
267 static $nchanges = array();
268 static $sinceLastVisitMsg = array();
270 $n = count( $block );
271 if ( !isset( $nchanges[$n] ) ) {
272 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
276 $unvisitedOldid = null;
277 /** @var $rcObj RCCacheEntry */
278 foreach ( $block as $rcObj ) {
279 // Same logic as below inside main foreach
280 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
282 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
285 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
286 $sinceLastVisitMsg[$sinceLast] =
287 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
293 /** @var $block0 RecentChange */
296 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
297 $logtext .= $nchanges[$n];
298 } elseif ( $isnew ) {
299 $logtext .= $nchanges[$n];
301 $logtext .= Linker
::link(
305 $queryParams +
array(
306 'diff' => $currentRevision,
309 array( 'known', 'noclasses' )
311 if ( $sinceLast > 0 && $sinceLast < $n ) {
312 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
314 $sinceLastVisitMsg[$sinceLast],
316 $queryParams +
array(
317 'diff' => $currentRevision,
318 'oldid' => $unvisitedOldid,
320 array( 'known', 'noclasses' )
328 // don't show history link for logs
329 } elseif ( $namehidden ||
!$block0->getTitle()->exists() ) {
330 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
332 $params = $queryParams;
333 $params['action'] = 'history';
335 $logtext .= $this->message
['pipe-separator'] .
338 $this->message
['enhancedrc-history'],
344 if ( $logtext !== '' ) {
345 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
348 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
350 # Character difference (does not apply if only log items)
351 if ( $wgRCShowChangedSize && !$allLogs ) {
353 $first = count( $block ) - 1;
354 # Some events (like logs) have an "empty" size, so we need to skip those...
355 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
358 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
362 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
364 if ( $chardiff == '' ) {
367 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
372 $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers
);
376 foreach ( $block as $rcObj ) {
377 # Classes to apply -- TODO implement
379 $type = $rcObj->mAttribs
['rc_type'];
381 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
382 ?
' class="mw-enhanced-watched"' : '';
384 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
385 $r .= $this->recentChangesFlags( array(
386 'newpage' => $type == RC_NEW
,
387 'minor' => $rcObj->mAttribs
['rc_minor'],
388 'unpatrolled' => $rcObj->unpatrolled
,
389 'bot' => $rcObj->mAttribs
['rc_bot'],
391 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
393 $params = $queryParams;
395 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
396 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
400 if ( $type == RC_LOG
) {
401 $link = $rcObj->timestamp
;
403 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
404 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
407 $link = Linker
::linkKnown(
413 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
414 $link = '<span class="history-deleted">' . $link . '</span> ';
417 $r .= $link . '</span>';
419 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
420 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
422 $this->message
['pipe-separator'] .
426 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
429 if ( $wgRCShowChangedSize ) {
430 $cd = $this->formatCharacterDifference( $rcObj );
432 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
436 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
437 $r .= $this->insertLogEntry( $rcObj );
440 $r .= $rcObj->userlink
;
441 $r .= $rcObj->usertalklink
;
442 $r .= $this->insertComment( $rcObj );
446 $this->insertRollback( $r, $rcObj );
448 $this->insertTags( $r, $rcObj, $classes );
450 $r .= "</td></tr>\n";
454 $this->rcCacheIndex++
;
456 wfProfileOut( __METHOD__
);
462 * Generate HTML for an arrow or placeholder graphic
463 * @param string $dir One of '', 'd', 'l', 'r'
465 * @param string $title
466 * @return string HTML "<img>" tag
468 protected function arrow( $dir, $alt = '', $title = '' ) {
470 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
471 $encAlt = htmlspecialchars( $alt );
472 $encTitle = htmlspecialchars( $title );
474 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
478 * Generate HTML for a right- or left-facing arrow,
479 * depending on language direction.
480 * @return string HTML "<img>" tag
482 protected function sideArrow() {
483 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
485 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
489 * Generate HTML for a down-facing arrow
490 * depending on language direction.
491 * @return string HTML "<img>" tag
493 protected function downArrow() {
494 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
498 * Generate HTML for a spacer image
499 * @return string HTML "<img>" tag
501 protected function spacerArrow() {
502 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
506 * Enhanced RC ungrouped line.
508 * @param RecentChange|RCCacheEntry $rcObj
509 * @return string A HTML formatted line (generated using $r)
511 protected function recentChangesBlockLine( $rcObj ) {
512 global $wgRCShowChangedSize;
514 wfProfileIn( __METHOD__
);
515 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
517 $type = $rcObj->mAttribs
['rc_type'];
518 $logType = $rcObj->mAttribs
['rc_log_type'];
519 $classes = array( 'mw-enhanced-rc' );
522 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType );
524 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
525 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
527 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
528 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
529 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
530 Html
::openElement( 'tr' );
532 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
534 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
535 $r .= $this->recentChangesFlags( array() ); // no flags, but need the placeholders
537 $r .= $this->recentChangesFlags( array(
538 'newpage' => $type == RC_NEW
,
539 'minor' => $rcObj->mAttribs
['rc_minor'],
540 'unpatrolled' => $rcObj->unpatrolled
,
541 'bot' => $rcObj->mAttribs
['rc_bot'],
544 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
545 # Article or log link
547 $logPage = new LogPage( $logType );
548 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
549 $logName = $logPage->getName()->escaped();
550 $r .= $this->msg( 'parentheses' )
551 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
553 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
555 # Diff and hist links
556 if ( $type != RC_LOG
) {
557 $query['action'] = 'history';
558 $r .= ' ' . $this->msg( 'parentheses' )
559 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
561 $this->message
['hist'],
566 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
568 if ( $wgRCShowChangedSize ) {
569 $cd = $this->formatCharacterDifference( $rcObj );
571 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
575 if ( $type == RC_LOG
) {
576 $r .= $this->insertLogEntry( $rcObj );
578 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
579 $r .= $this->insertComment( $rcObj );
580 $this->insertRollback( $r, $rcObj );
584 $this->insertTags( $r, $rcObj, $classes );
585 # Show how many people are watching this if enabled
586 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
588 $r .= "</td></tr></table>\n";
590 wfProfileOut( __METHOD__
);
596 * If enhanced RC is in use, this function takes the previously cached
597 * RC lines, arranges them, and outputs the HTML
601 protected function recentChangesBlock() {
602 if ( count( $this->rc_cache
) == 0 ) {
606 wfProfileIn( __METHOD__
);
609 foreach ( $this->rc_cache
as $block ) {
610 if ( count( $block ) < 2 ) {
611 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
613 $blockOut .= $this->recentChangesBlockGroup( $block );
617 wfProfileOut( __METHOD__
);
619 return '<div>' . $blockOut . '</div>';
623 * Returns text for the end of RC
624 * If enhanced RC is in use, returns pretty much all the text
627 public function endRecentChangesList() {
628 return $this->recentChangesBlock() . '</div>';