3 * Classes to show various lists of changes:
14 class RCCacheEntry
extends RecentChange
{
15 var $secureName, $link;
16 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
17 var $userlink, $timestamp, $watched;
20 * @param $rc RecentChange
21 * @return RCCacheEntry
23 static function newFromParent( $rc ) {
24 $rc2 = new RCCacheEntry
;
25 $rc2->mAttribs
= $rc->mAttribs
;
26 $rc2->mExtra
= $rc->mExtra
;
32 * Base class for all changes lists
34 class ChangesList
extends ContextSource
{
41 protected $watchlist = false;
46 * Changeslist contructor
48 * @param $obj Skin or IContextSource
50 public function __construct( $obj ) {
51 if ( $obj instanceof IContextSource
) {
52 $this->setContext( $obj );
53 $this->skin
= $obj->getSkin();
55 $this->setContext( $obj->getContext() );
58 $this->preCacheMessages();
62 * Fetch an appropriate changes list class for the main context
63 * This first argument used to be an User object.
65 * @deprecated in 1.18; use newFromContext() instead
66 * @param $unused Unused
67 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
69 public static function newFromUser( $unused ) {
70 wfDeprecated( __METHOD__
, '1.18' );
71 return self
::newFromContext( RequestContext
::getMain() );
75 * Fetch an appropriate changes list class for the specified context
76 * Some users might want to use an enhanced list format, for instance
78 * @param $context IContextSource to use
79 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
81 public static function newFromContext( IContextSource
$context ) {
82 $user = $context->getUser();
83 $sk = $context->getSkin();
85 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
86 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
87 return $new ?
new EnhancedChangesList( $context ) : new OldChangesList( $context );
94 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
95 * @param $value Boolean
97 public function setWatchlistDivs( $value = true ) {
98 $this->watchlist
= $value;
102 * As we use the same small set of messages in various methods and that
103 * they are called often, we call them once and save them in $this->message
105 private function preCacheMessages() {
106 if( !isset( $this->message
) ) {
107 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
108 'semicolon-separator pipe-separator' ) as $msg ) {
109 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
115 * Returns the appropriate flags for new page, minor change and patrolling
116 * @param $flags Array Associative array of 'flag' => Bool
117 * @param $nothing String to use for empty space
120 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
122 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
123 $f .= isset( $flags[$flag] ) && $flags[$flag]
124 ? self
::flag( $flag )
131 * Provide the <abbr> element appropriate to a given abbreviated flag,
132 * namely the flag indicating a new page, a minor edit, a bot edit, or an
133 * unpatrolled edit. By default in English it will contain "N", "m", "b",
134 * "!" respectively, plus it will have an appropriate title and class.
136 * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot'
137 * @return String: Raw HTML
139 public static function flag( $flag ) {
140 static $messages = null;
141 if ( is_null( $messages ) ) {
143 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
144 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
145 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
146 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
148 foreach( $messages as &$value ) {
149 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
150 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
154 # Inconsistent naming, bleh
156 'newpage' => 'newpage',
157 'minor' => 'minoredit',
159 'unpatrolled' => 'unpatrolled',
160 'minoredit' => 'minoredit',
161 'botedit' => 'botedit',
165 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
169 * Returns text for the start of the tabular part of RC
172 public function beginRecentChangesList() {
173 $this->rc_cache
= array();
174 $this->rcMoveIndex
= 0;
175 $this->rcCacheIndex
= 0;
176 $this->lastdate
= '';
177 $this->rclistOpen
= false;
182 * Show formatted char difference
183 * @param $old Integer: bytes
184 * @param $new Integer: bytes
187 public static function showCharacterDifference( $old, $new ) {
188 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
189 $szdiff = $new - $old;
191 $code = $wgLang->getCode();
192 static $fastCharDiff = array();
193 if ( !isset($fastCharDiff[$code]) ) {
194 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
197 $formattedSize = $wgLang->formatNum($szdiff);
199 if ( !$fastCharDiff[$code] ) {
200 $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize );
203 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
209 if ( $szdiff === 0 ) {
210 $formattedSizeClass = 'mw-plusminus-null';
213 $formattedSize = '+' . $formattedSize;
214 $formattedSizeClass = 'mw-plusminus-pos';
217 $formattedSizeClass = 'mw-plusminus-neg';
220 $formattedTotalSize = wfMsgExt( 'rc-change-size-new', 'parsemag', $wgLang->formatNum( $new ) );
222 return Html
::element( $tag,
223 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
224 wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark();
228 * Returns text for the end of RC
231 public function endRecentChangesList() {
232 if( $this->rclistOpen
) {
239 public function insertDateHeader( &$s, $rc_timestamp ) {
240 # Make date header if necessary
241 $date = $this->getLanguage()->date( $rc_timestamp, true, true );
242 if( $date != $this->lastdate
) {
243 if( $this->lastdate
!= '' ) {
246 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
247 $this->lastdate
= $date;
248 $this->rclistOpen
= true;
252 public function insertLog( &$s, $title, $logtype ) {
253 $page = new LogPage( $logtype );
254 $logname = $page->getName()->escaped();
255 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
260 * @param $rc RecentChange
261 * @param $unpatrolled
263 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
265 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
266 $diffLink = $this->message
['diff'];
267 } elseif ( !self
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
268 $diffLink = $this->message
['diff'];
271 'curid' => $rc->mAttribs
['rc_cur_id'],
272 'diff' => $rc->mAttribs
['rc_this_oldid'],
273 'oldid' => $rc->mAttribs
['rc_last_oldid']
277 $query['rcid'] = $rc->mAttribs
['rc_id'];
280 $diffLink = Linker
::linkKnown(
282 $this->message
['diff'],
283 array( 'tabindex' => $rc->counter
),
287 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
289 $s .= Linker
::linkKnown(
291 $this->message
['hist'],
294 'curid' => $rc->mAttribs
['rc_cur_id'],
295 'action' => 'history'
303 * @param $rc RecentChange
304 * @param $unpatrolled
307 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
308 # If it's a new article, there is no diff link, but if it hasn't been
309 # patrolled yet, we need to give users a way to do so
312 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
313 $params['rcid'] = $rc->mAttribs
['rc_id'];
316 $articlelink = Linker
::linkKnown(
322 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
323 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
325 # Bolden pages watched by this user
327 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
330 $articlelink .= $this->getLanguage()->getDirMark();
332 wfRunHooks( 'ChangesListInsertArticleLink',
333 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
335 $s .= " $articlelink";
340 * @param $rc RecentChange
342 public function insertTimestamp( &$s, $rc ) {
343 $s .= $this->message
['semicolon-separator'] .
344 $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
347 /** Insert links to user page, user talk page and eventually a blocking link
349 * @param $rc RecentChange
351 public function insertUserRelatedLinks( &$s, &$rc ) {
352 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
353 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
355 $s .= $this->getLanguage()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'],
356 $rc->mAttribs
['rc_user_text'] );
357 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
362 * insert a formatted action
364 * @param $rc RecentChange
366 public function insertLogEntry( $rc ) {
367 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
368 $formatter->setShowUserToolLinks( true );
369 $mark = $this->getLanguage()->getDirMark();
370 return $formatter->getActionText() . " $mark" . $formatter->getComment();
374 * Insert a formatted comment
375 * @param $rc RecentChange
377 public function insertComment( $rc ) {
378 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
379 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
380 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
382 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
388 * Check whether to enable recent changes patrol features
391 public static function usePatrol() {
393 return $wgUser->useRCPatrol();
397 * Returns the string which indicates the number of watching users
399 protected function numberofWatchingusers( $count ) {
400 static $cache = array();
402 if( !isset( $cache[$count] ) ) {
403 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
404 array('parsemag', 'escape' ), $this->getLanguage()->formatNum( $count ) );
406 return $cache[$count];
413 * Determine if said field of a revision is hidden
414 * @param $rc RCCacheEntry
415 * @param $field Integer: one of DELETED_* bitfield constants
418 public static function isDeleted( $rc, $field ) {
419 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
423 * Determine if the current user is allowed to view a particular
424 * field of this revision, if it's marked as deleted.
425 * @param $rc RCCacheEntry
426 * @param $field Integer
427 * @param $user User object to check, or null to use $wgUser
430 public static function userCan( $rc, $field, User
$user = null ) {
431 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
432 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
434 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
439 * @param $link string
440 * @param $watched bool
443 protected function maybeWatchedLink( $link, $watched = false ) {
445 return '<strong class="mw-watched">' . $link . '</strong>';
447 return '<span class="mw-rc-unwatched">' . $link . '</span>';
451 /** Inserts a rollback link
454 * @param $rc RecentChange
456 public function insertRollback( &$s, &$rc ) {
457 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
458 $page = $rc->getTitle();
459 /** Check for rollback and edit permissions, disallow special pages, and only
460 * show a link on the top-most revision */
461 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
463 $rev = new Revision( array(
464 'id' => $rc->mAttribs
['rc_this_oldid'],
465 'user' => $rc->mAttribs
['rc_user'],
466 'user_text' => $rc->mAttribs
['rc_user_text'],
467 'deleted' => $rc->mAttribs
['rc_deleted']
469 $rev->setTitle( $page );
470 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
477 * @param $rc RecentChange
480 public function insertTags( &$s, &$rc, &$classes ) {
481 if ( empty($rc->mAttribs
['ts_tags']) )
484 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
485 $classes = array_merge( $classes, $newClasses );
486 $s .= ' ' . $tagSummary;
489 public function insertExtra( &$s, &$rc, &$classes ) {
490 ## Empty, used for subclassers to add anything special.
493 protected function showAsUnpatrolled( RecentChange
$rc ) {
494 $unpatrolled = false;
495 if ( !$rc->mAttribs
['rc_patrolled'] ) {
496 if ( $this->getUser()->useRCPatrol() ) {
498 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs
['rc_new'] ) {
508 * Generate a list of changes using the good old system (no javascript)
510 class OldChangesList
extends ChangesList
{
512 * Format a line using the old system (aka without any javascript).
514 * @param $rc RecentChange
516 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
517 global $wgRCShowChangedSize;
518 wfProfileIn( __METHOD__
);
520 # Should patrol-related stuff be shown?
521 $unpatrolled = $this->showAsUnpatrolled( $rc );
523 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
524 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
528 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
530 if( $linenumber & 1 ) {
531 $classes[] = 'mw-line-odd';
534 $classes[] = 'mw-line-even';
538 // Moved pages (very very old, not supported anymore)
539 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
541 } elseif( $rc->mAttribs
['rc_log_type'] ) {
542 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
543 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
544 // Log entries (old format) or log targets, and special pages
545 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
546 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
547 if( $name == 'Log' ) {
548 $this->insertLog( $s, $rc->getTitle(), $subpage );
552 $this->insertDiffHist( $s, $rc, $unpatrolled );
553 # M, N, b and ! (minor, new, bot and unpatrolled)
554 $s .= $this->recentChangesFlags(
556 'newpage' => $rc->mAttribs
['rc_new'],
557 'minor' => $rc->mAttribs
['rc_minor'],
558 'unpatrolled' => $unpatrolled,
559 'bot' => $rc->mAttribs
['rc_bot']
563 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
566 $this->insertTimestamp( $s, $rc );
567 # Bytes added or removed
568 if( $wgRCShowChangedSize ) {
569 $cd = $rc->getCharacterDifference();
575 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
576 $s .= $this->insertLogEntry( $rc );
579 $this->insertUserRelatedLinks( $s, $rc );
580 # LTR/RTL direction mark
581 $s .= $this->getLanguage()->getDirMark();
582 $s .= $this->insertComment( $rc );
586 $this->insertTags( $s, $rc, $classes );
588 $this->insertRollback( $s, $rc );
590 $this->insertExtra( $s, $rc, $classes );
592 # How many users watch this page
593 if( $rc->numberofWatchingusers
> 0 ) {
594 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
595 array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $rc->numberofWatchingusers
) );
598 if( $this->watchlist
) {
599 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
602 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
604 wfProfileOut( __METHOD__
);
605 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
611 * Generate a list of changes using an Enhanced system (uses javascript).
613 class EnhancedChangesList
extends ChangesList
{
618 * Add the JavaScript file for enhanced changeslist
621 public function beginRecentChangesList() {
622 $this->rc_cache
= array();
623 $this->rcMoveIndex
= 0;
624 $this->rcCacheIndex
= 0;
625 $this->lastdate
= '';
626 $this->rclistOpen
= false;
627 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
631 * Format a line for enhanced recentchange (aka with javascript and block of lines).
633 * @param $baseRC RecentChange
634 * @param $watched bool
638 public function recentChangesLine( &$baseRC, $watched = false ) {
639 wfProfileIn( __METHOD__
);
641 # Create a specialised object
642 $rc = RCCacheEntry
::newFromParent( $baseRC );
644 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
646 # If it's a new day, add the headline and flush the cache
647 $date = $this->getLanguage()->date( $rc->mAttribs
['rc_timestamp'], true );
649 if( $date != $this->lastdate
) {
650 # Process current cache
651 $ret = $this->recentChangesBlock();
652 $this->rc_cache
= array();
653 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
654 $this->lastdate
= $date;
657 # Should patrol-related stuff be shown?
658 $rc->unpatrolled
= $this->showAsUnpatrolled( $rc );
660 $showdifflinks = true;
662 $type = $rc->mAttribs
['rc_type'];
663 $logType = $rc->mAttribs
['rc_log_type'];
664 // Page moves, very old style, not supported anymore
665 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
666 // New unpatrolled pages
667 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
668 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
669 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
671 } elseif( $type == RC_LOG
) {
673 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
674 $logpage = new LogPage( $logType );
675 $logname = $logpage->getName()->escaped();
676 $clink = '(' . Linker
::linkKnown( $logtitle, $logname ) . ')';
678 $clink = Linker
::link( $rc->getTitle() );
681 // Log entries (old format) and special pages
682 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
683 wfDebug( "Unexpected special page in recentchanges\n" );
687 $clink = Linker
::linkKnown( $rc->getTitle() );
690 # Don't show unusable diff links
691 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
692 $showdifflinks = false;
695 $time = $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true );
696 $rc->watched
= $watched;
698 $rc->timestamp
= $time;
699 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
701 # Make "cur" and "diff" links. Do not use link(), it is too slow if
702 # called too many times (50% of CPU time on RecentChanges!).
703 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
704 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
705 if( $rc->unpatrolled
) {
706 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
708 $rcIdQuery = array();
710 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
711 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
712 $lastOldid ) +
$rcIdQuery;
714 if( !$showdifflinks ) {
715 $curLink = $this->message
['cur'];
716 $diffLink = $this->message
['diff'];
717 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
718 if ( $type != RC_NEW
) {
719 $curLink = $this->message
['cur'];
721 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
722 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
724 $diffLink = $this->message
['diff'];
726 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
727 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
728 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
729 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
733 if( !$showdifflinks ||
!$lastOldid ) {
734 $lastLink = $this->message
['last'];
735 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
736 $lastLink = $this->message
['last'];
738 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
739 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
743 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
744 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
746 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
747 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
750 $rc->lastlink
= $lastLink;
751 $rc->curlink
= $curLink;
752 $rc->difflink
= $diffLink;
754 # Put accumulated information into the cache, for later display
755 # Page moves go on their own line
756 $title = $rc->getTitle();
757 $secureName = $title->getPrefixedDBkey();
758 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
759 # Use an @ character to prevent collision with page names
760 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
762 # Logs are grouped by type
763 if( $type == RC_LOG
){
764 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
766 if( !isset( $this->rc_cache
[$secureName] ) ) {
767 $this->rc_cache
[$secureName] = array();
770 array_push( $this->rc_cache
[$secureName], $rc );
773 wfProfileOut( __METHOD__
);
781 protected function recentChangesBlockGroup( $block ) {
782 global $wgRCShowChangedSize;
784 wfProfileIn( __METHOD__
);
786 # Add the namespace and title of the block as part of the class
787 if ( $block[0]->mAttribs
['rc_log_type'] ) {
789 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-'
790 . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
792 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns'
793 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
795 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
796 Html
::openElement( 'tr' );
798 # Collate list of users
799 $userlinks = array();
801 $unpatrolled = false;
803 $curId = $currentRevision = 0;
804 # Some catalyst variables...
807 foreach( $block as $rcObj ) {
808 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
809 if( $rcObj->mAttribs
['rc_new'] ) {
812 // If all log actions to this page were hidden, then don't
813 // give the name of the affected page for this block!
814 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
817 $u = $rcObj->userlink
;
818 if( !isset( $userlinks[$u] ) ) {
821 if( $rcObj->unpatrolled
) {
824 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
827 # Get the latest entry with a page_id and oldid
828 # since logs may not have these.
829 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
830 $curId = $rcObj->mAttribs
['rc_cur_id'];
832 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
833 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
836 $bot = $rcObj->mAttribs
['rc_bot'];
840 # Sort the list and convert to text
841 krsort( $userlinks );
844 foreach( $userlinks as $userlink => $count) {
846 $text .= $this->getLanguage()->getDirMark();
848 $text .= ' (' . $this->getLanguage()->formatNum( $count ) . '×)';
850 array_push( $users, $text );
853 $users = ' <span class="changedby">[' .
854 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
857 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
858 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
860 $tl = "<span class='mw-collapsible-toggle'>"
861 . "<span class='mw-rc-openarrow'>"
862 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
863 . "</span><span class='mw-rc-closearrow'>"
864 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
866 $r .= "<td>$tl</td>";
869 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
872 'unpatrolled' => $unpatrolled,
877 $r .= ' '.$block[0]->timestamp
.' </td><td>';
881 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
882 } elseif( $allLogs ) {
883 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
885 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
888 $r .= $this->getLanguage()->getDirMark();
890 $queryParams['curid'] = $curId;
893 static $nchanges = array();
894 if ( !isset( $nchanges[$n] ) ) {
895 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) );
901 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
906 $params = $queryParams;
907 $params['diff'] = $currentRevision;
908 $params['oldid'] = $oldid;
911 $block[0]->getTitle(),
915 array( 'known', 'noclasses' )
922 // don't show history link for logs
923 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
924 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
926 $params = $queryParams;
927 $params['action'] = 'history';
929 $r .= $this->message
['pipe-separator'] .
931 $block[0]->getTitle(),
932 $this->message
['hist'],
939 # Character difference (does not apply if only log items)
940 if( $wgRCShowChangedSize && !$allLogs ) {
942 $first = count($block) - 1;
943 # Some events (like logs) have an "empty" size, so we need to skip those...
944 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
947 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
951 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
952 $block[$last]->mAttribs
['rc_new_len'] );
954 if( $chardiff == '' ) {
957 $r .= ' ' . $chardiff. ' . . ';
962 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
965 foreach( $block as $rcObj ) {
966 # Classes to apply -- TODO implement
968 $type = $rcObj->mAttribs
['rc_type'];
970 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
971 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
972 $r .= $this->recentChangesFlags( array(
973 'newpage' => $rcObj->mAttribs
['rc_new'],
974 'minor' => $rcObj->mAttribs
['rc_minor'],
975 'unpatrolled' => $rcObj->unpatrolled
,
976 'bot' => $rcObj->mAttribs
['rc_bot'],
978 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
980 $params = $queryParams;
982 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
983 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
987 if( $type == RC_LOG
) {
988 $link = $rcObj->timestamp
;
990 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
991 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
993 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
994 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
997 $link = Linker
::linkKnown(
1003 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1004 $link = '<span class="history-deleted">'.$link.'</span> ';
1006 $r .= $link . '</span>';
1008 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1010 $r .= $rcObj->curlink
;
1011 $r .= $this->message
['pipe-separator'];
1012 $r .= $rcObj->lastlink
;
1018 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1019 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1022 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1023 $r .= $this->insertLogEntry( $rcObj );
1026 $r .= $rcObj->userlink
;
1027 $r .= $rcObj->usertalklink
;
1028 $r .= $this->insertComment( $rcObj );
1032 $this->insertRollback( $r, $rcObj );
1034 $this->insertTags( $r, $rcObj, $classes );
1036 $r .= "</td></tr>\n";
1040 $this->rcCacheIndex++
;
1042 wfProfileOut( __METHOD__
);
1048 * Generate HTML for an arrow or placeholder graphic
1049 * @param $dir String: one of '', 'd', 'l', 'r'
1050 * @param $alt String: text
1051 * @param $title String: text
1052 * @return String: HTML <img> tag
1054 protected function arrow( $dir, $alt='', $title='' ) {
1055 global $wgStylePath;
1056 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1057 $encAlt = htmlspecialchars( $alt );
1058 $encTitle = htmlspecialchars( $title );
1059 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1063 * Generate HTML for a right- or left-facing arrow,
1064 * depending on language direction.
1065 * @return String: HTML <img> tag
1067 protected function sideArrow() {
1069 $dir = $wgLang->isRTL() ?
'l' : 'r';
1070 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1074 * Generate HTML for a down-facing arrow
1075 * depending on language direction.
1076 * @return String: HTML <img> tag
1078 protected function downArrow() {
1079 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1083 * Generate HTML for a spacer image
1084 * @return String: HTML <img> tag
1086 protected function spacerArrow() {
1087 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1091 * Enhanced RC ungrouped line.
1093 * @param $rcObj RecentChange
1094 * @return String: a HTML formatted line (generated using $r)
1096 protected function recentChangesBlockLine( $rcObj ) {
1097 global $wgRCShowChangedSize;
1099 wfProfileIn( __METHOD__
);
1100 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1102 $type = $rcObj->mAttribs
['rc_type'];
1103 $logType = $rcObj->mAttribs
['rc_log_type'];
1106 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-'
1107 . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1109 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' .
1110 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1112 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1113 Html
::openElement( 'tr' );
1115 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1116 # Flag and Timestamp
1117 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1118 $r .= '    '; // 4 flags -> 4 spaces
1120 $r .= $this->recentChangesFlags( array(
1121 'newpage' => $type == RC_NEW
,
1122 'minor' => $rcObj->mAttribs
['rc_minor'],
1123 'unpatrolled' => $rcObj->unpatrolled
,
1124 'bot' => $rcObj->mAttribs
['rc_bot'],
1127 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1128 # Article or log link
1130 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1131 $logname = LogPage
::logName( $logType );
1132 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1134 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1136 # Diff and hist links
1137 if ( $type != RC_LOG
) {
1138 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1139 $query['action'] = 'history';
1140 $r .= Linker
::linkKnown(
1142 $this->message
['hist'],
1149 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1153 if ( $type == RC_LOG
) {
1154 $r .= $this->insertLogEntry( $rcObj );
1156 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1157 $r .= $this->insertComment( $rcObj );
1158 $r .= $this->insertRollback( $r, $rcObj );
1162 $classes = explode( ' ', $classes );
1163 $this->insertTags( $r, $rcObj, $classes );
1164 # Show how many people are watching this if enabled
1165 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1167 $r .= "</td></tr></table>\n";
1169 wfProfileOut( __METHOD__
);
1175 * If enhanced RC is in use, this function takes the previously cached
1176 * RC lines, arranges them, and outputs the HTML
1180 protected function recentChangesBlock() {
1181 if( count ( $this->rc_cache
) == 0 ) {
1185 wfProfileIn( __METHOD__
);
1188 foreach( $this->rc_cache
as $block ) {
1189 if( count( $block ) < 2 ) {
1190 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1192 $blockOut .= $this->recentChangesBlockGroup( $block );
1196 wfProfileOut( __METHOD__
);
1198 return '<div>'.$blockOut.'</div>';
1202 * Returns text for the end of RC
1203 * If enhanced RC is in use, returns pretty much all the text
1206 public function endRecentChangesList() {
1207 return $this->recentChangesBlock() . parent
::endRecentChangesList();