f2433c2876a813c1e505fea88694859f41d021a8
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 public static function flagLegend( $key ) {
135 return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities',
136 'replaceafter' ), self
::flag( $key ) );
140 * Returns text for the start of the tabular part of RC
143 public function beginRecentChangesList() {
144 $this->rc_cache
= array();
145 $this->rcMoveIndex
= 0;
146 $this->rcCacheIndex
= 0;
147 $this->lastdate
= '';
148 $this->rclistOpen
= false;
153 * Show formatted char difference
154 * @param int $old bytes
155 * @param int $new bytes
158 public static function showCharacterDifference( $old, $new ) {
159 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
160 $szdiff = $new - $old;
162 $code = $wgLang->getCode();
163 static $fastCharDiff = array();
164 if ( !isset($fastCharDiff[$code]) ) {
165 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
168 $formatedSize = $wgLang->formatNum($szdiff);
170 if ( !$fastCharDiff[$code] ) {
171 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
174 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
179 if( $szdiff === 0 ) {
180 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
181 } elseif( $szdiff > 0 ) {
182 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
184 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
189 * Returns text for the end of RC
192 public function endRecentChangesList() {
193 if( $this->rclistOpen
) {
200 protected function insertMove( &$s, $rc ) {
202 $s .= '(' . $this->message
['diff'] . ') (';
204 $s .= $this->skin
->link(
205 $rc->getMovedToTitle(),
206 $this->message
['hist'],
208 array( 'action' => 'history' ),
209 array( 'known', 'noclasses' )
211 # "[[x]] moved to [[y]]"
212 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
219 array( 'redirect' => 'no' ),
220 array( 'known', 'noclasses' )
223 $rc->getMovedToTitle(),
227 array( 'known', 'noclasses' )
232 protected function insertDateHeader( &$s, $rc_timestamp ) {
234 # Make date header if necessary
235 $date = $wgLang->date( $rc_timestamp, true, true );
236 if( $date != $this->lastdate
) {
237 if( '' != $this->lastdate
) {
240 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
241 $this->lastdate
= $date;
242 $this->rclistOpen
= true;
246 protected function insertLog( &$s, $title, $logtype ) {
247 $logname = LogPage
::logName( $logtype );
248 $s .= '(' . $this->skin
->link(
253 array( 'known', 'noclasses' )
257 protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
259 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
260 $diffLink = $this->message
['diff'];
261 } else if( !$this->userCan($rc,Revision
::DELETED_TEXT
) ) {
262 $diffLink = $this->message
['diff'];
265 'curid' => $rc->mAttribs
['rc_cur_id'],
266 'diff' => $rc->mAttribs
['rc_this_oldid'],
267 'oldid' => $rc->mAttribs
['rc_last_oldid']
271 $query['rcid'] = $rc->mAttribs
['rc_id'];
274 $diffLink = $this->skin
->link(
276 $this->message
['diff'],
277 array( 'tabindex' => $rc->counter
),
279 array( 'known', 'noclasses' )
282 $s .= '('.$diffLink.') (';
284 $s .= $this->skin
->link(
286 $this->message
['hist'],
289 'curid' => $rc->mAttribs
['rc_cur_id'],
290 'action' => 'history'
292 array( 'known', 'noclasses' )
297 protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
299 # If it's a new article, there is no diff link, but if it hasn't been
300 # patrolled yet, we need to give users a way to do so
303 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
304 $params['rcid'] = $rc->mAttribs
['rc_id'];
307 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
308 $articlelink = $this->skin
->link(
313 array( 'known', 'noclasses' )
315 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
317 $articlelink = ' '. $this->skin
->link(
322 array( 'known', 'noclasses' )
325 # Bolden pages watched by this user
327 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
330 $articlelink .= $wgContLang->getDirMark();
332 wfRunHooks( 'ChangesListInsertArticleLink',
333 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
335 $s .= " $articlelink";
338 protected function insertTimestamp( &$s, $rc ) {
340 $s .= $this->message
['semicolon-separator'] .
341 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
344 /** Insert links to user page, user talk page and eventually a blocking link */
345 public function insertUserRelatedLinks( &$s, &$rc ) {
346 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
347 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
349 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
350 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
354 /** insert a formatted action */
355 protected function insertAction( &$s, &$rc ) {
356 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
357 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
358 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
360 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
361 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
366 /** insert a formatted comment */
367 protected function insertComment( &$s, &$rc ) {
368 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
369 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
370 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
372 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
378 * Check whether to enable recent changes patrol features
381 public static function usePatrol() {
383 return $wgUser->useRCPatrol();
387 * Returns the string which indicates the number of watching users
389 protected function numberofWatchingusers( $count ) {
391 static $cache = array();
393 if( !isset( $cache[$count] ) ) {
394 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
395 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
397 return $cache[$count];
404 * Determine if said field of a revision is hidden
405 * @param RCCacheEntry $rc
406 * @param int $field one of DELETED_* bitfield constants
409 public static function isDeleted( $rc, $field ) {
410 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
414 * Determine if the current user is allowed to view a particular
415 * field of this revision, if it's marked as deleted.
416 * @param RCCacheEntry $rc
420 public static function userCan( $rc, $field ) {
421 if( ( $rc->mAttribs
['rc_deleted'] & $field ) == $field ) {
423 $permission = ( $rc->mAttribs
['rc_deleted'] & Revision
::DELETED_RESTRICTED
) == Revision
::DELETED_RESTRICTED
426 wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" );
427 return $wgUser->isAllowed( $permission );
433 protected function maybeWatchedLink( $link, $watched = false ) {
435 return '<strong class="mw-watched">' . $link . '</strong>';
437 return '<span class="mw-rc-unwatched">' . $link . '</span>';
441 /** Inserts a rollback link */
442 public function insertRollback( &$s, &$rc ) {
444 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
445 $page = $rc->getTitle();
446 /** Check for rollback and edit permissions, disallow special pages, and only
447 * show a link on the top-most revision */
448 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
450 $rev = new Revision( array(
451 'id' => $rc->mAttribs
['rc_this_oldid'],
452 'user' => $rc->mAttribs
['rc_user'],
453 'user_text' => $rc->mAttribs
['rc_user_text'],
454 'deleted' => $rc->mAttribs
['rc_deleted']
456 $rev->setTitle( $page );
457 $s .= ' '.$this->skin
->generateRollback( $rev );
462 public function insertTags( &$s, &$rc, &$classes ) {
463 if ( empty($rc->mAttribs
['ts_tags']) )
466 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
467 $classes = array_merge( $classes, $newClasses );
468 $s .= ' ' . $tagSummary;
471 public function insertExtra( &$s, &$rc, &$classes ) {
472 ## Empty, used for subclassers to add anything special.
478 * Generate a list of changes using the good old system (no javascript)
480 class OldChangesList
extends ChangesList
{
482 * Format a line using the old system (aka without any javascript).
484 public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) {
485 global $wgLang, $wgRCShowChangedSize, $wgUser;
486 wfProfileIn( __METHOD__
);
487 # Should patrol-related stuff be shown?
488 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
490 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
491 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
495 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
497 if( $linenumber & 1 ) {
498 $classes[] = 'mw-line-odd';
501 $classes[] = 'mw-line-even';
506 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
507 $this->insertMove( $s, $rc );
509 } elseif( $rc->mAttribs
['rc_log_type'] ) {
510 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
511 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
512 // Log entries (old format) or log targets, and special pages
513 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
514 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
515 if( $name == 'Log' ) {
516 $this->insertLog( $s, $rc->getTitle(), $subpage );
520 $this->insertDiffHist( $s, $rc, $unpatrolled );
521 # M, N, b and ! (minor, new, bot and unpatrolled)
522 $s .= $this->recentChangesFlags( $rc->mAttribs
['rc_new'], $rc->mAttribs
['rc_minor'],
523 $unpatrolled, '', $rc->mAttribs
['rc_bot'] );
524 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
527 $this->insertTimestamp( $s, $rc );
528 # Bytes added or removed
529 if( $wgRCShowChangedSize ) {
530 $cd = $rc->getCharacterDifference();
536 $this->insertUserRelatedLinks( $s, $rc );
537 # Log action text (if any)
538 $this->insertAction( $s, $rc );
539 # Edit or log comment
540 $this->insertComment( $s, $rc );
542 $this->insertTags( $s, $rc, $classes );
544 $this->insertRollback( $s, $rc );
546 $this->insertExtra( $s, $rc, $classes );
548 # How many users watch this page
549 if( $rc->numberofWatchingusers
> 0 ) {
550 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
551 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
554 if( $this->watchlist
) {
555 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
558 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
560 wfProfileOut( __METHOD__
);
561 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
567 * Generate a list of changes using an Enhanced system (uses javascript).
569 class EnhancedChangesList
extends ChangesList
{
571 * Add the JavaScript file for enhanced changeslist
574 public function beginRecentChangesList() {
575 global $wgStylePath, $wgJsMimeType, $wgStyleVersion;
576 $this->rc_cache
= array();
577 $this->rcMoveIndex
= 0;
578 $this->rcCacheIndex
= 0;
579 $this->lastdate
= '';
580 $this->rclistOpen
= false;
581 $script = Xml
::tags( 'script', array(
582 'type' => $wgJsMimeType,
583 'src' => $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" ), '' );
587 * Format a line for enhanced recentchange (aka with javascript and block of lines).
589 public function recentChangesLine( &$baseRC, $watched = false ) {
590 global $wgLang, $wgUser;
592 wfProfileIn( __METHOD__
);
594 # Create a specialised object
595 $rc = RCCacheEntry
::newFromParent( $baseRC );
597 # Extract fields from DB into the function scope (rc_xxxx variables)
598 // FIXME: Would be good to replace this extract() call with something
599 // that explicitly initializes variables.
600 extract( $rc->mAttribs
);
601 $curIdEq = array( 'curid' => $rc_cur_id );
603 # If it's a new day, add the headline and flush the cache
604 $date = $wgLang->date( $rc_timestamp, true );
606 if( $date != $this->lastdate
) {
607 # Process current cache
608 $ret = $this->recentChangesBlock();
609 $this->rc_cache
= array();
610 $ret .= Xml
::element( 'h4', null, $date );
611 $this->lastdate
= $date;
614 # Should patrol-related stuff be shown?
615 if( $wgUser->useRCPatrol() ) {
616 $rc->unpatrolled
= !$rc_patrolled;
618 $rc->unpatrolled
= false;
621 $showdifflinks = true;
624 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
625 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
626 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
627 array(), array( 'redirect' => 'no' ) ),
628 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
629 // New unpatrolled pages
630 } else if( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
631 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
632 array( 'rcid' => $rc_id ) );
634 } else if( $rc_type == RC_LOG
) {
636 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc_log_type );
637 $clink = '(' . $this->skin
->linkKnown( $logtitle,
638 LogPage
::logName($rc_log_type) ) . ')';
640 $clink = $this->skin
->link( $rc->getTitle() );
643 // Log entries (old format) and special pages
644 } elseif( $rc_namespace == NS_SPECIAL
) {
645 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
646 if ( $specialName == 'Log' ) {
648 $logname = LogPage
::logName( $logtype );
649 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
651 wfDebug( "Unexpected special page in recentchanges\n" );
656 $clink = $this->skin
->linkKnown( $rc->getTitle() );
659 # Don't show unusable diff links
660 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
661 $showdifflinks = false;
664 $time = $wgLang->time( $rc_timestamp, true, true );
665 $rc->watched
= $watched;
667 $rc->timestamp
= $time;
668 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
670 # Make "cur" and "diff" links. Do not use link(), it is too slow if
671 # called too many times (50% of CPU time on RecentChanges!).
672 if( $rc->unpatrolled
) {
673 $rcIdQuery = array( 'rcid' => $rc_id );
675 $rcIdQuery = array();
677 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $rc_this_oldid );
678 $querydiff = $curIdEq +
array( 'diff' => $rc_this_oldid, 'oldid' =>
679 $rc_last_oldid ) +
$rcIdQuery;
681 if( !$showdifflinks ) {
682 $curLink = $this->message
['cur'];
683 $diffLink = $this->message
['diff'];
684 } else if( in_array( $rc_type, array(RC_NEW
,RC_LOG
,RC_MOVE
,RC_MOVE_OVER_REDIRECT
) ) ) {
685 if ( $rc_type != RC_NEW
) {
686 $curLink = $this->message
['cur'];
688 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
689 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
691 $diffLink = $this->message
['diff'];
693 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
694 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
695 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
696 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
700 if( !$showdifflinks ||
!$rc_last_oldid ) {
701 $lastLink = $this->message
['last'];
702 } else if( $rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
703 $lastLink = $this->message
['last'];
705 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
706 array(), $curIdEq +
array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) +
$rcIdQuery );
710 if( $this->isDeleted($rc,Revision
::DELETED_USER
) ) {
711 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
713 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
714 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
717 $rc->lastlink
= $lastLink;
718 $rc->curlink
= $curLink;
719 $rc->difflink
= $diffLink;
721 # Put accumulated information into the cache, for later display
722 # Page moves go on their own line
723 $title = $rc->getTitle();
724 $secureName = $title->getPrefixedDBkey();
725 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
726 # Use an @ character to prevent collision with page names
727 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
729 # Logs are grouped by type
730 if( $rc_type == RC_LOG
){
731 $secureName = SpecialPage
::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
733 if( !isset( $this->rc_cache
[$secureName] ) ) {
734 $this->rc_cache
[$secureName] = array();
737 array_push( $this->rc_cache
[$secureName], $rc );
740 wfProfileOut( __METHOD__
);
748 protected function recentChangesBlockGroup( $block ) {
749 global $wgLang, $wgContLang, $wgRCShowChangedSize;
751 wfProfileIn( __METHOD__
);
753 $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
755 # Collate list of users
756 $userlinks = array();
758 $unpatrolled = false;
760 $curId = $currentRevision = 0;
761 # Some catalyst variables...
764 foreach( $block as $rcObj ) {
765 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
766 if( $rcObj->mAttribs
['rc_new'] ) {
769 // If all log actions to this page were hidden, then don't
770 // give the name of the affected page for this block!
771 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
774 $u = $rcObj->userlink
;
775 if( !isset( $userlinks[$u] ) ) {
778 if( $rcObj->unpatrolled
) {
781 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
784 # Get the latest entry with a page_id and oldid
785 # since logs may not have these.
786 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
787 $curId = $rcObj->mAttribs
['rc_cur_id'];
789 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
790 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
793 $bot = $rcObj->mAttribs
['rc_bot'];
797 # Sort the list and convert to text
798 krsort( $userlinks );
801 foreach( $userlinks as $userlink => $count) {
803 $text .= $wgContLang->getDirMark();
805 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
807 array_push( $users, $text );
810 $users = ' <span class="changedby">[' .
811 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
813 # ID for JS visibility toggle
814 $jsid = $this->rcCacheIndex
;
815 # onclick handler to toggle hidden/expanded
816 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
818 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
819 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
821 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
822 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
823 $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.' ';
826 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
829 $r .= ' '.$block[0]->timestamp
.' </tt></td><td>';
833 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
834 } else if( $allLogs ) {
835 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
837 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
840 $r .= $wgContLang->getDirMark();
842 $queryParams['curid'] = $curId;
845 static $nchanges = array();
846 if ( !isset( $nchanges[$n] ) ) {
847 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
853 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
855 } else if( $isnew ) {
858 $params = $queryParams;
859 $params['diff'] = $currentRevision;
860 $params['oldid'] = $oldid;
862 $r .= $this->skin
->link(
863 $block[0]->getTitle(),
867 array( 'known', 'noclasses' )
874 // don't show history link for logs
875 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
876 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
878 $params = $queryParams;
879 $params['action'] = 'history';
881 $r .= $this->message
['pipe-separator'] .
883 $block[0]->getTitle(),
884 $this->message
['hist'],
887 array( 'known', 'noclasses' )
892 # Character difference (does not apply if only log items)
893 if( $wgRCShowChangedSize && !$allLogs ) {
895 $first = count($block) - 1;
896 # Some events (like logs) have an "empty" size, so we need to skip those...
897 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === NULL ) {
900 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === NULL ) {
904 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
905 $block[$last]->mAttribs
['rc_new_len'] );
907 if( $chardiff == '' ) {
910 $r .= ' ' . $chardiff. ' . . ';
915 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
917 $r .= "</td></tr></table>\n";
920 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
921 $r .= '<table cellpadding="0" cellspacing="0" border="0" style="background: none">';
922 foreach( $block as $rcObj ) {
923 # Extract fields from DB into the function scope (rc_xxxx variables)
924 // FIXME: Would be good to replace this extract() call with something
925 // that explicitly initializes variables.
926 # Classes to apply -- TODO implement
928 extract( $rcObj->mAttribs
);
930 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
931 $r .= '<tr><td valign="top">';
932 $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
933 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
934 $r .= ' </tt></td><td valign="top">';
936 $params = $queryParams;
938 if( $rc_this_oldid != 0 ) {
939 $params['oldid'] = $rc_this_oldid;
943 if( $rc_type == RC_LOG
) {
944 $link = '<tt>'.$rcObj->timestamp
.'</tt> ';
946 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
947 $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp
.'</tt></span> ';
949 if ( $rcObj->unpatrolled
&& $rc_type == RC_NEW
) {
950 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
959 array( 'known', 'noclasses' )
961 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
962 $link = '<span class="history-deleted">'.$link.'</span> ';
966 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
968 $r .= $rcObj->curlink
;
969 $r .= $this->message
['pipe-separator'];
970 $r .= $rcObj->lastlink
;
976 if( $wgRCShowChangedSize ) {
977 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
980 $r .= $rcObj->userlink
;
981 $r .= $rcObj->usertalklink
;
983 $this->insertAction( $r, $rcObj );
985 $this->insertComment( $r, $rcObj );
987 $this->insertRollback( $r, $rcObj );
989 $this->insertTags( $r, $rcObj, $classes );
991 $r .= "</td></tr>\n";
993 $r .= "</table></div>\n";
995 $this->rcCacheIndex++
;
997 wfProfileOut( __METHOD__
);
1003 * Generate HTML for an arrow or placeholder graphic
1004 * @param string $dir one of '', 'd', 'l', 'r'
1005 * @param string $alt text
1006 * @param string $title text
1007 * @return string HTML <img> tag
1009 protected function arrow( $dir, $alt='', $title='' ) {
1010 global $wgStylePath;
1011 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1012 $encAlt = htmlspecialchars( $alt );
1013 $encTitle = htmlspecialchars( $title );
1014 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1018 * Generate HTML for a right- or left-facing arrow,
1019 * depending on language direction.
1020 * @return string HTML <img> tag
1022 protected function sideArrow() {
1024 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1025 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1029 * Generate HTML for a down-facing arrow
1030 * depending on language direction.
1031 * @return string HTML <img> tag
1033 protected function downArrow() {
1034 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1038 * Generate HTML for a spacer image
1039 * @return string HTML <img> tag
1041 protected function spacerArrow() {
1042 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1046 * Add a set of spaces
1047 * @return string HTML <td> tag
1049 protected function spacerIndent() {
1050 return ' ';
1054 * Enhanced RC ungrouped line.
1055 * @return string a HTML formated line (generated using $r)
1057 protected function recentChangesBlockLine( $rcObj ) {
1058 global $wgRCShowChangedSize;
1060 wfProfileIn( __METHOD__
);
1062 # Extract fields from DB into the function scope (rc_xxxx variables)
1063 // FIXME: Would be good to replace this extract() call with something
1064 // that explicitly initializes variables.
1065 $classes = array(); // TODO implement
1066 extract( $rcObj->mAttribs
);
1067 $query['curid'] = $rc_cur_id;
1069 $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
1070 $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . ' ';
1071 # Flag and Timestamp
1072 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
1073 $r .= ' '; // 4 flags -> 4 spaces
1075 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
1077 $r .= ' '.$rcObj->timestamp
.' </tt></td><td>';
1078 # Article or log link
1079 if( $rc_log_type ) {
1080 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
1081 $logname = LogPage
::logName( $rc_log_type );
1082 $r .= '(' . $this->skin
->link(
1087 array( 'known', 'noclasses' )
1090 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1092 # Diff and hist links
1093 if ( $rc_type != RC_LOG
) {
1094 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1095 $query['action'] = 'history';
1096 $r .= $this->skin
->link(
1098 $this->message
['hist'],
1101 array( 'known', 'noclasses' )
1106 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1110 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1111 # Log action (if any)
1112 if( $rc_log_type ) {
1113 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1114 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1116 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1117 $this->skin
, LogPage
::extractParams($rc_params), true, true );
1120 $this->insertComment( $r, $rcObj );
1121 $this->insertRollback( $r, $rcObj );
1123 $this->insertTags( $r, $rcObj, $classes );
1124 # Show how many people are watching this if enabled
1125 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1127 $r .= "</td></tr></table>\n";
1129 wfProfileOut( __METHOD__
);
1135 * If enhanced RC is in use, this function takes the previously cached
1136 * RC lines, arranges them, and outputs the HTML
1138 protected function recentChangesBlock() {
1139 if( count ( $this->rc_cache
) == 0 ) {
1143 wfProfileIn( __METHOD__
);
1146 foreach( $this->rc_cache
as $block ) {
1147 if( count( $block ) < 2 ) {
1148 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1150 $blockOut .= $this->recentChangesBlockGroup( $block );
1154 wfProfileOut( __METHOD__
);
1156 return '<div>'.$blockOut.'</div>';
1160 * Returns text for the end of RC
1161 * If enhanced RC is in use, returns pretty much all the text
1163 public function endRecentChangesList() {
1164 return $this->recentChangesBlock() . parent
::endRecentChangesList();