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',
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 $baseRC RecentChange
54 * @param $watched bool
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
) {
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__
);
214 protected function recentChangesBlockGroup( $block ) {
215 global $wgRCShowChangedSize;
217 wfProfileIn( __METHOD__
);
219 # Add the namespace and title of the block as part of the class
220 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
221 if ( $block[0]->mAttribs
['rc_log_type'] ) {
223 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
224 . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
226 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
227 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
229 $classes[] = $block[0]->watched
&& $block[0]->mAttribs
['rc_timestamp'] >= $block[0]->watched
230 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
231 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
232 Html
::openElement( 'tr' );
234 # Collate list of users
235 $userlinks = array();
237 $unpatrolled = false;
241 $curId = $currentRevision = 0;
242 # Some catalyst variables...
245 foreach ( $block as $rcObj ) {
246 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
247 if ( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
250 // If all log actions to this page were hidden, then don't
251 // give the name of the affected page for this block!
252 if ( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
255 $u = $rcObj->userlink
;
256 if ( !isset( $userlinks[$u] ) ) {
259 if ( $rcObj->unpatrolled
) {
262 if ( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
265 # Get the latest entry with a page_id and oldid
266 # since logs may not have these.
267 if ( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
268 $curId = $rcObj->mAttribs
['rc_cur_id'];
270 if ( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
271 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
274 if ( !$rcObj->mAttribs
['rc_bot'] ) {
277 if ( !$rcObj->mAttribs
['rc_minor'] ) {
284 # Sort the list and convert to text
285 krsort( $userlinks );
288 foreach ( $userlinks as $userlink => $count ) {
290 $text .= $this->getLanguage()->getDirMark();
292 // @todo FIXME: Hardcoded '×'. Should be a message.
293 $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
294 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
296 array_push( $users, $text );
299 $users = ' <span class="changedby">'
300 . $this->msg( 'brackets' )->rawParams(
301 implode( $this->message
['semicolon-separator'], $users )
302 )->escaped() . '</span>';
304 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
305 'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
306 $r .= "<td>$tl</td>";
309 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
310 'newpage' => $isnew, # show, when one have this flag
311 'minor' => $allMinors, # show only, when all have this flag
312 'unpatrolled' => $unpatrolled, # show, when one have this flag
313 'bot' => $allBots, # show only, when all have this flag
317 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
321 $r .= ' <span class="history-deleted">' .
322 $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
323 } elseif ( $allLogs ) {
324 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
326 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
329 $r .= $this->getLanguage()->getDirMark();
331 $queryParams['curid'] = $curId;
334 static $nchanges = array();
335 static $sinceLastVisitMsg = array();
337 $n = count( $block );
338 if ( !isset( $nchanges[$n] ) ) {
339 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
343 $unvisitedOldid = null;
344 foreach ( $block as $rcObj ) {
345 // Same logic as below inside main foreach
346 if ( $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
) {
348 $unvisitedOldid = $rcObj->mAttribs
['rc_last_oldid'];
351 if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) {
352 $sinceLastVisitMsg[$sinceLast] =
353 $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped();
360 if ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
361 $logtext .= $nchanges[$n];
362 } elseif ( $isnew ) {
363 $logtext .= $nchanges[$n];
365 $logtext .= Linker
::link(
366 $block[0]->getTitle(),
369 $queryParams +
array(
370 'diff' => $currentRevision,
373 array( 'known', 'noclasses' )
375 if ( $sinceLast > 0 && $sinceLast < $n ) {
376 $logtext .= $this->message
['pipe-separator'] . Linker
::link(
377 $block[0]->getTitle(),
378 $sinceLastVisitMsg[$sinceLast],
380 $queryParams +
array(
381 'diff' => $currentRevision,
382 'oldid' => $unvisitedOldid,
384 array( 'known', 'noclasses' )
392 // don't show history link for logs
393 } elseif ( $namehidden ||
!$block[0]->getTitle()->exists() ) {
394 $logtext .= $this->message
['pipe-separator'] . $this->message
['enhancedrc-history'];
396 $params = $queryParams;
397 $params['action'] = 'history';
399 $logtext .= $this->message
['pipe-separator'] .
401 $block[0]->getTitle(),
402 $this->message
['enhancedrc-history'],
408 if ( $logtext !== '' ) {
409 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
412 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
414 # Character difference (does not apply if only log items)
415 if ( $wgRCShowChangedSize && !$allLogs ) {
417 $first = count( $block ) - 1;
418 # Some events (like logs) have an "empty" size, so we need to skip those...
419 while ( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
422 while ( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
426 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
428 if ( $chardiff == '' ) {
431 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
436 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers
);
440 foreach ( $block as $rcObj ) {
441 # Classes to apply -- TODO implement
443 $type = $rcObj->mAttribs
['rc_type'];
445 $trClass = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
446 ?
' class="mw-enhanced-watched"' : '';
448 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
449 $r .= $this->recentChangesFlags( array(
450 'newpage' => $type == RC_NEW
,
451 'minor' => $rcObj->mAttribs
['rc_minor'],
452 'unpatrolled' => $rcObj->unpatrolled
,
453 'bot' => $rcObj->mAttribs
['rc_bot'],
455 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
457 $params = $queryParams;
459 if ( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
460 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
464 if ( $type == RC_LOG
) {
465 $link = $rcObj->timestamp
;
467 } elseif ( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
468 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
471 $link = Linker
::linkKnown(
477 if ( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
478 $link = '<span class="history-deleted">' . $link . '</span> ';
481 $r .= $link . '</span>';
483 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
484 $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
486 $this->message
['pipe-separator'] .
490 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
493 if ( $wgRCShowChangedSize ) {
494 $cd = $this->formatCharacterDifference( $rcObj );
496 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
500 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
501 $r .= $this->insertLogEntry( $rcObj );
504 $r .= $rcObj->userlink
;
505 $r .= $rcObj->usertalklink
;
506 $r .= $this->insertComment( $rcObj );
510 $this->insertRollback( $r, $rcObj );
512 $this->insertTags( $r, $rcObj, $classes );
514 $r .= "</td></tr>\n";
518 $this->rcCacheIndex++
;
520 wfProfileOut( __METHOD__
);
526 * Generate HTML for an arrow or placeholder graphic
527 * @param string $dir one of '', 'd', 'l', 'r'
528 * @param string $alt text
529 * @param string $title text
530 * @return String: HTML "<img>" tag
532 protected function arrow( $dir, $alt = '', $title = '' ) {
534 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
535 $encAlt = htmlspecialchars( $alt );
536 $encTitle = htmlspecialchars( $title );
538 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
542 * Generate HTML for a right- or left-facing arrow,
543 * depending on language direction.
544 * @return String: HTML "<img>" tag
546 protected function sideArrow() {
547 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
549 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
553 * Generate HTML for a down-facing arrow
554 * depending on language direction.
555 * @return String: HTML "<img>" tag
557 protected function downArrow() {
558 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
562 * Generate HTML for a spacer image
563 * @return String: HTML "<img>" tag
565 protected function spacerArrow() {
566 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
570 * Enhanced RC ungrouped line.
572 * @param $rcObj RecentChange
573 * @return String: a HTML formatted line (generated using $r)
575 protected function recentChangesBlockLine( $rcObj ) {
576 global $wgRCShowChangedSize;
578 wfProfileIn( __METHOD__
);
579 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
581 $type = $rcObj->mAttribs
['rc_type'];
582 $logType = $rcObj->mAttribs
['rc_log_type'];
583 $classes = array( 'mw-enhanced-rc' );
586 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
587 . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
589 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
590 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
592 $classes[] = $rcObj->watched
&& $rcObj->mAttribs
['rc_timestamp'] >= $rcObj->watched
593 ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
594 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
595 Html
::openElement( 'tr' );
597 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
599 if ( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
600 $r .= $this->recentChangesFlags( array() ); // no flags, but need the placeholders
602 $r .= $this->recentChangesFlags( array(
603 'newpage' => $type == RC_NEW
,
604 'minor' => $rcObj->mAttribs
['rc_minor'],
605 'unpatrolled' => $rcObj->unpatrolled
,
606 'bot' => $rcObj->mAttribs
['rc_bot'],
609 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
610 # Article or log link
612 $logPage = new LogPage( $logType );
613 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
614 $logName = $logPage->getName()->escaped();
615 $r .= $this->msg( 'parentheses' )
616 ->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
618 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
620 # Diff and hist links
621 if ( $type != RC_LOG
) {
622 $query['action'] = 'history';
623 $r .= ' ' . $this->msg( 'parentheses' )
624 ->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
626 $this->message
['hist'],
631 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
633 if ( $wgRCShowChangedSize ) {
634 $cd = $this->formatCharacterDifference( $rcObj );
636 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
640 if ( $type == RC_LOG
) {
641 $r .= $this->insertLogEntry( $rcObj );
643 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
644 $r .= $this->insertComment( $rcObj );
645 $this->insertRollback( $r, $rcObj );
649 $this->insertTags( $r, $rcObj, $classes );
650 # Show how many people are watching this if enabled
651 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
653 $r .= "</td></tr></table>\n";
655 wfProfileOut( __METHOD__
);
661 * If enhanced RC is in use, this function takes the previously cached
662 * RC lines, arranges them, and outputs the HTML
666 protected function recentChangesBlock() {
667 if ( count( $this->rc_cache
) == 0 ) {
671 wfProfileIn( __METHOD__
);
674 foreach ( $this->rc_cache
as $block ) {
675 if ( count( $block ) < 2 ) {
676 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
678 $blockOut .= $this->recentChangesBlockGroup( $block );
682 wfProfileOut( __METHOD__
);
684 return '<div>' . $blockOut . '</div>';
688 * Returns text for the end of RC
689 * If enhanced RC is in use, returns pretty much all the text
692 public function endRecentChangesList() {
693 return $this->recentChangesBlock() . '</div>';