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;
21 * @param $rc RecentChange
22 * @return RCCacheEntry
24 static function newFromParent( $rc ) {
25 $rc2 = new RCCacheEntry
;
26 $rc2->mAttribs
= $rc->mAttribs
;
27 $rc2->mExtra
= $rc->mExtra
;
33 * Base class for all changes lists
41 protected $watchlist = false;
44 * Changeslist contructor
47 public function __construct( $skin ) {
49 $this->preCacheMessages();
53 * Fetch an appropriate changes list class for the specified user
54 * Some users might want to use an enhanced list format, for instance
56 * @param $user User to fetch the list class for
57 * @return ChangesList derivative
59 public static function newFromUser( $user ) {
62 $sk = $user->getSkin();
64 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
65 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
66 return $new ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
73 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
74 * @param $value Boolean
76 public function setWatchlistDivs( $value = true ) {
77 $this->watchlist
= $value;
81 * As we use the same small set of messages in various methods and that
82 * they are called often, we call them once and save them in $this->message
84 private function preCacheMessages() {
85 if( !isset( $this->message
) ) {
86 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
87 'semicolon-separator pipe-separator' ) as $msg ) {
88 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
94 * Returns the appropriate flags for new page, minor change and patrolling
95 * @param $flags Array Associative array of 'flag' => Bool
96 * @param $nothing String to use for empty space
99 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
101 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
102 $f .= isset( $flags[$flag] ) && $flags[$flag]
103 ? self
::flag( $flag )
110 * Provide the <abbr> element appropriate to a given abbreviated flag,
111 * namely the flag indicating a new page, a minor edit, a bot edit, or an
112 * unpatrolled edit. By default in English it will contain "N", "m", "b",
113 * "!" respectively, plus it will have an appropriate title and class.
115 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
116 * @return String: Raw HTML
118 public static function flag( $flag ) {
119 static $messages = null;
120 if ( is_null( $messages ) ) {
122 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
123 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
124 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
125 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
127 foreach( $messages as &$value ) {
128 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
129 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
133 # Inconsistent naming, bleh
135 'newpage' => 'newpage',
136 'minor' => 'minoredit',
138 'unpatrolled' => 'unpatrolled',
139 'minoredit' => 'minoredit',
140 'botedit' => 'botedit',
144 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
148 * Returns text for the start of the tabular part of RC
151 public function beginRecentChangesList() {
152 $this->rc_cache
= array();
153 $this->rcMoveIndex
= 0;
154 $this->rcCacheIndex
= 0;
155 $this->lastdate
= '';
156 $this->rclistOpen
= false;
161 * Show formatted char difference
162 * @param $old Integer: bytes
163 * @param $new Integer: bytes
166 public static function showCharacterDifference( $old, $new ) {
167 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
168 $szdiff = $new - $old;
170 $code = $wgLang->getCode();
171 static $fastCharDiff = array();
172 if ( !isset($fastCharDiff[$code]) ) {
173 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
176 $formatedSize = $wgLang->formatNum($szdiff);
178 if ( !$fastCharDiff[$code] ) {
179 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
182 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
187 if( $szdiff === 0 ) {
188 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
189 } elseif( $szdiff > 0 ) {
190 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
192 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
197 * Returns text for the end of RC
200 public function endRecentChangesList() {
201 if( $this->rclistOpen
) {
210 * @param $rc RecentChange
213 public function insertMove( &$s, $rc ) {
215 $s .= '(' . $this->message
['diff'] . ') (';
217 $s .= $this->skin
->link(
218 $rc->getMovedToTitle(),
219 $this->message
['hist'],
221 array( 'action' => 'history' ),
222 array( 'known', 'noclasses' )
224 # "[[x]] moved to [[y]]"
225 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
232 array( 'redirect' => 'no' ),
233 array( 'known', 'noclasses' )
236 $rc->getMovedToTitle(),
240 array( 'known', 'noclasses' )
245 public function insertDateHeader( &$s, $rc_timestamp ) {
247 # Make date header if necessary
248 $date = $wgLang->date( $rc_timestamp, true, true );
249 if( $date != $this->lastdate
) {
250 if( $this->lastdate
!= '' ) {
253 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
254 $this->lastdate
= $date;
255 $this->rclistOpen
= true;
259 public function insertLog( &$s, $title, $logtype ) {
260 $logname = LogPage
::logName( $logtype );
261 $s .= '(' . $this->skin
->link(
266 array( 'known', 'noclasses' )
272 * @param $rc RecentChange
273 * @param $unpatrolled
276 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
278 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
279 $diffLink = $this->message
['diff'];
280 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
281 $diffLink = $this->message
['diff'];
284 'curid' => $rc->mAttribs
['rc_cur_id'],
285 'diff' => $rc->mAttribs
['rc_this_oldid'],
286 'oldid' => $rc->mAttribs
['rc_last_oldid']
290 $query['rcid'] = $rc->mAttribs
['rc_id'];
293 $diffLink = $this->skin
->link(
295 $this->message
['diff'],
296 array( 'tabindex' => $rc->counter
),
298 array( 'known', 'noclasses' )
301 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
303 $s .= $this->skin
->link(
305 $this->message
['hist'],
308 'curid' => $rc->mAttribs
['rc_cur_id'],
309 'action' => 'history'
311 array( 'known', 'noclasses' )
318 * @param $rc RecentChange
319 * @param $unpatrolled
323 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
325 # If it's a new article, there is no diff link, but if it hasn't been
326 # patrolled yet, we need to give users a way to do so
329 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
330 $params['rcid'] = $rc->mAttribs
['rc_id'];
333 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
334 $articlelink = $this->skin
->link(
339 array( 'known', 'noclasses' )
341 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
343 $articlelink = ' '. $this->skin
->link(
348 array( 'known', 'noclasses' )
351 # Bolden pages watched by this user
353 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
356 $articlelink .= $wgContLang->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 ) {
371 $s .= $this->message
['semicolon-separator'] .
372 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
375 /** Insert links to user page, user talk page and eventually a blocking link
377 * @param $rc RecentChange
379 public function insertUserRelatedLinks( &$s, &$rc ) {
380 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
381 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
383 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
384 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
388 /** insert a formatted action
390 * @param $rc RecentChange
392 public function insertAction( &$s, &$rc ) {
393 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
394 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
395 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
397 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
398 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
403 /** insert a formatted comment
405 * @param $rc RecentChange
407 public function insertComment( &$s, &$rc ) {
408 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
409 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
410 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
412 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
418 * Check whether to enable recent changes patrol features
421 public static function usePatrol() {
423 return $wgUser->useRCPatrol();
427 * Returns the string which indicates the number of watching users
429 protected function numberofWatchingusers( $count ) {
431 static $cache = array();
433 if( !isset( $cache[$count] ) ) {
434 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
435 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
437 return $cache[$count];
444 * Determine if said field of a revision is hidden
445 * @param $rc RCCacheEntry
446 * @param $field Integer: one of DELETED_* bitfield constants
449 public static function isDeleted( $rc, $field ) {
450 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
454 * Determine if the current user is allowed to view a particular
455 * field of this revision, if it's marked as deleted.
456 * @param $rc RCCacheEntry
457 * @param $field Integer
460 public static function userCan( $rc, $field ) {
461 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
462 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
464 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
468 protected function maybeWatchedLink( $link, $watched = false ) {
470 return '<strong class="mw-watched">' . $link . '</strong>';
472 return '<span class="mw-rc-unwatched">' . $link . '</span>';
476 /** Inserts a rollback link
479 * @param $rc RecentChange
481 public function insertRollback( &$s, &$rc ) {
483 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
484 $page = $rc->getTitle();
485 /** Check for rollback and edit permissions, disallow special pages, and only
486 * show a link on the top-most revision */
487 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
489 $rev = new Revision( array(
490 'id' => $rc->mAttribs
['rc_this_oldid'],
491 'user' => $rc->mAttribs
['rc_user'],
492 'user_text' => $rc->mAttribs
['rc_user_text'],
493 'deleted' => $rc->mAttribs
['rc_deleted']
495 $rev->setTitle( $page );
496 $s .= ' '.$this->skin
->generateRollback( $rev );
503 * @param $rc RecentChange
507 public function insertTags( &$s, &$rc, &$classes ) {
508 if ( empty($rc->mAttribs
['ts_tags']) )
511 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
512 $classes = array_merge( $classes, $newClasses );
513 $s .= ' ' . $tagSummary;
516 public function insertExtra( &$s, &$rc, &$classes ) {
517 ## Empty, used for subclassers to add anything special.
523 * Generate a list of changes using the good old system (no javascript)
525 class OldChangesList
extends ChangesList
{
527 * Format a line using the old system (aka without any javascript).
529 * @param $rc RecentChange
531 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
532 global $wgLang, $wgRCShowChangedSize, $wgUser;
533 wfProfileIn( __METHOD__
);
534 # Should patrol-related stuff be shown?
535 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
537 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
538 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
542 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
544 if( $linenumber & 1 ) {
545 $classes[] = 'mw-line-odd';
548 $classes[] = 'mw-line-even';
553 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
554 $this->insertMove( $s, $rc );
556 } elseif( $rc->mAttribs
['rc_log_type'] ) {
557 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
558 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
559 // Log entries (old format) or log targets, and special pages
560 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
561 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
562 if( $name == 'Log' ) {
563 $this->insertLog( $s, $rc->getTitle(), $subpage );
567 $this->insertDiffHist( $s, $rc, $unpatrolled );
568 # M, N, b and ! (minor, new, bot and unpatrolled)
569 $s .= $this->recentChangesFlags(
571 'newpage' => $rc->mAttribs
['rc_new'],
572 'minor' => $rc->mAttribs
['rc_minor'],
573 'unpatrolled' => $unpatrolled,
574 'bot' => $rc->mAttribs
['rc_bot']
578 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
581 $this->insertTimestamp( $s, $rc );
582 # Bytes added or removed
583 if( $wgRCShowChangedSize ) {
584 $cd = $rc->getCharacterDifference();
590 $this->insertUserRelatedLinks( $s, $rc );
591 # Log action text (if any)
592 $this->insertAction( $s, $rc );
593 # Edit or log comment
594 $this->insertComment( $s, $rc );
596 $this->insertTags( $s, $rc, $classes );
598 $this->insertRollback( $s, $rc );
600 $this->insertExtra( $s, $rc, $classes );
602 # How many users watch this page
603 if( $rc->numberofWatchingusers
> 0 ) {
604 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
605 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
608 if( $this->watchlist
) {
609 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
612 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
614 wfProfileOut( __METHOD__
);
615 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
621 * Generate a list of changes using an Enhanced system (uses javascript).
623 class EnhancedChangesList
extends ChangesList
{
625 * Add the JavaScript file for enhanced changeslist
628 public function beginRecentChangesList() {
630 $this->rc_cache
= array();
631 $this->rcMoveIndex
= 0;
632 $this->rcCacheIndex
= 0;
633 $this->lastdate
= '';
634 $this->rclistOpen
= false;
635 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
639 * Format a line for enhanced recentchange (aka with javascript and block of lines).
641 * @param $baseRC RecentChange
643 public function recentChangesLine( &$baseRC, $watched = false ) {
644 global $wgLang, $wgUser;
646 wfProfileIn( __METHOD__
);
648 # Create a specialised object
649 $rc = RCCacheEntry
::newFromParent( $baseRC );
651 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
653 # If it's a new day, add the headline and flush the cache
654 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
656 if( $date != $this->lastdate
) {
657 # Process current cache
658 $ret = $this->recentChangesBlock();
659 $this->rc_cache
= array();
660 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
661 $this->lastdate
= $date;
664 # Should patrol-related stuff be shown?
665 if( $wgUser->useRCPatrol() ) {
666 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
668 $rc->unpatrolled
= false;
671 $showdifflinks = true;
673 $type = $rc->mAttribs
['rc_type'];
674 $logType = $rc->mAttribs
['rc_log_type'];
676 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
677 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
678 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
679 array(), array( 'redirect' => 'no' ) ),
680 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
681 // New unpatrolled pages
682 } else if( $rc->unpatrolled
&& $type == RC_NEW
) {
683 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
684 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
686 } else if( $type == RC_LOG
) {
688 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
689 $clink = '(' . $this->skin
->linkKnown( $logtitle,
690 LogPage
::logName( $logType ) ) . ')';
692 $clink = $this->skin
->link( $rc->getTitle() );
695 // Log entries (old format) and special pages
696 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
697 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
698 if ( $specialName == 'Log' ) {
700 $logname = LogPage
::logName( $logtype );
701 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
703 wfDebug( "Unexpected special page in recentchanges\n" );
708 $clink = $this->skin
->linkKnown( $rc->getTitle() );
711 # Don't show unusable diff links
712 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
713 $showdifflinks = false;
716 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
717 $rc->watched
= $watched;
719 $rc->timestamp
= $time;
720 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
722 # Make "cur" and "diff" links. Do not use link(), it is too slow if
723 # called too many times (50% of CPU time on RecentChanges!).
724 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
725 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
726 if( $rc->unpatrolled
) {
727 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
729 $rcIdQuery = array();
731 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
732 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
733 $lastOldid ) +
$rcIdQuery;
735 if( !$showdifflinks ) {
736 $curLink = $this->message
['cur'];
737 $diffLink = $this->message
['diff'];
738 } else if( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
739 if ( $type != RC_NEW
) {
740 $curLink = $this->message
['cur'];
742 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
743 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
745 $diffLink = $this->message
['diff'];
747 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
748 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
749 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
750 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
754 if( !$showdifflinks ||
!$lastOldid ) {
755 $lastLink = $this->message
['last'];
756 } else if( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
757 $lastLink = $this->message
['last'];
759 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
760 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
764 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
765 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
767 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
768 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
771 $rc->lastlink
= $lastLink;
772 $rc->curlink
= $curLink;
773 $rc->difflink
= $diffLink;
775 # Put accumulated information into the cache, for later display
776 # Page moves go on their own line
777 $title = $rc->getTitle();
778 $secureName = $title->getPrefixedDBkey();
779 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
780 # Use an @ character to prevent collision with page names
781 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
783 # Logs are grouped by type
784 if( $type == RC_LOG
){
785 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
787 if( !isset( $this->rc_cache
[$secureName] ) ) {
788 $this->rc_cache
[$secureName] = array();
791 array_push( $this->rc_cache
[$secureName], $rc );
794 wfProfileOut( __METHOD__
);
802 protected function recentChangesBlockGroup( $block ) {
803 global $wgLang, $wgContLang, $wgRCShowChangedSize;
805 wfProfileIn( __METHOD__
);
807 # Add the namespace and title of the block as part of the class
808 if ( $block[0]->mAttribs
['rc_log_type'] ) {
810 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
812 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
814 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
815 Html
::openElement( 'tr' );
817 # Collate list of users
818 $userlinks = array();
820 $unpatrolled = false;
822 $curId = $currentRevision = 0;
823 # Some catalyst variables...
826 foreach( $block as $rcObj ) {
827 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
828 if( $rcObj->mAttribs
['rc_new'] ) {
831 // If all log actions to this page were hidden, then don't
832 // give the name of the affected page for this block!
833 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
836 $u = $rcObj->userlink
;
837 if( !isset( $userlinks[$u] ) ) {
840 if( $rcObj->unpatrolled
) {
843 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
846 # Get the latest entry with a page_id and oldid
847 # since logs may not have these.
848 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
849 $curId = $rcObj->mAttribs
['rc_cur_id'];
851 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
852 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
855 $bot = $rcObj->mAttribs
['rc_bot'];
859 # Sort the list and convert to text
860 krsort( $userlinks );
863 foreach( $userlinks as $userlink => $count) {
865 $text .= $wgContLang->getDirMark();
867 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
869 array_push( $users, $text );
872 $users = ' <span class="changedby">[' .
873 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
876 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
877 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
879 $tl = "<span class='mw-collapsible-toggle'>"
880 . "<span class='mw-rc-openarrow'>"
881 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
882 . "</span><span class='mw-rc-closearrow'>"
883 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
885 $r .= "<td>$tl</td>";
888 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
891 'unpatrolled' => $unpatrolled,
896 $r .= ' '.$block[0]->timestamp
.' </td><td>';
900 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
901 } else if( $allLogs ) {
902 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
904 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
907 $r .= $wgContLang->getDirMark();
909 $queryParams['curid'] = $curId;
912 static $nchanges = array();
913 if ( !isset( $nchanges[$n] ) ) {
914 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
920 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
922 } else if( $isnew ) {
925 $params = $queryParams;
926 $params['diff'] = $currentRevision;
927 $params['oldid'] = $oldid;
929 $r .= $this->skin
->link(
930 $block[0]->getTitle(),
934 array( 'known', 'noclasses' )
941 // don't show history link for logs
942 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
943 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
945 $params = $queryParams;
946 $params['action'] = 'history';
948 $r .= $this->message
['pipe-separator'] .
950 $block[0]->getTitle(),
951 $this->message
['hist'],
954 array( 'known', 'noclasses' )
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 } else if( !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 = $this->skin
->link(
1022 array( 'known', 'noclasses' )
1024 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1025 $link = '<span class="history-deleted">'.$link.'</span> ';
1027 $r .= $link . '</span>';
1029 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1031 $r .= $rcObj->curlink
;
1032 $r .= $this->message
['pipe-separator'];
1033 $r .= $rcObj->lastlink
;
1039 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1040 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1044 $r .= $rcObj->userlink
;
1045 $r .= $rcObj->usertalklink
;
1047 $this->insertAction( $r, $rcObj );
1049 $this->insertComment( $r, $rcObj );
1051 $this->insertRollback( $r, $rcObj );
1053 $this->insertTags( $r, $rcObj, $classes );
1055 $r .= "</td></tr>\n";
1059 $this->rcCacheIndex++
;
1061 wfProfileOut( __METHOD__
);
1067 * Generate HTML for an arrow or placeholder graphic
1068 * @param $dir String: one of '', 'd', 'l', 'r'
1069 * @param $alt String: text
1070 * @param $title String: text
1071 * @return String: HTML <img> tag
1073 protected function arrow( $dir, $alt='', $title='' ) {
1074 global $wgStylePath;
1075 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1076 $encAlt = htmlspecialchars( $alt );
1077 $encTitle = htmlspecialchars( $title );
1078 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1082 * Generate HTML for a right- or left-facing arrow,
1083 * depending on language direction.
1084 * @return String: HTML <img> tag
1086 protected function sideArrow() {
1088 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1089 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1093 * Generate HTML for a down-facing arrow
1094 * depending on language direction.
1095 * @return String: HTML <img> tag
1097 protected function downArrow() {
1098 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1102 * Generate HTML for a spacer image
1103 * @return String: HTML <img> tag
1105 protected function spacerArrow() {
1106 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1110 * Enhanced RC ungrouped line.
1112 * @param $rcObj RecentChange
1113 * @return String: a HTML formated line (generated using $r)
1115 protected function recentChangesBlockLine( $rcObj ) {
1116 global $wgRCShowChangedSize;
1118 wfProfileIn( __METHOD__
);
1119 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1121 $type = $rcObj->mAttribs
['rc_type'];
1122 $logType = $rcObj->mAttribs
['rc_log_type'];
1125 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1127 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1129 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1130 Html
::openElement( 'tr' );
1132 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1133 # Flag and Timestamp
1134 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1135 $r .= '    '; // 4 flags -> 4 spaces
1137 $r .= $this->recentChangesFlags( array(
1138 'newpage' => $type == RC_NEW
,
1139 'mino' => $rcObj->mAttribs
['rc_minor'],
1140 'unpatrolled' => $rcObj->unpatrolled
,
1141 'bot' => $rcObj->mAttribs
['rc_bot'],
1144 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1145 # Article or log link
1147 $logtitle = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1148 $logname = LogPage
::logName( $logType );
1149 $r .= '(' . $this->skin
->link(
1154 array( 'known', 'noclasses' )
1157 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1159 # Diff and hist links
1160 if ( $type != RC_LOG
) {
1161 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1162 $query['action'] = 'history';
1163 $r .= $this->skin
->link(
1165 $this->message
['hist'],
1168 array( 'known', 'noclasses' )
1173 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1177 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1178 # Log action (if any)
1180 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1181 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1183 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1184 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1187 $this->insertComment( $r, $rcObj );
1188 $this->insertRollback( $r, $rcObj );
1190 $classes = explode( ' ', $classes );
1191 $this->insertTags( $r, $rcObj, $classes );
1192 # Show how many people are watching this if enabled
1193 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1195 $r .= "</td></tr></table>\n";
1197 wfProfileOut( __METHOD__
);
1203 * If enhanced RC is in use, this function takes the previously cached
1204 * RC lines, arranges them, and outputs the HTML
1206 protected function recentChangesBlock() {
1207 if( count ( $this->rc_cache
) == 0 ) {
1211 wfProfileIn( __METHOD__
);
1214 foreach( $this->rc_cache
as $block ) {
1215 if( count( $block ) < 2 ) {
1216 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1218 $blockOut .= $this->recentChangesBlockGroup( $block );
1222 wfProfileOut( __METHOD__
);
1224 return '<div>'.$blockOut.'</div>';
1228 * Returns text for the end of RC
1229 * If enhanced RC is in use, returns pretty much all the text
1231 public function endRecentChangesList() {
1232 return $this->recentChangesBlock() . parent
::endRecentChangesList();