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 return self
::newFromContext( RequestContext
::getMain() );
74 * Fetch an appropriate changes list class for the specified context
75 * Some users might want to use an enhanced list format, for instance
77 * @param $context IContextSource to use
78 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
80 public static function newFromContext( IContextSource
$context ) {
81 $user = $context->getUser();
82 $sk = $context->getSkin();
84 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
85 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
86 return $new ?
new EnhancedChangesList( $context ) : new OldChangesList( $context );
93 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
94 * @param $value Boolean
96 public function setWatchlistDivs( $value = true ) {
97 $this->watchlist
= $value;
101 * As we use the same small set of messages in various methods and that
102 * they are called often, we call them once and save them in $this->message
104 private function preCacheMessages() {
105 if( !isset( $this->message
) ) {
106 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
107 'semicolon-separator pipe-separator' ) as $msg ) {
108 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
114 * Returns the appropriate flags for new page, minor change and patrolling
115 * @param $flags Array Associative array of 'flag' => Bool
116 * @param $nothing String to use for empty space
119 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
121 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
122 $f .= isset( $flags[$flag] ) && $flags[$flag]
123 ? self
::flag( $flag )
130 * Provide the <abbr> element appropriate to a given abbreviated flag,
131 * namely the flag indicating a new page, a minor edit, a bot edit, or an
132 * unpatrolled edit. By default in English it will contain "N", "m", "b",
133 * "!" respectively, plus it will have an appropriate title and class.
135 * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot'
136 * @return String: Raw HTML
138 public static function flag( $flag ) {
139 static $messages = null;
140 if ( is_null( $messages ) ) {
142 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
143 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
144 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
145 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
147 foreach( $messages as &$value ) {
148 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
149 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
153 # Inconsistent naming, bleh
155 'newpage' => 'newpage',
156 'minor' => 'minoredit',
158 'unpatrolled' => 'unpatrolled',
159 'minoredit' => 'minoredit',
160 'botedit' => 'botedit',
164 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
168 * Returns text for the start of the tabular part of RC
171 public function beginRecentChangesList() {
172 $this->rc_cache
= array();
173 $this->rcMoveIndex
= 0;
174 $this->rcCacheIndex
= 0;
175 $this->lastdate
= '';
176 $this->rclistOpen
= false;
181 * Show formatted char difference
182 * @param $old Integer: bytes
183 * @param $new Integer: bytes
186 public static function showCharacterDifference( $old, $new ) {
187 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
188 $szdiff = $new - $old;
190 $code = $wgLang->getCode();
191 static $fastCharDiff = array();
192 if ( !isset($fastCharDiff[$code]) ) {
193 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
196 $formattedSize = $wgLang->formatNum($szdiff);
198 if ( !$fastCharDiff[$code] ) {
199 $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize );
202 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
208 if ( $szdiff === 0 ) {
209 $formattedSizeClass = 'mw-plusminus-null';
212 $formattedSize = '+' . $formattedSize;
213 $formattedSizeClass = 'mw-plusminus-pos';
216 $formattedSizeClass = 'mw-plusminus-neg';
219 $formattedTotalSize = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $new ) );
221 return Html
::element( $tag,
222 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
223 wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark();
227 * Returns text for the end of RC
230 public function endRecentChangesList() {
231 if( $this->rclistOpen
) {
238 public function insertDateHeader( &$s, $rc_timestamp ) {
239 # Make date header if necessary
240 $date = $this->getLanguage()->date( $rc_timestamp, true, true );
241 if( $date != $this->lastdate
) {
242 if( $this->lastdate
!= '' ) {
245 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
246 $this->lastdate
= $date;
247 $this->rclistOpen
= true;
251 public function insertLog( &$s, $title, $logtype ) {
252 $page = new LogPage( $logtype );
253 $logname = $page->getName()->escaped();
254 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
259 * @param $rc RecentChange
260 * @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
308 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
309 # If it's a new article, there is no diff link, but if it hasn't been
310 # patrolled yet, we need to give users a way to do so
313 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
314 $params['rcid'] = $rc->mAttribs
['rc_id'];
317 $articlelink = Linker
::linkKnown(
323 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
324 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
326 # Bolden pages watched by this user
328 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
331 $articlelink .= $this->getLanguage()->getDirMark();
333 wfRunHooks( 'ChangesListInsertArticleLink',
334 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
336 $s .= " $articlelink";
341 * @param $rc RecentChange
344 public function insertTimestamp( &$s, $rc ) {
345 $s .= $this->message
['semicolon-separator'] .
346 $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
349 /** Insert links to user page, user talk page and eventually a blocking link
351 * @param $rc RecentChange
353 public function insertUserRelatedLinks( &$s, &$rc ) {
354 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
355 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
357 $s .= $this->getLanguage()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
358 $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 );
438 protected function maybeWatchedLink( $link, $watched = false ) {
440 return '<strong class="mw-watched">' . $link . '</strong>';
442 return '<span class="mw-rc-unwatched">' . $link . '</span>';
446 /** Inserts a rollback link
449 * @param $rc RecentChange
451 public function insertRollback( &$s, &$rc ) {
452 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
453 $page = $rc->getTitle();
454 /** Check for rollback and edit permissions, disallow special pages, and only
455 * show a link on the top-most revision */
456 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
458 $rev = new Revision( array(
459 'id' => $rc->mAttribs
['rc_this_oldid'],
460 'user' => $rc->mAttribs
['rc_user'],
461 'user_text' => $rc->mAttribs
['rc_user_text'],
462 'deleted' => $rc->mAttribs
['rc_deleted']
464 $rev->setTitle( $page );
465 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
472 * @param $rc RecentChange
476 public function insertTags( &$s, &$rc, &$classes ) {
477 if ( empty($rc->mAttribs
['ts_tags']) )
480 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
481 $classes = array_merge( $classes, $newClasses );
482 $s .= ' ' . $tagSummary;
485 public function insertExtra( &$s, &$rc, &$classes ) {
486 ## Empty, used for subclassers to add anything special.
489 protected function showAsUnpatrolled( RecentChange
$rc ) {
490 $unpatrolled = false;
491 if ( !$rc->mAttribs
['rc_patrolled'] ) {
492 if ( $this->getUser()->useRCPatrol() ) {
494 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs
['rc_new'] ) {
504 * Generate a list of changes using the good old system (no javascript)
506 class OldChangesList
extends ChangesList
{
508 * Format a line using the old system (aka without any javascript).
510 * @param $rc RecentChange
512 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
513 global $wgRCShowChangedSize;
514 wfProfileIn( __METHOD__
);
516 # Should patrol-related stuff be shown?
517 $unpatrolled = $this->showAsUnpatrolled( $rc );
519 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
520 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
524 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
526 if( $linenumber & 1 ) {
527 $classes[] = 'mw-line-odd';
530 $classes[] = 'mw-line-even';
534 // Moved pages (very very old, not supported anymore)
535 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
537 } elseif( $rc->mAttribs
['rc_log_type'] ) {
538 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
539 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
540 // Log entries (old format) or log targets, and special pages
541 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
542 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
543 if( $name == 'Log' ) {
544 $this->insertLog( $s, $rc->getTitle(), $subpage );
548 $this->insertDiffHist( $s, $rc, $unpatrolled );
549 # M, N, b and ! (minor, new, bot and unpatrolled)
550 $s .= $this->recentChangesFlags(
552 'newpage' => $rc->mAttribs
['rc_new'],
553 'minor' => $rc->mAttribs
['rc_minor'],
554 'unpatrolled' => $unpatrolled,
555 'bot' => $rc->mAttribs
['rc_bot']
559 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
562 $this->insertTimestamp( $s, $rc );
563 # Bytes added or removed
564 if( $wgRCShowChangedSize ) {
565 $cd = $rc->getCharacterDifference();
571 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
572 $s .= $this->insertLogEntry( $rc );
575 $this->insertUserRelatedLinks( $s, $rc );
576 # LTR/RTL direction mark
577 $s .= $this->getLanguage()->getDirMark();
578 $s .= $this->insertComment( $rc );
582 $this->insertTags( $s, $rc, $classes );
584 $this->insertRollback( $s, $rc );
586 $this->insertExtra( $s, $rc, $classes );
588 # How many users watch this page
589 if( $rc->numberofWatchingusers
> 0 ) {
590 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
591 array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $rc->numberofWatchingusers
) );
594 if( $this->watchlist
) {
595 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
598 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
600 wfProfileOut( __METHOD__
);
601 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
607 * Generate a list of changes using an Enhanced system (uses javascript).
609 class EnhancedChangesList
extends ChangesList
{
611 * Add the JavaScript file for enhanced changeslist
614 public function beginRecentChangesList() {
615 $this->rc_cache
= array();
616 $this->rcMoveIndex
= 0;
617 $this->rcCacheIndex
= 0;
618 $this->lastdate
= '';
619 $this->rclistOpen
= false;
620 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
624 * Format a line for enhanced recentchange (aka with javascript and block of lines).
626 * @param $baseRC RecentChange
627 * @param $watched bool
631 public function recentChangesLine( &$baseRC, $watched = false ) {
632 wfProfileIn( __METHOD__
);
634 # Create a specialised object
635 $rc = RCCacheEntry
::newFromParent( $baseRC );
637 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
639 # If it's a new day, add the headline and flush the cache
640 $date = $this->getLanguage()->date( $rc->mAttribs
['rc_timestamp'], true );
642 if( $date != $this->lastdate
) {
643 # Process current cache
644 $ret = $this->recentChangesBlock();
645 $this->rc_cache
= array();
646 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
647 $this->lastdate
= $date;
650 # Should patrol-related stuff be shown?
651 $rc->unpatrolled
= $this->showAsUnpatrolled( $rc );
653 $showdifflinks = true;
655 $type = $rc->mAttribs
['rc_type'];
656 $logType = $rc->mAttribs
['rc_log_type'];
657 // Page moves, very old style, not supported anymore
658 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
659 // New unpatrolled pages
660 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
661 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
662 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
664 } elseif( $type == RC_LOG
) {
666 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
667 $clink = '(' . Linker
::linkKnown( $logtitle,
668 LogPage
::logName( $logType ) ) . ')';
670 $clink = Linker
::link( $rc->getTitle() );
673 // Log entries (old format) and special pages
674 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
675 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
676 if ( $specialName == 'Log' ) {
678 $logname = LogPage
::logName( $logtype );
679 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
681 wfDebug( "Unexpected special page in recentchanges\n" );
686 $clink = Linker
::linkKnown( $rc->getTitle() );
689 # Don't show unusable diff links
690 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
691 $showdifflinks = false;
694 $time = $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true );
695 $rc->watched
= $watched;
697 $rc->timestamp
= $time;
698 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
700 # Make "cur" and "diff" links. Do not use link(), it is too slow if
701 # called too many times (50% of CPU time on RecentChanges!).
702 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
703 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
704 if( $rc->unpatrolled
) {
705 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
707 $rcIdQuery = array();
709 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
710 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
711 $lastOldid ) +
$rcIdQuery;
713 if( !$showdifflinks ) {
714 $curLink = $this->message
['cur'];
715 $diffLink = $this->message
['diff'];
716 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
717 if ( $type != RC_NEW
) {
718 $curLink = $this->message
['cur'];
720 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
721 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
723 $diffLink = $this->message
['diff'];
725 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
726 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
727 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
728 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
732 if( !$showdifflinks ||
!$lastOldid ) {
733 $lastLink = $this->message
['last'];
734 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
735 $lastLink = $this->message
['last'];
737 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
738 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
742 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
743 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
745 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
746 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
749 $rc->lastlink
= $lastLink;
750 $rc->curlink
= $curLink;
751 $rc->difflink
= $diffLink;
753 # Put accumulated information into the cache, for later display
754 # Page moves go on their own line
755 $title = $rc->getTitle();
756 $secureName = $title->getPrefixedDBkey();
757 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
758 # Use an @ character to prevent collision with page names
759 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
761 # Logs are grouped by type
762 if( $type == RC_LOG
){
763 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
765 if( !isset( $this->rc_cache
[$secureName] ) ) {
766 $this->rc_cache
[$secureName] = array();
769 array_push( $this->rc_cache
[$secureName], $rc );
772 wfProfileOut( __METHOD__
);
780 protected function recentChangesBlockGroup( $block ) {
781 global $wgRCShowChangedSize;
783 wfProfileIn( __METHOD__
);
785 # Add the namespace and title of the block as part of the class
786 if ( $block[0]->mAttribs
['rc_log_type'] ) {
788 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
790 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
792 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
793 Html
::openElement( 'tr' );
795 # Collate list of users
796 $userlinks = array();
798 $unpatrolled = false;
800 $curId = $currentRevision = 0;
801 # Some catalyst variables...
804 foreach( $block as $rcObj ) {
805 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
806 if( $rcObj->mAttribs
['rc_new'] ) {
809 // If all log actions to this page were hidden, then don't
810 // give the name of the affected page for this block!
811 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
814 $u = $rcObj->userlink
;
815 if( !isset( $userlinks[$u] ) ) {
818 if( $rcObj->unpatrolled
) {
821 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
824 # Get the latest entry with a page_id and oldid
825 # since logs may not have these.
826 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
827 $curId = $rcObj->mAttribs
['rc_cur_id'];
829 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
830 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
833 $bot = $rcObj->mAttribs
['rc_bot'];
837 # Sort the list and convert to text
838 krsort( $userlinks );
841 foreach( $userlinks as $userlink => $count) {
843 $text .= $this->getLanguage()->getDirMark();
845 $text .= ' (' . $this->getLanguage()->formatNum( $count ) . '×)';
847 array_push( $users, $text );
850 $users = ' <span class="changedby">[' .
851 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
854 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
855 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
857 $tl = "<span class='mw-collapsible-toggle'>"
858 . "<span class='mw-rc-openarrow'>"
859 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
860 . "</span><span class='mw-rc-closearrow'>"
861 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
863 $r .= "<td>$tl</td>";
866 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
869 'unpatrolled' => $unpatrolled,
874 $r .= ' '.$block[0]->timestamp
.' </td><td>';
878 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
879 } elseif( $allLogs ) {
880 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
882 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
885 $r .= $this->getLanguage()->getDirMark();
887 $queryParams['curid'] = $curId;
890 static $nchanges = array();
891 if ( !isset( $nchanges[$n] ) ) {
892 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) );
898 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
903 $params = $queryParams;
904 $params['diff'] = $currentRevision;
905 $params['oldid'] = $oldid;
908 $block[0]->getTitle(),
912 array( 'known', 'noclasses' )
919 // don't show history link for logs
920 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
921 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
923 $params = $queryParams;
924 $params['action'] = 'history';
926 $r .= $this->message
['pipe-separator'] .
928 $block[0]->getTitle(),
929 $this->message
['hist'],
936 # Character difference (does not apply if only log items)
937 if( $wgRCShowChangedSize && !$allLogs ) {
939 $first = count($block) - 1;
940 # Some events (like logs) have an "empty" size, so we need to skip those...
941 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
944 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
948 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
949 $block[$last]->mAttribs
['rc_new_len'] );
951 if( $chardiff == '' ) {
954 $r .= ' ' . $chardiff. ' . . ';
959 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
962 foreach( $block as $rcObj ) {
963 # Classes to apply -- TODO implement
965 $type = $rcObj->mAttribs
['rc_type'];
967 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
968 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
969 $r .= $this->recentChangesFlags( array(
970 'newpage' => $rcObj->mAttribs
['rc_new'],
971 'minor' => $rcObj->mAttribs
['rc_minor'],
972 'unpatrolled' => $rcObj->unpatrolled
,
973 'bot' => $rcObj->mAttribs
['rc_bot'],
975 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
977 $params = $queryParams;
979 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
980 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
984 if( $type == RC_LOG
) {
985 $link = $rcObj->timestamp
;
987 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
988 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
990 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
991 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
994 $link = Linker
::linkKnown(
1000 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1001 $link = '<span class="history-deleted">'.$link.'</span> ';
1003 $r .= $link . '</span>';
1005 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1007 $r .= $rcObj->curlink
;
1008 $r .= $this->message
['pipe-separator'];
1009 $r .= $rcObj->lastlink
;
1015 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1016 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1019 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1020 $r .= $this->insertLogEntry( $rcObj );
1023 $r .= $rcObj->userlink
;
1024 $r .= $rcObj->usertalklink
;
1025 $r .= $this->insertComment( $rcObj );
1029 $this->insertRollback( $r, $rcObj );
1031 $this->insertTags( $r, $rcObj, $classes );
1033 $r .= "</td></tr>\n";
1037 $this->rcCacheIndex++
;
1039 wfProfileOut( __METHOD__
);
1045 * Generate HTML for an arrow or placeholder graphic
1046 * @param $dir String: one of '', 'd', 'l', 'r'
1047 * @param $alt String: text
1048 * @param $title String: text
1049 * @return String: HTML <img> tag
1051 protected function arrow( $dir, $alt='', $title='' ) {
1052 global $wgStylePath;
1053 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1054 $encAlt = htmlspecialchars( $alt );
1055 $encTitle = htmlspecialchars( $title );
1056 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1060 * Generate HTML for a right- or left-facing arrow,
1061 * depending on language direction.
1062 * @return String: HTML <img> tag
1064 protected function sideArrow() {
1066 $dir = $wgLang->isRTL() ?
'l' : 'r';
1067 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1071 * Generate HTML for a down-facing arrow
1072 * depending on language direction.
1073 * @return String: HTML <img> tag
1075 protected function downArrow() {
1076 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1080 * Generate HTML for a spacer image
1081 * @return String: HTML <img> tag
1083 protected function spacerArrow() {
1084 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1088 * Enhanced RC ungrouped line.
1090 * @param $rcObj RecentChange
1091 * @return String: a HTML formatted line (generated using $r)
1093 protected function recentChangesBlockLine( $rcObj ) {
1094 global $wgRCShowChangedSize;
1096 wfProfileIn( __METHOD__
);
1097 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1099 $type = $rcObj->mAttribs
['rc_type'];
1100 $logType = $rcObj->mAttribs
['rc_log_type'];
1103 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1105 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1107 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1108 Html
::openElement( 'tr' );
1110 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1111 # Flag and Timestamp
1112 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1113 $r .= '    '; // 4 flags -> 4 spaces
1115 $r .= $this->recentChangesFlags( array(
1116 'newpage' => $type == RC_NEW
,
1117 'minor' => $rcObj->mAttribs
['rc_minor'],
1118 'unpatrolled' => $rcObj->unpatrolled
,
1119 'bot' => $rcObj->mAttribs
['rc_bot'],
1122 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1123 # Article or log link
1125 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1126 $logname = LogPage
::logName( $logType );
1127 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1129 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1131 # Diff and hist links
1132 if ( $type != RC_LOG
) {
1133 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1134 $query['action'] = 'history';
1135 $r .= Linker
::linkKnown(
1137 $this->message
['hist'],
1144 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1148 if ( $type == RC_LOG
) {
1149 $r .= $this->insertLogEntry( $rcObj );
1151 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1152 $r .= $this->insertComment( $rcObj );
1153 $r .= $this->insertRollback( $r, $rcObj );
1157 $classes = explode( ' ', $classes );
1158 $this->insertTags( $r, $rcObj, $classes );
1159 # Show how many people are watching this if enabled
1160 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1162 $r .= "</td></tr></table>\n";
1164 wfProfileOut( __METHOD__
);
1170 * If enhanced RC is in use, this function takes the previously cached
1171 * RC lines, arranges them, and outputs the HTML
1175 protected function recentChangesBlock() {
1176 if( count ( $this->rc_cache
) == 0 ) {
1180 wfProfileIn( __METHOD__
);
1183 foreach( $this->rc_cache
as $block ) {
1184 if( count( $block ) < 2 ) {
1185 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1187 $blockOut .= $this->recentChangesBlockGroup( $block );
1191 wfProfileOut( __METHOD__
);
1193 return '<div>'.$blockOut.'</div>';
1197 * Returns text for the end of RC
1198 * If enhanced RC is in use, returns pretty much all the text
1200 public function endRecentChangesList() {
1201 return $this->recentChangesBlock() . parent
::endRecentChangesList();