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 RequestContext
50 public function __construct( $obj ) {
51 if ( $obj instanceof RequestContext
) {
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.19; 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 RequestContext to use
78 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
80 public static function newFromContext( RequestContext
$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 $formatedSize = $wgLang->formatNum($szdiff);
198 if ( !$fastCharDiff[$code] ) {
199 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
202 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
207 if( $szdiff === 0 ) {
208 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
209 } elseif( $szdiff > 0 ) {
210 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
212 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
217 * Returns text for the end of RC
220 public function endRecentChangesList() {
221 if( $this->rclistOpen
) {
230 * @param $rc RecentChange
233 public function insertMove( &$s, $rc ) {
235 $s .= '(' . $this->message
['diff'] . ') (';
237 $s .= Linker
::linkKnown(
238 $rc->getMovedToTitle(),
239 $this->message
['hist'],
241 array( 'action' => 'history' )
243 # "[[x]] moved to [[y]]"
244 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
251 array( 'redirect' => 'no' )
253 Linker
::linkKnown( $rc->getMovedToTitle() )
257 public function insertDateHeader( &$s, $rc_timestamp ) {
258 # Make date header if necessary
259 $date = $this->getLang()->date( $rc_timestamp, true, true );
260 if( $date != $this->lastdate
) {
261 if( $this->lastdate
!= '' ) {
264 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
265 $this->lastdate
= $date;
266 $this->rclistOpen
= true;
270 public function insertLog( &$s, $title, $logtype ) {
271 $logname = LogPage
::logName( $logtype );
272 $s .= '(' . Linker
::linkKnown( $title, htmlspecialchars( $logname ) ) . ')';
277 * @param $rc RecentChange
278 * @param $unpatrolled
281 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
283 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
284 $diffLink = $this->message
['diff'];
285 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
286 $diffLink = $this->message
['diff'];
289 'curid' => $rc->mAttribs
['rc_cur_id'],
290 'diff' => $rc->mAttribs
['rc_this_oldid'],
291 'oldid' => $rc->mAttribs
['rc_last_oldid']
295 $query['rcid'] = $rc->mAttribs
['rc_id'];
298 $diffLink = Linker
::linkKnown(
300 $this->message
['diff'],
301 array( 'tabindex' => $rc->counter
),
305 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
307 $s .= Linker
::linkKnown(
309 $this->message
['hist'],
312 'curid' => $rc->mAttribs
['rc_cur_id'],
313 'action' => 'history'
321 * @param $rc RecentChange
322 * @param $unpatrolled
326 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
327 # If it's a new article, there is no diff link, but if it hasn't been
328 # patrolled yet, we need to give users a way to do so
331 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
332 $params['rcid'] = $rc->mAttribs
['rc_id'];
335 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
336 $articlelink = Linker
::linkKnown(
342 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
344 $articlelink = ' '. Linker
::linkKnown(
351 # Bolden pages watched by this user
353 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
356 $articlelink .= $this->getLang()->getDirMark();
358 wfRunHooks( 'ChangesListInsertArticleLink',
359 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
361 $s .= " $articlelink";
366 * @param $rc RecentChange
369 public function insertTimestamp( &$s, $rc ) {
370 $s .= $this->message
['semicolon-separator'] .
371 $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
374 /** Insert links to user page, user talk page and eventually a blocking link
376 * @param $rc RecentChange
378 public function insertUserRelatedLinks( &$s, &$rc ) {
379 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
380 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
382 $s .= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
383 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
387 /** insert a formatted action
389 * @param $rc RecentChange
391 public function insertAction( &$s, &$rc ) {
392 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
393 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
394 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
396 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
397 $rc->getTitle(), $this->getSkin(), LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
402 /** insert a formatted comment
404 * @param $rc RecentChange
406 public function insertComment( &$s, &$rc ) {
407 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
408 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
409 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
411 $s .= Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
417 * Check whether to enable recent changes patrol features
420 public static function usePatrol() {
422 return $wgUser->useRCPatrol();
426 * Returns the string which indicates the number of watching users
428 protected function numberofWatchingusers( $count ) {
429 static $cache = array();
431 if( !isset( $cache[$count] ) ) {
432 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
433 array('parsemag', 'escape' ), $this->getLang()->formatNum( $count ) );
435 return $cache[$count];
442 * Determine if said field of a revision is hidden
443 * @param $rc RCCacheEntry
444 * @param $field Integer: one of DELETED_* bitfield constants
447 public static function isDeleted( $rc, $field ) {
448 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
452 * Determine if the current user is allowed to view a particular
453 * field of this revision, if it's marked as deleted.
454 * @param $rc RCCacheEntry
455 * @param $field Integer
458 public static function userCan( $rc, $field ) {
459 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
460 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
462 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
466 protected function maybeWatchedLink( $link, $watched = false ) {
468 return '<strong class="mw-watched">' . $link . '</strong>';
470 return '<span class="mw-rc-unwatched">' . $link . '</span>';
474 /** Inserts a rollback link
477 * @param $rc RecentChange
479 public function insertRollback( &$s, &$rc ) {
480 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
481 $page = $rc->getTitle();
482 /** Check for rollback and edit permissions, disallow special pages, and only
483 * show a link on the top-most revision */
484 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
486 $rev = new Revision( array(
487 'id' => $rc->mAttribs
['rc_this_oldid'],
488 'user' => $rc->mAttribs
['rc_user'],
489 'user_text' => $rc->mAttribs
['rc_user_text'],
490 'deleted' => $rc->mAttribs
['rc_deleted']
492 $rev->setTitle( $page );
493 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
500 * @param $rc RecentChange
504 public function insertTags( &$s, &$rc, &$classes ) {
505 if ( empty($rc->mAttribs
['ts_tags']) )
508 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
509 $classes = array_merge( $classes, $newClasses );
510 $s .= ' ' . $tagSummary;
513 public function insertExtra( &$s, &$rc, &$classes ) {
514 ## Empty, used for subclassers to add anything special.
520 * Generate a list of changes using the good old system (no javascript)
522 class OldChangesList
extends ChangesList
{
524 * Format a line using the old system (aka without any javascript).
526 * @param $rc RecentChange
528 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
529 global $wgRCShowChangedSize;
530 wfProfileIn( __METHOD__
);
531 # Should patrol-related stuff be shown?
532 $unpatrolled = $this->getUser()->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
534 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
535 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
539 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
541 if( $linenumber & 1 ) {
542 $classes[] = 'mw-line-odd';
545 $classes[] = 'mw-line-even';
550 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
551 $this->insertMove( $s, $rc );
553 } elseif( $rc->mAttribs
['rc_log_type'] ) {
554 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
555 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
556 // Log entries (old format) or log targets, and special pages
557 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
558 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
559 if( $name == 'Log' ) {
560 $this->insertLog( $s, $rc->getTitle(), $subpage );
564 $this->insertDiffHist( $s, $rc, $unpatrolled );
565 # M, N, b and ! (minor, new, bot and unpatrolled)
566 $s .= $this->recentChangesFlags(
568 'newpage' => $rc->mAttribs
['rc_new'],
569 'minor' => $rc->mAttribs
['rc_minor'],
570 'unpatrolled' => $unpatrolled,
571 'bot' => $rc->mAttribs
['rc_bot']
575 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
578 $this->insertTimestamp( $s, $rc );
579 # Bytes added or removed
580 if( $wgRCShowChangedSize ) {
581 $cd = $rc->getCharacterDifference();
587 $this->insertUserRelatedLinks( $s, $rc );
588 # LTR/RTL direction mark
589 $s .= $this->getLang()->getDirMark();
590 # Log action text (if any)
591 $this->insertAction( $s, $rc );
592 # Edit or log comment
593 $this->insertComment( $s, $rc );
595 $this->insertTags( $s, $rc, $classes );
597 $this->insertRollback( $s, $rc );
599 $this->insertExtra( $s, $rc, $classes );
601 # How many users watch this page
602 if( $rc->numberofWatchingusers
> 0 ) {
603 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
604 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
607 if( $this->watchlist
) {
608 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
611 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
613 wfProfileOut( __METHOD__
);
614 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
620 * Generate a list of changes using an Enhanced system (uses javascript).
622 class EnhancedChangesList
extends ChangesList
{
624 * Add the JavaScript file for enhanced changeslist
627 public function beginRecentChangesList() {
628 $this->rc_cache
= array();
629 $this->rcMoveIndex
= 0;
630 $this->rcCacheIndex
= 0;
631 $this->lastdate
= '';
632 $this->rclistOpen
= false;
633 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
637 * Format a line for enhanced recentchange (aka with javascript and block of lines).
639 * @param $baseRC RecentChange
640 * @param $watched bool
644 public function recentChangesLine( &$baseRC, $watched = false ) {
645 wfProfileIn( __METHOD__
);
647 # Create a specialised object
648 $rc = RCCacheEntry
::newFromParent( $baseRC );
650 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
652 # If it's a new day, add the headline and flush the cache
653 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
655 if( $date != $this->lastdate
) {
656 # Process current cache
657 $ret = $this->recentChangesBlock();
658 $this->rc_cache
= array();
659 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
660 $this->lastdate
= $date;
663 # Should patrol-related stuff be shown?
664 if( $this->getUser()->useRCPatrol() ) {
665 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
667 $rc->unpatrolled
= false;
670 $showdifflinks = true;
672 $type = $rc->mAttribs
['rc_type'];
673 $logType = $rc->mAttribs
['rc_log_type'];
675 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
676 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
677 $clink = wfMsg( $msg, Linker
::linkKnown( $rc->getTitle(), null,
678 array(), array( 'redirect' => 'no' ) ),
679 Linker
::linkKnown( $rc->getMovedToTitle() ) );
680 // New unpatrolled pages
681 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
682 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
683 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
685 } elseif( $type == RC_LOG
) {
687 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
688 $clink = '(' . Linker
::linkKnown( $logtitle,
689 LogPage
::logName( $logType ) ) . ')';
691 $clink = Linker
::link( $rc->getTitle() );
694 // Log entries (old format) and special pages
695 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
696 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
697 if ( $specialName == 'Log' ) {
699 $logname = LogPage
::logName( $logtype );
700 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
702 wfDebug( "Unexpected special page in recentchanges\n" );
707 $clink = Linker
::linkKnown( $rc->getTitle() );
710 # Don't show unusable diff links
711 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
712 $showdifflinks = false;
715 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
716 $rc->watched
= $watched;
718 $rc->timestamp
= $time;
719 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
721 # Make "cur" and "diff" links. Do not use link(), it is too slow if
722 # called too many times (50% of CPU time on RecentChanges!).
723 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
724 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
725 if( $rc->unpatrolled
) {
726 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
728 $rcIdQuery = array();
730 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
731 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
732 $lastOldid ) +
$rcIdQuery;
734 if( !$showdifflinks ) {
735 $curLink = $this->message
['cur'];
736 $diffLink = $this->message
['diff'];
737 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
738 if ( $type != RC_NEW
) {
739 $curLink = $this->message
['cur'];
741 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
742 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
744 $diffLink = $this->message
['diff'];
746 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
747 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
748 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
749 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
753 if( !$showdifflinks ||
!$lastOldid ) {
754 $lastLink = $this->message
['last'];
755 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
756 $lastLink = $this->message
['last'];
758 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
759 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
763 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
764 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
766 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
767 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
770 $rc->lastlink
= $lastLink;
771 $rc->curlink
= $curLink;
772 $rc->difflink
= $diffLink;
774 # Put accumulated information into the cache, for later display
775 # Page moves go on their own line
776 $title = $rc->getTitle();
777 $secureName = $title->getPrefixedDBkey();
778 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
779 # Use an @ character to prevent collision with page names
780 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
782 # Logs are grouped by type
783 if( $type == RC_LOG
){
784 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
786 if( !isset( $this->rc_cache
[$secureName] ) ) {
787 $this->rc_cache
[$secureName] = array();
790 array_push( $this->rc_cache
[$secureName], $rc );
793 wfProfileOut( __METHOD__
);
801 protected function recentChangesBlockGroup( $block ) {
802 global $wgRCShowChangedSize;
804 wfProfileIn( __METHOD__
);
806 # Add the namespace and title of the block as part of the class
807 if ( $block[0]->mAttribs
['rc_log_type'] ) {
809 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
811 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
813 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
814 Html
::openElement( 'tr' );
816 # Collate list of users
817 $userlinks = array();
819 $unpatrolled = false;
821 $curId = $currentRevision = 0;
822 # Some catalyst variables...
825 foreach( $block as $rcObj ) {
826 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
827 if( $rcObj->mAttribs
['rc_new'] ) {
830 // If all log actions to this page were hidden, then don't
831 // give the name of the affected page for this block!
832 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
835 $u = $rcObj->userlink
;
836 if( !isset( $userlinks[$u] ) ) {
839 if( $rcObj->unpatrolled
) {
842 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
845 # Get the latest entry with a page_id and oldid
846 # since logs may not have these.
847 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
848 $curId = $rcObj->mAttribs
['rc_cur_id'];
850 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
851 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
854 $bot = $rcObj->mAttribs
['rc_bot'];
858 # Sort the list and convert to text
859 krsort( $userlinks );
862 foreach( $userlinks as $userlink => $count) {
864 $text .= $this->getLang()->getDirMark();
866 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
868 array_push( $users, $text );
871 $users = ' <span class="changedby">[' .
872 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
875 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
876 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
878 $tl = "<span class='mw-collapsible-toggle'>"
879 . "<span class='mw-rc-openarrow'>"
880 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
881 . "</span><span class='mw-rc-closearrow'>"
882 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
884 $r .= "<td>$tl</td>";
887 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
890 'unpatrolled' => $unpatrolled,
895 $r .= ' '.$block[0]->timestamp
.' </td><td>';
899 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
900 } elseif( $allLogs ) {
901 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
903 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
906 $r .= $this->getLang()->getDirMark();
908 $queryParams['curid'] = $curId;
911 static $nchanges = array();
912 if ( !isset( $nchanges[$n] ) ) {
913 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
919 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
924 $params = $queryParams;
925 $params['diff'] = $currentRevision;
926 $params['oldid'] = $oldid;
929 $block[0]->getTitle(),
933 array( 'known', 'noclasses' )
940 // don't show history link for logs
941 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
942 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
944 $params = $queryParams;
945 $params['action'] = 'history';
947 $r .= $this->message
['pipe-separator'] .
949 $block[0]->getTitle(),
950 $this->message
['hist'],
957 # Character difference (does not apply if only log items)
958 if( $wgRCShowChangedSize && !$allLogs ) {
960 $first = count($block) - 1;
961 # Some events (like logs) have an "empty" size, so we need to skip those...
962 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
965 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
969 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
970 $block[$last]->mAttribs
['rc_new_len'] );
972 if( $chardiff == '' ) {
975 $r .= ' ' . $chardiff. ' . . ';
980 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
983 foreach( $block as $rcObj ) {
984 # Classes to apply -- TODO implement
986 $type = $rcObj->mAttribs
['rc_type'];
988 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
989 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
990 $r .= $this->recentChangesFlags( array(
991 'newpage' => $rcObj->mAttribs
['rc_new'],
992 'minor' => $rcObj->mAttribs
['rc_minor'],
993 'unpatrolled' => $rcObj->unpatrolled
,
994 'bot' => $rcObj->mAttribs
['rc_bot'],
996 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
998 $params = $queryParams;
1000 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1001 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1005 if( $type == RC_LOG
) {
1006 $link = $rcObj->timestamp
;
1008 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
1009 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1011 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1012 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1015 $link = Linker
::linkKnown(
1021 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1022 $link = '<span class="history-deleted">'.$link.'</span> ';
1024 $r .= $link . '</span>';
1026 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1028 $r .= $rcObj->curlink
;
1029 $r .= $this->message
['pipe-separator'];
1030 $r .= $rcObj->lastlink
;
1036 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1037 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1041 $r .= $rcObj->userlink
;
1042 $r .= $rcObj->usertalklink
;
1044 $this->insertAction( $r, $rcObj );
1046 $this->insertComment( $r, $rcObj );
1048 $this->insertRollback( $r, $rcObj );
1050 $this->insertTags( $r, $rcObj, $classes );
1052 $r .= "</td></tr>\n";
1056 $this->rcCacheIndex++
;
1058 wfProfileOut( __METHOD__
);
1064 * Generate HTML for an arrow or placeholder graphic
1065 * @param $dir String: one of '', 'd', 'l', 'r'
1066 * @param $alt String: text
1067 * @param $title String: text
1068 * @return String: HTML <img> tag
1070 protected function arrow( $dir, $alt='', $title='' ) {
1071 global $wgStylePath;
1072 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1073 $encAlt = htmlspecialchars( $alt );
1074 $encTitle = htmlspecialchars( $title );
1075 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1079 * Generate HTML for a right- or left-facing arrow,
1080 * depending on language direction.
1081 * @return String: HTML <img> tag
1083 protected function sideArrow() {
1085 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1086 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1090 * Generate HTML for a down-facing arrow
1091 * depending on language direction.
1092 * @return String: HTML <img> tag
1094 protected function downArrow() {
1095 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1099 * Generate HTML for a spacer image
1100 * @return String: HTML <img> tag
1102 protected function spacerArrow() {
1103 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1107 * Enhanced RC ungrouped line.
1109 * @param $rcObj RecentChange
1110 * @return String: a HTML formated line (generated using $r)
1112 protected function recentChangesBlockLine( $rcObj ) {
1113 global $wgRCShowChangedSize;
1115 wfProfileIn( __METHOD__
);
1116 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1118 $type = $rcObj->mAttribs
['rc_type'];
1119 $logType = $rcObj->mAttribs
['rc_log_type'];
1122 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1124 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1126 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1127 Html
::openElement( 'tr' );
1129 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1130 # Flag and Timestamp
1131 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1132 $r .= '    '; // 4 flags -> 4 spaces
1134 $r .= $this->recentChangesFlags( array(
1135 'newpage' => $type == RC_NEW
,
1136 'mino' => $rcObj->mAttribs
['rc_minor'],
1137 'unpatrolled' => $rcObj->unpatrolled
,
1138 'bot' => $rcObj->mAttribs
['rc_bot'],
1141 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1142 # Article or log link
1144 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1145 $logname = LogPage
::logName( $logType );
1146 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1148 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1150 # Diff and hist links
1151 if ( $type != RC_LOG
) {
1152 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1153 $query['action'] = 'history';
1154 $r .= Linker
::linkKnown(
1156 $this->message
['hist'],
1163 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1167 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1168 # Log action (if any)
1170 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1171 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1173 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1174 $this->getSkin(), LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1177 $this->insertComment( $r, $rcObj );
1178 $this->insertRollback( $r, $rcObj );
1180 $classes = explode( ' ', $classes );
1181 $this->insertTags( $r, $rcObj, $classes );
1182 # Show how many people are watching this if enabled
1183 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1185 $r .= "</td></tr></table>\n";
1187 wfProfileOut( __METHOD__
);
1193 * If enhanced RC is in use, this function takes the previously cached
1194 * RC lines, arranges them, and outputs the HTML
1198 protected function recentChangesBlock() {
1199 if( count ( $this->rc_cache
) == 0 ) {
1203 wfProfileIn( __METHOD__
);
1206 foreach( $this->rc_cache
as $block ) {
1207 if( count( $block ) < 2 ) {
1208 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1210 $blockOut .= $this->recentChangesBlockGroup( $block );
1214 wfProfileOut( __METHOD__
);
1216 return '<div>'.$blockOut.'</div>';
1220 * Returns text for the end of RC
1221 * If enhanced RC is in use, returns pretty much all the text
1223 public function endRecentChangesList() {
1224 return $this->recentChangesBlock() . parent
::endRecentChangesList();