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',
44 'mediawiki.special.changeslist.js',
47 return '<div class="mw-changeslist">';
51 * Format a line for enhanced recentchange (aka with javascript and block of lines).
53 * @param RecentChange $baseRC
54 * @param bool $watched
58 public function recentChangesLine( &$baseRC, $watched = false ) {
59 wfProfileIn( __METHOD__
);
61 # If it's a new day, add the headline and flush the cache
62 $date = $this->getLanguage()->userDate(
63 $baseRC->mAttribs
['rc_timestamp'],
69 if ( $date != $this->lastdate
) {
70 # Process current cache
71 $ret = $this->recentChangesBlock();
72 $this->rc_cache
= array();
73 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
74 $this->lastdate
= $date;
77 # Create a specialised object
78 $cacheEntry = RCCacheEntry
::newFromParent( $baseRC );
80 $curIdEq = array( 'curid' => $cacheEntry->mAttribs
['rc_cur_id'] );
82 # Should patrol-related stuff be shown?
83 $cacheEntry->unpatrolled
= $this->showAsUnpatrolled( $cacheEntry );
85 $showdifflinks = true;
88 $type = $cacheEntry->mAttribs
['rc_type'];
89 $logType = $cacheEntry->mAttribs
['rc_log_type'];
91 // Page moves, very old style, not supported anymore
92 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
94 // New unpatrolled pages
95 } elseif ( $cacheEntry->unpatrolled
&& $type == RC_NEW
) {
96 $clink = Linker
::linkKnown( $cacheEntry->getTitle() );
98 } elseif ( $type == RC_LOG
) {
100 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
101 $logpage = new LogPage( $logType );
102 $logname = $logpage->getName()->escaped();
103 $clink = $this->msg( 'parentheses' )
104 ->rawParams( Linker
::linkKnown( $logtitle, $logname ) )->escaped();
106 $clink = Linker
::link( $cacheEntry->getTitle() );
109 // Log entries (old format) and special pages
110 } elseif ( $cacheEntry->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
111 wfDebug( "Unexpected special page in recentchanges\n" );
115 $clink = Linker
::linkKnown( $cacheEntry->getTitle() );
118 # Don't show unusable diff links
119 if ( !ChangesList
::userCan( $cacheEntry, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
120 $showdifflinks = false;
123 $time = $this->getLanguage()->userTime( $cacheEntry->mAttribs
['rc_timestamp'], $this->getUser() );
125 $cacheEntry->watched
= $watched;
126 $cacheEntry->link
= $clink;
127 $cacheEntry->timestamp
= $time;
128 $cacheEntry->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
130 # Make "cur" and "diff" links. Do not use link(), it is too slow if
131 # called too many times (50% of CPU time on RecentChanges!).
132 $thisOldid = $cacheEntry->mAttribs
['rc_this_oldid'];
133 $lastOldid = $cacheEntry->mAttribs
['rc_last_oldid'];
135 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
136 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
138 if ( !$showdifflinks ) {
139 $curLink = $this->message
['cur'];
140 $diffLink = $this->message
['diff'];
141 } elseif ( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
142 if ( $type != RC_NEW
) {
143 $curLink = $this->message
['cur'];
145 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
146 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
148 $diffLink = $this->message
['diff'];
150 $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querydiff ) );
151 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
152 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
153 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
157 if ( !$showdifflinks ||
!$lastOldid ) {
158 $lastLink = $this->message
['last'];
159 } elseif ( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
160 $lastLink = $this->message
['last'];
162 $lastLink = Linker
::linkKnown( $cacheEntry->getTitle(), $this->message
['last'],
163 array(), $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
167 if ( $this->isDeleted( $cacheEntry, Revision
::DELETED_USER
) ) {
168 $cacheEntry->userlink
= ' <span class="history-deleted">' .
169 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
171 $cacheEntry->userlink
= Linker
::userLink(
172 $cacheEntry->mAttribs
['rc_user'],
173 $cacheEntry->mAttribs
['rc_user_text']
176 $cacheEntry->usertalklink
= Linker
::userToolLinks(
177 $cacheEntry->mAttribs
['rc_user'],
178 $cacheEntry->mAttribs
['rc_user_text']
182 $cacheEntry->lastlink
= $lastLink;
183 $cacheEntry->curlink
= $curLink;
184 $cacheEntry->difflink
= $diffLink;
186 # Put accumulated information into the cache, for later display
187 # Page moves go on their own line
188 $title = $cacheEntry->getTitle();
189 $secureName = $title->getPrefixedDBkey();
191 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
192 # Use an @ character to prevent collision with page names
193 $this->rc_cache
['@@' . ( $this->rcMoveIndex++
)] = array( $cacheEntry );
195 # Logs are grouped by type
196 if ( $type == RC_LOG
) {
197 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
199 if ( !isset( $this->rc_cache
[$secureName] ) ) {
200 $this->rc_cache
[$secureName] = array();
203 array_push( $this->rc_cache
[$secureName], $cacheEntry );
206 wfProfileOut( __METHOD__
);
213 * @param RCCacheEntry[] $block
216 protected function recentChangesBlockGroup( $block ) {
217 global $wgRCShowChangedSize;
219 wfProfileIn( __METHOD__
);
221 # Add the namespace and title of the block as part of the class
222 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
223 if ( $block[0]->mAttribs
['rc_log_type'] ) {
225 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
226 . $block[0]->mAttribs
['rc_log_type'] );
228 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
229 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
231 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
232 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
233 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
234 Html
::openElement( 'tr' );
236 # Collate list of users
237 $userlinks = array();
239 $unpatrolled = false;
243 $curId = $currentRevision = 0;
244 # Some catalyst variables...
248 foreach ( $block as $rcObj ) {
249 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
250 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
253 // If all log actions to this page were hidden, then don't
254 // give the name of the affected page for this block!
255 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
258 $u = $rcObj->userlink
;
259 if ( !isset( $userlinks[$u] ) ) {
262 if ( $rcObj->unpatrolled
) {
265 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
268 # Get the latest entry with a page_id and oldid
269 # since logs may not have these.
270 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
271 $curId = $rcObj->mAttribs
['rc_cur_id'];
273 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
274 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
277 if ( !$rcObj->mAttribs
['rc_bot'] ) {
280 if ( !$rcObj->mAttribs
['rc_minor'] ) {
287 # Sort the list and convert to text
288 krsort( $userlinks );
291 foreach ( $userlinks as $userlink => $count ) {
293 $text .= $this->getLanguage()->getDirMark();
295 // @todo FIXME: Hardcoded '×'. Should be a message.
296 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
297 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
299 array_push( $users, $text );
302 $users = ' <span class="changedby">'
303 . $this->msg( 'brackets' )->rawParams(
304 implode( $this->message
['semicolon-separator'], $users )
305 )->escaped() . '</span>';
307 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
308 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
309 $r .= "<td>$tl</td>";
312 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
313 'newpage' => $isnew, # show, when one have this flag
314 'minor' => $allMinors, # show only, when all have this flag
315 'unpatrolled' => $unpatrolled, # show, when one have this flag
316 'bot' => $allBots, # show only, when all have this flag
320 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
324 $r .= ' <span class="history-deleted">' .
325 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
326 } elseif ( $allLogs ) {
327 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
329 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
332 $r .= $this->getLanguage()->getDirMark();
334 $queryParams['curid'] = $curId;
337 static $nchanges = array();
338 static $sinceLastVisitMsg = array();
340 $n = count( $block );
341 if ( !isset( $nchanges[$n] ) ) {
342 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
346 $unvisitedOldid = null;
347 /** @var $rcObj RCCacheEntry */
348 foreach ( $block as $rcObj ) {
349 // Same logic as below inside main foreach
350 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
352 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
355 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
356 $sinceLastVisitMsg[$sinceLast] =
357 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
363 /** @var $block0 RecentChange */
366 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
367 $logtext .= $nchanges[$n];
368 } elseif ( $isnew ) {
369 $logtext .= $nchanges[$n];
371 $logtext .= Linker
::link(
375 $queryParams +
array(
376 'diff' => $currentRevision,
379 array( 'known', 'noclasses' )
381 if ( $sinceLast > 0 && $sinceLast < $n ) {
382 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
384 $sinceLastVisitMsg[$sinceLast],
386 $queryParams +
array(
387 'diff' => $currentRevision,
388 'oldid' => $unvisitedOldid,
390 array( 'known', 'noclasses' )
398 // don't show history link for logs
399 } elseif ( $namehidden ||
!$block0->getTitle()->exists() ) {
400 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
402 $params = $queryParams;
403 $params['action'] = 'history';
405 $logtext .= $this->message
['pipe-separator'] .
408 $this->message
['enhancedrc-history'],
414 if ( $logtext !== '' ) {
415 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
418 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
420 # Character difference (does not apply if only log items)
421 if ( $wgRCShowChangedSize && !$allLogs ) {
423 $first = count( $block ) - 1;
424 # Some events (like logs) have an "empty" size, so we need to skip those...
425 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
428 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
432 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
434 if ( $chardiff == '' ) {
437 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
442 $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers
);
446 foreach ( $block as $rcObj ) {
447 # Classes to apply -- TODO implement
449 $type = $rcObj->mAttribs
['rc_type'];
451 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
452 ?
' class="mw-enhanced-watched"' : '';
454 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
455 $r .= $this->recentChangesFlags( array(
456 'newpage' => $type == RC_NEW
,
457 'minor' => $rcObj->mAttribs
['rc_minor'],
458 'unpatrolled' => $rcObj->unpatrolled
,
459 'bot' => $rcObj->mAttribs
['rc_bot'],
461 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
463 $params = $queryParams;
465 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
466 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
470 if ( $type == RC_LOG
) {
471 $link = $rcObj->timestamp
;
473 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
474 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
477 $link = Linker
::linkKnown(
483 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
484 $link = '<span class="history-deleted">' . $link . '</span> ';
487 $r .= $link . '</span>';
489 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
490 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
492 $this->message
['pipe-separator'] .
496 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
499 if ( $wgRCShowChangedSize ) {
500 $cd = $this->formatCharacterDifference( $rcObj );
502 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
506 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
507 $r .= $this->insertLogEntry( $rcObj );
510 $r .= $rcObj->userlink
;
511 $r .= $rcObj->usertalklink
;
512 $r .= $this->insertComment( $rcObj );
516 $this->insertRollback( $r, $rcObj );
518 $this->insertTags( $r, $rcObj, $classes );
520 $r .= "</td></tr>\n";
524 $this->rcCacheIndex++
;
526 wfProfileOut( __METHOD__
);
532 * Generate HTML for an arrow or placeholder graphic
533 * @param string $dir One of '', 'd', 'l', 'r'
535 * @param string $title
536 * @return string HTML "<img>" tag
538 protected function arrow( $dir, $alt = '', $title = '' ) {
540 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
541 $encAlt = htmlspecialchars( $alt );
542 $encTitle = htmlspecialchars( $title );
544 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
548 * Generate HTML for a right- or left-facing arrow,
549 * depending on language direction.
550 * @return string HTML "<img>" tag
552 protected function sideArrow() {
553 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
555 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
559 * Generate HTML for a down-facing arrow
560 * depending on language direction.
561 * @return string HTML "<img>" tag
563 protected function downArrow() {
564 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
568 * Generate HTML for a spacer image
569 * @return string HTML "<img>" tag
571 protected function spacerArrow() {
572 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
576 * Enhanced RC ungrouped line.
578 * @param RecentChange|RCCacheEntry $rcObj
579 * @return string A HTML formatted line (generated using $r)
581 protected function recentChangesBlockLine( $rcObj ) {
582 global $wgRCShowChangedSize;
584 wfProfileIn( __METHOD__
);
585 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
587 $type = $rcObj->mAttribs
['rc_type'];
588 $logType = $rcObj->mAttribs
['rc_log_type'];
589 $classes = array( 'mw-enhanced-rc' );
592 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType );
594 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
595 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
597 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
598 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
599 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
600 Html
::openElement( 'tr' );
602 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
604 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
605 $r .= $this->recentChangesFlags( array() ); // no flags, but need the placeholders
607 $r .= $this->recentChangesFlags( array(
608 'newpage' => $type == RC_NEW
,
609 'minor' => $rcObj->mAttribs
['rc_minor'],
610 'unpatrolled' => $rcObj->unpatrolled
,
611 'bot' => $rcObj->mAttribs
['rc_bot'],
614 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
615 # Article or log link
617 $logPage = new LogPage( $logType );
618 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
619 $logName = $logPage->getName()->escaped();
620 $r .= $this->msg( 'parentheses' )
621 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
623 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
625 # Diff and hist links
626 if ( $type != RC_LOG
) {
627 $query['action'] = 'history';
628 $r .= ' ' . $this->msg( 'parentheses' )
629 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
631 $this->message
['hist'],
636 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
638 if ( $wgRCShowChangedSize ) {
639 $cd = $this->formatCharacterDifference( $rcObj );
641 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
645 if ( $type == RC_LOG
) {
646 $r .= $this->insertLogEntry( $rcObj );
648 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
649 $r .= $this->insertComment( $rcObj );
650 $this->insertRollback( $r, $rcObj );
654 $this->insertTags( $r, $rcObj, $classes );
655 # Show how many people are watching this if enabled
656 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
658 $r .= "</td></tr></table>\n";
660 wfProfileOut( __METHOD__
);
666 * If enhanced RC is in use, this function takes the previously cached
667 * RC lines, arranges them, and outputs the HTML
671 protected function recentChangesBlock() {
672 if ( count( $this->rc_cache
) == 0 ) {
676 wfProfileIn( __METHOD__
);
679 foreach ( $this->rc_cache
as $block ) {
680 if ( count( $block ) < 2 ) {
681 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
683 $blockOut .= $this->recentChangesBlockGroup( $block );
687 wfProfileOut( __METHOD__
);
689 return '<div>' . $blockOut . '</div>';
693 * Returns text for the end of RC
694 * If enhanced RC is in use, returns pretty much all the text
697 public function endRecentChangesList() {
698 return $this->recentChangesBlock() . '</div>';