6 class RCCacheEntry
extends RecentChange
{
7 var $secureName, $link;
8 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
9 var $userlink, $timestamp, $watched;
11 static function newFromParent( $rc ) {
12 $rc2 = new RCCacheEntry
;
13 $rc2->mAttribs
= $rc->mAttribs
;
14 $rc2->mExtra
= $rc->mExtra
;
20 * Class to show various lists of changes:
26 # Called by history lists and recent changes
28 protected $watchlist = false;
31 * Changeslist contructor
34 public function __construct( &$skin ) {
36 $this->preCacheMessages();
40 * Fetch an appropriate changes list class for the specified user
41 * Some users might want to use an enhanced list format, for instance
43 * @param $user User to fetch the list class for
44 * @return ChangesList derivative
46 public static function newFromUser( &$user ) {
47 $sk = $user->getSkin();
49 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
50 return $user->getOption( 'usenewrc' ) ?
51 new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
58 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
61 public function setWatchlistDivs( $value = true ) {
62 $this->watchlist
= $value;
66 * As we use the same small set of messages in various methods and that
67 * they are called often, we call them once and save them in $this->message
69 private function preCacheMessages() {
70 if( !isset( $this->message
) ) {
71 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
72 'semicolon-separator pipe-separator' ) as $msg ) {
73 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
80 * Returns the appropriate flags for new page, minor change and patrolling
83 * @param bool $patrolled
84 * @param string $nothing, string to use for empty space
88 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
89 $f = $new ? self
::flag( 'newpage' ) : $nothing;
90 $f .= $minor ? self
::flag( 'minor' ) : $nothing;
91 $f .= $bot ? self
::flag( 'bot' ) : $nothing;
92 $f .= $patrolled ? self
::flag( 'unpatrolled' ) : $nothing;
97 * Provide the <abbr> element appropriate to a given abbreviated flag,
98 * namely the flag indicating a new page, a minor edit, a bot edit, or an
99 * unpatrolled edit. By default in English it will contain "N", "m", "b",
100 * "!" respectively, plus it will have an appropriate title and class.
102 * @param $key string 'newpage', 'unpatrolled', 'minor', or 'bot'
103 * @return string Raw HTML
105 public static function flag( $key ) {
106 static $messages = null;
107 if ( is_null( $messages ) ) {
108 foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' .
109 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' .
110 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) {
111 $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' );
114 # Inconsistent naming, bleh
115 if ( $key == 'newpage' ||
$key == 'unpatrolled' ) {
118 $key2 = $key . 'edit';
120 return "<abbr class=\"$key\" title=\""
121 . $messages["recentchanges-label-$key"] . "\">"
122 . $messages["${key2}letter"]
127 * Some explanatory wrapper text for the given flag, to be used in a legend
128 * explaining what the flags mean. For instance, "N - new page". See
131 * @param $key string 'newpage', 'unpatrolled', 'minor', or 'bot'
132 * @return string Raw HTML
134 private static function flagLine( $key ) {
135 return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities',
136 'replaceafter' ), self
::flag( $key ) );
140 * A handy legend to tell users what the little "m", "b", and so on mean.
142 * @return string Raw HTML
144 public static function flagLegend() {
145 global $wgGroupPermissions, $wgLang;
147 $flags = array( self
::flagLine( 'newpage' ),
148 self
::flagLine( 'minor' ) );
150 # Don't show info on bot edits unless there's a bot group of some kind
151 foreach ( $wgGroupPermissions as $rights ) {
152 if ( isset( $rights['bot'] ) && $rights['bot'] ) {
153 $flags[] = self
::flagLine( 'bot' );
158 if ( self
::usePatrol() ) {
159 $flags[] = self
::flagLine( 'unpatrolled' );
162 return '<div class="mw-rc-label-legend">' .
163 wfMsgExt( 'recentchanges-label-legend', 'parseinline',
164 $wgLang->commaList( $flags ) ) . '</div>';
168 * Returns text for the start of the tabular part of RC
171 public function beginRecentChangesList() {
172 $this->rc_cache
= array();
173 $this->rcMoveIndex
= 0;
174 $this->rcCacheIndex
= 0;
175 $this->lastdate
= '';
176 $this->rclistOpen
= false;
181 * Show formatted char difference
182 * @param int $old bytes
183 * @param int $new bytes
186 public static function showCharacterDifference( $old, $new ) {
187 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
188 $szdiff = $new - $old;
190 $code = $wgLang->getCode();
191 static $fastCharDiff = array();
192 if ( !isset($fastCharDiff[$code]) ) {
193 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
196 $formatedSize = $wgLang->formatNum($szdiff);
198 if ( !$fastCharDiff[$code] ) {
199 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
202 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
207 if( $szdiff === 0 ) {
208 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
209 } elseif( $szdiff > 0 ) {
210 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
212 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
217 * Returns text for the end of RC
220 public function endRecentChangesList() {
221 if( $this->rclistOpen
) {
228 protected function insertMove( &$s, $rc ) {
230 $s .= '(' . $this->message
['diff'] . ') (';
232 $s .= $this->skin
->link(
233 $rc->getMovedToTitle(),
234 $this->message
['hist'],
236 array( 'action' => 'history' ),
237 array( 'known', 'noclasses' )
239 # "[[x]] moved to [[y]]"
240 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
247 array( 'redirect' => 'no' ),
248 array( 'known', 'noclasses' )
251 $rc->getMovedToTitle(),
255 array( 'known', 'noclasses' )
260 protected function insertDateHeader( &$s, $rc_timestamp ) {
262 # Make date header if necessary
263 $date = $wgLang->date( $rc_timestamp, true, true );
264 if( $date != $this->lastdate
) {
265 if( '' != $this->lastdate
) {
268 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
269 $this->lastdate
= $date;
270 $this->rclistOpen
= true;
274 protected function insertLog( &$s, $title, $logtype ) {
275 $logname = LogPage
::logName( $logtype );
276 $s .= '(' . $this->skin
->link(
281 array( 'known', 'noclasses' )
285 protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
287 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
288 $diffLink = $this->message
['diff'];
289 } else if( !$this->userCan($rc,Revision
::DELETED_TEXT
) ) {
290 $diffLink = $this->message
['diff'];
293 'curid' => $rc->mAttribs
['rc_cur_id'],
294 'diff' => $rc->mAttribs
['rc_this_oldid'],
295 'oldid' => $rc->mAttribs
['rc_last_oldid']
299 $query['rcid'] = $rc->mAttribs
['rc_id'];
302 $diffLink = $this->skin
->link(
304 $this->message
['diff'],
305 array( 'tabindex' => $rc->counter
),
307 array( 'known', 'noclasses' )
310 $s .= '('.$diffLink.') (';
312 $s .= $this->skin
->link(
314 $this->message
['hist'],
317 'curid' => $rc->mAttribs
['rc_cur_id'],
318 'action' => 'history'
320 array( 'known', 'noclasses' )
325 protected 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";
366 protected function insertTimestamp( &$s, $rc ) {
368 $s .= $this->message
['semicolon-separator'] .
369 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
372 /** Insert links to user page, user talk page and eventually a blocking link */
373 public function insertUserRelatedLinks( &$s, &$rc ) {
374 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
375 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
377 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
378 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
382 /** insert a formatted action */
383 protected function insertAction( &$s, &$rc ) {
384 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
385 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
386 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
388 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
389 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
394 /** insert a formatted comment */
395 protected function insertComment( &$s, &$rc ) {
396 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
397 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
398 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
400 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
406 * Check whether to enable recent changes patrol features
409 public static function usePatrol() {
411 return $wgUser->useRCPatrol();
415 * Returns the string which indicates the number of watching users
417 protected function numberofWatchingusers( $count ) {
419 static $cache = array();
421 if( !isset( $cache[$count] ) ) {
422 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
423 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
425 return $cache[$count];
432 * Determine if said field of a revision is hidden
433 * @param RCCacheEntry $rc
434 * @param int $field one of DELETED_* bitfield constants
437 public static function isDeleted( $rc, $field ) {
438 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
442 * Determine if the current user is allowed to view a particular
443 * field of this revision, if it's marked as deleted.
444 * @param RCCacheEntry $rc
448 public static function userCan( $rc, $field ) {
449 if( ( $rc->mAttribs
['rc_deleted'] & $field ) == $field ) {
451 $permission = ( $rc->mAttribs
['rc_deleted'] & Revision
::DELETED_RESTRICTED
) == Revision
::DELETED_RESTRICTED
454 wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" );
455 return $wgUser->isAllowed( $permission );
461 protected function maybeWatchedLink( $link, $watched = false ) {
463 return '<strong class="mw-watched">' . $link . '</strong>';
465 return '<span class="mw-rc-unwatched">' . $link . '</span>';
469 /** Inserts a rollback link */
470 public function insertRollback( &$s, &$rc ) {
472 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
473 $page = $rc->getTitle();
474 /** Check for rollback and edit permissions, disallow special pages, and only
475 * show a link on the top-most revision */
476 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
478 $rev = new Revision( array(
479 'id' => $rc->mAttribs
['rc_this_oldid'],
480 'user' => $rc->mAttribs
['rc_user'],
481 'user_text' => $rc->mAttribs
['rc_user_text'],
482 'deleted' => $rc->mAttribs
['rc_deleted']
484 $rev->setTitle( $page );
485 $s .= ' '.$this->skin
->generateRollback( $rev );
490 public function insertTags( &$s, &$rc, &$classes ) {
491 if ( empty($rc->mAttribs
['ts_tags']) )
494 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
495 $classes = array_merge( $classes, $newClasses );
496 $s .= ' ' . $tagSummary;
499 public function insertExtra( &$s, &$rc, &$classes ) {
500 ## Empty, used for subclassers to add anything special.
506 * Generate a list of changes using the good old system (no javascript)
508 class OldChangesList
extends ChangesList
{
510 * Format a line using the old system (aka without any javascript).
512 public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) {
513 global $wgLang, $wgRCShowChangedSize, $wgUser;
514 wfProfileIn( __METHOD__
);
515 # Should patrol-related stuff be shown?
516 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
518 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
519 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
523 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
525 if( $linenumber & 1 ) {
526 $classes[] = 'mw-line-odd';
529 $classes[] = 'mw-line-even';
534 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
535 $this->insertMove( $s, $rc );
537 } elseif( $rc->mAttribs
['rc_log_type'] ) {
538 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
539 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
540 // Log entries (old format) or log targets, and special pages
541 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
542 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
543 if( $name == 'Log' ) {
544 $this->insertLog( $s, $rc->getTitle(), $subpage );
548 $this->insertDiffHist( $s, $rc, $unpatrolled );
549 # M, N, b and ! (minor, new, bot and unpatrolled)
550 $s .= $this->recentChangesFlags( $rc->mAttribs
['rc_new'], $rc->mAttribs
['rc_minor'],
551 $unpatrolled, '', $rc->mAttribs
['rc_bot'] );
552 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
555 $this->insertTimestamp( $s, $rc );
556 # Bytes added or removed
557 if( $wgRCShowChangedSize ) {
558 $cd = $rc->getCharacterDifference();
564 $this->insertUserRelatedLinks( $s, $rc );
565 # Log action text (if any)
566 $this->insertAction( $s, $rc );
567 # Edit or log comment
568 $this->insertComment( $s, $rc );
570 $this->insertTags( $s, $rc, $classes );
572 $this->insertRollback( $s, $rc );
574 $this->insertExtra( $s, $rc, $classes );
576 # How many users watch this page
577 if( $rc->numberofWatchingusers
> 0 ) {
578 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
579 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
582 if( $this->watchlist
) {
583 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
586 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
588 wfProfileOut( __METHOD__
);
589 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
595 * Generate a list of changes using an Enhanced system (uses javascript).
597 class EnhancedChangesList
extends ChangesList
{
599 * Add the JavaScript file for enhanced changeslist
602 public function beginRecentChangesList() {
603 global $wgStylePath, $wgStyleVersion;
604 $this->rc_cache
= array();
605 $this->rcMoveIndex
= 0;
606 $this->rcCacheIndex
= 0;
607 $this->lastdate
= '';
608 $this->rclistOpen
= false;
609 $script = Html
::linkedScript( $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" );
613 * Format a line for enhanced recentchange (aka with javascript and block of lines).
615 public function recentChangesLine( &$baseRC, $watched = false ) {
616 global $wgLang, $wgUser;
618 wfProfileIn( __METHOD__
);
620 # Create a specialised object
621 $rc = RCCacheEntry
::newFromParent( $baseRC );
623 # Extract fields from DB into the function scope (rc_xxxx variables)
624 // FIXME: Would be good to replace this extract() call with something
625 // that explicitly initializes variables.
626 extract( $rc->mAttribs
);
627 $curIdEq = array( 'curid' => $rc_cur_id );
629 # If it's a new day, add the headline and flush the cache
630 $date = $wgLang->date( $rc_timestamp, true );
632 if( $date != $this->lastdate
) {
633 # Process current cache
634 $ret = $this->recentChangesBlock();
635 $this->rc_cache
= array();
636 $ret .= Xml
::element( 'h4', null, $date );
637 $this->lastdate
= $date;
640 # Should patrol-related stuff be shown?
641 if( $wgUser->useRCPatrol() ) {
642 $rc->unpatrolled
= !$rc_patrolled;
644 $rc->unpatrolled
= false;
647 $showdifflinks = true;
650 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
651 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
652 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
653 array(), array( 'redirect' => 'no' ) ),
654 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
655 // New unpatrolled pages
656 } else if( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
657 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
658 array( 'rcid' => $rc_id ) );
660 } else if( $rc_type == RC_LOG
) {
662 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc_log_type );
663 $clink = '(' . $this->skin
->linkKnown( $logtitle,
664 LogPage
::logName($rc_log_type) ) . ')';
666 $clink = $this->skin
->link( $rc->getTitle() );
669 // Log entries (old format) and special pages
670 } elseif( $rc_namespace == NS_SPECIAL
) {
671 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
672 if ( $specialName == 'Log' ) {
674 $logname = LogPage
::logName( $logtype );
675 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
677 wfDebug( "Unexpected special page in recentchanges\n" );
682 $clink = $this->skin
->linkKnown( $rc->getTitle() );
685 # Don't show unusable diff links
686 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
687 $showdifflinks = false;
690 $time = $wgLang->time( $rc_timestamp, true, true );
691 $rc->watched
= $watched;
693 $rc->timestamp
= $time;
694 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
696 # Make "cur" and "diff" links. Do not use link(), it is too slow if
697 # called too many times (50% of CPU time on RecentChanges!).
698 if( $rc->unpatrolled
) {
699 $rcIdQuery = array( 'rcid' => $rc_id );
701 $rcIdQuery = array();
703 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $rc_this_oldid );
704 $querydiff = $curIdEq +
array( 'diff' => $rc_this_oldid, 'oldid' =>
705 $rc_last_oldid ) +
$rcIdQuery;
707 if( !$showdifflinks ) {
708 $curLink = $this->message
['cur'];
709 $diffLink = $this->message
['diff'];
710 } else if( in_array( $rc_type, array(RC_NEW
,RC_LOG
,RC_MOVE
,RC_MOVE_OVER_REDIRECT
) ) ) {
711 if ( $rc_type != RC_NEW
) {
712 $curLink = $this->message
['cur'];
714 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
715 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
717 $diffLink = $this->message
['diff'];
719 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
720 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
721 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
722 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
726 if( !$showdifflinks ||
!$rc_last_oldid ) {
727 $lastLink = $this->message
['last'];
728 } else if( $rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
729 $lastLink = $this->message
['last'];
731 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
732 array(), $curIdEq +
array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) +
$rcIdQuery );
736 if( $this->isDeleted($rc,Revision
::DELETED_USER
) ) {
737 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
739 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
740 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
743 $rc->lastlink
= $lastLink;
744 $rc->curlink
= $curLink;
745 $rc->difflink
= $diffLink;
747 # Put accumulated information into the cache, for later display
748 # Page moves go on their own line
749 $title = $rc->getTitle();
750 $secureName = $title->getPrefixedDBkey();
751 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
752 # Use an @ character to prevent collision with page names
753 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
755 # Logs are grouped by type
756 if( $rc_type == RC_LOG
){
757 $secureName = SpecialPage
::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
759 if( !isset( $this->rc_cache
[$secureName] ) ) {
760 $this->rc_cache
[$secureName] = array();
763 array_push( $this->rc_cache
[$secureName], $rc );
766 wfProfileOut( __METHOD__
);
774 protected function recentChangesBlockGroup( $block ) {
775 global $wgLang, $wgContLang, $wgRCShowChangedSize;
777 wfProfileIn( __METHOD__
);
779 $r = '<table class="mw-enhanced-rc"><tr>';
781 # Collate list of users
782 $userlinks = array();
784 $unpatrolled = false;
786 $curId = $currentRevision = 0;
787 # Some catalyst variables...
790 foreach( $block as $rcObj ) {
791 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
792 if( $rcObj->mAttribs
['rc_new'] ) {
795 // If all log actions to this page were hidden, then don't
796 // give the name of the affected page for this block!
797 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
800 $u = $rcObj->userlink
;
801 if( !isset( $userlinks[$u] ) ) {
804 if( $rcObj->unpatrolled
) {
807 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
810 # Get the latest entry with a page_id and oldid
811 # since logs may not have these.
812 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
813 $curId = $rcObj->mAttribs
['rc_cur_id'];
815 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
816 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
819 $bot = $rcObj->mAttribs
['rc_bot'];
823 # Sort the list and convert to text
824 krsort( $userlinks );
827 foreach( $userlinks as $userlink => $count) {
829 $text .= $wgContLang->getDirMark();
831 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
833 array_push( $users, $text );
836 $users = ' <span class="changedby">[' .
837 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
839 # ID for JS visibility toggle
840 $jsid = $this->rcCacheIndex
;
841 # onclick handler to toggle hidden/expanded
842 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
844 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
845 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
847 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
848 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
849 $r .= '<td class="mw-enhanced-rc">'.$tl.' ';
852 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
855 $r .= ' '.$block[0]->timestamp
.' </td><td>';
859 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
860 } else if( $allLogs ) {
861 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
863 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
866 $r .= $wgContLang->getDirMark();
868 $queryParams['curid'] = $curId;
871 static $nchanges = array();
872 if ( !isset( $nchanges[$n] ) ) {
873 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
879 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
881 } else if( $isnew ) {
884 $params = $queryParams;
885 $params['diff'] = $currentRevision;
886 $params['oldid'] = $oldid;
888 $r .= $this->skin
->link(
889 $block[0]->getTitle(),
893 array( 'known', 'noclasses' )
900 // don't show history link for logs
901 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
902 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
904 $params = $queryParams;
905 $params['action'] = 'history';
907 $r .= $this->message
['pipe-separator'] .
909 $block[0]->getTitle(),
910 $this->message
['hist'],
913 array( 'known', 'noclasses' )
918 # Character difference (does not apply if only log items)
919 if( $wgRCShowChangedSize && !$allLogs ) {
921 $first = count($block) - 1;
922 # Some events (like logs) have an "empty" size, so we need to skip those...
923 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === NULL ) {
926 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === NULL ) {
930 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
931 $block[$last]->mAttribs
['rc_new_len'] );
933 if( $chardiff == '' ) {
936 $r .= ' ' . $chardiff. ' . . ';
941 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
943 $r .= "</td></tr></table>\n";
946 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
947 $r .= '<table class="mw-enhanced-rc">';
948 foreach( $block as $rcObj ) {
949 # Extract fields from DB into the function scope (rc_xxxx variables)
950 // FIXME: Would be good to replace this extract() call with something
951 // that explicitly initializes variables.
952 # Classes to apply -- TODO implement
954 extract( $rcObj->mAttribs
);
956 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
957 $r .= '<tr><td style="vertical-align:top;font-family:monospace">';
958 $r .= $this->spacerIndent() . $this->spacerIndent();
959 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
960 $r .= ' </td><td style="vertical-align:top"><span style="font-family:monospace">';
962 $params = $queryParams;
964 if( $rc_this_oldid != 0 ) {
965 $params['oldid'] = $rc_this_oldid;
969 if( $rc_type == RC_LOG
) {
970 $link = $rcObj->timestamp
;
972 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
973 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
975 if ( $rcObj->unpatrolled
&& $rc_type == RC_NEW
) {
976 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
979 $link = $this->skin
->link(
984 array( 'known', 'noclasses' )
986 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
987 $link = '<span class="history-deleted">'.$link.'</span> ';
989 $r .= $link . '</span>';
991 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
993 $r .= $rcObj->curlink
;
994 $r .= $this->message
['pipe-separator'];
995 $r .= $rcObj->lastlink
;
1001 if( $wgRCShowChangedSize ) {
1002 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
1005 $r .= $rcObj->userlink
;
1006 $r .= $rcObj->usertalklink
;
1008 $this->insertAction( $r, $rcObj );
1010 $this->insertComment( $r, $rcObj );
1012 $this->insertRollback( $r, $rcObj );
1014 $this->insertTags( $r, $rcObj, $classes );
1016 $r .= "</td></tr>\n";
1018 $r .= "</table></div>\n";
1020 $this->rcCacheIndex++
;
1022 wfProfileOut( __METHOD__
);
1028 * Generate HTML for an arrow or placeholder graphic
1029 * @param string $dir one of '', 'd', 'l', 'r'
1030 * @param string $alt text
1031 * @param string $title text
1032 * @return string HTML <img> tag
1034 protected function arrow( $dir, $alt='', $title='' ) {
1035 global $wgStylePath;
1036 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1037 $encAlt = htmlspecialchars( $alt );
1038 $encTitle = htmlspecialchars( $title );
1039 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1043 * Generate HTML for a right- or left-facing arrow,
1044 * depending on language direction.
1045 * @return string HTML <img> tag
1047 protected function sideArrow() {
1049 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1050 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1054 * Generate HTML for a down-facing arrow
1055 * depending on language direction.
1056 * @return string HTML <img> tag
1058 protected function downArrow() {
1059 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1063 * Generate HTML for a spacer image
1064 * @return string HTML <img> tag
1066 protected function spacerArrow() {
1067 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1071 * Add a set of spaces
1072 * @return string HTML <td> tag
1074 protected function spacerIndent() {
1075 return ' ';
1079 * Enhanced RC ungrouped line.
1080 * @return string a HTML formated line (generated using $r)
1082 protected function recentChangesBlockLine( $rcObj ) {
1083 global $wgRCShowChangedSize;
1085 wfProfileIn( __METHOD__
);
1087 # Extract fields from DB into the function scope (rc_xxxx variables)
1088 // FIXME: Would be good to replace this extract() call with something
1089 // that explicitly initializes variables.
1090 $classes = array(); // TODO implement
1091 extract( $rcObj->mAttribs
);
1092 $query['curid'] = $rc_cur_id;
1094 $r = '<table class="mw-enhanced-rc"><tr>';
1095 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . ' ';
1096 # Flag and Timestamp
1097 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
1098 $r .= ' '; // 4 flags -> 4 spaces
1100 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
1102 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1103 # Article or log link
1104 if( $rc_log_type ) {
1105 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
1106 $logname = LogPage
::logName( $rc_log_type );
1107 $r .= '(' . $this->skin
->link(
1112 array( 'known', 'noclasses' )
1115 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1117 # Diff and hist links
1118 if ( $rc_type != RC_LOG
) {
1119 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1120 $query['action'] = 'history';
1121 $r .= $this->skin
->link(
1123 $this->message
['hist'],
1126 array( 'known', 'noclasses' )
1131 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1135 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1136 # Log action (if any)
1137 if( $rc_log_type ) {
1138 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1139 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1141 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1142 $this->skin
, LogPage
::extractParams($rc_params), true, true );
1145 $this->insertComment( $r, $rcObj );
1146 $this->insertRollback( $r, $rcObj );
1148 $this->insertTags( $r, $rcObj, $classes );
1149 # Show how many people are watching this if enabled
1150 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1152 $r .= "</td></tr></table>\n";
1154 wfProfileOut( __METHOD__
);
1160 * If enhanced RC is in use, this function takes the previously cached
1161 * RC lines, arranges them, and outputs the HTML
1163 protected function recentChangesBlock() {
1164 if( count ( $this->rc_cache
) == 0 ) {
1168 wfProfileIn( __METHOD__
);
1171 foreach( $this->rc_cache
as $block ) {
1172 if( count( $block ) < 2 ) {
1173 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1175 $blockOut .= $this->recentChangesBlockGroup( $block );
1179 wfProfileOut( __METHOD__
);
1181 return '<div>'.$blockOut.'</div>';
1185 * Returns text for the end of RC
1186 * If enhanced RC is in use, returns pretty much all the text
1188 public function endRecentChangesList() {
1189 return $this->recentChangesBlock() . parent
::endRecentChangesList();