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.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 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 # LTR/RTL direction mark
593 $s .= $this->getLang()->getDirMark();
594 # Edit or log comment
595 $this->insertComment( $s, $rc );
597 $this->insertTags( $s, $rc, $classes );
599 $this->insertRollback( $s, $rc );
601 $this->insertExtra( $s, $rc, $classes );
603 # How many users watch this page
604 if( $rc->numberofWatchingusers
> 0 ) {
605 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
606 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
609 if( $this->watchlist
) {
610 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
613 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
615 wfProfileOut( __METHOD__
);
616 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
622 * Generate a list of changes using an Enhanced system (uses javascript).
624 class EnhancedChangesList
extends ChangesList
{
626 * Add the JavaScript file for enhanced changeslist
629 public function beginRecentChangesList() {
630 $this->rc_cache
= array();
631 $this->rcMoveIndex
= 0;
632 $this->rcCacheIndex
= 0;
633 $this->lastdate
= '';
634 $this->rclistOpen
= false;
635 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
639 * Format a line for enhanced recentchange (aka with javascript and block of lines).
641 * @param $baseRC RecentChange
642 * @param $watched bool
646 public function recentChangesLine( &$baseRC, $watched = false ) {
647 wfProfileIn( __METHOD__
);
649 # Create a specialised object
650 $rc = RCCacheEntry
::newFromParent( $baseRC );
652 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
654 # If it's a new day, add the headline and flush the cache
655 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
657 if( $date != $this->lastdate
) {
658 # Process current cache
659 $ret = $this->recentChangesBlock();
660 $this->rc_cache
= array();
661 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
662 $this->lastdate
= $date;
665 # Should patrol-related stuff be shown?
666 if( $this->getUser()->useRCPatrol() ) {
667 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
669 $rc->unpatrolled
= false;
672 $showdifflinks = true;
674 $type = $rc->mAttribs
['rc_type'];
675 $logType = $rc->mAttribs
['rc_log_type'];
677 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
678 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
679 $clink = wfMsg( $msg, Linker
::linkKnown( $rc->getTitle(), null,
680 array(), array( 'redirect' => 'no' ) ),
681 Linker
::linkKnown( $rc->getMovedToTitle() ) );
682 // New unpatrolled pages
683 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
684 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
685 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
687 } elseif( $type == RC_LOG
) {
689 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
690 $clink = '(' . Linker
::linkKnown( $logtitle,
691 LogPage
::logName( $logType ) ) . ')';
693 $clink = Linker
::link( $rc->getTitle() );
696 // Log entries (old format) and special pages
697 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
698 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
699 if ( $specialName == 'Log' ) {
701 $logname = LogPage
::logName( $logtype );
702 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
704 wfDebug( "Unexpected special page in recentchanges\n" );
709 $clink = Linker
::linkKnown( $rc->getTitle() );
712 # Don't show unusable diff links
713 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
714 $showdifflinks = false;
717 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
718 $rc->watched
= $watched;
720 $rc->timestamp
= $time;
721 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
723 # Make "cur" and "diff" links. Do not use link(), it is too slow if
724 # called too many times (50% of CPU time on RecentChanges!).
725 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
726 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
727 if( $rc->unpatrolled
) {
728 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
730 $rcIdQuery = array();
732 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
733 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
734 $lastOldid ) +
$rcIdQuery;
736 if( !$showdifflinks ) {
737 $curLink = $this->message
['cur'];
738 $diffLink = $this->message
['diff'];
739 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
740 if ( $type != RC_NEW
) {
741 $curLink = $this->message
['cur'];
743 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
744 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
746 $diffLink = $this->message
['diff'];
748 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
749 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
750 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
751 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
755 if( !$showdifflinks ||
!$lastOldid ) {
756 $lastLink = $this->message
['last'];
757 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
758 $lastLink = $this->message
['last'];
760 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
761 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
765 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
766 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
768 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
769 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
772 $rc->lastlink
= $lastLink;
773 $rc->curlink
= $curLink;
774 $rc->difflink
= $diffLink;
776 # Put accumulated information into the cache, for later display
777 # Page moves go on their own line
778 $title = $rc->getTitle();
779 $secureName = $title->getPrefixedDBkey();
780 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
781 # Use an @ character to prevent collision with page names
782 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
784 # Logs are grouped by type
785 if( $type == RC_LOG
){
786 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
788 if( !isset( $this->rc_cache
[$secureName] ) ) {
789 $this->rc_cache
[$secureName] = array();
792 array_push( $this->rc_cache
[$secureName], $rc );
795 wfProfileOut( __METHOD__
);
803 protected function recentChangesBlockGroup( $block ) {
804 global $wgRCShowChangedSize;
806 wfProfileIn( __METHOD__
);
808 # Add the namespace and title of the block as part of the class
809 if ( $block[0]->mAttribs
['rc_log_type'] ) {
811 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
813 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
815 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
816 Html
::openElement( 'tr' );
818 # Collate list of users
819 $userlinks = array();
821 $unpatrolled = false;
823 $curId = $currentRevision = 0;
824 # Some catalyst variables...
827 foreach( $block as $rcObj ) {
828 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
829 if( $rcObj->mAttribs
['rc_new'] ) {
832 // If all log actions to this page were hidden, then don't
833 // give the name of the affected page for this block!
834 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
837 $u = $rcObj->userlink
;
838 if( !isset( $userlinks[$u] ) ) {
841 if( $rcObj->unpatrolled
) {
844 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
847 # Get the latest entry with a page_id and oldid
848 # since logs may not have these.
849 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
850 $curId = $rcObj->mAttribs
['rc_cur_id'];
852 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
853 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
856 $bot = $rcObj->mAttribs
['rc_bot'];
860 # Sort the list and convert to text
861 krsort( $userlinks );
864 foreach( $userlinks as $userlink => $count) {
866 $text .= $this->getLang()->getDirMark();
868 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
870 array_push( $users, $text );
873 $users = ' <span class="changedby">[' .
874 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
877 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
878 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
880 $tl = "<span class='mw-collapsible-toggle'>"
881 . "<span class='mw-rc-openarrow'>"
882 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
883 . "</span><span class='mw-rc-closearrow'>"
884 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
886 $r .= "<td>$tl</td>";
889 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
892 'unpatrolled' => $unpatrolled,
897 $r .= ' '.$block[0]->timestamp
.' </td><td>';
901 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
902 } elseif( $allLogs ) {
903 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
905 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
908 $r .= $this->getLang()->getDirMark();
910 $queryParams['curid'] = $curId;
913 static $nchanges = array();
914 if ( !isset( $nchanges[$n] ) ) {
915 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
921 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
926 $params = $queryParams;
927 $params['diff'] = $currentRevision;
928 $params['oldid'] = $oldid;
931 $block[0]->getTitle(),
935 array( 'known', 'noclasses' )
942 // don't show history link for logs
943 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
944 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
946 $params = $queryParams;
947 $params['action'] = 'history';
949 $r .= $this->message
['pipe-separator'] .
951 $block[0]->getTitle(),
952 $this->message
['hist'],
959 # Character difference (does not apply if only log items)
960 if( $wgRCShowChangedSize && !$allLogs ) {
962 $first = count($block) - 1;
963 # Some events (like logs) have an "empty" size, so we need to skip those...
964 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
967 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
971 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
972 $block[$last]->mAttribs
['rc_new_len'] );
974 if( $chardiff == '' ) {
977 $r .= ' ' . $chardiff. ' . . ';
982 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
985 foreach( $block as $rcObj ) {
986 # Classes to apply -- TODO implement
988 $type = $rcObj->mAttribs
['rc_type'];
990 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
991 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
992 $r .= $this->recentChangesFlags( array(
993 'newpage' => $rcObj->mAttribs
['rc_new'],
994 'minor' => $rcObj->mAttribs
['rc_minor'],
995 'unpatrolled' => $rcObj->unpatrolled
,
996 'bot' => $rcObj->mAttribs
['rc_bot'],
998 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1000 $params = $queryParams;
1002 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1003 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1007 if( $type == RC_LOG
) {
1008 $link = $rcObj->timestamp
;
1010 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
1011 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1013 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1014 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1017 $link = Linker
::linkKnown(
1023 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1024 $link = '<span class="history-deleted">'.$link.'</span> ';
1026 $r .= $link . '</span>';
1028 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1030 $r .= $rcObj->curlink
;
1031 $r .= $this->message
['pipe-separator'];
1032 $r .= $rcObj->lastlink
;
1038 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1039 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1043 $r .= $rcObj->userlink
;
1044 $r .= $rcObj->usertalklink
;
1046 $this->insertAction( $r, $rcObj );
1048 $this->insertComment( $r, $rcObj );
1050 $this->insertRollback( $r, $rcObj );
1052 $this->insertTags( $r, $rcObj, $classes );
1054 $r .= "</td></tr>\n";
1058 $this->rcCacheIndex++
;
1060 wfProfileOut( __METHOD__
);
1066 * Generate HTML for an arrow or placeholder graphic
1067 * @param $dir String: one of '', 'd', 'l', 'r'
1068 * @param $alt String: text
1069 * @param $title String: text
1070 * @return String: HTML <img> tag
1072 protected function arrow( $dir, $alt='', $title='' ) {
1073 global $wgStylePath;
1074 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1075 $encAlt = htmlspecialchars( $alt );
1076 $encTitle = htmlspecialchars( $title );
1077 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1081 * Generate HTML for a right- or left-facing arrow,
1082 * depending on language direction.
1083 * @return String: HTML <img> tag
1085 protected function sideArrow() {
1087 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1088 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1092 * Generate HTML for a down-facing arrow
1093 * depending on language direction.
1094 * @return String: HTML <img> tag
1096 protected function downArrow() {
1097 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1101 * Generate HTML for a spacer image
1102 * @return String: HTML <img> tag
1104 protected function spacerArrow() {
1105 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1109 * Enhanced RC ungrouped line.
1111 * @param $rcObj RecentChange
1112 * @return String: a HTML formated line (generated using $r)
1114 protected function recentChangesBlockLine( $rcObj ) {
1115 global $wgRCShowChangedSize;
1117 wfProfileIn( __METHOD__
);
1118 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1120 $type = $rcObj->mAttribs
['rc_type'];
1121 $logType = $rcObj->mAttribs
['rc_log_type'];
1124 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1126 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1128 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1129 Html
::openElement( 'tr' );
1131 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1132 # Flag and Timestamp
1133 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1134 $r .= '    '; // 4 flags -> 4 spaces
1136 $r .= $this->recentChangesFlags( array(
1137 'newpage' => $type == RC_NEW
,
1138 'mino' => $rcObj->mAttribs
['rc_minor'],
1139 'unpatrolled' => $rcObj->unpatrolled
,
1140 'bot' => $rcObj->mAttribs
['rc_bot'],
1143 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1144 # Article or log link
1146 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1147 $logname = LogPage
::logName( $logType );
1148 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1150 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1152 # Diff and hist links
1153 if ( $type != RC_LOG
) {
1154 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1155 $query['action'] = 'history';
1156 $r .= Linker
::linkKnown(
1158 $this->message
['hist'],
1165 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1169 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1170 # Log action (if any)
1172 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1173 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1175 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1176 $this->getSkin(), LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1179 $this->insertComment( $r, $rcObj );
1180 $this->insertRollback( $r, $rcObj );
1182 $classes = explode( ' ', $classes );
1183 $this->insertTags( $r, $rcObj, $classes );
1184 # Show how many people are watching this if enabled
1185 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1187 $r .= "</td></tr></table>\n";
1189 wfProfileOut( __METHOD__
);
1195 * If enhanced RC is in use, this function takes the previously cached
1196 * RC lines, arranges them, and outputs the HTML
1200 protected function recentChangesBlock() {
1201 if( count ( $this->rc_cache
) == 0 ) {
1205 wfProfileIn( __METHOD__
);
1208 foreach( $this->rc_cache
as $block ) {
1209 if( count( $block ) < 2 ) {
1210 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1212 $blockOut .= $this->recentChangesBlockGroup( $block );
1216 wfProfileOut( __METHOD__
);
1218 return '<div>'.$blockOut.'</div>';
1222 * Returns text for the end of RC
1223 * If enhanced RC is in use, returns pretty much all the text
1225 public function endRecentChangesList() {
1226 return $this->recentChangesBlock() . parent
::endRecentChangesList();