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
41 protected $watchlist = false;
46 * Changeslist contructor
49 public function __construct( $skin ) {
51 $this->preCacheMessages();
55 * Fetch an appropriate changes list class for the specified user
56 * Some users might want to use an enhanced list format, for instance
58 * @param $user User to fetch the list class for
59 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
61 public static function newFromUser( $user ) {
64 $sk = $user->getSkin();
66 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
67 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
68 return $new ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
75 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
76 * @param $value Boolean
78 public function setWatchlistDivs( $value = true ) {
79 $this->watchlist
= $value;
83 * As we use the same small set of messages in various methods and that
84 * they are called often, we call them once and save them in $this->message
86 private function preCacheMessages() {
87 if( !isset( $this->message
) ) {
88 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
89 'semicolon-separator pipe-separator' ) as $msg ) {
90 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
96 * Returns the appropriate flags for new page, minor change and patrolling
97 * @param $flags Array Associative array of 'flag' => Bool
98 * @param $nothing String to use for empty space
101 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
103 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
104 $f .= isset( $flags[$flag] ) && $flags[$flag]
105 ? self
::flag( $flag )
112 * Provide the <abbr> element appropriate to a given abbreviated flag,
113 * namely the flag indicating a new page, a minor edit, a bot edit, or an
114 * unpatrolled edit. By default in English it will contain "N", "m", "b",
115 * "!" respectively, plus it will have an appropriate title and class.
117 * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot'
118 * @return String: Raw HTML
120 public static function flag( $flag ) {
121 static $messages = null;
122 if ( is_null( $messages ) ) {
124 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
125 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
126 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
127 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
129 foreach( $messages as &$value ) {
130 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
131 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
135 # Inconsistent naming, bleh
137 'newpage' => 'newpage',
138 'minor' => 'minoredit',
140 'unpatrolled' => 'unpatrolled',
141 'minoredit' => 'minoredit',
142 'botedit' => 'botedit',
146 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
150 * Returns text for the start of the tabular part of RC
153 public function beginRecentChangesList() {
154 $this->rc_cache
= array();
155 $this->rcMoveIndex
= 0;
156 $this->rcCacheIndex
= 0;
157 $this->lastdate
= '';
158 $this->rclistOpen
= false;
163 * Show formatted char difference
164 * @param $old Integer: bytes
165 * @param $new Integer: bytes
168 public static function showCharacterDifference( $old, $new ) {
169 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
170 $szdiff = $new - $old;
172 $code = $wgLang->getCode();
173 static $fastCharDiff = array();
174 if ( !isset($fastCharDiff[$code]) ) {
175 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
178 $formatedSize = $wgLang->formatNum($szdiff);
180 if ( !$fastCharDiff[$code] ) {
181 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
184 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
189 if( $szdiff === 0 ) {
190 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
191 } elseif( $szdiff > 0 ) {
192 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
194 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
199 * Returns text for the end of RC
202 public function endRecentChangesList() {
203 if( $this->rclistOpen
) {
212 * @param $rc RecentChange
215 public function insertMove( &$s, $rc ) {
217 $s .= '(' . $this->message
['diff'] . ') (';
219 $s .= $this->skin
->link(
220 $rc->getMovedToTitle(),
221 $this->message
['hist'],
223 array( 'action' => 'history' ),
224 array( 'known', 'noclasses' )
226 # "[[x]] moved to [[y]]"
227 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
234 array( 'redirect' => 'no' ),
235 array( 'known', 'noclasses' )
238 $rc->getMovedToTitle(),
242 array( 'known', 'noclasses' )
247 public function insertDateHeader( &$s, $rc_timestamp ) {
249 # Make date header if necessary
250 $date = $wgLang->date( $rc_timestamp, true, true );
251 if( $date != $this->lastdate
) {
252 if( $this->lastdate
!= '' ) {
255 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
256 $this->lastdate
= $date;
257 $this->rclistOpen
= true;
261 public function insertLog( &$s, $title, $logtype ) {
262 $logname = LogPage
::logName( $logtype );
263 $s .= '(' . $this->skin
->link(
268 array( 'known', 'noclasses' )
274 * @param $rc RecentChange
275 * @param $unpatrolled
278 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
280 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
281 $diffLink = $this->message
['diff'];
282 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
283 $diffLink = $this->message
['diff'];
286 'curid' => $rc->mAttribs
['rc_cur_id'],
287 'diff' => $rc->mAttribs
['rc_this_oldid'],
288 'oldid' => $rc->mAttribs
['rc_last_oldid']
292 $query['rcid'] = $rc->mAttribs
['rc_id'];
295 $diffLink = $this->skin
->link(
297 $this->message
['diff'],
298 array( 'tabindex' => $rc->counter
),
300 array( 'known', 'noclasses' )
303 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
305 $s .= $this->skin
->link(
307 $this->message
['hist'],
310 'curid' => $rc->mAttribs
['rc_cur_id'],
311 'action' => 'history'
313 array( 'known', 'noclasses' )
320 * @param $rc RecentChange
321 * @param $unpatrolled
325 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
326 # If it's a new article, there is no diff link, but if it hasn't been
327 # patrolled yet, we need to give users a way to do so
330 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
331 $params['rcid'] = $rc->mAttribs
['rc_id'];
334 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
335 $articlelink = $this->skin
->link(
340 array( 'known', 'noclasses' )
342 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
344 $articlelink = ' '. $this->skin
->link(
349 array( 'known', 'noclasses' )
352 # Bolden pages watched by this user
354 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
357 $articlelink .= wfUILang()->getDirMark();
359 wfRunHooks( 'ChangesListInsertArticleLink',
360 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
362 $s .= " $articlelink";
367 * @param $rc RecentChange
370 public function insertTimestamp( &$s, $rc ) {
372 $s .= $this->message
['semicolon-separator'] .
373 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
376 /** Insert links to user page, user talk page and eventually a blocking link
378 * @param $rc RecentChange
380 public function insertUserRelatedLinks( &$s, &$rc ) {
381 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
382 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
384 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
385 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
389 /** insert a formatted action
391 * @param $rc RecentChange
393 public function insertAction( &$s, &$rc ) {
394 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
395 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
396 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
398 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
399 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
404 /** insert a formatted comment
406 * @param $rc RecentChange
408 public function insertComment( &$s, &$rc ) {
409 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
410 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
411 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
413 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
419 * Check whether to enable recent changes patrol features
422 public static function usePatrol() {
424 return $wgUser->useRCPatrol();
428 * Returns the string which indicates the number of watching users
430 protected function numberofWatchingusers( $count ) {
432 static $cache = array();
434 if( !isset( $cache[$count] ) ) {
435 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
436 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
438 return $cache[$count];
445 * Determine if said field of a revision is hidden
446 * @param $rc RCCacheEntry
447 * @param $field Integer: one of DELETED_* bitfield constants
450 public static function isDeleted( $rc, $field ) {
451 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
455 * Determine if the current user is allowed to view a particular
456 * field of this revision, if it's marked as deleted.
457 * @param $rc RCCacheEntry
458 * @param $field Integer
461 public static function userCan( $rc, $field ) {
462 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
463 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
465 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
469 protected function maybeWatchedLink( $link, $watched = false ) {
471 return '<strong class="mw-watched">' . $link . '</strong>';
473 return '<span class="mw-rc-unwatched">' . $link . '</span>';
477 /** Inserts a rollback link
480 * @param $rc RecentChange
482 public function insertRollback( &$s, &$rc ) {
484 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
485 $page = $rc->getTitle();
486 /** Check for rollback and edit permissions, disallow special pages, and only
487 * show a link on the top-most revision */
488 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
490 $rev = new Revision( array(
491 'id' => $rc->mAttribs
['rc_this_oldid'],
492 'user' => $rc->mAttribs
['rc_user'],
493 'user_text' => $rc->mAttribs
['rc_user_text'],
494 'deleted' => $rc->mAttribs
['rc_deleted']
496 $rev->setTitle( $page );
497 $s .= ' '.$this->skin
->generateRollback( $rev );
504 * @param $rc RecentChange
508 public function insertTags( &$s, &$rc, &$classes ) {
509 if ( empty($rc->mAttribs
['ts_tags']) )
512 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
513 $classes = array_merge( $classes, $newClasses );
514 $s .= ' ' . $tagSummary;
517 public function insertExtra( &$s, &$rc, &$classes ) {
518 ## Empty, used for subclassers to add anything special.
524 * Generate a list of changes using the good old system (no javascript)
526 class OldChangesList
extends ChangesList
{
528 * Format a line using the old system (aka without any javascript).
530 * @param $rc RecentChange
532 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
533 global $wgLang, $wgRCShowChangedSize, $wgUser;
534 wfProfileIn( __METHOD__
);
535 # Should patrol-related stuff be shown?
536 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
538 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
539 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
543 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
545 if( $linenumber & 1 ) {
546 $classes[] = 'mw-line-odd';
549 $classes[] = 'mw-line-even';
554 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
555 $this->insertMove( $s, $rc );
557 } elseif( $rc->mAttribs
['rc_log_type'] ) {
558 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
559 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
560 // Log entries (old format) or log targets, and special pages
561 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
562 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
563 if( $name == 'Log' ) {
564 $this->insertLog( $s, $rc->getTitle(), $subpage );
568 $this->insertDiffHist( $s, $rc, $unpatrolled );
569 # M, N, b and ! (minor, new, bot and unpatrolled)
570 $s .= $this->recentChangesFlags(
572 'newpage' => $rc->mAttribs
['rc_new'],
573 'minor' => $rc->mAttribs
['rc_minor'],
574 'unpatrolled' => $unpatrolled,
575 'bot' => $rc->mAttribs
['rc_bot']
579 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
582 $this->insertTimestamp( $s, $rc );
583 # Bytes added or removed
584 if( $wgRCShowChangedSize ) {
585 $cd = $rc->getCharacterDifference();
591 $this->insertUserRelatedLinks( $s, $rc );
592 # Log action text (if any)
593 $this->insertAction( $s, $rc );
594 # Edit or log comment
595 $this->insertComment( $s, $rc );
597 $this->insertTags( $s, $rc, $classes );
599 $this->insertRollback( $s, $rc );
601 $this->insertExtra( $s, $rc, $classes );
603 # How many users watch this page
604 if( $rc->numberofWatchingusers
> 0 ) {
605 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
606 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
609 if( $this->watchlist
) {
610 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
613 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
615 wfProfileOut( __METHOD__
);
616 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
622 * Generate a list of changes using an Enhanced system (uses javascript).
624 class EnhancedChangesList
extends ChangesList
{
626 * Add the JavaScript file for enhanced changeslist
629 public function beginRecentChangesList() {
631 $this->rc_cache
= array();
632 $this->rcMoveIndex
= 0;
633 $this->rcCacheIndex
= 0;
634 $this->lastdate
= '';
635 $this->rclistOpen
= false;
636 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
640 * Format a line for enhanced recentchange (aka with javascript and block of lines).
642 * @param $baseRC RecentChange
643 * @param $watched bool
647 public function recentChangesLine( &$baseRC, $watched = false ) {
648 global $wgLang, $wgUser;
650 wfProfileIn( __METHOD__
);
652 # Create a specialised object
653 $rc = RCCacheEntry
::newFromParent( $baseRC );
655 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
657 # If it's a new day, add the headline and flush the cache
658 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
660 if( $date != $this->lastdate
) {
661 # Process current cache
662 $ret = $this->recentChangesBlock();
663 $this->rc_cache
= array();
664 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
665 $this->lastdate
= $date;
668 # Should patrol-related stuff be shown?
669 if( $wgUser->useRCPatrol() ) {
670 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
672 $rc->unpatrolled
= false;
675 $showdifflinks = true;
677 $type = $rc->mAttribs
['rc_type'];
678 $logType = $rc->mAttribs
['rc_log_type'];
680 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
681 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
682 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
683 array(), array( 'redirect' => 'no' ) ),
684 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
685 // New unpatrolled pages
686 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
687 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
688 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
690 } elseif( $type == RC_LOG
) {
692 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
693 $clink = '(' . $this->skin
->linkKnown( $logtitle,
694 LogPage
::logName( $logType ) ) . ')';
696 $clink = $this->skin
->link( $rc->getTitle() );
699 // Log entries (old format) and special pages
700 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
701 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
702 if ( $specialName == 'Log' ) {
704 $logname = LogPage
::logName( $logtype );
705 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
707 wfDebug( "Unexpected special page in recentchanges\n" );
712 $clink = $this->skin
->linkKnown( $rc->getTitle() );
715 # Don't show unusable diff links
716 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
717 $showdifflinks = false;
720 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
721 $rc->watched
= $watched;
723 $rc->timestamp
= $time;
724 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
726 # Make "cur" and "diff" links. Do not use link(), it is too slow if
727 # called too many times (50% of CPU time on RecentChanges!).
728 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
729 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
730 if( $rc->unpatrolled
) {
731 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
733 $rcIdQuery = array();
735 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
736 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
737 $lastOldid ) +
$rcIdQuery;
739 if( !$showdifflinks ) {
740 $curLink = $this->message
['cur'];
741 $diffLink = $this->message
['diff'];
742 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
743 if ( $type != RC_NEW
) {
744 $curLink = $this->message
['cur'];
746 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
747 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
749 $diffLink = $this->message
['diff'];
751 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
752 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
753 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
754 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
758 if( !$showdifflinks ||
!$lastOldid ) {
759 $lastLink = $this->message
['last'];
760 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
761 $lastLink = $this->message
['last'];
763 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
764 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
768 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
769 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
771 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
772 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
775 $rc->lastlink
= $lastLink;
776 $rc->curlink
= $curLink;
777 $rc->difflink
= $diffLink;
779 # Put accumulated information into the cache, for later display
780 # Page moves go on their own line
781 $title = $rc->getTitle();
782 $secureName = $title->getPrefixedDBkey();
783 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
784 # Use an @ character to prevent collision with page names
785 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
787 # Logs are grouped by type
788 if( $type == RC_LOG
){
789 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
791 if( !isset( $this->rc_cache
[$secureName] ) ) {
792 $this->rc_cache
[$secureName] = array();
795 array_push( $this->rc_cache
[$secureName], $rc );
798 wfProfileOut( __METHOD__
);
806 protected function recentChangesBlockGroup( $block ) {
807 global $wgLang, $wgRCShowChangedSize;
809 wfProfileIn( __METHOD__
);
811 # Add the namespace and title of the block as part of the class
812 if ( $block[0]->mAttribs
['rc_log_type'] ) {
814 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
816 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
818 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
819 Html
::openElement( 'tr' );
821 # Collate list of users
822 $userlinks = array();
824 $unpatrolled = false;
826 $curId = $currentRevision = 0;
827 # Some catalyst variables...
830 foreach( $block as $rcObj ) {
831 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
832 if( $rcObj->mAttribs
['rc_new'] ) {
835 // If all log actions to this page were hidden, then don't
836 // give the name of the affected page for this block!
837 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
840 $u = $rcObj->userlink
;
841 if( !isset( $userlinks[$u] ) ) {
844 if( $rcObj->unpatrolled
) {
847 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
850 # Get the latest entry with a page_id and oldid
851 # since logs may not have these.
852 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
853 $curId = $rcObj->mAttribs
['rc_cur_id'];
855 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
856 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
859 $bot = $rcObj->mAttribs
['rc_bot'];
863 # Sort the list and convert to text
864 krsort( $userlinks );
867 foreach( $userlinks as $userlink => $count) {
869 $text .= wfUILang()->getDirMark();
871 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
873 array_push( $users, $text );
876 $users = ' <span class="changedby">[' .
877 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
880 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
881 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
883 $tl = "<span class='mw-collapsible-toggle'>"
884 . "<span class='mw-rc-openarrow'>"
885 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
886 . "</span><span class='mw-rc-closearrow'>"
887 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
889 $r .= "<td>$tl</td>";
892 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
895 'unpatrolled' => $unpatrolled,
900 $r .= ' '.$block[0]->timestamp
.' </td><td>';
904 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
905 } elseif( $allLogs ) {
906 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
908 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
911 $r .= wfUILang()->getDirMark();
913 $queryParams['curid'] = $curId;
916 static $nchanges = array();
917 if ( !isset( $nchanges[$n] ) ) {
918 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
924 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
929 $params = $queryParams;
930 $params['diff'] = $currentRevision;
931 $params['oldid'] = $oldid;
933 $r .= $this->skin
->link(
934 $block[0]->getTitle(),
938 array( 'known', 'noclasses' )
945 // don't show history link for logs
946 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
947 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
949 $params = $queryParams;
950 $params['action'] = 'history';
952 $r .= $this->message
['pipe-separator'] .
954 $block[0]->getTitle(),
955 $this->message
['hist'],
958 array( 'known', 'noclasses' )
963 # Character difference (does not apply if only log items)
964 if( $wgRCShowChangedSize && !$allLogs ) {
966 $first = count($block) - 1;
967 # Some events (like logs) have an "empty" size, so we need to skip those...
968 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
971 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
975 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
976 $block[$last]->mAttribs
['rc_new_len'] );
978 if( $chardiff == '' ) {
981 $r .= ' ' . $chardiff. ' . . ';
986 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
989 foreach( $block as $rcObj ) {
990 # Classes to apply -- TODO implement
992 $type = $rcObj->mAttribs
['rc_type'];
994 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
995 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
996 $r .= $this->recentChangesFlags( array(
997 'newpage' => $rcObj->mAttribs
['rc_new'],
998 'minor' => $rcObj->mAttribs
['rc_minor'],
999 'unpatrolled' => $rcObj->unpatrolled
,
1000 'bot' => $rcObj->mAttribs
['rc_bot'],
1002 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1004 $params = $queryParams;
1006 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1007 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1011 if( $type == RC_LOG
) {
1012 $link = $rcObj->timestamp
;
1014 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
1015 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1017 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1018 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1021 $link = $this->skin
->link(
1026 array( 'known', 'noclasses' )
1028 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1029 $link = '<span class="history-deleted">'.$link.'</span> ';
1031 $r .= $link . '</span>';
1033 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1035 $r .= $rcObj->curlink
;
1036 $r .= $this->message
['pipe-separator'];
1037 $r .= $rcObj->lastlink
;
1043 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1044 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1048 $r .= $rcObj->userlink
;
1049 $r .= $rcObj->usertalklink
;
1051 $this->insertAction( $r, $rcObj );
1053 $this->insertComment( $r, $rcObj );
1055 $this->insertRollback( $r, $rcObj );
1057 $this->insertTags( $r, $rcObj, $classes );
1059 $r .= "</td></tr>\n";
1063 $this->rcCacheIndex++
;
1065 wfProfileOut( __METHOD__
);
1071 * Generate HTML for an arrow or placeholder graphic
1072 * @param $dir String: one of '', 'd', 'l', 'r'
1073 * @param $alt String: text
1074 * @param $title String: text
1075 * @return String: HTML <img> tag
1077 protected function arrow( $dir, $alt='', $title='' ) {
1078 global $wgStylePath;
1079 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1080 $encAlt = htmlspecialchars( $alt );
1081 $encTitle = htmlspecialchars( $title );
1082 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1086 * Generate HTML for a right- or left-facing arrow,
1087 * depending on language direction.
1088 * @return String: HTML <img> tag
1090 protected function sideArrow() {
1092 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1093 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1097 * Generate HTML for a down-facing arrow
1098 * depending on language direction.
1099 * @return String: HTML <img> tag
1101 protected function downArrow() {
1102 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1106 * Generate HTML for a spacer image
1107 * @return String: HTML <img> tag
1109 protected function spacerArrow() {
1110 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1114 * Enhanced RC ungrouped line.
1116 * @param $rcObj RecentChange
1117 * @return String: a HTML formated line (generated using $r)
1119 protected function recentChangesBlockLine( $rcObj ) {
1120 global $wgRCShowChangedSize;
1122 wfProfileIn( __METHOD__
);
1123 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1125 $type = $rcObj->mAttribs
['rc_type'];
1126 $logType = $rcObj->mAttribs
['rc_log_type'];
1129 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1131 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1133 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1134 Html
::openElement( 'tr' );
1136 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1137 # Flag and Timestamp
1138 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1139 $r .= '    '; // 4 flags -> 4 spaces
1141 $r .= $this->recentChangesFlags( array(
1142 'newpage' => $type == RC_NEW
,
1143 'mino' => $rcObj->mAttribs
['rc_minor'],
1144 'unpatrolled' => $rcObj->unpatrolled
,
1145 'bot' => $rcObj->mAttribs
['rc_bot'],
1148 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1149 # Article or log link
1151 $logtitle = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1152 $logname = LogPage
::logName( $logType );
1153 $r .= '(' . $this->skin
->link(
1158 array( 'known', 'noclasses' )
1161 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1163 # Diff and hist links
1164 if ( $type != RC_LOG
) {
1165 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1166 $query['action'] = 'history';
1167 $r .= $this->skin
->link(
1169 $this->message
['hist'],
1172 array( 'known', 'noclasses' )
1177 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1181 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1182 # Log action (if any)
1184 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1185 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1187 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1188 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1191 $this->insertComment( $r, $rcObj );
1192 $this->insertRollback( $r, $rcObj );
1194 $classes = explode( ' ', $classes );
1195 $this->insertTags( $r, $rcObj, $classes );
1196 # Show how many people are watching this if enabled
1197 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1199 $r .= "</td></tr></table>\n";
1201 wfProfileOut( __METHOD__
);
1207 * If enhanced RC is in use, this function takes the previously cached
1208 * RC lines, arranges them, and outputs the HTML
1212 protected function recentChangesBlock() {
1213 if( count ( $this->rc_cache
) == 0 ) {
1217 wfProfileIn( __METHOD__
);
1220 foreach( $this->rc_cache
as $block ) {
1221 if( count( $block ) < 2 ) {
1222 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1224 $blockOut .= $this->recentChangesBlockGroup( $block );
1228 wfProfileOut( __METHOD__
);
1230 return '<div>'.$blockOut.'</div>';
1234 * Returns text for the end of RC
1235 * If enhanced RC is in use, returns pretty much all the text
1237 public function endRecentChangesList() {
1238 return $this->recentChangesBlock() . parent
::endRecentChangesList();