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 } else if( !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 ) {
327 # If it's a new article, there is no diff link, but if it hasn't been
328 # patrolled yet, we need to give users a way to do so
331 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
332 $params['rcid'] = $rc->mAttribs
['rc_id'];
335 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
336 $articlelink = $this->skin
->link(
341 array( 'known', 'noclasses' )
343 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
345 $articlelink = ' '. $this->skin
->link(
350 array( 'known', 'noclasses' )
353 # Bolden pages watched by this user
355 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
358 $articlelink .= $wgContLang->getDirMark();
360 wfRunHooks( 'ChangesListInsertArticleLink',
361 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
363 $s .= " $articlelink";
368 * @param $rc RecentChange
371 public function insertTimestamp( &$s, $rc ) {
373 $s .= $this->message
['semicolon-separator'] .
374 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
377 /** Insert links to user page, user talk page and eventually a blocking link
379 * @param $rc RecentChange
381 public function insertUserRelatedLinks( &$s, &$rc ) {
382 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
383 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
385 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
386 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
390 /** insert a formatted action
392 * @param $rc RecentChange
394 public function insertAction( &$s, &$rc ) {
395 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
396 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
397 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
399 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
400 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
405 /** insert a formatted comment
407 * @param $rc RecentChange
409 public function insertComment( &$s, &$rc ) {
410 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
411 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
412 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
414 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
420 * Check whether to enable recent changes patrol features
423 public static function usePatrol() {
425 return $wgUser->useRCPatrol();
429 * Returns the string which indicates the number of watching users
431 protected function numberofWatchingusers( $count ) {
433 static $cache = array();
435 if( !isset( $cache[$count] ) ) {
436 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
437 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
439 return $cache[$count];
446 * Determine if said field of a revision is hidden
447 * @param $rc RCCacheEntry
448 * @param $field Integer: one of DELETED_* bitfield constants
451 public static function isDeleted( $rc, $field ) {
452 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
456 * Determine if the current user is allowed to view a particular
457 * field of this revision, if it's marked as deleted.
458 * @param $rc RCCacheEntry
459 * @param $field Integer
462 public static function userCan( $rc, $field ) {
463 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
464 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
466 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
470 protected function maybeWatchedLink( $link, $watched = false ) {
472 return '<strong class="mw-watched">' . $link . '</strong>';
474 return '<span class="mw-rc-unwatched">' . $link . '</span>';
478 /** Inserts a rollback link
481 * @param $rc RecentChange
483 public function insertRollback( &$s, &$rc ) {
485 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
486 $page = $rc->getTitle();
487 /** Check for rollback and edit permissions, disallow special pages, and only
488 * show a link on the top-most revision */
489 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
491 $rev = new Revision( array(
492 'id' => $rc->mAttribs
['rc_this_oldid'],
493 'user' => $rc->mAttribs
['rc_user'],
494 'user_text' => $rc->mAttribs
['rc_user_text'],
495 'deleted' => $rc->mAttribs
['rc_deleted']
497 $rev->setTitle( $page );
498 $s .= ' '.$this->skin
->generateRollback( $rev );
505 * @param $rc RecentChange
509 public function insertTags( &$s, &$rc, &$classes ) {
510 if ( empty($rc->mAttribs
['ts_tags']) )
513 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
514 $classes = array_merge( $classes, $newClasses );
515 $s .= ' ' . $tagSummary;
518 public function insertExtra( &$s, &$rc, &$classes ) {
519 ## Empty, used for subclassers to add anything special.
525 * Generate a list of changes using the good old system (no javascript)
527 class OldChangesList
extends ChangesList
{
529 * Format a line using the old system (aka without any javascript).
531 * @param $rc RecentChange
533 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
534 global $wgLang, $wgRCShowChangedSize, $wgUser;
535 wfProfileIn( __METHOD__
);
536 # Should patrol-related stuff be shown?
537 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
539 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
540 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
544 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
546 if( $linenumber & 1 ) {
547 $classes[] = 'mw-line-odd';
550 $classes[] = 'mw-line-even';
555 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
556 $this->insertMove( $s, $rc );
558 } elseif( $rc->mAttribs
['rc_log_type'] ) {
559 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
560 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
561 // Log entries (old format) or log targets, and special pages
562 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
563 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
564 if( $name == 'Log' ) {
565 $this->insertLog( $s, $rc->getTitle(), $subpage );
569 $this->insertDiffHist( $s, $rc, $unpatrolled );
570 # M, N, b and ! (minor, new, bot and unpatrolled)
571 $s .= $this->recentChangesFlags(
573 'newpage' => $rc->mAttribs
['rc_new'],
574 'minor' => $rc->mAttribs
['rc_minor'],
575 'unpatrolled' => $unpatrolled,
576 'bot' => $rc->mAttribs
['rc_bot']
580 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
583 $this->insertTimestamp( $s, $rc );
584 # Bytes added or removed
585 if( $wgRCShowChangedSize ) {
586 $cd = $rc->getCharacterDifference();
592 $this->insertUserRelatedLinks( $s, $rc );
593 # Log action text (if any)
594 $this->insertAction( $s, $rc );
595 # Edit or log comment
596 $this->insertComment( $s, $rc );
598 $this->insertTags( $s, $rc, $classes );
600 $this->insertRollback( $s, $rc );
602 $this->insertExtra( $s, $rc, $classes );
604 # How many users watch this page
605 if( $rc->numberofWatchingusers
> 0 ) {
606 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
607 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
610 if( $this->watchlist
) {
611 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
614 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
616 wfProfileOut( __METHOD__
);
617 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
623 * Generate a list of changes using an Enhanced system (uses javascript).
625 class EnhancedChangesList
extends ChangesList
{
627 * Add the JavaScript file for enhanced changeslist
630 public function beginRecentChangesList() {
632 $this->rc_cache
= array();
633 $this->rcMoveIndex
= 0;
634 $this->rcCacheIndex
= 0;
635 $this->lastdate
= '';
636 $this->rclistOpen
= false;
637 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
641 * Format a line for enhanced recentchange (aka with javascript and block of lines).
643 * @param $baseRC RecentChange
644 * @param $watched bool
648 public function recentChangesLine( &$baseRC, $watched = false ) {
649 global $wgLang, $wgUser;
651 wfProfileIn( __METHOD__
);
653 # Create a specialised object
654 $rc = RCCacheEntry
::newFromParent( $baseRC );
656 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
658 # If it's a new day, add the headline and flush the cache
659 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
661 if( $date != $this->lastdate
) {
662 # Process current cache
663 $ret = $this->recentChangesBlock();
664 $this->rc_cache
= array();
665 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
666 $this->lastdate
= $date;
669 # Should patrol-related stuff be shown?
670 if( $wgUser->useRCPatrol() ) {
671 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
673 $rc->unpatrolled
= false;
676 $showdifflinks = true;
678 $type = $rc->mAttribs
['rc_type'];
679 $logType = $rc->mAttribs
['rc_log_type'];
681 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
682 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
683 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
684 array(), array( 'redirect' => 'no' ) ),
685 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
686 // New unpatrolled pages
687 } else if( $rc->unpatrolled
&& $type == RC_NEW
) {
688 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
689 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
691 } else if( $type == RC_LOG
) {
693 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
694 $clink = '(' . $this->skin
->linkKnown( $logtitle,
695 LogPage
::logName( $logType ) ) . ')';
697 $clink = $this->skin
->link( $rc->getTitle() );
700 // Log entries (old format) and special pages
701 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
702 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
703 if ( $specialName == 'Log' ) {
705 $logname = LogPage
::logName( $logtype );
706 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
708 wfDebug( "Unexpected special page in recentchanges\n" );
713 $clink = $this->skin
->linkKnown( $rc->getTitle() );
716 # Don't show unusable diff links
717 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
718 $showdifflinks = false;
721 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
722 $rc->watched
= $watched;
724 $rc->timestamp
= $time;
725 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
727 # Make "cur" and "diff" links. Do not use link(), it is too slow if
728 # called too many times (50% of CPU time on RecentChanges!).
729 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
730 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
731 if( $rc->unpatrolled
) {
732 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
734 $rcIdQuery = array();
736 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
737 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
738 $lastOldid ) +
$rcIdQuery;
740 if( !$showdifflinks ) {
741 $curLink = $this->message
['cur'];
742 $diffLink = $this->message
['diff'];
743 } else if( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
744 if ( $type != RC_NEW
) {
745 $curLink = $this->message
['cur'];
747 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
748 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
750 $diffLink = $this->message
['diff'];
752 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
753 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
754 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
755 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
759 if( !$showdifflinks ||
!$lastOldid ) {
760 $lastLink = $this->message
['last'];
761 } else if( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
762 $lastLink = $this->message
['last'];
764 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
765 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
769 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
770 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
772 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
773 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
776 $rc->lastlink
= $lastLink;
777 $rc->curlink
= $curLink;
778 $rc->difflink
= $diffLink;
780 # Put accumulated information into the cache, for later display
781 # Page moves go on their own line
782 $title = $rc->getTitle();
783 $secureName = $title->getPrefixedDBkey();
784 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
785 # Use an @ character to prevent collision with page names
786 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
788 # Logs are grouped by type
789 if( $type == RC_LOG
){
790 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
792 if( !isset( $this->rc_cache
[$secureName] ) ) {
793 $this->rc_cache
[$secureName] = array();
796 array_push( $this->rc_cache
[$secureName], $rc );
799 wfProfileOut( __METHOD__
);
807 protected function recentChangesBlockGroup( $block ) {
808 global $wgLang, $wgContLang, $wgRCShowChangedSize;
810 wfProfileIn( __METHOD__
);
812 # Add the namespace and title of the block as part of the class
813 if ( $block[0]->mAttribs
['rc_log_type'] ) {
815 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
817 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
819 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
820 Html
::openElement( 'tr' );
822 # Collate list of users
823 $userlinks = array();
825 $unpatrolled = false;
827 $curId = $currentRevision = 0;
828 # Some catalyst variables...
831 foreach( $block as $rcObj ) {
832 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
833 if( $rcObj->mAttribs
['rc_new'] ) {
836 // If all log actions to this page were hidden, then don't
837 // give the name of the affected page for this block!
838 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
841 $u = $rcObj->userlink
;
842 if( !isset( $userlinks[$u] ) ) {
845 if( $rcObj->unpatrolled
) {
848 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
851 # Get the latest entry with a page_id and oldid
852 # since logs may not have these.
853 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
854 $curId = $rcObj->mAttribs
['rc_cur_id'];
856 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
857 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
860 $bot = $rcObj->mAttribs
['rc_bot'];
864 # Sort the list and convert to text
865 krsort( $userlinks );
868 foreach( $userlinks as $userlink => $count) {
870 $text .= $wgContLang->getDirMark();
872 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
874 array_push( $users, $text );
877 $users = ' <span class="changedby">[' .
878 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
881 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
882 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
884 $tl = "<span class='mw-collapsible-toggle'>"
885 . "<span class='mw-rc-openarrow'>"
886 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
887 . "</span><span class='mw-rc-closearrow'>"
888 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
890 $r .= "<td>$tl</td>";
893 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
896 'unpatrolled' => $unpatrolled,
901 $r .= ' '.$block[0]->timestamp
.' </td><td>';
905 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
906 } else if( $allLogs ) {
907 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
909 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
912 $r .= $wgContLang->getDirMark();
914 $queryParams['curid'] = $curId;
917 static $nchanges = array();
918 if ( !isset( $nchanges[$n] ) ) {
919 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
925 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
927 } else if( $isnew ) {
930 $params = $queryParams;
931 $params['diff'] = $currentRevision;
932 $params['oldid'] = $oldid;
934 $r .= $this->skin
->link(
935 $block[0]->getTitle(),
939 array( 'known', 'noclasses' )
946 // don't show history link for logs
947 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
948 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
950 $params = $queryParams;
951 $params['action'] = 'history';
953 $r .= $this->message
['pipe-separator'] .
955 $block[0]->getTitle(),
956 $this->message
['hist'],
959 array( 'known', 'noclasses' )
964 # Character difference (does not apply if only log items)
965 if( $wgRCShowChangedSize && !$allLogs ) {
967 $first = count($block) - 1;
968 # Some events (like logs) have an "empty" size, so we need to skip those...
969 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
972 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
976 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
977 $block[$last]->mAttribs
['rc_new_len'] );
979 if( $chardiff == '' ) {
982 $r .= ' ' . $chardiff. ' . . ';
987 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
990 foreach( $block as $rcObj ) {
991 # Classes to apply -- TODO implement
993 $type = $rcObj->mAttribs
['rc_type'];
995 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
996 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
997 $r .= $this->recentChangesFlags( array(
998 'newpage' => $rcObj->mAttribs
['rc_new'],
999 'minor' => $rcObj->mAttribs
['rc_minor'],
1000 'unpatrolled' => $rcObj->unpatrolled
,
1001 'bot' => $rcObj->mAttribs
['rc_bot'],
1003 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1005 $params = $queryParams;
1007 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1008 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1012 if( $type == RC_LOG
) {
1013 $link = $rcObj->timestamp
;
1015 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
1016 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1018 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1019 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1022 $link = $this->skin
->link(
1027 array( 'known', 'noclasses' )
1029 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1030 $link = '<span class="history-deleted">'.$link.'</span> ';
1032 $r .= $link . '</span>';
1034 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1036 $r .= $rcObj->curlink
;
1037 $r .= $this->message
['pipe-separator'];
1038 $r .= $rcObj->lastlink
;
1044 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1045 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1049 $r .= $rcObj->userlink
;
1050 $r .= $rcObj->usertalklink
;
1052 $this->insertAction( $r, $rcObj );
1054 $this->insertComment( $r, $rcObj );
1056 $this->insertRollback( $r, $rcObj );
1058 $this->insertTags( $r, $rcObj, $classes );
1060 $r .= "</td></tr>\n";
1064 $this->rcCacheIndex++
;
1066 wfProfileOut( __METHOD__
);
1072 * Generate HTML for an arrow or placeholder graphic
1073 * @param $dir String: one of '', 'd', 'l', 'r'
1074 * @param $alt String: text
1075 * @param $title String: text
1076 * @return String: HTML <img> tag
1078 protected function arrow( $dir, $alt='', $title='' ) {
1079 global $wgStylePath;
1080 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1081 $encAlt = htmlspecialchars( $alt );
1082 $encTitle = htmlspecialchars( $title );
1083 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1087 * Generate HTML for a right- or left-facing arrow,
1088 * depending on language direction.
1089 * @return String: HTML <img> tag
1091 protected function sideArrow() {
1093 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1094 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1098 * Generate HTML for a down-facing arrow
1099 * depending on language direction.
1100 * @return String: HTML <img> tag
1102 protected function downArrow() {
1103 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1107 * Generate HTML for a spacer image
1108 * @return String: HTML <img> tag
1110 protected function spacerArrow() {
1111 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1115 * Enhanced RC ungrouped line.
1117 * @param $rcObj RecentChange
1118 * @return String: a HTML formated line (generated using $r)
1120 protected function recentChangesBlockLine( $rcObj ) {
1121 global $wgRCShowChangedSize;
1123 wfProfileIn( __METHOD__
);
1124 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1126 $type = $rcObj->mAttribs
['rc_type'];
1127 $logType = $rcObj->mAttribs
['rc_log_type'];
1130 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1132 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1134 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1135 Html
::openElement( 'tr' );
1137 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1138 # Flag and Timestamp
1139 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1140 $r .= '    '; // 4 flags -> 4 spaces
1142 $r .= $this->recentChangesFlags( array(
1143 'newpage' => $type == RC_NEW
,
1144 'mino' => $rcObj->mAttribs
['rc_minor'],
1145 'unpatrolled' => $rcObj->unpatrolled
,
1146 'bot' => $rcObj->mAttribs
['rc_bot'],
1149 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1150 # Article or log link
1152 $logtitle = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1153 $logname = LogPage
::logName( $logType );
1154 $r .= '(' . $this->skin
->link(
1159 array( 'known', 'noclasses' )
1162 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1164 # Diff and hist links
1165 if ( $type != RC_LOG
) {
1166 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1167 $query['action'] = 'history';
1168 $r .= $this->skin
->link(
1170 $this->message
['hist'],
1173 array( 'known', 'noclasses' )
1178 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1182 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1183 # Log action (if any)
1185 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1186 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1188 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1189 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1192 $this->insertComment( $r, $rcObj );
1193 $this->insertRollback( $r, $rcObj );
1195 $classes = explode( ' ', $classes );
1196 $this->insertTags( $r, $rcObj, $classes );
1197 # Show how many people are watching this if enabled
1198 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1200 $r .= "</td></tr></table>\n";
1202 wfProfileOut( __METHOD__
);
1208 * If enhanced RC is in use, this function takes the previously cached
1209 * RC lines, arranges them, and outputs the HTML
1213 protected function recentChangesBlock() {
1214 if( count ( $this->rc_cache
) == 0 ) {
1218 wfProfileIn( __METHOD__
);
1221 foreach( $this->rc_cache
as $block ) {
1222 if( count( $block ) < 2 ) {
1223 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1225 $blockOut .= $this->recentChangesBlockGroup( $block );
1229 wfProfileOut( __METHOD__
);
1231 return '<div>'.$blockOut.'</div>';
1235 * Returns text for the end of RC
1236 * If enhanced RC is in use, returns pretty much all the text
1238 public function endRecentChangesList() {
1239 return $this->recentChangesBlock() . parent
::endRecentChangesList();