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
{
24 /** @var array Array of array of RCCacheEntry */
28 * Add the JavaScript file for enhanced changeslist
31 public function beginRecentChangesList() {
32 $this->rc_cache
= array();
33 $this->rcMoveIndex
= 0;
34 $this->rcCacheIndex
= 0;
36 $this->rclistOpen
= false;
37 $this->getOutput()->addModuleStyles( array(
38 'mediawiki.special.changeslist',
39 'mediawiki.special.changeslist.enhanced',
41 $this->getOutput()->addModules( array(
42 'jquery.makeCollapsible',
46 return '<div class="mw-changeslist">';
50 * Format a line for enhanced recentchange (aka with javascript and block of lines).
52 * @param RecentChange $baseRC
53 * @param bool $watched
57 public function recentChangesLine( &$baseRC, $watched = false ) {
58 wfProfileIn( __METHOD__
);
60 # If it's a new day, add the headline and flush the cache
61 $date = $this->getLanguage()->userDate(
62 $baseRC->mAttribs
['rc_timestamp'],
68 if ( $date != $this->lastdate
) {
69 # Process current cache
70 $ret = $this->recentChangesBlock();
71 $this->rc_cache
= array();
72 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
73 $this->lastdate
= $date;
76 # Create a specialised object
77 $cacheEntry = RCCacheEntry
::newFromParent( $baseRC );
79 $curIdEq = array( 'curid' => $cacheEntry->mAttribs
['rc_cur_id'] );
81 # Should patrol-related stuff be shown?
82 $cacheEntry->unpatrolled
= $this->showAsUnpatrolled( $cacheEntry );
84 $showdifflinks = true;
87 $type = $cacheEntry->mAttribs
['rc_type'];
88 $logType = $cacheEntry->mAttribs
['rc_log_type'];
90 // Page moves, very old style, not supported anymore
91 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
93 // New unpatrolled pages
94 } elseif ( $cacheEntry->unpatrolled
&& $type == RC_NEW
) {
95 $clink = Linker
::linkKnown( $cacheEntry->getTitle() );
97 } elseif ( $type == RC_LOG
) {
99 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
100 $logpage = new LogPage( $logType );
101 $logname = $logpage->getName()->escaped();
102 $clink = $this->msg( 'parentheses' )
103 ->rawParams( Linker
::linkKnown( $logtitle, $logname ) )->escaped();
105 $clink = Linker
::link( $cacheEntry->getTitle() );
108 // Log entries (old format) and special pages
109 } elseif ( $cacheEntry->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
110 wfDebug( "Unexpected special page in recentchanges\n" );
114 $clink = Linker
::linkKnown( $cacheEntry->getTitle() );
117 # Don't show unusable diff links
118 if ( !ChangesList
::userCan( $cacheEntry, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
119 $showdifflinks = false;
122 $time = $this->getLanguage()->userTime( $cacheEntry->mAttribs
['rc_timestamp'], $this->getUser() );
124 $cacheEntry->watched
= $watched;
125 $cacheEntry->link
= $clink;
126 $cacheEntry->timestamp
= $time;
127 $cacheEntry->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
129 # Make "cur" and "diff" links. Do not use link(), it is too slow if
130 # called too many times (50% of CPU time on RecentChanges!).
131 $thisOldid = $cacheEntry->mAttribs
['rc_this_oldid'];
132 $lastOldid = $cacheEntry->mAttribs
['rc_last_oldid'];
134 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
135 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
137 if ( !$showdifflinks ) {
138 $curLink = $this->message
['cur'];
139 $diffLink = $this->message
['diff'];
140 } elseif ( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
141 if ( $type != RC_NEW
) {
142 $curLink = $this->message
['cur'];
144 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
145 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
147 $diffLink = $this->message
['diff'];
149 $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querydiff ) );
150 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
151 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
152 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
156 if ( !$showdifflinks ||
!$lastOldid ) {
157 $lastLink = $this->message
['last'];
158 } elseif ( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
159 $lastLink = $this->message
['last'];
161 $lastLink = Linker
::linkKnown( $cacheEntry->getTitle(), $this->message
['last'],
162 array(), $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
166 if ( $this->isDeleted( $cacheEntry, Revision
::DELETED_USER
) ) {
167 $cacheEntry->userlink
= ' <span class="history-deleted">' .
168 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
170 $cacheEntry->userlink
= Linker
::userLink(
171 $cacheEntry->mAttribs
['rc_user'],
172 $cacheEntry->mAttribs
['rc_user_text']
175 $cacheEntry->usertalklink
= Linker
::userToolLinks(
176 $cacheEntry->mAttribs
['rc_user'],
177 $cacheEntry->mAttribs
['rc_user_text']
181 $cacheEntry->lastlink
= $lastLink;
182 $cacheEntry->curlink
= $curLink;
183 $cacheEntry->difflink
= $diffLink;
185 # Put accumulated information into the cache, for later display
186 # Page moves go on their own line
187 $title = $cacheEntry->getTitle();
188 $secureName = $title->getPrefixedDBkey();
190 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
191 # Use an @ character to prevent collision with page names
192 $this->rc_cache
['@@' . ( $this->rcMoveIndex++
)] = array( $cacheEntry );
194 # Logs are grouped by type
195 if ( $type == RC_LOG
) {
196 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
198 if ( !isset( $this->rc_cache
[$secureName] ) ) {
199 $this->rc_cache
[$secureName] = array();
202 array_push( $this->rc_cache
[$secureName], $cacheEntry );
205 wfProfileOut( __METHOD__
);
212 * @param RCCacheEntry[] $block
215 protected function recentChangesBlockGroup( $block ) {
216 global $wgRCShowChangedSize;
218 wfProfileIn( __METHOD__
);
220 # Add the namespace and title of the block as part of the class
221 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
222 if ( $block[0]->mAttribs
['rc_log_type'] ) {
224 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
225 . $block[0]->mAttribs
['rc_log_type'] );
227 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
228 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
230 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
231 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
232 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
233 Html
::openElement( 'tr' );
235 # Collate list of users
236 $userlinks = array();
238 $unpatrolled = false;
242 $curId = $currentRevision = 0;
243 # Some catalyst variables...
247 foreach ( $block as $rcObj ) {
248 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
249 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
252 // If all log actions to this page were hidden, then don't
253 // give the name of the affected page for this block!
254 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
257 $u = $rcObj->userlink
;
258 if ( !isset( $userlinks[$u] ) ) {
261 if ( $rcObj->unpatrolled
) {
264 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
267 # Get the latest entry with a page_id and oldid
268 # since logs may not have these.
269 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
270 $curId = $rcObj->mAttribs
['rc_cur_id'];
272 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
273 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
276 if ( !$rcObj->mAttribs
['rc_bot'] ) {
279 if ( !$rcObj->mAttribs
['rc_minor'] ) {
286 # Sort the list and convert to text
287 krsort( $userlinks );
290 foreach ( $userlinks as $userlink => $count ) {
292 $text .= $this->getLanguage()->getDirMark();
294 // @todo FIXME: Hardcoded '×'. Should be a message.
295 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
296 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
298 array_push( $users, $text );
301 $users = ' <span class="changedby">'
302 . $this->msg( 'brackets' )->rawParams(
303 implode( $this->message
['semicolon-separator'], $users )
304 )->escaped() . '</span>';
306 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
307 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
308 $r .= "<td>$tl</td>";
311 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
312 'newpage' => $isnew, # show, when one have this flag
313 'minor' => $allMinors, # show only, when all have this flag
314 'unpatrolled' => $unpatrolled, # show, when one have this flag
315 'bot' => $allBots, # show only, when all have this flag
319 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
323 $r .= ' <span class="history-deleted">' .
324 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
325 } elseif ( $allLogs ) {
326 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
328 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
331 $r .= $this->getLanguage()->getDirMark();
333 $queryParams['curid'] = $curId;
336 static $nchanges = array();
337 static $sinceLastVisitMsg = array();
339 $n = count( $block );
340 if ( !isset( $nchanges[$n] ) ) {
341 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
345 $unvisitedOldid = null;
346 /** @var $rcObj RCCacheEntry */
347 foreach ( $block as $rcObj ) {
348 // Same logic as below inside main foreach
349 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
351 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
354 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
355 $sinceLastVisitMsg[$sinceLast] =
356 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
362 /** @var $block0 RecentChange */
365 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
366 $logtext .= $nchanges[$n];
367 } elseif ( $isnew ) {
368 $logtext .= $nchanges[$n];
370 $logtext .= Linker
::link(
374 $queryParams +
array(
375 'diff' => $currentRevision,
378 array( 'known', 'noclasses' )
380 if ( $sinceLast > 0 && $sinceLast < $n ) {
381 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
383 $sinceLastVisitMsg[$sinceLast],
385 $queryParams +
array(
386 'diff' => $currentRevision,
387 'oldid' => $unvisitedOldid,
389 array( 'known', 'noclasses' )
397 // don't show history link for logs
398 } elseif ( $namehidden ||
!$block0->getTitle()->exists() ) {
399 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
401 $params = $queryParams;
402 $params['action'] = 'history';
404 $logtext .= $this->message
['pipe-separator'] .
407 $this->message
['enhancedrc-history'],
413 if ( $logtext !== '' ) {
414 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
417 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
419 # Character difference (does not apply if only log items)
420 if ( $wgRCShowChangedSize && !$allLogs ) {
422 $first = count( $block ) - 1;
423 # Some events (like logs) have an "empty" size, so we need to skip those...
424 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
427 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
431 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
433 if ( $chardiff == '' ) {
436 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
441 $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers
);
445 foreach ( $block as $rcObj ) {
446 # Classes to apply -- TODO implement
448 $type = $rcObj->mAttribs
['rc_type'];
450 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
451 ?
' class="mw-enhanced-watched"' : '';
453 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
454 $r .= $this->recentChangesFlags( array(
455 'newpage' => $type == RC_NEW
,
456 'minor' => $rcObj->mAttribs
['rc_minor'],
457 'unpatrolled' => $rcObj->unpatrolled
,
458 'bot' => $rcObj->mAttribs
['rc_bot'],
460 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
462 $params = $queryParams;
464 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
465 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
469 if ( $type == RC_LOG
) {
470 $link = $rcObj->timestamp
;
472 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
473 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
476 $link = Linker
::linkKnown(
482 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
483 $link = '<span class="history-deleted">' . $link . '</span> ';
486 $r .= $link . '</span>';
488 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
489 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
491 $this->message
['pipe-separator'] .
495 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
498 if ( $wgRCShowChangedSize ) {
499 $cd = $this->formatCharacterDifference( $rcObj );
501 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
505 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
506 $r .= $this->insertLogEntry( $rcObj );
509 $r .= $rcObj->userlink
;
510 $r .= $rcObj->usertalklink
;
511 $r .= $this->insertComment( $rcObj );
515 $this->insertRollback( $r, $rcObj );
517 $this->insertTags( $r, $rcObj, $classes );
519 $r .= "</td></tr>\n";
523 $this->rcCacheIndex++
;
525 wfProfileOut( __METHOD__
);
531 * Generate HTML for an arrow or placeholder graphic
532 * @param string $dir One of '', 'd', 'l', 'r'
534 * @param string $title
535 * @return string HTML "<img>" tag
537 protected function arrow( $dir, $alt = '', $title = '' ) {
539 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
540 $encAlt = htmlspecialchars( $alt );
541 $encTitle = htmlspecialchars( $title );
543 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
547 * Generate HTML for a right- or left-facing arrow,
548 * depending on language direction.
549 * @return string HTML "<img>" tag
551 protected function sideArrow() {
552 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
554 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
558 * Generate HTML for a down-facing arrow
559 * depending on language direction.
560 * @return string HTML "<img>" tag
562 protected function downArrow() {
563 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
567 * Generate HTML for a spacer image
568 * @return string HTML "<img>" tag
570 protected function spacerArrow() {
571 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
575 * Enhanced RC ungrouped line.
577 * @param RecentChange|RCCacheEntry $rcObj
578 * @return string A HTML formatted line (generated using $r)
580 protected function recentChangesBlockLine( $rcObj ) {
581 global $wgRCShowChangedSize;
583 wfProfileIn( __METHOD__
);
584 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
586 $type = $rcObj->mAttribs
['rc_type'];
587 $logType = $rcObj->mAttribs
['rc_log_type'];
588 $classes = array( 'mw-enhanced-rc' );
591 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType );
593 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
594 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
596 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
597 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
598 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
599 Html
::openElement( 'tr' );
601 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
603 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
604 $r .= $this->recentChangesFlags( array() ); // no flags, but need the placeholders
606 $r .= $this->recentChangesFlags( array(
607 'newpage' => $type == RC_NEW
,
608 'minor' => $rcObj->mAttribs
['rc_minor'],
609 'unpatrolled' => $rcObj->unpatrolled
,
610 'bot' => $rcObj->mAttribs
['rc_bot'],
613 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
614 # Article or log link
616 $logPage = new LogPage( $logType );
617 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
618 $logName = $logPage->getName()->escaped();
619 $r .= $this->msg( 'parentheses' )
620 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
622 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
624 # Diff and hist links
625 if ( $type != RC_LOG
) {
626 $query['action'] = 'history';
627 $r .= ' ' . $this->msg( 'parentheses' )
628 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
630 $this->message
['hist'],
635 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
637 if ( $wgRCShowChangedSize ) {
638 $cd = $this->formatCharacterDifference( $rcObj );
640 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
644 if ( $type == RC_LOG
) {
645 $r .= $this->insertLogEntry( $rcObj );
647 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
648 $r .= $this->insertComment( $rcObj );
649 $this->insertRollback( $r, $rcObj );
653 $this->insertTags( $r, $rcObj, $classes );
654 # Show how many people are watching this if enabled
655 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
657 $r .= "</td></tr></table>\n";
659 wfProfileOut( __METHOD__
);
665 * If enhanced RC is in use, this function takes the previously cached
666 * RC lines, arranges them, and outputs the HTML
670 protected function recentChangesBlock() {
671 if ( count( $this->rc_cache
) == 0 ) {
675 wfProfileIn( __METHOD__
);
678 foreach ( $this->rc_cache
as $block ) {
679 if ( count( $block ) < 2 ) {
680 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
682 $blockOut .= $this->recentChangesBlockGroup( $block );
686 wfProfileOut( __METHOD__
);
688 return '<div>' . $blockOut . '</div>';
692 * Returns text for the end of RC
693 * If enhanced RC is in use, returns pretty much all the text
696 public function endRecentChangesList() {
697 return $this->recentChangesBlock() . '</div>';