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
264 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
266 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
267 $diffLink = $this->message
['diff'];
268 } elseif ( !self
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
269 $diffLink = $this->message
['diff'];
272 'curid' => $rc->mAttribs
['rc_cur_id'],
273 'diff' => $rc->mAttribs
['rc_this_oldid'],
274 'oldid' => $rc->mAttribs
['rc_last_oldid']
278 $query['rcid'] = $rc->mAttribs
['rc_id'];
281 $diffLink = Linker
::linkKnown(
283 $this->message
['diff'],
284 array( 'tabindex' => $rc->counter
),
288 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
290 $s .= Linker
::linkKnown(
292 $this->message
['hist'],
295 'curid' => $rc->mAttribs
['rc_cur_id'],
296 'action' => 'history'
304 * @param $rc RecentChange
305 * @param $unpatrolled
309 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
310 # If it's a new article, there is no diff link, but if it hasn't been
311 # patrolled yet, we need to give users a way to do so
314 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
315 $params['rcid'] = $rc->mAttribs
['rc_id'];
318 $articlelink = Linker
::linkKnown(
324 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
325 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
327 # Bolden pages watched by this user
329 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
332 $articlelink .= $this->getLanguage()->getDirMark();
334 wfRunHooks( 'ChangesListInsertArticleLink',
335 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
337 $s .= " $articlelink";
342 * @param $rc RecentChange
345 public function insertTimestamp( &$s, $rc ) {
346 $s .= $this->message
['semicolon-separator'] .
347 $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
350 /** Insert links to user page, user talk page and eventually a blocking link
352 * @param $rc RecentChange
354 public function insertUserRelatedLinks( &$s, &$rc ) {
355 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
356 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
358 $s .= $this->getLanguage()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
359 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
363 /** insert a formatted action
365 * @param $rc RecentChange
367 public function insertLogEntry( $rc ) {
368 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
369 $formatter->setShowUserToolLinks( true );
370 $mark = $this->getLanguage()->getDirMark();
371 return $formatter->getActionText() . " $mark" . $formatter->getComment();
375 * Insert a formatted comment
376 * @param $rc RecentChange
378 public function insertComment( $rc ) {
379 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
380 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
381 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
383 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
389 * Check whether to enable recent changes patrol features
392 public static function usePatrol() {
394 return $wgUser->useRCPatrol();
398 * Returns the string which indicates the number of watching users
400 protected function numberofWatchingusers( $count ) {
401 static $cache = array();
403 if( !isset( $cache[$count] ) ) {
404 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
405 array('parsemag', 'escape' ), $this->getLanguage()->formatNum( $count ) );
407 return $cache[$count];
414 * Determine if said field of a revision is hidden
415 * @param $rc RCCacheEntry
416 * @param $field Integer: one of DELETED_* bitfield constants
419 public static function isDeleted( $rc, $field ) {
420 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
424 * Determine if the current user is allowed to view a particular
425 * field of this revision, if it's marked as deleted.
426 * @param $rc RCCacheEntry
427 * @param $field Integer
428 * @param $user User object to check, or null to use $wgUser
431 public static function userCan( $rc, $field, User
$user = null ) {
432 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
433 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
435 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
439 protected function maybeWatchedLink( $link, $watched = false ) {
441 return '<strong class="mw-watched">' . $link . '</strong>';
443 return '<span class="mw-rc-unwatched">' . $link . '</span>';
447 /** Inserts a rollback link
450 * @param $rc RecentChange
452 public function insertRollback( &$s, &$rc ) {
453 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
454 $page = $rc->getTitle();
455 /** Check for rollback and edit permissions, disallow special pages, and only
456 * show a link on the top-most revision */
457 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
459 $rev = new Revision( array(
460 'id' => $rc->mAttribs
['rc_this_oldid'],
461 'user' => $rc->mAttribs
['rc_user'],
462 'user_text' => $rc->mAttribs
['rc_user_text'],
463 'deleted' => $rc->mAttribs
['rc_deleted']
465 $rev->setTitle( $page );
466 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
473 * @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 $logpage = new LogPage( $logType );
668 $logname = $logpage->getName()->escaped();
669 $clink = '(' . Linker
::linkKnown( $logtitle, $logname ) . ')';
671 $clink = Linker
::link( $rc->getTitle() );
674 // Log entries (old format) and special pages
675 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
676 wfDebug( "Unexpected special page in recentchanges\n" );
680 $clink = Linker
::linkKnown( $rc->getTitle() );
683 # Don't show unusable diff links
684 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
685 $showdifflinks = false;
688 $time = $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true );
689 $rc->watched
= $watched;
691 $rc->timestamp
= $time;
692 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
694 # Make "cur" and "diff" links. Do not use link(), it is too slow if
695 # called too many times (50% of CPU time on RecentChanges!).
696 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
697 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
698 if( $rc->unpatrolled
) {
699 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
701 $rcIdQuery = array();
703 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
704 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
705 $lastOldid ) +
$rcIdQuery;
707 if( !$showdifflinks ) {
708 $curLink = $this->message
['cur'];
709 $diffLink = $this->message
['diff'];
710 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
711 if ( $type != RC_NEW
) {
712 $curLink = $this->message
['cur'];
714 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
715 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
717 $diffLink = $this->message
['diff'];
719 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
720 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
721 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
722 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
726 if( !$showdifflinks ||
!$lastOldid ) {
727 $lastLink = $this->message
['last'];
728 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
729 $lastLink = $this->message
['last'];
731 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
732 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
736 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
737 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
739 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
740 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
743 $rc->lastlink
= $lastLink;
744 $rc->curlink
= $curLink;
745 $rc->difflink
= $diffLink;
747 # Put accumulated information into the cache, for later display
748 # Page moves go on their own line
749 $title = $rc->getTitle();
750 $secureName = $title->getPrefixedDBkey();
751 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
752 # Use an @ character to prevent collision with page names
753 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
755 # Logs are grouped by type
756 if( $type == RC_LOG
){
757 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
759 if( !isset( $this->rc_cache
[$secureName] ) ) {
760 $this->rc_cache
[$secureName] = array();
763 array_push( $this->rc_cache
[$secureName], $rc );
766 wfProfileOut( __METHOD__
);
774 protected function recentChangesBlockGroup( $block ) {
775 global $wgRCShowChangedSize;
777 wfProfileIn( __METHOD__
);
779 # Add the namespace and title of the block as part of the class
780 if ( $block[0]->mAttribs
['rc_log_type'] ) {
782 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
784 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
786 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
787 Html
::openElement( 'tr' );
789 # Collate list of users
790 $userlinks = array();
792 $unpatrolled = false;
794 $curId = $currentRevision = 0;
795 # Some catalyst variables...
798 foreach( $block as $rcObj ) {
799 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
800 if( $rcObj->mAttribs
['rc_new'] ) {
803 // If all log actions to this page were hidden, then don't
804 // give the name of the affected page for this block!
805 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
808 $u = $rcObj->userlink
;
809 if( !isset( $userlinks[$u] ) ) {
812 if( $rcObj->unpatrolled
) {
815 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
818 # Get the latest entry with a page_id and oldid
819 # since logs may not have these.
820 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
821 $curId = $rcObj->mAttribs
['rc_cur_id'];
823 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
824 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
827 $bot = $rcObj->mAttribs
['rc_bot'];
831 # Sort the list and convert to text
832 krsort( $userlinks );
835 foreach( $userlinks as $userlink => $count) {
837 $text .= $this->getLanguage()->getDirMark();
839 $text .= ' (' . $this->getLanguage()->formatNum( $count ) . '×)';
841 array_push( $users, $text );
844 $users = ' <span class="changedby">[' .
845 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
848 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
849 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
851 $tl = "<span class='mw-collapsible-toggle'>"
852 . "<span class='mw-rc-openarrow'>"
853 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
854 . "</span><span class='mw-rc-closearrow'>"
855 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
857 $r .= "<td>$tl</td>";
860 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
863 'unpatrolled' => $unpatrolled,
868 $r .= ' '.$block[0]->timestamp
.' </td><td>';
872 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
873 } elseif( $allLogs ) {
874 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
876 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
879 $r .= $this->getLanguage()->getDirMark();
881 $queryParams['curid'] = $curId;
884 static $nchanges = array();
885 if ( !isset( $nchanges[$n] ) ) {
886 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) );
892 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
897 $params = $queryParams;
898 $params['diff'] = $currentRevision;
899 $params['oldid'] = $oldid;
902 $block[0]->getTitle(),
906 array( 'known', 'noclasses' )
913 // don't show history link for logs
914 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
915 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
917 $params = $queryParams;
918 $params['action'] = 'history';
920 $r .= $this->message
['pipe-separator'] .
922 $block[0]->getTitle(),
923 $this->message
['hist'],
930 # Character difference (does not apply if only log items)
931 if( $wgRCShowChangedSize && !$allLogs ) {
933 $first = count($block) - 1;
934 # Some events (like logs) have an "empty" size, so we need to skip those...
935 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
938 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
942 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
943 $block[$last]->mAttribs
['rc_new_len'] );
945 if( $chardiff == '' ) {
948 $r .= ' ' . $chardiff. ' . . ';
953 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
956 foreach( $block as $rcObj ) {
957 # Classes to apply -- TODO implement
959 $type = $rcObj->mAttribs
['rc_type'];
961 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
962 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
963 $r .= $this->recentChangesFlags( array(
964 'newpage' => $rcObj->mAttribs
['rc_new'],
965 'minor' => $rcObj->mAttribs
['rc_minor'],
966 'unpatrolled' => $rcObj->unpatrolled
,
967 'bot' => $rcObj->mAttribs
['rc_bot'],
969 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
971 $params = $queryParams;
973 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
974 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
978 if( $type == RC_LOG
) {
979 $link = $rcObj->timestamp
;
981 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
982 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
984 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
985 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
988 $link = Linker
::linkKnown(
994 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
995 $link = '<span class="history-deleted">'.$link.'</span> ';
997 $r .= $link . '</span>';
999 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1001 $r .= $rcObj->curlink
;
1002 $r .= $this->message
['pipe-separator'];
1003 $r .= $rcObj->lastlink
;
1009 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1010 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1013 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1014 $r .= $this->insertLogEntry( $rcObj );
1017 $r .= $rcObj->userlink
;
1018 $r .= $rcObj->usertalklink
;
1019 $r .= $this->insertComment( $rcObj );
1023 $this->insertRollback( $r, $rcObj );
1025 $this->insertTags( $r, $rcObj, $classes );
1027 $r .= "</td></tr>\n";
1031 $this->rcCacheIndex++
;
1033 wfProfileOut( __METHOD__
);
1039 * Generate HTML for an arrow or placeholder graphic
1040 * @param $dir String: one of '', 'd', 'l', 'r'
1041 * @param $alt String: text
1042 * @param $title String: text
1043 * @return String: HTML <img> tag
1045 protected function arrow( $dir, $alt='', $title='' ) {
1046 global $wgStylePath;
1047 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1048 $encAlt = htmlspecialchars( $alt );
1049 $encTitle = htmlspecialchars( $title );
1050 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1054 * Generate HTML for a right- or left-facing arrow,
1055 * depending on language direction.
1056 * @return String: HTML <img> tag
1058 protected function sideArrow() {
1060 $dir = $wgLang->isRTL() ?
'l' : 'r';
1061 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1065 * Generate HTML for a down-facing arrow
1066 * depending on language direction.
1067 * @return String: HTML <img> tag
1069 protected function downArrow() {
1070 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1074 * Generate HTML for a spacer image
1075 * @return String: HTML <img> tag
1077 protected function spacerArrow() {
1078 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1082 * Enhanced RC ungrouped line.
1084 * @param $rcObj RecentChange
1085 * @return String: a HTML formatted line (generated using $r)
1087 protected function recentChangesBlockLine( $rcObj ) {
1088 global $wgRCShowChangedSize;
1090 wfProfileIn( __METHOD__
);
1091 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1093 $type = $rcObj->mAttribs
['rc_type'];
1094 $logType = $rcObj->mAttribs
['rc_log_type'];
1097 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1099 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1101 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1102 Html
::openElement( 'tr' );
1104 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1105 # Flag and Timestamp
1106 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1107 $r .= '    '; // 4 flags -> 4 spaces
1109 $r .= $this->recentChangesFlags( array(
1110 'newpage' => $type == RC_NEW
,
1111 'minor' => $rcObj->mAttribs
['rc_minor'],
1112 'unpatrolled' => $rcObj->unpatrolled
,
1113 'bot' => $rcObj->mAttribs
['rc_bot'],
1116 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1117 # Article or log link
1119 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1120 $logname = LogPage
::logName( $logType );
1121 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1123 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1125 # Diff and hist links
1126 if ( $type != RC_LOG
) {
1127 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1128 $query['action'] = 'history';
1129 $r .= Linker
::linkKnown(
1131 $this->message
['hist'],
1138 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1142 if ( $type == RC_LOG
) {
1143 $r .= $this->insertLogEntry( $rcObj );
1145 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1146 $r .= $this->insertComment( $rcObj );
1147 $r .= $this->insertRollback( $r, $rcObj );
1151 $classes = explode( ' ', $classes );
1152 $this->insertTags( $r, $rcObj, $classes );
1153 # Show how many people are watching this if enabled
1154 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1156 $r .= "</td></tr></table>\n";
1158 wfProfileOut( __METHOD__
);
1164 * If enhanced RC is in use, this function takes the previously cached
1165 * RC lines, arranges them, and outputs the HTML
1169 protected function recentChangesBlock() {
1170 if( count ( $this->rc_cache
) == 0 ) {
1174 wfProfileIn( __METHOD__
);
1177 foreach( $this->rc_cache
as $block ) {
1178 if( count( $block ) < 2 ) {
1179 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1181 $blockOut .= $this->recentChangesBlockGroup( $block );
1185 wfProfileOut( __METHOD__
);
1187 return '<div>'.$blockOut.'</div>';
1191 * Returns text for the end of RC
1192 * If enhanced RC is in use, returns pretty much all the text
1194 public function endRecentChangesList() {
1195 return $this->recentChangesBlock() . parent
::endRecentChangesList();