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 return Html
::element( $tag,
220 array( 'dir' => 'ltr', 'class' => $formattedSizeClass ),
221 wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark();
225 * Returns text for the end of RC
228 public function endRecentChangesList() {
229 if( $this->rclistOpen
) {
236 public function insertDateHeader( &$s, $rc_timestamp ) {
237 # Make date header if necessary
238 $date = $this->getLanguage()->date( $rc_timestamp, true, true );
239 if( $date != $this->lastdate
) {
240 if( $this->lastdate
!= '' ) {
243 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
244 $this->lastdate
= $date;
245 $this->rclistOpen
= true;
249 public function insertLog( &$s, $title, $logtype ) {
250 $page = new LogPage( $logtype );
251 $logname = $page->getName()->escaped();
252 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
257 * @param $rc RecentChange
258 * @param $unpatrolled
261 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
263 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
264 $diffLink = $this->message
['diff'];
265 } elseif ( !self
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
266 $diffLink = $this->message
['diff'];
269 'curid' => $rc->mAttribs
['rc_cur_id'],
270 'diff' => $rc->mAttribs
['rc_this_oldid'],
271 'oldid' => $rc->mAttribs
['rc_last_oldid']
275 $query['rcid'] = $rc->mAttribs
['rc_id'];
278 $diffLink = Linker
::linkKnown(
280 $this->message
['diff'],
281 array( 'tabindex' => $rc->counter
),
285 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
287 $s .= Linker
::linkKnown(
289 $this->message
['hist'],
292 'curid' => $rc->mAttribs
['rc_cur_id'],
293 'action' => 'history'
301 * @param $rc RecentChange
302 * @param $unpatrolled
306 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
307 # If it's a new article, there is no diff link, but if it hasn't been
308 # patrolled yet, we need to give users a way to do so
311 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
312 $params['rcid'] = $rc->mAttribs
['rc_id'];
315 $articlelink = Linker
::linkKnown(
321 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
322 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
324 # Bolden pages watched by this user
326 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
329 $articlelink .= $this->getLanguage()->getDirMark();
331 wfRunHooks( 'ChangesListInsertArticleLink',
332 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
334 $s .= " $articlelink";
339 * @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'], $rc->mAttribs
['rc_user_text'] );
356 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
360 /** insert a formatted action
362 * @param $rc RecentChange
364 public function insertLogEntry( $rc ) {
365 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
366 $formatter->setShowUserToolLinks( true );
367 $mark = $this->getLanguage()->getDirMark();
368 return $formatter->getActionText() . " $mark" . $formatter->getComment();
372 * Insert a formatted comment
373 * @param $rc RecentChange
375 public function insertComment( $rc ) {
376 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
377 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
378 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
380 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
386 * Check whether to enable recent changes patrol features
389 public static function usePatrol() {
391 return $wgUser->useRCPatrol();
395 * Returns the string which indicates the number of watching users
397 protected function numberofWatchingusers( $count ) {
398 static $cache = array();
400 if( !isset( $cache[$count] ) ) {
401 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
402 array('parsemag', 'escape' ), $this->getLanguage()->formatNum( $count ) );
404 return $cache[$count];
411 * Determine if said field of a revision is hidden
412 * @param $rc RCCacheEntry
413 * @param $field Integer: one of DELETED_* bitfield constants
416 public static function isDeleted( $rc, $field ) {
417 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
421 * Determine if the current user is allowed to view a particular
422 * field of this revision, if it's marked as deleted.
423 * @param $rc RCCacheEntry
424 * @param $field Integer
425 * @param $user User object to check, or null to use $wgUser
428 public static function userCan( $rc, $field, User
$user = null ) {
429 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
430 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
432 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
436 protected function maybeWatchedLink( $link, $watched = false ) {
438 return '<strong class="mw-watched">' . $link . '</strong>';
440 return '<span class="mw-rc-unwatched">' . $link . '</span>';
444 /** Inserts a rollback link
447 * @param $rc RecentChange
449 public function insertRollback( &$s, &$rc ) {
450 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
451 $page = $rc->getTitle();
452 /** Check for rollback and edit permissions, disallow special pages, and only
453 * show a link on the top-most revision */
454 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
456 $rev = new Revision( array(
457 'id' => $rc->mAttribs
['rc_this_oldid'],
458 'user' => $rc->mAttribs
['rc_user'],
459 'user_text' => $rc->mAttribs
['rc_user_text'],
460 'deleted' => $rc->mAttribs
['rc_deleted']
462 $rev->setTitle( $page );
463 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
470 * @param $rc RecentChange
474 public function insertTags( &$s, &$rc, &$classes ) {
475 if ( empty($rc->mAttribs
['ts_tags']) )
478 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
479 $classes = array_merge( $classes, $newClasses );
480 $s .= ' ' . $tagSummary;
483 public function insertExtra( &$s, &$rc, &$classes ) {
484 ## Empty, used for subclassers to add anything special.
487 protected function showAsUnpatrolled( RecentChange
$rc ) {
488 $unpatrolled = false;
489 if ( !$rc->mAttribs
['rc_patrolled'] ) {
490 if ( $this->getUser()->useRCPatrol() ) {
492 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs
['rc_new'] ) {
502 * Generate a list of changes using the good old system (no javascript)
504 class OldChangesList
extends ChangesList
{
506 * Format a line using the old system (aka without any javascript).
508 * @param $rc RecentChange
510 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
511 global $wgRCShowChangedSize;
512 wfProfileIn( __METHOD__
);
514 # Should patrol-related stuff be shown?
515 $unpatrolled = $this->showAsUnpatrolled( $rc );
517 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
518 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
522 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
524 if( $linenumber & 1 ) {
525 $classes[] = 'mw-line-odd';
528 $classes[] = 'mw-line-even';
532 // Moved pages (very very old, not supported anymore)
533 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
535 } elseif( $rc->mAttribs
['rc_log_type'] ) {
536 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
537 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
538 // Log entries (old format) or log targets, and special pages
539 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
540 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
541 if( $name == 'Log' ) {
542 $this->insertLog( $s, $rc->getTitle(), $subpage );
546 $this->insertDiffHist( $s, $rc, $unpatrolled );
547 # M, N, b and ! (minor, new, bot and unpatrolled)
548 $s .= $this->recentChangesFlags(
550 'newpage' => $rc->mAttribs
['rc_new'],
551 'minor' => $rc->mAttribs
['rc_minor'],
552 'unpatrolled' => $unpatrolled,
553 'bot' => $rc->mAttribs
['rc_bot']
557 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
560 $this->insertTimestamp( $s, $rc );
561 # Bytes added or removed
562 if( $wgRCShowChangedSize ) {
563 $cd = $rc->getCharacterDifference();
569 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
570 $s .= $this->insertLogEntry( $rc );
573 $this->insertUserRelatedLinks( $s, $rc );
574 # LTR/RTL direction mark
575 $s .= $this->getLanguage()->getDirMark();
576 $s .= $this->insertComment( $rc );
580 $this->insertTags( $s, $rc, $classes );
582 $this->insertRollback( $s, $rc );
584 $this->insertExtra( $s, $rc, $classes );
586 # How many users watch this page
587 if( $rc->numberofWatchingusers
> 0 ) {
588 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
589 array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $rc->numberofWatchingusers
) );
592 if( $this->watchlist
) {
593 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
596 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
598 wfProfileOut( __METHOD__
);
599 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
605 * Generate a list of changes using an Enhanced system (uses javascript).
607 class EnhancedChangesList
extends ChangesList
{
609 * Add the JavaScript file for enhanced changeslist
612 public function beginRecentChangesList() {
613 $this->rc_cache
= array();
614 $this->rcMoveIndex
= 0;
615 $this->rcCacheIndex
= 0;
616 $this->lastdate
= '';
617 $this->rclistOpen
= false;
618 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
622 * Format a line for enhanced recentchange (aka with javascript and block of lines).
624 * @param $baseRC RecentChange
625 * @param $watched bool
629 public function recentChangesLine( &$baseRC, $watched = false ) {
630 wfProfileIn( __METHOD__
);
632 # Create a specialised object
633 $rc = RCCacheEntry
::newFromParent( $baseRC );
635 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
637 # If it's a new day, add the headline and flush the cache
638 $date = $this->getLanguage()->date( $rc->mAttribs
['rc_timestamp'], true );
640 if( $date != $this->lastdate
) {
641 # Process current cache
642 $ret = $this->recentChangesBlock();
643 $this->rc_cache
= array();
644 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
645 $this->lastdate
= $date;
648 # Should patrol-related stuff be shown?
649 $rc->unpatrolled
= $this->showAsUnpatrolled( $rc );
651 $showdifflinks = true;
653 $type = $rc->mAttribs
['rc_type'];
654 $logType = $rc->mAttribs
['rc_log_type'];
655 // Page moves, very old style, not supported anymore
656 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
657 // New unpatrolled pages
658 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
659 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
660 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
662 } elseif( $type == RC_LOG
) {
664 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
665 $clink = '(' . Linker
::linkKnown( $logtitle,
666 LogPage
::logName( $logType ) ) . ')';
668 $clink = Linker
::link( $rc->getTitle() );
671 // Log entries (old format) and special pages
672 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
673 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
674 if ( $specialName == 'Log' ) {
676 $logname = LogPage
::logName( $logtype );
677 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
679 wfDebug( "Unexpected special page in recentchanges\n" );
684 $clink = Linker
::linkKnown( $rc->getTitle() );
687 # Don't show unusable diff links
688 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
689 $showdifflinks = false;
692 $time = $this->getLanguage()->time( $rc->mAttribs
['rc_timestamp'], true, true );
693 $rc->watched
= $watched;
695 $rc->timestamp
= $time;
696 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
698 # Make "cur" and "diff" links. Do not use link(), it is too slow if
699 # called too many times (50% of CPU time on RecentChanges!).
700 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
701 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
702 if( $rc->unpatrolled
) {
703 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
705 $rcIdQuery = array();
707 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
708 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
709 $lastOldid ) +
$rcIdQuery;
711 if( !$showdifflinks ) {
712 $curLink = $this->message
['cur'];
713 $diffLink = $this->message
['diff'];
714 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
715 if ( $type != RC_NEW
) {
716 $curLink = $this->message
['cur'];
718 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
719 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
721 $diffLink = $this->message
['diff'];
723 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
724 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
725 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
726 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
730 if( !$showdifflinks ||
!$lastOldid ) {
731 $lastLink = $this->message
['last'];
732 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
733 $lastLink = $this->message
['last'];
735 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
736 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
740 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
741 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
743 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
744 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
747 $rc->lastlink
= $lastLink;
748 $rc->curlink
= $curLink;
749 $rc->difflink
= $diffLink;
751 # Put accumulated information into the cache, for later display
752 # Page moves go on their own line
753 $title = $rc->getTitle();
754 $secureName = $title->getPrefixedDBkey();
755 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
756 # Use an @ character to prevent collision with page names
757 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
759 # Logs are grouped by type
760 if( $type == RC_LOG
){
761 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
763 if( !isset( $this->rc_cache
[$secureName] ) ) {
764 $this->rc_cache
[$secureName] = array();
767 array_push( $this->rc_cache
[$secureName], $rc );
770 wfProfileOut( __METHOD__
);
778 protected function recentChangesBlockGroup( $block ) {
779 global $wgRCShowChangedSize;
781 wfProfileIn( __METHOD__
);
783 # Add the namespace and title of the block as part of the class
784 if ( $block[0]->mAttribs
['rc_log_type'] ) {
786 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
788 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
790 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
791 Html
::openElement( 'tr' );
793 # Collate list of users
794 $userlinks = array();
796 $unpatrolled = false;
798 $curId = $currentRevision = 0;
799 # Some catalyst variables...
802 foreach( $block as $rcObj ) {
803 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
804 if( $rcObj->mAttribs
['rc_new'] ) {
807 // If all log actions to this page were hidden, then don't
808 // give the name of the affected page for this block!
809 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
812 $u = $rcObj->userlink
;
813 if( !isset( $userlinks[$u] ) ) {
816 if( $rcObj->unpatrolled
) {
819 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
822 # Get the latest entry with a page_id and oldid
823 # since logs may not have these.
824 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
825 $curId = $rcObj->mAttribs
['rc_cur_id'];
827 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
828 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
831 $bot = $rcObj->mAttribs
['rc_bot'];
835 # Sort the list and convert to text
836 krsort( $userlinks );
839 foreach( $userlinks as $userlink => $count) {
841 $text .= $this->getLanguage()->getDirMark();
843 $text .= ' (' . $this->getLanguage()->formatNum( $count ) . '×)';
845 array_push( $users, $text );
848 $users = ' <span class="changedby">[' .
849 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
852 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
853 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
855 $tl = "<span class='mw-collapsible-toggle'>"
856 . "<span class='mw-rc-openarrow'>"
857 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
858 . "</span><span class='mw-rc-closearrow'>"
859 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
861 $r .= "<td>$tl</td>";
864 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
867 'unpatrolled' => $unpatrolled,
872 $r .= ' '.$block[0]->timestamp
.' </td><td>';
876 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
877 } elseif( $allLogs ) {
878 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
880 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
883 $r .= $this->getLanguage()->getDirMark();
885 $queryParams['curid'] = $curId;
888 static $nchanges = array();
889 if ( !isset( $nchanges[$n] ) ) {
890 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) );
896 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
901 $params = $queryParams;
902 $params['diff'] = $currentRevision;
903 $params['oldid'] = $oldid;
906 $block[0]->getTitle(),
910 array( 'known', 'noclasses' )
917 // don't show history link for logs
918 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
919 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
921 $params = $queryParams;
922 $params['action'] = 'history';
924 $r .= $this->message
['pipe-separator'] .
926 $block[0]->getTitle(),
927 $this->message
['hist'],
934 # Character difference (does not apply if only log items)
935 if( $wgRCShowChangedSize && !$allLogs ) {
937 $first = count($block) - 1;
938 # Some events (like logs) have an "empty" size, so we need to skip those...
939 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
942 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
946 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
947 $block[$last]->mAttribs
['rc_new_len'] );
949 if( $chardiff == '' ) {
952 $r .= ' ' . $chardiff. ' . . ';
957 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
960 foreach( $block as $rcObj ) {
961 # Classes to apply -- TODO implement
963 $type = $rcObj->mAttribs
['rc_type'];
965 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
966 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
967 $r .= $this->recentChangesFlags( array(
968 'newpage' => $rcObj->mAttribs
['rc_new'],
969 'minor' => $rcObj->mAttribs
['rc_minor'],
970 'unpatrolled' => $rcObj->unpatrolled
,
971 'bot' => $rcObj->mAttribs
['rc_bot'],
973 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
975 $params = $queryParams;
977 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
978 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
982 if( $type == RC_LOG
) {
983 $link = $rcObj->timestamp
;
985 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
986 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
988 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
989 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
992 $link = Linker
::linkKnown(
998 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
999 $link = '<span class="history-deleted">'.$link.'</span> ';
1001 $r .= $link . '</span>';
1003 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1005 $r .= $rcObj->curlink
;
1006 $r .= $this->message
['pipe-separator'];
1007 $r .= $rcObj->lastlink
;
1013 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1014 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1017 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1018 $r .= $this->insertLogEntry( $rcObj );
1021 $r .= $rcObj->userlink
;
1022 $r .= $rcObj->usertalklink
;
1023 $r .= $this->insertComment( $rcObj );
1027 $this->insertRollback( $r, $rcObj );
1029 $this->insertTags( $r, $rcObj, $classes );
1031 $r .= "</td></tr>\n";
1035 $this->rcCacheIndex++
;
1037 wfProfileOut( __METHOD__
);
1043 * Generate HTML for an arrow or placeholder graphic
1044 * @param $dir String: one of '', 'd', 'l', 'r'
1045 * @param $alt String: text
1046 * @param $title String: text
1047 * @return String: HTML <img> tag
1049 protected function arrow( $dir, $alt='', $title='' ) {
1050 global $wgStylePath;
1051 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1052 $encAlt = htmlspecialchars( $alt );
1053 $encTitle = htmlspecialchars( $title );
1054 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1058 * Generate HTML for a right- or left-facing arrow,
1059 * depending on language direction.
1060 * @return String: HTML <img> tag
1062 protected function sideArrow() {
1064 $dir = $wgLang->isRTL() ?
'l' : 'r';
1065 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1069 * Generate HTML for a down-facing arrow
1070 * depending on language direction.
1071 * @return String: HTML <img> tag
1073 protected function downArrow() {
1074 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1078 * Generate HTML for a spacer image
1079 * @return String: HTML <img> tag
1081 protected function spacerArrow() {
1082 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1086 * Enhanced RC ungrouped line.
1088 * @param $rcObj RecentChange
1089 * @return String: a HTML formatted line (generated using $r)
1091 protected function recentChangesBlockLine( $rcObj ) {
1092 global $wgRCShowChangedSize;
1094 wfProfileIn( __METHOD__
);
1095 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1097 $type = $rcObj->mAttribs
['rc_type'];
1098 $logType = $rcObj->mAttribs
['rc_log_type'];
1101 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1103 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1105 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1106 Html
::openElement( 'tr' );
1108 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1109 # Flag and Timestamp
1110 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1111 $r .= '    '; // 4 flags -> 4 spaces
1113 $r .= $this->recentChangesFlags( array(
1114 'newpage' => $type == RC_NEW
,
1115 'minor' => $rcObj->mAttribs
['rc_minor'],
1116 'unpatrolled' => $rcObj->unpatrolled
,
1117 'bot' => $rcObj->mAttribs
['rc_bot'],
1120 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1121 # Article or log link
1123 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1124 $logname = LogPage
::logName( $logType );
1125 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1127 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1129 # Diff and hist links
1130 if ( $type != RC_LOG
) {
1131 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1132 $query['action'] = 'history';
1133 $r .= Linker
::linkKnown(
1135 $this->message
['hist'],
1142 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1146 if ( $type == RC_LOG
) {
1147 $r .= $this->insertLogEntry( $rcObj );
1149 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1150 $r .= $this->insertComment( $rcObj );
1151 $r .= $this->insertRollback( $r, $rcObj );
1155 $classes = explode( ' ', $classes );
1156 $this->insertTags( $r, $rcObj, $classes );
1157 # Show how many people are watching this if enabled
1158 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1160 $r .= "</td></tr></table>\n";
1162 wfProfileOut( __METHOD__
);
1168 * If enhanced RC is in use, this function takes the previously cached
1169 * RC lines, arranges them, and outputs the HTML
1173 protected function recentChangesBlock() {
1174 if( count ( $this->rc_cache
) == 0 ) {
1178 wfProfileIn( __METHOD__
);
1181 foreach( $this->rc_cache
as $block ) {
1182 if( count( $block ) < 2 ) {
1183 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1185 $blockOut .= $this->recentChangesBlockGroup( $block );
1189 wfProfileOut( __METHOD__
);
1191 return '<div>'.$blockOut.'</div>';
1195 * Returns text for the end of RC
1196 * If enhanced RC is in use, returns pretty much all the text
1198 public function endRecentChangesList() {
1199 return $this->recentChangesBlock() . parent
::endRecentChangesList();