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 $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
) {
228 public function insertDateHeader( &$s, $rc_timestamp ) {
229 # Make date header if necessary
230 $date = $this->getLang()->date( $rc_timestamp, true, true );
231 if( $date != $this->lastdate
) {
232 if( $this->lastdate
!= '' ) {
235 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
236 $this->lastdate
= $date;
237 $this->rclistOpen
= true;
241 public function insertLog( &$s, $title, $logtype ) {
242 $page = new LogPage( $logtype );
243 $logname = $page->getName()->escaped();
244 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
249 * @param $rc RecentChange
250 * @param $unpatrolled
253 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
255 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
256 $diffLink = $this->message
['diff'];
257 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
258 $diffLink = $this->message
['diff'];
261 'curid' => $rc->mAttribs
['rc_cur_id'],
262 'diff' => $rc->mAttribs
['rc_this_oldid'],
263 'oldid' => $rc->mAttribs
['rc_last_oldid']
267 $query['rcid'] = $rc->mAttribs
['rc_id'];
270 $diffLink = Linker
::linkKnown(
272 $this->message
['diff'],
273 array( 'tabindex' => $rc->counter
),
277 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
279 $s .= Linker
::linkKnown(
281 $this->message
['hist'],
284 'curid' => $rc->mAttribs
['rc_cur_id'],
285 'action' => 'history'
293 * @param $rc RecentChange
294 * @param $unpatrolled
298 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
299 # If it's a new article, there is no diff link, but if it hasn't been
300 # patrolled yet, we need to give users a way to do so
303 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
304 $params['rcid'] = $rc->mAttribs
['rc_id'];
307 $articlelink = Linker
::linkKnown(
313 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
314 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
316 # Bolden pages watched by this user
318 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
321 $articlelink .= $this->getLang()->getDirMark();
323 wfRunHooks( 'ChangesListInsertArticleLink',
324 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
326 $s .= " $articlelink";
331 * @param $rc RecentChange
334 public function insertTimestamp( &$s, $rc ) {
335 $s .= $this->message
['semicolon-separator'] .
336 $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
339 /** Insert links to user page, user talk page and eventually a blocking link
341 * @param $rc RecentChange
343 public function insertUserRelatedLinks( &$s, &$rc ) {
344 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
345 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
347 $s .= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
348 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
352 /** insert a formatted action
354 * @param $rc RecentChange
356 public function insertLogEntry( $rc ) {
357 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
358 $formatter->setShowUserToolLinks( true );
359 $mark = $this->getLang()->getDirMark();
360 return $formatter->getActionText() . " $mark" . $formatter->getComment();
364 * Insert a formatted comment
365 * @param $rc RecentChange
367 public function insertComment( $rc ) {
368 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
369 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
370 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
372 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
378 * Check whether to enable recent changes patrol features
381 public static function usePatrol() {
383 return $wgUser->useRCPatrol();
387 * Returns the string which indicates the number of watching users
389 protected function numberofWatchingusers( $count ) {
390 static $cache = array();
392 if( !isset( $cache[$count] ) ) {
393 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
394 array('parsemag', 'escape' ), $this->getLang()->formatNum( $count ) );
396 return $cache[$count];
403 * Determine if said field of a revision is hidden
404 * @param $rc RCCacheEntry
405 * @param $field Integer: one of DELETED_* bitfield constants
408 public static function isDeleted( $rc, $field ) {
409 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
413 * Determine if the current user is allowed to view a particular
414 * field of this revision, if it's marked as deleted.
415 * @param $rc RCCacheEntry
416 * @param $field Integer
419 public static function userCan( $rc, $field ) {
420 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
421 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
423 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
427 protected function maybeWatchedLink( $link, $watched = false ) {
429 return '<strong class="mw-watched">' . $link . '</strong>';
431 return '<span class="mw-rc-unwatched">' . $link . '</span>';
435 /** Inserts a rollback link
438 * @param $rc RecentChange
440 public function insertRollback( &$s, &$rc ) {
441 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
442 $page = $rc->getTitle();
443 /** Check for rollback and edit permissions, disallow special pages, and only
444 * show a link on the top-most revision */
445 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
447 $rev = new Revision( array(
448 'id' => $rc->mAttribs
['rc_this_oldid'],
449 'user' => $rc->mAttribs
['rc_user'],
450 'user_text' => $rc->mAttribs
['rc_user_text'],
451 'deleted' => $rc->mAttribs
['rc_deleted']
453 $rev->setTitle( $page );
454 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
461 * @param $rc RecentChange
465 public function insertTags( &$s, &$rc, &$classes ) {
466 if ( empty($rc->mAttribs
['ts_tags']) )
469 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
470 $classes = array_merge( $classes, $newClasses );
471 $s .= ' ' . $tagSummary;
474 public function insertExtra( &$s, &$rc, &$classes ) {
475 ## Empty, used for subclassers to add anything special.
481 * Generate a list of changes using the good old system (no javascript)
483 class OldChangesList
extends ChangesList
{
485 * Format a line using the old system (aka without any javascript).
487 * @param $rc RecentChange
489 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
490 global $wgRCShowChangedSize;
491 wfProfileIn( __METHOD__
);
492 # Should patrol-related stuff be shown?
493 $unpatrolled = $this->getUser()->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
495 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
496 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
500 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
502 if( $linenumber & 1 ) {
503 $classes[] = 'mw-line-odd';
506 $classes[] = 'mw-line-even';
510 // Moved pages (very very old, not supported anymore)
511 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
513 } elseif( $rc->mAttribs
['rc_log_type'] ) {
514 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
515 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
516 // Log entries (old format) or log targets, and special pages
517 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
518 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
519 if( $name == 'Log' ) {
520 $this->insertLog( $s, $rc->getTitle(), $subpage );
524 $this->insertDiffHist( $s, $rc, $unpatrolled );
525 # M, N, b and ! (minor, new, bot and unpatrolled)
526 $s .= $this->recentChangesFlags(
528 'newpage' => $rc->mAttribs
['rc_new'],
529 'minor' => $rc->mAttribs
['rc_minor'],
530 'unpatrolled' => $unpatrolled,
531 'bot' => $rc->mAttribs
['rc_bot']
535 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
538 $this->insertTimestamp( $s, $rc );
539 # Bytes added or removed
540 if( $wgRCShowChangedSize ) {
541 $cd = $rc->getCharacterDifference();
547 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
548 $s .= $this->insertLogEntry( $rc );
551 $this->insertUserRelatedLinks( $s, $rc );
552 # LTR/RTL direction mark
553 $s .= $this->getLang()->getDirMark();
554 $s .= $this->insertComment( $rc );
558 $this->insertTags( $s, $rc, $classes );
560 $this->insertRollback( $s, $rc );
562 $this->insertExtra( $s, $rc, $classes );
564 # How many users watch this page
565 if( $rc->numberofWatchingusers
> 0 ) {
566 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
567 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
570 if( $this->watchlist
) {
571 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
574 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
576 wfProfileOut( __METHOD__
);
577 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
583 * Generate a list of changes using an Enhanced system (uses javascript).
585 class EnhancedChangesList
extends ChangesList
{
587 * Add the JavaScript file for enhanced changeslist
590 public function beginRecentChangesList() {
591 $this->rc_cache
= array();
592 $this->rcMoveIndex
= 0;
593 $this->rcCacheIndex
= 0;
594 $this->lastdate
= '';
595 $this->rclistOpen
= false;
596 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
600 * Format a line for enhanced recentchange (aka with javascript and block of lines).
602 * @param $baseRC RecentChange
603 * @param $watched bool
607 public function recentChangesLine( &$baseRC, $watched = false ) {
608 wfProfileIn( __METHOD__
);
610 # Create a specialised object
611 $rc = RCCacheEntry
::newFromParent( $baseRC );
613 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
615 # If it's a new day, add the headline and flush the cache
616 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
618 if( $date != $this->lastdate
) {
619 # Process current cache
620 $ret = $this->recentChangesBlock();
621 $this->rc_cache
= array();
622 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
623 $this->lastdate
= $date;
626 # Should patrol-related stuff be shown?
627 if( $this->getUser()->useRCPatrol() ) {
628 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
630 $rc->unpatrolled
= false;
633 $showdifflinks = true;
635 $type = $rc->mAttribs
['rc_type'];
636 $logType = $rc->mAttribs
['rc_log_type'];
637 // Page moves, very old style, not supported anymore
638 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
639 // New unpatrolled pages
640 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
641 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
642 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
644 } elseif( $type == RC_LOG
) {
646 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
647 $clink = '(' . Linker
::linkKnown( $logtitle,
648 LogPage
::logName( $logType ) ) . ')';
650 $clink = Linker
::link( $rc->getTitle() );
653 // Log entries (old format) and special pages
654 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
655 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
656 if ( $specialName == 'Log' ) {
658 $logname = LogPage
::logName( $logtype );
659 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
661 wfDebug( "Unexpected special page in recentchanges\n" );
666 $clink = Linker
::linkKnown( $rc->getTitle() );
669 # Don't show unusable diff links
670 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
671 $showdifflinks = false;
674 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
675 $rc->watched
= $watched;
677 $rc->timestamp
= $time;
678 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
680 # Make "cur" and "diff" links. Do not use link(), it is too slow if
681 # called too many times (50% of CPU time on RecentChanges!).
682 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
683 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
684 if( $rc->unpatrolled
) {
685 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
687 $rcIdQuery = array();
689 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
690 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
691 $lastOldid ) +
$rcIdQuery;
693 if( !$showdifflinks ) {
694 $curLink = $this->message
['cur'];
695 $diffLink = $this->message
['diff'];
696 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
697 if ( $type != RC_NEW
) {
698 $curLink = $this->message
['cur'];
700 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
701 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
703 $diffLink = $this->message
['diff'];
705 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
706 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
707 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
708 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
712 if( !$showdifflinks ||
!$lastOldid ) {
713 $lastLink = $this->message
['last'];
714 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
715 $lastLink = $this->message
['last'];
717 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
718 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
722 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
723 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
725 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
726 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
729 $rc->lastlink
= $lastLink;
730 $rc->curlink
= $curLink;
731 $rc->difflink
= $diffLink;
733 # Put accumulated information into the cache, for later display
734 # Page moves go on their own line
735 $title = $rc->getTitle();
736 $secureName = $title->getPrefixedDBkey();
737 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
738 # Use an @ character to prevent collision with page names
739 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
741 # Logs are grouped by type
742 if( $type == RC_LOG
){
743 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
745 if( !isset( $this->rc_cache
[$secureName] ) ) {
746 $this->rc_cache
[$secureName] = array();
749 array_push( $this->rc_cache
[$secureName], $rc );
752 wfProfileOut( __METHOD__
);
760 protected function recentChangesBlockGroup( $block ) {
761 global $wgRCShowChangedSize;
763 wfProfileIn( __METHOD__
);
765 # Add the namespace and title of the block as part of the class
766 if ( $block[0]->mAttribs
['rc_log_type'] ) {
768 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
770 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
772 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
773 Html
::openElement( 'tr' );
775 # Collate list of users
776 $userlinks = array();
778 $unpatrolled = false;
780 $curId = $currentRevision = 0;
781 # Some catalyst variables...
784 foreach( $block as $rcObj ) {
785 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
786 if( $rcObj->mAttribs
['rc_new'] ) {
789 // If all log actions to this page were hidden, then don't
790 // give the name of the affected page for this block!
791 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
794 $u = $rcObj->userlink
;
795 if( !isset( $userlinks[$u] ) ) {
798 if( $rcObj->unpatrolled
) {
801 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
804 # Get the latest entry with a page_id and oldid
805 # since logs may not have these.
806 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
807 $curId = $rcObj->mAttribs
['rc_cur_id'];
809 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
810 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
813 $bot = $rcObj->mAttribs
['rc_bot'];
817 # Sort the list and convert to text
818 krsort( $userlinks );
821 foreach( $userlinks as $userlink => $count) {
823 $text .= $this->getLang()->getDirMark();
825 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
827 array_push( $users, $text );
830 $users = ' <span class="changedby">[' .
831 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
834 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
835 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
837 $tl = "<span class='mw-collapsible-toggle'>"
838 . "<span class='mw-rc-openarrow'>"
839 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
840 . "</span><span class='mw-rc-closearrow'>"
841 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
843 $r .= "<td>$tl</td>";
846 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
849 'unpatrolled' => $unpatrolled,
854 $r .= ' '.$block[0]->timestamp
.' </td><td>';
858 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
859 } elseif( $allLogs ) {
860 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
862 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
865 $r .= $this->getLang()->getDirMark();
867 $queryParams['curid'] = $curId;
870 static $nchanges = array();
871 if ( !isset( $nchanges[$n] ) ) {
872 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
878 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
883 $params = $queryParams;
884 $params['diff'] = $currentRevision;
885 $params['oldid'] = $oldid;
888 $block[0]->getTitle(),
892 array( 'known', 'noclasses' )
899 // don't show history link for logs
900 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
901 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
903 $params = $queryParams;
904 $params['action'] = 'history';
906 $r .= $this->message
['pipe-separator'] .
908 $block[0]->getTitle(),
909 $this->message
['hist'],
916 # Character difference (does not apply if only log items)
917 if( $wgRCShowChangedSize && !$allLogs ) {
919 $first = count($block) - 1;
920 # Some events (like logs) have an "empty" size, so we need to skip those...
921 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
924 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
928 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
929 $block[$last]->mAttribs
['rc_new_len'] );
931 if( $chardiff == '' ) {
934 $r .= ' ' . $chardiff. ' . . ';
939 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
942 foreach( $block as $rcObj ) {
943 # Classes to apply -- TODO implement
945 $type = $rcObj->mAttribs
['rc_type'];
947 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
948 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
949 $r .= $this->recentChangesFlags( array(
950 'newpage' => $rcObj->mAttribs
['rc_new'],
951 'minor' => $rcObj->mAttribs
['rc_minor'],
952 'unpatrolled' => $rcObj->unpatrolled
,
953 'bot' => $rcObj->mAttribs
['rc_bot'],
955 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
957 $params = $queryParams;
959 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
960 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
964 if( $type == RC_LOG
) {
965 $link = $rcObj->timestamp
;
967 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
968 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
970 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
971 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
974 $link = Linker
::linkKnown(
980 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
981 $link = '<span class="history-deleted">'.$link.'</span> ';
983 $r .= $link . '</span>';
985 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
987 $r .= $rcObj->curlink
;
988 $r .= $this->message
['pipe-separator'];
989 $r .= $rcObj->lastlink
;
995 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
996 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
999 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1000 $r .= $this->insertLogEntry( $rcObj );
1003 $r .= $rcObj->userlink
;
1004 $r .= $rcObj->usertalklink
;
1005 $r .= $this->insertComment( $rcObj );
1009 $this->insertRollback( $r, $rcObj );
1011 $this->insertTags( $r, $rcObj, $classes );
1013 $r .= "</td></tr>\n";
1017 $this->rcCacheIndex++
;
1019 wfProfileOut( __METHOD__
);
1025 * Generate HTML for an arrow or placeholder graphic
1026 * @param $dir String: one of '', 'd', 'l', 'r'
1027 * @param $alt String: text
1028 * @param $title String: text
1029 * @return String: HTML <img> tag
1031 protected function arrow( $dir, $alt='', $title='' ) {
1032 global $wgStylePath;
1033 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1034 $encAlt = htmlspecialchars( $alt );
1035 $encTitle = htmlspecialchars( $title );
1036 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1040 * Generate HTML for a right- or left-facing arrow,
1041 * depending on language direction.
1042 * @return String: HTML <img> tag
1044 protected function sideArrow() {
1046 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1047 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1051 * Generate HTML for a down-facing arrow
1052 * depending on language direction.
1053 * @return String: HTML <img> tag
1055 protected function downArrow() {
1056 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1060 * Generate HTML for a spacer image
1061 * @return String: HTML <img> tag
1063 protected function spacerArrow() {
1064 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1068 * Enhanced RC ungrouped line.
1070 * @param $rcObj RecentChange
1071 * @return String: a HTML formated line (generated using $r)
1073 protected function recentChangesBlockLine( $rcObj ) {
1074 global $wgRCShowChangedSize;
1076 wfProfileIn( __METHOD__
);
1077 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1079 $type = $rcObj->mAttribs
['rc_type'];
1080 $logType = $rcObj->mAttribs
['rc_log_type'];
1083 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1085 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1087 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1088 Html
::openElement( 'tr' );
1090 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1091 # Flag and Timestamp
1092 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1093 $r .= '    '; // 4 flags -> 4 spaces
1095 $r .= $this->recentChangesFlags( array(
1096 'newpage' => $type == RC_NEW
,
1097 'mino' => $rcObj->mAttribs
['rc_minor'],
1098 'unpatrolled' => $rcObj->unpatrolled
,
1099 'bot' => $rcObj->mAttribs
['rc_bot'],
1102 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1103 # Article or log link
1105 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1106 $logname = LogPage
::logName( $logType );
1107 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1109 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1111 # Diff and hist links
1112 if ( $type != RC_LOG
) {
1113 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1114 $query['action'] = 'history';
1115 $r .= Linker
::linkKnown(
1117 $this->message
['hist'],
1124 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1128 if ( $type == RC_LOG
) {
1129 $r .= $this->insertLogEntry( $rcObj );
1131 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1132 $r .= $this->insertComment( $rcObj );
1133 $r .= $this->insertRollback( $r, $rcObj );
1137 $classes = explode( ' ', $classes );
1138 $this->insertTags( $r, $rcObj, $classes );
1139 # Show how many people are watching this if enabled
1140 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1142 $r .= "</td></tr></table>\n";
1144 wfProfileOut( __METHOD__
);
1150 * If enhanced RC is in use, this function takes the previously cached
1151 * RC lines, arranges them, and outputs the HTML
1155 protected function recentChangesBlock() {
1156 if( count ( $this->rc_cache
) == 0 ) {
1160 wfProfileIn( __METHOD__
);
1163 foreach( $this->rc_cache
as $block ) {
1164 if( count( $block ) < 2 ) {
1165 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1167 $blockOut .= $this->recentChangesBlockGroup( $block );
1171 wfProfileOut( __METHOD__
);
1173 return '<div>'.$blockOut.'</div>';
1177 * Returns text for the end of RC
1178 * If enhanced RC is in use, returns pretty much all the text
1180 public function endRecentChangesList() {
1181 return $this->recentChangesBlock() . parent
::endRecentChangesList();