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
{
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',
50 * Format a line for enhanced recentchange (aka with javascript and block of lines).
52 * @param $baseRC RecentChange
53 * @param $watched bool
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
) {
92 // New unpatrolled pages
93 } elseif ( $cacheEntry->unpatrolled
&& $type == RC_NEW
) {
94 $clink = Linker
::linkKnown( $cacheEntry->getTitle() );
96 } elseif ( $type == RC_LOG
) {
98 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
99 $logpage = new LogPage( $logType );
100 $logname = $logpage->getName()->escaped();
101 $clink = $this->msg( 'parentheses' )
102 ->rawParams( Linker
::linkKnown( $logtitle, $logname ) )->escaped();
104 $clink = Linker
::link( $cacheEntry->getTitle() );
107 // Log entries (old format) and special pages
108 } elseif ( $cacheEntry->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
109 wfDebug( "Unexpected special page in recentchanges\n" );
113 $clink = Linker
::linkKnown( $cacheEntry->getTitle() );
116 # Don't show unusable diff links
117 if ( !ChangesList
::userCan( $cacheEntry, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
118 $showdifflinks = false;
121 $time = $this->getLanguage()->userTime( $cacheEntry->mAttribs
['rc_timestamp'], $this->getUser() );
123 $cacheEntry->watched
= $watched;
124 $cacheEntry->link
= $clink;
125 $cacheEntry->timestamp
= $time;
126 $cacheEntry->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
128 # Make "cur" and "diff" links. Do not use link(), it is too slow if
129 # called too many times (50% of CPU time on RecentChanges!).
130 $thisOldid = $cacheEntry->mAttribs
['rc_this_oldid'];
131 $lastOldid = $cacheEntry->mAttribs
['rc_last_oldid'];
133 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
134 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
136 if ( !$showdifflinks ) {
137 $curLink = $this->message
['cur'];
138 $diffLink = $this->message
['diff'];
139 } elseif ( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
140 if ( $type != RC_NEW
) {
141 $curLink = $this->message
['cur'];
143 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
144 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
146 $diffLink = $this->message
['diff'];
148 $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querydiff ) );
149 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
150 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
151 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
155 if ( !$showdifflinks ||
!$lastOldid ) {
156 $lastLink = $this->message
['last'];
157 } elseif ( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
158 $lastLink = $this->message
['last'];
160 $lastLink = Linker
::linkKnown( $cacheEntry->getTitle(), $this->message
['last'],
161 array(), $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
165 if ( $this->isDeleted( $cacheEntry, Revision
::DELETED_USER
) ) {
166 $cacheEntry->userlink
= ' <span class="history-deleted">' .
167 $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
169 $cacheEntry->userlink
= Linker
::userLink(
170 $cacheEntry->mAttribs
['rc_user'],
171 $cacheEntry->mAttribs
['rc_user_text']
174 $cacheEntry->usertalklink
= Linker
::userToolLinks(
175 $cacheEntry->mAttribs
['rc_user'],
176 $cacheEntry->mAttribs
['rc_user_text']
180 $cacheEntry->lastlink
= $lastLink;
181 $cacheEntry->curlink
= $curLink;
182 $cacheEntry->difflink
= $diffLink;
184 # Put accumulated information into the cache, for later display
185 # Page moves go on their own line
186 $title = $cacheEntry->getTitle();
187 $secureName = $title->getPrefixedDBkey();
189 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
190 # Use an @ character to prevent collision with page names
191 $this->rc_cache
['@@' . ( $this->rcMoveIndex++
)] = array( $cacheEntry );
193 # Logs are grouped by type
194 if ( $type == RC_LOG
) {
195 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
197 if ( !isset( $this->rc_cache
[$secureName] ) ) {
198 $this->rc_cache
[$secureName] = array();
201 array_push( $this->rc_cache
[$secureName], $cacheEntry );
204 wfProfileOut( __METHOD__
);
213 protected function recentChangesBlockGroup( $block ) {
214 global $wgRCShowChangedSize;
216 wfProfileIn( __METHOD__
);
218 # Add the namespace and title of the block as part of the class
219 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
220 if ( $block[0]->mAttribs
['rc_log_type'] ) {
222 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
223 . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
225 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
226 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
228 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
229 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
230 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
231 Html
::openElement( 'tr' );
233 # Collate list of users
234 $userlinks = array();
236 $unpatrolled = false;
240 $curId = $currentRevision = 0;
241 # Some catalyst variables...
244 foreach ( $block as $rcObj ) {
245 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
246 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
249 // If all log actions to this page were hidden, then don't
250 // give the name of the affected page for this block!
251 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
254 $u = $rcObj->userlink
;
255 if ( !isset( $userlinks[$u] ) ) {
258 if ( $rcObj->unpatrolled
) {
261 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
264 # Get the latest entry with a page_id and oldid
265 # since logs may not have these.
266 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
267 $curId = $rcObj->mAttribs
['rc_cur_id'];
269 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
270 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
273 if ( !$rcObj->mAttribs
['rc_bot'] ) {
276 if ( !$rcObj->mAttribs
['rc_minor'] ) {
283 # Sort the list and convert to text
284 krsort( $userlinks );
287 foreach ( $userlinks as $userlink => $count ) {
289 $text .= $this->getLanguage()->getDirMark();
291 // @todo FIXME: Hardcoded '×'. Should be a message.
292 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
293 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
295 array_push( $users, $text );
298 $users = ' <span class="changedby">'
299 . $this->msg( 'brackets' )->rawParams(
300 implode( $this->message
['semicolon-separator'], $users )
301 )->escaped() . '</span>';
303 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
304 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
305 $r .= "<td>$tl</td>";
308 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
309 'newpage' => $isnew, # show, when one have this flag
310 'minor' => $allMinors, # show only, when all have this flag
311 'unpatrolled' => $unpatrolled, # show, when one have this flag
312 'bot' => $allBots, # show only, when all have this flag
316 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
320 $r .= ' <span class="history-deleted">' .
321 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
322 } elseif ( $allLogs ) {
323 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
325 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
328 $r .= $this->getLanguage()->getDirMark();
330 $queryParams['curid'] = $curId;
333 static $nchanges = array();
334 static $sinceLastVisitMsg = array();
336 $n = count( $block );
337 if ( !isset( $nchanges[$n] ) ) {
338 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
342 $unvisitedOldid = null;
343 foreach ( $block as $rcObj ) {
344 // Same logic as below inside main foreach
345 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
347 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
350 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
351 $sinceLastVisitMsg[$sinceLast] =
352 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
359 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
360 $logtext .= $nchanges[$n];
361 } elseif ( $isnew ) {
362 $logtext .= $nchanges[$n];
364 $logtext .= Linker
::link(
365 $block[0]->getTitle(),
368 $queryParams +
array(
369 'diff' => $currentRevision,
372 array( 'known', 'noclasses' )
374 if ( $sinceLast > 0 && $sinceLast < $n ) {
375 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
376 $block[0]->getTitle(),
377 $sinceLastVisitMsg[$sinceLast],
379 $queryParams +
array(
380 'diff' => $currentRevision,
381 'oldid' => $unvisitedOldid,
383 array( 'known', 'noclasses' )
391 // don't show history link for logs
392 } elseif ( $namehidden ||
!$block[0]->getTitle()->exists() ) {
393 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
395 $params = $queryParams;
396 $params['action'] = 'history';
398 $logtext .= $this->message
['pipe-separator'] .
400 $block[0]->getTitle(),
401 $this->message
['enhancedrc-history'],
407 if ( $logtext !== '' ) {
408 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
411 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
413 # Character difference (does not apply if only log items)
414 if ( $wgRCShowChangedSize && !$allLogs ) {
416 $first = count( $block ) - 1;
417 # Some events (like logs) have an "empty" size, so we need to skip those...
418 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
421 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
425 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
427 if ( $chardiff == '' ) {
430 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
435 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers
);
439 foreach ( $block as $rcObj ) {
440 # Classes to apply -- TODO implement
442 $type = $rcObj->mAttribs
['rc_type'];
444 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
445 ?
' class="mw-enhanced-watched"' : '';
447 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
448 $r .= $this->recentChangesFlags( array(
449 'newpage' => $type == RC_NEW
,
450 'minor' => $rcObj->mAttribs
['rc_minor'],
451 'unpatrolled' => $rcObj->unpatrolled
,
452 'bot' => $rcObj->mAttribs
['rc_bot'],
454 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
456 $params = $queryParams;
458 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
459 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
463 if ( $type == RC_LOG
) {
464 $link = $rcObj->timestamp
;
466 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
467 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
470 $link = Linker
::linkKnown(
476 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
477 $link = '<span class="history-deleted">' . $link . '</span> ';
480 $r .= $link . '</span>';
482 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
483 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
485 $this->message
['pipe-separator'] .
489 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
492 if ( $wgRCShowChangedSize ) {
493 $cd = $this->formatCharacterDifference( $rcObj );
495 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
499 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
500 $r .= $this->insertLogEntry( $rcObj );
503 $r .= $rcObj->userlink
;
504 $r .= $rcObj->usertalklink
;
505 $r .= $this->insertComment( $rcObj );
509 $this->insertRollback( $r, $rcObj );
511 $this->insertTags( $r, $rcObj, $classes );
513 $r .= "</td></tr>\n";
517 $this->rcCacheIndex++
;
519 wfProfileOut( __METHOD__
);
525 * Generate HTML for an arrow or placeholder graphic
526 * @param string $dir one of '', 'd', 'l', 'r'
527 * @param string $alt text
528 * @param string $title text
529 * @return String: HTML "<img>" tag
531 protected function arrow( $dir, $alt = '', $title = '' ) {
533 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
534 $encAlt = htmlspecialchars( $alt );
535 $encTitle = htmlspecialchars( $title );
537 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
541 * Generate HTML for a right- or left-facing arrow,
542 * depending on language direction.
543 * @return String: HTML "<img>" tag
545 protected function sideArrow() {
546 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
548 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
552 * Generate HTML for a down-facing arrow
553 * depending on language direction.
554 * @return String: HTML "<img>" tag
556 protected function downArrow() {
557 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
561 * Generate HTML for a spacer image
562 * @return String: HTML "<img>" tag
564 protected function spacerArrow() {
565 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
569 * Enhanced RC ungrouped line.
571 * @param $rcObj RecentChange
572 * @return String: a HTML formatted line (generated using $r)
574 protected function recentChangesBlockLine( $rcObj ) {
575 global $wgRCShowChangedSize;
577 wfProfileIn( __METHOD__
);
578 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
580 $type = $rcObj->mAttribs
['rc_type'];
581 $logType = $rcObj->mAttribs
['rc_log_type'];
582 $classes = array( 'mw-enhanced-rc' );
585 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
586 . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
588 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
589 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
591 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
592 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
593 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
594 Html
::openElement( 'tr' );
596 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
598 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
599 $r .= $this->recentChangesFlags( array() ); // no flags, but need the placeholders
601 $r .= $this->recentChangesFlags( array(
602 'newpage' => $type == RC_NEW
,
603 'minor' => $rcObj->mAttribs
['rc_minor'],
604 'unpatrolled' => $rcObj->unpatrolled
,
605 'bot' => $rcObj->mAttribs
['rc_bot'],
608 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
609 # Article or log link
611 $logPage = new LogPage( $logType );
612 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
613 $logName = $logPage->getName()->escaped();
614 $r .= $this->msg( 'parentheses' )
615 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
617 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
619 # Diff and hist links
620 if ( $type != RC_LOG
) {
621 $query['action'] = 'history';
622 $r .= ' ' . $this->msg( 'parentheses' )
623 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
625 $this->message
['hist'],
630 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
632 if ( $wgRCShowChangedSize ) {
633 $cd = $this->formatCharacterDifference( $rcObj );
635 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
639 if ( $type == RC_LOG
) {
640 $r .= $this->insertLogEntry( $rcObj );
642 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
643 $r .= $this->insertComment( $rcObj );
644 $this->insertRollback( $r, $rcObj );
648 $this->insertTags( $r, $rcObj, $classes );
649 # Show how many people are watching this if enabled
650 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
652 $r .= "</td></tr></table>\n";
654 wfProfileOut( __METHOD__
);
660 * If enhanced RC is in use, this function takes the previously cached
661 * RC lines, arranges them, and outputs the HTML
665 protected function recentChangesBlock() {
666 if ( count( $this->rc_cache
) == 0 ) {
670 wfProfileIn( __METHOD__
);
673 foreach ( $this->rc_cache
as $block ) {
674 if ( count( $block ) < 2 ) {
675 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
677 $blockOut .= $this->recentChangesBlockGroup( $block );
681 wfProfileOut( __METHOD__
);
683 return '<div>' . $blockOut . '</div>';
687 * Returns text for the end of RC
688 * If enhanced RC is in use, returns pretty much all the text
691 public function endRecentChangesList() {
692 return $this->recentChangesBlock() . parent
::endRecentChangesList();