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 "($formattedSize)" );
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->getLang()->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->getLang()->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->getLang()->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->getLang()->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->getLang()->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->getLang()->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.
490 * Generate a list of changes using the good old system (no javascript)
492 class OldChangesList
extends ChangesList
{
494 * Format a line using the old system (aka without any javascript).
496 * @param $rc RecentChange
498 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
499 global $wgRCShowChangedSize;
500 wfProfileIn( __METHOD__
);
501 # Should patrol-related stuff be shown?
502 $unpatrolled = $this->getUser()->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
504 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
505 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
509 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
511 if( $linenumber & 1 ) {
512 $classes[] = 'mw-line-odd';
515 $classes[] = 'mw-line-even';
519 // Moved pages (very very old, not supported anymore)
520 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
522 } elseif( $rc->mAttribs
['rc_log_type'] ) {
523 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
524 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
525 // Log entries (old format) or log targets, and special pages
526 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
527 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
528 if( $name == 'Log' ) {
529 $this->insertLog( $s, $rc->getTitle(), $subpage );
533 $this->insertDiffHist( $s, $rc, $unpatrolled );
534 # M, N, b and ! (minor, new, bot and unpatrolled)
535 $s .= $this->recentChangesFlags(
537 'newpage' => $rc->mAttribs
['rc_new'],
538 'minor' => $rc->mAttribs
['rc_minor'],
539 'unpatrolled' => $unpatrolled,
540 'bot' => $rc->mAttribs
['rc_bot']
544 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
547 $this->insertTimestamp( $s, $rc );
548 # Bytes added or removed
549 if( $wgRCShowChangedSize ) {
550 $cd = $rc->getCharacterDifference();
556 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
557 $s .= $this->insertLogEntry( $rc );
560 $this->insertUserRelatedLinks( $s, $rc );
561 # LTR/RTL direction mark
562 $s .= $this->getLang()->getDirMark();
563 $s .= $this->insertComment( $rc );
567 $this->insertTags( $s, $rc, $classes );
569 $this->insertRollback( $s, $rc );
571 $this->insertExtra( $s, $rc, $classes );
573 # How many users watch this page
574 if( $rc->numberofWatchingusers
> 0 ) {
575 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
576 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
579 if( $this->watchlist
) {
580 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
583 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
585 wfProfileOut( __METHOD__
);
586 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
592 * Generate a list of changes using an Enhanced system (uses javascript).
594 class EnhancedChangesList
extends ChangesList
{
596 * Add the JavaScript file for enhanced changeslist
599 public function beginRecentChangesList() {
600 $this->rc_cache
= array();
601 $this->rcMoveIndex
= 0;
602 $this->rcCacheIndex
= 0;
603 $this->lastdate
= '';
604 $this->rclistOpen
= false;
605 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
609 * Format a line for enhanced recentchange (aka with javascript and block of lines).
611 * @param $baseRC RecentChange
612 * @param $watched bool
616 public function recentChangesLine( &$baseRC, $watched = false ) {
617 wfProfileIn( __METHOD__
);
619 # Create a specialised object
620 $rc = RCCacheEntry
::newFromParent( $baseRC );
622 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
624 # If it's a new day, add the headline and flush the cache
625 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
627 if( $date != $this->lastdate
) {
628 # Process current cache
629 $ret = $this->recentChangesBlock();
630 $this->rc_cache
= array();
631 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
632 $this->lastdate
= $date;
635 # Should patrol-related stuff be shown?
636 if( $this->getUser()->useRCPatrol() ) {
637 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
639 $rc->unpatrolled
= false;
642 $showdifflinks = true;
644 $type = $rc->mAttribs
['rc_type'];
645 $logType = $rc->mAttribs
['rc_log_type'];
646 // Page moves, very old style, not supported anymore
647 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
648 // New unpatrolled pages
649 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
650 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
651 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
653 } elseif( $type == RC_LOG
) {
655 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
656 $clink = '(' . Linker
::linkKnown( $logtitle,
657 LogPage
::logName( $logType ) ) . ')';
659 $clink = Linker
::link( $rc->getTitle() );
662 // Log entries (old format) and special pages
663 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
664 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
665 if ( $specialName == 'Log' ) {
667 $logname = LogPage
::logName( $logtype );
668 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
670 wfDebug( "Unexpected special page in recentchanges\n" );
675 $clink = Linker
::linkKnown( $rc->getTitle() );
678 # Don't show unusable diff links
679 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
680 $showdifflinks = false;
683 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
684 $rc->watched
= $watched;
686 $rc->timestamp
= $time;
687 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
689 # Make "cur" and "diff" links. Do not use link(), it is too slow if
690 # called too many times (50% of CPU time on RecentChanges!).
691 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
692 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
693 if( $rc->unpatrolled
) {
694 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
696 $rcIdQuery = array();
698 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
699 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
700 $lastOldid ) +
$rcIdQuery;
702 if( !$showdifflinks ) {
703 $curLink = $this->message
['cur'];
704 $diffLink = $this->message
['diff'];
705 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
706 if ( $type != RC_NEW
) {
707 $curLink = $this->message
['cur'];
709 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
710 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
712 $diffLink = $this->message
['diff'];
714 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
715 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
716 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
717 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
721 if( !$showdifflinks ||
!$lastOldid ) {
722 $lastLink = $this->message
['last'];
723 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
724 $lastLink = $this->message
['last'];
726 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
727 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
731 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
732 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
734 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
735 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
738 $rc->lastlink
= $lastLink;
739 $rc->curlink
= $curLink;
740 $rc->difflink
= $diffLink;
742 # Put accumulated information into the cache, for later display
743 # Page moves go on their own line
744 $title = $rc->getTitle();
745 $secureName = $title->getPrefixedDBkey();
746 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
747 # Use an @ character to prevent collision with page names
748 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
750 # Logs are grouped by type
751 if( $type == RC_LOG
){
752 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
754 if( !isset( $this->rc_cache
[$secureName] ) ) {
755 $this->rc_cache
[$secureName] = array();
758 array_push( $this->rc_cache
[$secureName], $rc );
761 wfProfileOut( __METHOD__
);
769 protected function recentChangesBlockGroup( $block ) {
770 global $wgRCShowChangedSize;
772 wfProfileIn( __METHOD__
);
774 # Add the namespace and title of the block as part of the class
775 if ( $block[0]->mAttribs
['rc_log_type'] ) {
777 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
779 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
781 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
782 Html
::openElement( 'tr' );
784 # Collate list of users
785 $userlinks = array();
787 $unpatrolled = false;
789 $curId = $currentRevision = 0;
790 # Some catalyst variables...
793 foreach( $block as $rcObj ) {
794 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
795 if( $rcObj->mAttribs
['rc_new'] ) {
798 // If all log actions to this page were hidden, then don't
799 // give the name of the affected page for this block!
800 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
803 $u = $rcObj->userlink
;
804 if( !isset( $userlinks[$u] ) ) {
807 if( $rcObj->unpatrolled
) {
810 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
813 # Get the latest entry with a page_id and oldid
814 # since logs may not have these.
815 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
816 $curId = $rcObj->mAttribs
['rc_cur_id'];
818 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
819 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
822 $bot = $rcObj->mAttribs
['rc_bot'];
826 # Sort the list and convert to text
827 krsort( $userlinks );
830 foreach( $userlinks as $userlink => $count) {
832 $text .= $this->getLang()->getDirMark();
834 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
836 array_push( $users, $text );
839 $users = ' <span class="changedby">[' .
840 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
843 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
844 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
846 $tl = "<span class='mw-collapsible-toggle'>"
847 . "<span class='mw-rc-openarrow'>"
848 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
849 . "</span><span class='mw-rc-closearrow'>"
850 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
852 $r .= "<td>$tl</td>";
855 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
858 'unpatrolled' => $unpatrolled,
863 $r .= ' '.$block[0]->timestamp
.' </td><td>';
867 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
868 } elseif( $allLogs ) {
869 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
871 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
874 $r .= $this->getLang()->getDirMark();
876 $queryParams['curid'] = $curId;
879 static $nchanges = array();
880 if ( !isset( $nchanges[$n] ) ) {
881 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
887 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
892 $params = $queryParams;
893 $params['diff'] = $currentRevision;
894 $params['oldid'] = $oldid;
897 $block[0]->getTitle(),
901 array( 'known', 'noclasses' )
908 // don't show history link for logs
909 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
910 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
912 $params = $queryParams;
913 $params['action'] = 'history';
915 $r .= $this->message
['pipe-separator'] .
917 $block[0]->getTitle(),
918 $this->message
['hist'],
925 # Character difference (does not apply if only log items)
926 if( $wgRCShowChangedSize && !$allLogs ) {
928 $first = count($block) - 1;
929 # Some events (like logs) have an "empty" size, so we need to skip those...
930 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
933 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
937 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
938 $block[$last]->mAttribs
['rc_new_len'] );
940 if( $chardiff == '' ) {
943 $r .= ' ' . $chardiff. ' . . ';
948 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
951 foreach( $block as $rcObj ) {
952 # Classes to apply -- TODO implement
954 $type = $rcObj->mAttribs
['rc_type'];
956 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
957 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
958 $r .= $this->recentChangesFlags( array(
959 'newpage' => $rcObj->mAttribs
['rc_new'],
960 'minor' => $rcObj->mAttribs
['rc_minor'],
961 'unpatrolled' => $rcObj->unpatrolled
,
962 'bot' => $rcObj->mAttribs
['rc_bot'],
964 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
966 $params = $queryParams;
968 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
969 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
973 if( $type == RC_LOG
) {
974 $link = $rcObj->timestamp
;
976 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
977 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
979 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
980 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
983 $link = Linker
::linkKnown(
989 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
990 $link = '<span class="history-deleted">'.$link.'</span> ';
992 $r .= $link . '</span>';
994 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
996 $r .= $rcObj->curlink
;
997 $r .= $this->message
['pipe-separator'];
998 $r .= $rcObj->lastlink
;
1004 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1005 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1008 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1009 $r .= $this->insertLogEntry( $rcObj );
1012 $r .= $rcObj->userlink
;
1013 $r .= $rcObj->usertalklink
;
1014 $r .= $this->insertComment( $rcObj );
1018 $this->insertRollback( $r, $rcObj );
1020 $this->insertTags( $r, $rcObj, $classes );
1022 $r .= "</td></tr>\n";
1026 $this->rcCacheIndex++
;
1028 wfProfileOut( __METHOD__
);
1034 * Generate HTML for an arrow or placeholder graphic
1035 * @param $dir String: one of '', 'd', 'l', 'r'
1036 * @param $alt String: text
1037 * @param $title String: text
1038 * @return String: HTML <img> tag
1040 protected function arrow( $dir, $alt='', $title='' ) {
1041 global $wgStylePath;
1042 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1043 $encAlt = htmlspecialchars( $alt );
1044 $encTitle = htmlspecialchars( $title );
1045 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1049 * Generate HTML for a right- or left-facing arrow,
1050 * depending on language direction.
1051 * @return String: HTML <img> tag
1053 protected function sideArrow() {
1055 $dir = $wgLang->isRTL() ?
'l' : 'r';
1056 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1060 * Generate HTML for a down-facing arrow
1061 * depending on language direction.
1062 * @return String: HTML <img> tag
1064 protected function downArrow() {
1065 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1069 * Generate HTML for a spacer image
1070 * @return String: HTML <img> tag
1072 protected function spacerArrow() {
1073 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1077 * Enhanced RC ungrouped line.
1079 * @param $rcObj RecentChange
1080 * @return String: a HTML formatted line (generated using $r)
1082 protected function recentChangesBlockLine( $rcObj ) {
1083 global $wgRCShowChangedSize;
1085 wfProfileIn( __METHOD__
);
1086 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1088 $type = $rcObj->mAttribs
['rc_type'];
1089 $logType = $rcObj->mAttribs
['rc_log_type'];
1092 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1094 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1096 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1097 Html
::openElement( 'tr' );
1099 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1100 # Flag and Timestamp
1101 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1102 $r .= '    '; // 4 flags -> 4 spaces
1104 $r .= $this->recentChangesFlags( array(
1105 'newpage' => $type == RC_NEW
,
1106 'mino' => $rcObj->mAttribs
['rc_minor'],
1107 'unpatrolled' => $rcObj->unpatrolled
,
1108 'bot' => $rcObj->mAttribs
['rc_bot'],
1111 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1112 # Article or log link
1114 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1115 $logname = LogPage
::logName( $logType );
1116 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1118 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1120 # Diff and hist links
1121 if ( $type != RC_LOG
) {
1122 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1123 $query['action'] = 'history';
1124 $r .= Linker
::linkKnown(
1126 $this->message
['hist'],
1133 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1137 if ( $type == RC_LOG
) {
1138 $r .= $this->insertLogEntry( $rcObj );
1140 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1141 $r .= $this->insertComment( $rcObj );
1142 $r .= $this->insertRollback( $r, $rcObj );
1146 $classes = explode( ' ', $classes );
1147 $this->insertTags( $r, $rcObj, $classes );
1148 # Show how many people are watching this if enabled
1149 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1151 $r .= "</td></tr></table>\n";
1153 wfProfileOut( __METHOD__
);
1159 * If enhanced RC is in use, this function takes the previously cached
1160 * RC lines, arranges them, and outputs the HTML
1164 protected function recentChangesBlock() {
1165 if( count ( $this->rc_cache
) == 0 ) {
1169 wfProfileIn( __METHOD__
);
1172 foreach( $this->rc_cache
as $block ) {
1173 if( count( $block ) < 2 ) {
1174 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1176 $blockOut .= $this->recentChangesBlockGroup( $block );
1180 wfProfileOut( __METHOD__
);
1182 return '<div>'.$blockOut.'</div>';
1186 * Returns text for the end of RC
1187 * If enhanced RC is in use, returns pretty much all the text
1189 public function endRecentChangesList() {
1190 return $this->recentChangesBlock() . parent
::endRecentChangesList();