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
40 protected $watchlist = false;
43 * Changeslist contructor
46 public function __construct( $skin ) {
48 $this->preCacheMessages();
52 * Fetch an appropriate changes list class for the specified user
53 * Some users might want to use an enhanced list format, for instance
55 * @param $user User to fetch the list class for
56 * @return ChangesList derivative
58 public static function newFromUser( $user ) {
61 $sk = $user->getSkin();
63 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
64 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
65 return $new ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
72 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
73 * @param $value Boolean
75 public function setWatchlistDivs( $value = true ) {
76 $this->watchlist
= $value;
80 * As we use the same small set of messages in various methods and that
81 * they are called often, we call them once and save them in $this->message
83 private function preCacheMessages() {
84 if( !isset( $this->message
) ) {
85 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
86 'semicolon-separator pipe-separator' ) as $msg ) {
87 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
93 * Returns the appropriate flags for new page, minor change and patrolling
94 * @param $flags Array Associative array of 'flag' => Bool
95 * @param $nothing String to use for empty space
98 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
100 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
101 $f .= isset( $flags[$flag] ) && $flags[$flag]
102 ? self
::flag( $flag )
109 * Provide the <abbr> element appropriate to a given abbreviated flag,
110 * namely the flag indicating a new page, a minor edit, a bot edit, or an
111 * unpatrolled edit. By default in English it will contain "N", "m", "b",
112 * "!" respectively, plus it will have an appropriate title and class.
114 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
115 * @return String: Raw HTML
117 public static function flag( $flag ) {
118 static $messages = null;
119 if ( is_null( $messages ) ) {
121 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
122 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
123 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
124 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
126 foreach( $messages as &$value ) {
127 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
128 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
132 # Inconsistent naming, bleh
134 'newpage' => 'newpage',
135 'minor' => 'minoredit',
137 'unpatrolled' => 'unpatrolled',
138 'minoredit' => 'minoredit',
139 'botedit' => 'botedit',
143 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
147 * Returns text for the start of the tabular part of RC
150 public function beginRecentChangesList() {
151 $this->rc_cache
= array();
152 $this->rcMoveIndex
= 0;
153 $this->rcCacheIndex
= 0;
154 $this->lastdate
= '';
155 $this->rclistOpen
= false;
160 * Show formatted char difference
161 * @param $old Integer: bytes
162 * @param $new Integer: bytes
165 public static function showCharacterDifference( $old, $new ) {
166 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
167 $szdiff = $new - $old;
169 $code = $wgLang->getCode();
170 static $fastCharDiff = array();
171 if ( !isset($fastCharDiff[$code]) ) {
172 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
175 $formatedSize = $wgLang->formatNum($szdiff);
177 if ( !$fastCharDiff[$code] ) {
178 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
181 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
186 if( $szdiff === 0 ) {
187 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
188 } elseif( $szdiff > 0 ) {
189 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
191 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
196 * Returns text for the end of RC
199 public function endRecentChangesList() {
200 if( $this->rclistOpen
) {
209 * @param $rc RecentChange
212 public function insertMove( &$s, $rc ) {
214 $s .= '(' . $this->message
['diff'] . ') (';
216 $s .= $this->skin
->link(
217 $rc->getMovedToTitle(),
218 $this->message
['hist'],
220 array( 'action' => 'history' ),
221 array( 'known', 'noclasses' )
223 # "[[x]] moved to [[y]]"
224 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
231 array( 'redirect' => 'no' ),
232 array( 'known', 'noclasses' )
235 $rc->getMovedToTitle(),
239 array( 'known', 'noclasses' )
244 public function insertDateHeader( &$s, $rc_timestamp ) {
246 # Make date header if necessary
247 $date = $wgLang->date( $rc_timestamp, true, true );
248 if( $date != $this->lastdate
) {
249 if( $this->lastdate
!= '' ) {
252 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
253 $this->lastdate
= $date;
254 $this->rclistOpen
= true;
258 public function insertLog( &$s, $title, $logtype ) {
259 $logname = LogPage
::logName( $logtype );
260 $s .= '(' . $this->skin
->link(
265 array( 'known', 'noclasses' )
271 * @param $rc RecentChange
272 * @param $unpatrolled
275 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
277 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
278 $diffLink = $this->message
['diff'];
279 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
280 $diffLink = $this->message
['diff'];
283 'curid' => $rc->mAttribs
['rc_cur_id'],
284 'diff' => $rc->mAttribs
['rc_this_oldid'],
285 'oldid' => $rc->mAttribs
['rc_last_oldid']
289 $query['rcid'] = $rc->mAttribs
['rc_id'];
292 $diffLink = $this->skin
->link(
294 $this->message
['diff'],
295 array( 'tabindex' => $rc->counter
),
297 array( 'known', 'noclasses' )
300 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
302 $s .= $this->skin
->link(
304 $this->message
['hist'],
307 'curid' => $rc->mAttribs
['rc_cur_id'],
308 'action' => 'history'
310 array( 'known', 'noclasses' )
317 * @param $rc RecentChange
318 * @param $unpatrolled
322 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
324 # If it's a new article, there is no diff link, but if it hasn't been
325 # patrolled yet, we need to give users a way to do so
328 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
329 $params['rcid'] = $rc->mAttribs
['rc_id'];
332 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
333 $articlelink = $this->skin
->link(
338 array( 'known', 'noclasses' )
340 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
342 $articlelink = ' '. $this->skin
->link(
347 array( 'known', 'noclasses' )
350 # Bolden pages watched by this user
352 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
355 $articlelink .= $wgContLang->getDirMark();
357 wfRunHooks( 'ChangesListInsertArticleLink',
358 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
360 $s .= " $articlelink";
365 * @param $rc RecentChange
368 public function insertTimestamp( &$s, $rc ) {
370 $s .= $this->message
['semicolon-separator'] .
371 $wgLang->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 .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
383 $s .= $this->skin
->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->skin
, 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 .= $this->skin
->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 ) {
430 static $cache = array();
432 if( !isset( $cache[$count] ) ) {
433 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
434 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
436 return $cache[$count];
443 * Determine if said field of a revision is hidden
444 * @param $rc RCCacheEntry
445 * @param $field Integer: one of DELETED_* bitfield constants
448 public static function isDeleted( $rc, $field ) {
449 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
453 * Determine if the current user is allowed to view a particular
454 * field of this revision, if it's marked as deleted.
455 * @param $rc RCCacheEntry
456 * @param $field Integer
459 public static function userCan( $rc, $field ) {
460 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
461 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
463 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
467 protected function maybeWatchedLink( $link, $watched = false ) {
469 return '<strong class="mw-watched">' . $link . '</strong>';
471 return '<span class="mw-rc-unwatched">' . $link . '</span>';
475 /** Inserts a rollback link
478 * @param $rc RecentChange
480 public function insertRollback( &$s, &$rc ) {
482 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
483 $page = $rc->getTitle();
484 /** Check for rollback and edit permissions, disallow special pages, and only
485 * show a link on the top-most revision */
486 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
488 $rev = new Revision( array(
489 'id' => $rc->mAttribs
['rc_this_oldid'],
490 'user' => $rc->mAttribs
['rc_user'],
491 'user_text' => $rc->mAttribs
['rc_user_text'],
492 'deleted' => $rc->mAttribs
['rc_deleted']
494 $rev->setTitle( $page );
495 $s .= ' '.$this->skin
->generateRollback( $rev );
502 * @param $rc RecentChange
506 public function insertTags( &$s, &$rc, &$classes ) {
507 if ( empty($rc->mAttribs
['ts_tags']) )
510 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
511 $classes = array_merge( $classes, $newClasses );
512 $s .= ' ' . $tagSummary;
515 public function insertExtra( &$s, &$rc, &$classes ) {
516 ## Empty, used for subclassers to add anything special.
522 * Generate a list of changes using the good old system (no javascript)
524 class OldChangesList
extends ChangesList
{
526 * Format a line using the old system (aka without any javascript).
528 * @param $rc RecentChange
530 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
531 global $wgLang, $wgRCShowChangedSize, $wgUser;
532 wfProfileIn( __METHOD__
);
533 # Should patrol-related stuff be shown?
534 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
536 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
537 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
541 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
543 if( $linenumber & 1 ) {
544 $classes[] = 'mw-line-odd';
547 $classes[] = 'mw-line-even';
552 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
553 $this->insertMove( $s, $rc );
555 } elseif( $rc->mAttribs
['rc_log_type'] ) {
556 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
557 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
558 // Log entries (old format) or log targets, and special pages
559 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
560 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
561 if( $name == 'Log' ) {
562 $this->insertLog( $s, $rc->getTitle(), $subpage );
566 $this->insertDiffHist( $s, $rc, $unpatrolled );
567 # M, N, b and ! (minor, new, bot and unpatrolled)
568 $s .= $this->recentChangesFlags(
570 'newpage' => $rc->mAttribs
['rc_new'],
571 'minor' => $rc->mAttribs
['rc_minor'],
572 'unpatrolled' => $unpatrolled,
573 'bot' => $rc->mAttribs
['rc_bot']
577 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
580 $this->insertTimestamp( $s, $rc );
581 # Bytes added or removed
582 if( $wgRCShowChangedSize ) {
583 $cd = $rc->getCharacterDifference();
589 $this->insertUserRelatedLinks( $s, $rc );
590 # Log action text (if any)
591 $this->insertAction( $s, $rc );
592 # Edit or log comment
593 $this->insertComment( $s, $rc );
595 $this->insertTags( $s, $rc, $classes );
597 $this->insertRollback( $s, $rc );
599 $this->insertExtra( $s, $rc, $classes );
601 # How many users watch this page
602 if( $rc->numberofWatchingusers
> 0 ) {
603 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
604 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
607 if( $this->watchlist
) {
608 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
611 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
613 wfProfileOut( __METHOD__
);
614 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
620 * Generate a list of changes using an Enhanced system (uses javascript).
622 class EnhancedChangesList
extends ChangesList
{
624 * Add the JavaScript file for enhanced changeslist
627 public function beginRecentChangesList() {
629 $this->rc_cache
= array();
630 $this->rcMoveIndex
= 0;
631 $this->rcCacheIndex
= 0;
632 $this->lastdate
= '';
633 $this->rclistOpen
= false;
634 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
638 * Format a line for enhanced recentchange (aka with javascript and block of lines).
640 * @param $baseRC RecentChange
642 public function recentChangesLine( &$baseRC, $watched = false ) {
643 global $wgLang, $wgUser;
645 wfProfileIn( __METHOD__
);
647 # Create a specialised object
648 $rc = RCCacheEntry
::newFromParent( $baseRC );
650 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
652 # If it's a new day, add the headline and flush the cache
653 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
655 if( $date != $this->lastdate
) {
656 # Process current cache
657 $ret = $this->recentChangesBlock();
658 $this->rc_cache
= array();
659 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
660 $this->lastdate
= $date;
663 # Should patrol-related stuff be shown?
664 if( $wgUser->useRCPatrol() ) {
665 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
667 $rc->unpatrolled
= false;
670 $showdifflinks = true;
672 $type = $rc->mAttribs
['rc_type'];
673 $logType = $rc->mAttribs
['rc_log_type'];
675 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
676 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
677 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
678 array(), array( 'redirect' => 'no' ) ),
679 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
680 // New unpatrolled pages
681 } else if( $rc->unpatrolled
&& $type == RC_NEW
) {
682 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
683 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
685 } else if( $type == RC_LOG
) {
687 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
688 $clink = '(' . $this->skin
->linkKnown( $logtitle,
689 LogPage
::logName( $logType ) ) . ')';
691 $clink = $this->skin
->link( $rc->getTitle() );
694 // Log entries (old format) and special pages
695 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
696 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
697 if ( $specialName == 'Log' ) {
699 $logname = LogPage
::logName( $logtype );
700 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
702 wfDebug( "Unexpected special page in recentchanges\n" );
707 $clink = $this->skin
->linkKnown( $rc->getTitle() );
710 # Don't show unusable diff links
711 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
712 $showdifflinks = false;
715 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
716 $rc->watched
= $watched;
718 $rc->timestamp
= $time;
719 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
721 # Make "cur" and "diff" links. Do not use link(), it is too slow if
722 # called too many times (50% of CPU time on RecentChanges!).
723 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
724 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
725 if( $rc->unpatrolled
) {
726 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
728 $rcIdQuery = array();
730 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
731 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
732 $lastOldid ) +
$rcIdQuery;
734 if( !$showdifflinks ) {
735 $curLink = $this->message
['cur'];
736 $diffLink = $this->message
['diff'];
737 } else if( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
738 if ( $type != RC_NEW
) {
739 $curLink = $this->message
['cur'];
741 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
742 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
744 $diffLink = $this->message
['diff'];
746 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
747 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
748 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
749 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
753 if( !$showdifflinks ||
!$lastOldid ) {
754 $lastLink = $this->message
['last'];
755 } else if( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
756 $lastLink = $this->message
['last'];
758 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
759 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
763 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
764 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
766 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
767 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
770 $rc->lastlink
= $lastLink;
771 $rc->curlink
= $curLink;
772 $rc->difflink
= $diffLink;
774 # Put accumulated information into the cache, for later display
775 # Page moves go on their own line
776 $title = $rc->getTitle();
777 $secureName = $title->getPrefixedDBkey();
778 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
779 # Use an @ character to prevent collision with page names
780 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
782 # Logs are grouped by type
783 if( $type == RC_LOG
){
784 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
786 if( !isset( $this->rc_cache
[$secureName] ) ) {
787 $this->rc_cache
[$secureName] = array();
790 array_push( $this->rc_cache
[$secureName], $rc );
793 wfProfileOut( __METHOD__
);
801 protected function recentChangesBlockGroup( $block ) {
802 global $wgLang, $wgContLang, $wgRCShowChangedSize;
804 wfProfileIn( __METHOD__
);
806 # Add the namespace and title of the block as part of the class
807 if ( $block[0]->mAttribs
['rc_log_type'] ) {
809 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
811 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
813 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
814 Html
::openElement( 'tr' );
816 # Collate list of users
817 $userlinks = array();
819 $unpatrolled = false;
821 $curId = $currentRevision = 0;
822 # Some catalyst variables...
825 foreach( $block as $rcObj ) {
826 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
827 if( $rcObj->mAttribs
['rc_new'] ) {
830 // If all log actions to this page were hidden, then don't
831 // give the name of the affected page for this block!
832 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
835 $u = $rcObj->userlink
;
836 if( !isset( $userlinks[$u] ) ) {
839 if( $rcObj->unpatrolled
) {
842 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
845 # Get the latest entry with a page_id and oldid
846 # since logs may not have these.
847 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
848 $curId = $rcObj->mAttribs
['rc_cur_id'];
850 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
851 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
854 $bot = $rcObj->mAttribs
['rc_bot'];
858 # Sort the list and convert to text
859 krsort( $userlinks );
862 foreach( $userlinks as $userlink => $count) {
864 $text .= $wgContLang->getDirMark();
866 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
868 array_push( $users, $text );
871 $users = ' <span class="changedby">[' .
872 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
875 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
876 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
878 $tl = "<span class='mw-collapsible-toggle'>"
879 . "<span class='mw-rc-openarrow'>"
880 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
881 . "</span><span class='mw-rc-closearrow'>"
882 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
884 $r .= "<td>$tl</td>";
887 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
890 'unpatrolled' => $unpatrolled,
895 $r .= ' '.$block[0]->timestamp
.' </td><td>';
899 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
900 } else if( $allLogs ) {
901 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
903 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
906 $r .= $wgContLang->getDirMark();
908 $queryParams['curid'] = $curId;
911 static $nchanges = array();
912 if ( !isset( $nchanges[$n] ) ) {
913 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
919 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
921 } else if( $isnew ) {
924 $params = $queryParams;
925 $params['diff'] = $currentRevision;
926 $params['oldid'] = $oldid;
928 $r .= $this->skin
->link(
929 $block[0]->getTitle(),
933 array( 'known', 'noclasses' )
940 // don't show history link for logs
941 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
942 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
944 $params = $queryParams;
945 $params['action'] = 'history';
947 $r .= $this->message
['pipe-separator'] .
949 $block[0]->getTitle(),
950 $this->message
['hist'],
953 array( 'known', 'noclasses' )
958 # Character difference (does not apply if only log items)
959 if( $wgRCShowChangedSize && !$allLogs ) {
961 $first = count($block) - 1;
962 # Some events (like logs) have an "empty" size, so we need to skip those...
963 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
966 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
970 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
971 $block[$last]->mAttribs
['rc_new_len'] );
973 if( $chardiff == '' ) {
976 $r .= ' ' . $chardiff. ' . . ';
981 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
984 foreach( $block as $rcObj ) {
985 # Classes to apply -- TODO implement
987 $type = $rcObj->mAttribs
['rc_type'];
989 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
990 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
991 $r .= $this->recentChangesFlags( array(
992 'newpage' => $rcObj->mAttribs
['rc_new'],
993 'minor' => $rcObj->mAttribs
['rc_minor'],
994 'unpatrolled' => $rcObj->unpatrolled
,
995 'bot' => $rcObj->mAttribs
['rc_bot'],
997 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
999 $params = $queryParams;
1001 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1002 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1006 if( $type == RC_LOG
) {
1007 $link = $rcObj->timestamp
;
1009 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
1010 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1012 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1013 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1016 $link = $this->skin
->link(
1021 array( 'known', 'noclasses' )
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 = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1147 $logname = LogPage
::logName( $logType );
1148 $r .= '(' . $this->skin
->link(
1153 array( 'known', 'noclasses' )
1156 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1158 # Diff and hist links
1159 if ( $type != RC_LOG
) {
1160 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1161 $query['action'] = 'history';
1162 $r .= $this->skin
->link(
1164 $this->message
['hist'],
1167 array( 'known', 'noclasses' )
1172 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1176 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1177 # Log action (if any)
1179 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1180 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1182 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1183 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1186 $this->insertComment( $r, $rcObj );
1187 $this->insertRollback( $r, $rcObj );
1189 $classes = explode( ' ', $classes );
1190 $this->insertTags( $r, $rcObj, $classes );
1191 # Show how many people are watching this if enabled
1192 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1194 $r .= "</td></tr></table>\n";
1196 wfProfileOut( __METHOD__
);
1202 * If enhanced RC is in use, this function takes the previously cached
1203 * RC lines, arranges them, and outputs the HTML
1205 protected function recentChangesBlock() {
1206 if( count ( $this->rc_cache
) == 0 ) {
1210 wfProfileIn( __METHOD__
);
1213 foreach( $this->rc_cache
as $block ) {
1214 if( count( $block ) < 2 ) {
1215 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1217 $blockOut .= $this->recentChangesBlockGroup( $block );
1221 wfProfileOut( __METHOD__
);
1223 return '<div>'.$blockOut.'</div>';
1227 * Returns text for the end of RC
1228 * If enhanced RC is in use, returns pretty much all the text
1230 public function endRecentChangesList() {
1231 return $this->recentChangesBlock() . parent
::endRecentChangesList();