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 ) {
49 $sk = $user->getSkin();
51 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
52 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
53 return $new ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
60 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
61 * @param $value Boolean
63 public function setWatchlistDivs( $value = true ) {
64 $this->watchlist
= $value;
68 * As we use the same small set of messages in various methods and that
69 * they are called often, we call them once and save them in $this->message
71 private function preCacheMessages() {
72 if( !isset( $this->message
) ) {
73 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
74 'semicolon-separator pipe-separator' ) as $msg ) {
75 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
82 * Returns the appropriate flags for new page, minor change and patrolling
84 * @param $minor Boolean
85 * @param $patrolled Boolean
86 * @param $nothing String to use for empty space
90 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
91 $f = $new ? self
::flag( 'newpage' ) : $nothing;
92 $f .= $minor ? self
::flag( 'minor' ) : $nothing;
93 $f .= $bot ? self
::flag( 'bot' ) : $nothing;
94 $f .= $patrolled ? self
::flag( 'unpatrolled' ) : $nothing;
99 * Provide the <abbr> element appropriate to a given abbreviated flag,
100 * namely the flag indicating a new page, a minor edit, a bot edit, or an
101 * unpatrolled edit. By default in English it will contain "N", "m", "b",
102 * "!" respectively, plus it will have an appropriate title and class.
104 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
105 * @return String: Raw HTML
107 public static function flag( $key ) {
108 static $messages = null;
109 if ( is_null( $messages ) ) {
110 foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' .
111 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' .
112 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) {
113 $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' );
116 # Inconsistent naming, bleh
117 if ( $key == 'newpage' ||
$key == 'unpatrolled' ) {
120 $key2 = $key . 'edit';
122 return "<abbr class=\"$key\" title=\""
123 . $messages["recentchanges-label-$key"] . "\">"
124 . $messages["${key2}letter"]
129 * Some explanatory wrapper text for the given flag, to be used in a legend
130 * explaining what the flags mean. For instance, "N - new page". See
133 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
134 * @return String: Raw HTML
136 private static function flagLine( $key ) {
137 return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities',
138 'replaceafter' ), self
::flag( $key ) );
142 * A handy legend to tell users what the little "m", "b", and so on mean.
144 * @return String: Raw HTML
146 public static function flagLegend() {
147 global $wgGroupPermissions, $wgLang;
149 $flags = array( self
::flagLine( 'newpage' ),
150 self
::flagLine( 'minor' ) );
152 # Don't show info on bot edits unless there's a bot group of some kind
153 foreach ( $wgGroupPermissions as $rights ) {
154 if ( isset( $rights['bot'] ) && $rights['bot'] ) {
155 $flags[] = self
::flagLine( 'bot' );
160 if ( self
::usePatrol() ) {
161 $flags[] = self
::flagLine( 'unpatrolled' );
164 return '<div class="mw-rc-label-legend">' .
165 wfMsgExt( 'recentchanges-label-legend', 'parseinline',
166 $wgLang->commaList( $flags ) ) . '</div>';
170 * Returns text for the start of the tabular part of RC
173 public function beginRecentChangesList() {
174 $this->rc_cache
= array();
175 $this->rcMoveIndex
= 0;
176 $this->rcCacheIndex
= 0;
177 $this->lastdate
= '';
178 $this->rclistOpen
= false;
183 * Show formatted char difference
184 * @param $old Integer: bytes
185 * @param $new Integer: bytes
188 public static function showCharacterDifference( $old, $new ) {
189 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
190 $szdiff = $new - $old;
192 $code = $wgLang->getCode();
193 static $fastCharDiff = array();
194 if ( !isset($fastCharDiff[$code]) ) {
195 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
198 $formatedSize = $wgLang->formatNum($szdiff);
200 if ( !$fastCharDiff[$code] ) {
201 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
204 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
209 if( $szdiff === 0 ) {
210 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
211 } elseif( $szdiff > 0 ) {
212 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
214 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
219 * Returns text for the end of RC
222 public function endRecentChangesList() {
223 if( $this->rclistOpen
) {
230 public function insertMove( &$s, $rc ) {
232 $s .= '(' . $this->message
['diff'] . ') (';
234 $s .= $this->skin
->link(
235 $rc->getMovedToTitle(),
236 $this->message
['hist'],
238 array( 'action' => 'history' ),
239 array( 'known', 'noclasses' )
241 # "[[x]] moved to [[y]]"
242 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
249 array( 'redirect' => 'no' ),
250 array( 'known', 'noclasses' )
253 $rc->getMovedToTitle(),
257 array( 'known', 'noclasses' )
262 public function insertDateHeader( &$s, $rc_timestamp ) {
264 # Make date header if necessary
265 $date = $wgLang->date( $rc_timestamp, true, true );
266 if( $date != $this->lastdate
) {
267 if( $this->lastdate
!= '' ) {
270 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
271 $this->lastdate
= $date;
272 $this->rclistOpen
= true;
276 public function insertLog( &$s, $title, $logtype ) {
277 $logname = LogPage
::logName( $logtype );
278 $s .= '(' . $this->skin
->link(
283 array( 'known', 'noclasses' )
287 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
289 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
290 $diffLink = $this->message
['diff'];
291 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
292 $diffLink = $this->message
['diff'];
295 'curid' => $rc->mAttribs
['rc_cur_id'],
296 'diff' => $rc->mAttribs
['rc_this_oldid'],
297 'oldid' => $rc->mAttribs
['rc_last_oldid']
301 $query['rcid'] = $rc->mAttribs
['rc_id'];
304 $diffLink = $this->skin
->link(
306 $this->message
['diff'],
307 array( 'tabindex' => $rc->counter
),
309 array( 'known', 'noclasses' )
312 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
314 $s .= $this->skin
->link(
316 $this->message
['hist'],
319 'curid' => $rc->mAttribs
['rc_cur_id'],
320 'action' => 'history'
322 array( 'known', 'noclasses' )
327 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
329 # If it's a new article, there is no diff link, but if it hasn't been
330 # patrolled yet, we need to give users a way to do so
333 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
334 $params['rcid'] = $rc->mAttribs
['rc_id'];
337 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
338 $articlelink = $this->skin
->link(
343 array( 'known', 'noclasses' )
345 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
347 $articlelink = ' '. $this->skin
->link(
352 array( 'known', 'noclasses' )
355 # Bolden pages watched by this user
357 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
360 $articlelink .= $wgContLang->getDirMark();
362 wfRunHooks( 'ChangesListInsertArticleLink',
363 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
365 $s .= " $articlelink";
368 public function insertTimestamp( &$s, $rc ) {
370 $s .= $this->message
['semicolon-separator'] .
371 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
374 /** Insert links to user page, user talk page and eventually a blocking link */
375 public function insertUserRelatedLinks( &$s, &$rc ) {
376 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
377 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
379 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
380 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
384 /** insert a formatted action */
385 public function insertAction( &$s, &$rc ) {
386 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
387 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
388 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
390 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
391 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
396 /** insert a formatted comment */
397 public function insertComment( &$s, &$rc ) {
398 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
399 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
400 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
402 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
408 * Check whether to enable recent changes patrol features
411 public static function usePatrol() {
413 return $wgUser->useRCPatrol();
417 * Returns the string which indicates the number of watching users
419 protected function numberofWatchingusers( $count ) {
421 static $cache = array();
423 if( !isset( $cache[$count] ) ) {
424 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
425 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
427 return $cache[$count];
434 * Determine if said field of a revision is hidden
435 * @param $rc RCCacheEntry
436 * @param $field Integer: one of DELETED_* bitfield constants
439 public static function isDeleted( $rc, $field ) {
440 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
444 * Determine if the current user is allowed to view a particular
445 * field of this revision, if it's marked as deleted.
446 * @param $rc RCCacheEntry
447 * @param $field Integer
450 public static function userCan( $rc, $field ) {
451 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
452 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
454 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
458 protected function maybeWatchedLink( $link, $watched = false ) {
460 return '<strong class="mw-watched">' . $link . '</strong>';
462 return '<span class="mw-rc-unwatched">' . $link . '</span>';
466 /** Inserts a rollback link */
467 public function insertRollback( &$s, &$rc ) {
469 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
470 $page = $rc->getTitle();
471 /** Check for rollback and edit permissions, disallow special pages, and only
472 * show a link on the top-most revision */
473 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
475 $rev = new Revision( array(
476 'id' => $rc->mAttribs
['rc_this_oldid'],
477 'user' => $rc->mAttribs
['rc_user'],
478 'user_text' => $rc->mAttribs
['rc_user_text'],
479 'deleted' => $rc->mAttribs
['rc_deleted']
481 $rev->setTitle( $page );
482 $s .= ' '.$this->skin
->generateRollback( $rev );
487 public function insertTags( &$s, &$rc, &$classes ) {
488 if ( empty($rc->mAttribs
['ts_tags']) )
491 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
492 $classes = array_merge( $classes, $newClasses );
493 $s .= ' ' . $tagSummary;
496 public function insertExtra( &$s, &$rc, &$classes ) {
497 ## Empty, used for subclassers to add anything special.
503 * Generate a list of changes using the good old system (no javascript)
505 class OldChangesList
extends ChangesList
{
507 * Format a line using the old system (aka without any javascript).
509 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
510 global $wgLang, $wgRCShowChangedSize, $wgUser;
511 wfProfileIn( __METHOD__
);
512 # Should patrol-related stuff be shown?
513 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
515 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
516 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
520 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
522 if( $linenumber & 1 ) {
523 $classes[] = 'mw-line-odd';
526 $classes[] = 'mw-line-even';
531 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
532 $this->insertMove( $s, $rc );
534 } elseif( $rc->mAttribs
['rc_log_type'] ) {
535 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
536 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
537 // Log entries (old format) or log targets, and special pages
538 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
539 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
540 if( $name == 'Log' ) {
541 $this->insertLog( $s, $rc->getTitle(), $subpage );
545 $this->insertDiffHist( $s, $rc, $unpatrolled );
546 # M, N, b and ! (minor, new, bot and unpatrolled)
547 $s .= $this->recentChangesFlags( $rc->mAttribs
['rc_new'], $rc->mAttribs
['rc_minor'],
548 $unpatrolled, '', $rc->mAttribs
['rc_bot'] );
549 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
552 $this->insertTimestamp( $s, $rc );
553 # Bytes added or removed
554 if( $wgRCShowChangedSize ) {
555 $cd = $rc->getCharacterDifference();
561 $this->insertUserRelatedLinks( $s, $rc );
562 # Log action text (if any)
563 $this->insertAction( $s, $rc );
564 # Edit or log comment
565 $this->insertComment( $s, $rc );
567 $this->insertTags( $s, $rc, $classes );
569 $this->insertRollback( $s, $rc );
571 $this->insertExtra( $s, $rc, $classes );
573 # How many users watch this page
574 if( $rc->numberofWatchingusers
> 0 ) {
575 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
576 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
579 if( $this->watchlist
) {
580 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
583 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
585 wfProfileOut( __METHOD__
);
586 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
592 * Generate a list of changes using an Enhanced system (uses javascript).
594 class EnhancedChangesList
extends ChangesList
{
596 * Add the JavaScript file for enhanced changeslist
599 public function beginRecentChangesList() {
600 global $wgStylePath, $wgStyleVersion;
601 $this->rc_cache
= array();
602 $this->rcMoveIndex
= 0;
603 $this->rcCacheIndex
= 0;
604 $this->lastdate
= '';
605 $this->rclistOpen
= false;
606 $script = Html
::linkedScript( $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" );
610 * Format a line for enhanced recentchange (aka with javascript and block of lines).
612 public function recentChangesLine( &$baseRC, $watched = false ) {
613 global $wgLang, $wgUser;
615 wfProfileIn( __METHOD__
);
617 # Create a specialised object
618 $rc = RCCacheEntry
::newFromParent( $baseRC );
620 # Extract fields from DB into the function scope (rc_xxxx variables)
621 // FIXME: Would be good to replace this extract() call with something
622 // that explicitly initializes variables.
623 extract( $rc->mAttribs
);
624 $curIdEq = array( 'curid' => $rc_cur_id );
626 # If it's a new day, add the headline and flush the cache
627 $date = $wgLang->date( $rc_timestamp, true );
629 if( $date != $this->lastdate
) {
630 # Process current cache
631 $ret = $this->recentChangesBlock();
632 $this->rc_cache
= array();
633 $ret .= Xml
::element( 'h4', null, $date );
634 $this->lastdate
= $date;
637 # Should patrol-related stuff be shown?
638 if( $wgUser->useRCPatrol() ) {
639 $rc->unpatrolled
= !$rc_patrolled;
641 $rc->unpatrolled
= false;
644 $showdifflinks = true;
647 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
648 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
649 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
650 array(), array( 'redirect' => 'no' ) ),
651 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
652 // New unpatrolled pages
653 } else if( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
654 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
655 array( 'rcid' => $rc_id ) );
657 } else if( $rc_type == RC_LOG
) {
659 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc_log_type );
660 $clink = '(' . $this->skin
->linkKnown( $logtitle,
661 LogPage
::logName($rc_log_type) ) . ')';
663 $clink = $this->skin
->link( $rc->getTitle() );
666 // Log entries (old format) and special pages
667 } elseif( $rc_namespace == NS_SPECIAL
) {
668 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
669 if ( $specialName == 'Log' ) {
671 $logname = LogPage
::logName( $logtype );
672 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
674 wfDebug( "Unexpected special page in recentchanges\n" );
679 $clink = $this->skin
->linkKnown( $rc->getTitle() );
682 # Don't show unusable diff links
683 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
684 $showdifflinks = false;
687 $time = $wgLang->time( $rc_timestamp, true, true );
688 $rc->watched
= $watched;
690 $rc->timestamp
= $time;
691 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
693 # Make "cur" and "diff" links. Do not use link(), it is too slow if
694 # called too many times (50% of CPU time on RecentChanges!).
695 if( $rc->unpatrolled
) {
696 $rcIdQuery = array( 'rcid' => $rc_id );
698 $rcIdQuery = array();
700 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $rc_this_oldid );
701 $querydiff = $curIdEq +
array( 'diff' => $rc_this_oldid, 'oldid' =>
702 $rc_last_oldid ) +
$rcIdQuery;
704 if( !$showdifflinks ) {
705 $curLink = $this->message
['cur'];
706 $diffLink = $this->message
['diff'];
707 } else if( in_array( $rc_type, array(RC_NEW
,RC_LOG
,RC_MOVE
,RC_MOVE_OVER_REDIRECT
) ) ) {
708 if ( $rc_type != RC_NEW
) {
709 $curLink = $this->message
['cur'];
711 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
712 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
714 $diffLink = $this->message
['diff'];
716 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
717 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
718 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
719 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
723 if( !$showdifflinks ||
!$rc_last_oldid ) {
724 $lastLink = $this->message
['last'];
725 } else if( $rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
726 $lastLink = $this->message
['last'];
728 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
729 array(), $curIdEq +
array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) +
$rcIdQuery );
733 if( $this->isDeleted($rc,Revision
::DELETED_USER
) ) {
734 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
736 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
737 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
740 $rc->lastlink
= $lastLink;
741 $rc->curlink
= $curLink;
742 $rc->difflink
= $diffLink;
744 # Put accumulated information into the cache, for later display
745 # Page moves go on their own line
746 $title = $rc->getTitle();
747 $secureName = $title->getPrefixedDBkey();
748 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
749 # Use an @ character to prevent collision with page names
750 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
752 # Logs are grouped by type
753 if( $rc_type == RC_LOG
){
754 $secureName = SpecialPage
::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
756 if( !isset( $this->rc_cache
[$secureName] ) ) {
757 $this->rc_cache
[$secureName] = array();
760 array_push( $this->rc_cache
[$secureName], $rc );
763 wfProfileOut( __METHOD__
);
771 protected function recentChangesBlockGroup( $block ) {
772 global $wgLang, $wgContLang, $wgRCShowChangedSize;
774 wfProfileIn( __METHOD__
);
776 $r = '<table class="mw-enhanced-rc"><tr>';
778 # Collate list of users
779 $userlinks = array();
781 $unpatrolled = false;
783 $curId = $currentRevision = 0;
784 # Some catalyst variables...
787 foreach( $block as $rcObj ) {
788 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
789 if( $rcObj->mAttribs
['rc_new'] ) {
792 // If all log actions to this page were hidden, then don't
793 // give the name of the affected page for this block!
794 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
797 $u = $rcObj->userlink
;
798 if( !isset( $userlinks[$u] ) ) {
801 if( $rcObj->unpatrolled
) {
804 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
807 # Get the latest entry with a page_id and oldid
808 # since logs may not have these.
809 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
810 $curId = $rcObj->mAttribs
['rc_cur_id'];
812 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
813 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
816 $bot = $rcObj->mAttribs
['rc_bot'];
820 # Sort the list and convert to text
821 krsort( $userlinks );
824 foreach( $userlinks as $userlink => $count) {
826 $text .= $wgContLang->getDirMark();
828 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
830 array_push( $users, $text );
833 $users = ' <span class="changedby">[' .
834 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
836 # ID for JS visibility toggle
837 $jsid = $this->rcCacheIndex
;
838 # onclick handler to toggle hidden/expanded
839 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
841 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
842 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
844 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
845 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
846 $r .= '<td class="mw-enhanced-rc">'.$tl.' ';
849 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
852 $r .= ' '.$block[0]->timestamp
.' </td><td style="padding:0px;">';
856 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
857 } else if( $allLogs ) {
858 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
860 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
863 $r .= $wgContLang->getDirMark();
865 $queryParams['curid'] = $curId;
868 static $nchanges = array();
869 if ( !isset( $nchanges[$n] ) ) {
870 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
876 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
878 } else if( $isnew ) {
881 $params = $queryParams;
882 $params['diff'] = $currentRevision;
883 $params['oldid'] = $oldid;
885 $r .= $this->skin
->link(
886 $block[0]->getTitle(),
890 array( 'known', 'noclasses' )
897 // don't show history link for logs
898 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
899 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
901 $params = $queryParams;
902 $params['action'] = 'history';
904 $r .= $this->message
['pipe-separator'] .
906 $block[0]->getTitle(),
907 $this->message
['hist'],
910 array( 'known', 'noclasses' )
915 # Character difference (does not apply if only log items)
916 if( $wgRCShowChangedSize && !$allLogs ) {
918 $first = count($block) - 1;
919 # Some events (like logs) have an "empty" size, so we need to skip those...
920 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
923 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
927 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
928 $block[$last]->mAttribs
['rc_new_len'] );
930 if( $chardiff == '' ) {
933 $r .= ' ' . $chardiff. ' . . ';
938 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
940 $r .= "</td></tr></table>\n";
943 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
944 $r .= '<table class="mw-enhanced-rc">';
945 foreach( $block as $rcObj ) {
946 # Extract fields from DB into the function scope (rc_xxxx variables)
947 // FIXME: Would be good to replace this extract() call with something
948 // that explicitly initializes variables.
949 # Classes to apply -- TODO implement
951 extract( $rcObj->mAttribs
);
953 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
954 $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
955 $r .= $this->spacerIndent() . $this->spacerIndent();
956 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
957 $r .= ' </td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
959 $params = $queryParams;
961 if( $rc_this_oldid != 0 ) {
962 $params['oldid'] = $rc_this_oldid;
966 if( $rc_type == RC_LOG
) {
967 $link = $rcObj->timestamp
;
969 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
970 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
972 if ( $rcObj->unpatrolled
&& $rc_type == RC_NEW
) {
973 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
976 $link = $this->skin
->link(
981 array( 'known', 'noclasses' )
983 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
984 $link = '<span class="history-deleted">'.$link.'</span> ';
986 $r .= $link . '</span>';
988 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
990 $r .= $rcObj->curlink
;
991 $r .= $this->message
['pipe-separator'];
992 $r .= $rcObj->lastlink
;
998 if( $wgRCShowChangedSize ) {
999 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
1002 $r .= $rcObj->userlink
;
1003 $r .= $rcObj->usertalklink
;
1005 $this->insertAction( $r, $rcObj );
1007 $this->insertComment( $r, $rcObj );
1009 $this->insertRollback( $r, $rcObj );
1011 $this->insertTags( $r, $rcObj, $classes );
1013 $r .= "</td></tr>\n";
1015 $r .= "</table></div>\n";
1017 $this->rcCacheIndex++
;
1019 wfProfileOut( __METHOD__
);
1025 * Generate HTML for an arrow or placeholder graphic
1026 * @param $dir String: one of '', 'd', 'l', 'r'
1027 * @param $alt String: text
1028 * @param $title String: text
1029 * @return String: HTML <img> tag
1031 protected function arrow( $dir, $alt='', $title='' ) {
1032 global $wgStylePath;
1033 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1034 $encAlt = htmlspecialchars( $alt );
1035 $encTitle = htmlspecialchars( $title );
1036 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1040 * Generate HTML for a right- or left-facing arrow,
1041 * depending on language direction.
1042 * @return String: HTML <img> tag
1044 protected function sideArrow() {
1046 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1047 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1051 * Generate HTML for a down-facing arrow
1052 * depending on language direction.
1053 * @return String: HTML <img> tag
1055 protected function downArrow() {
1056 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1060 * Generate HTML for a spacer image
1061 * @return String: HTML <img> tag
1063 protected function spacerArrow() {
1064 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1068 * Add a set of spaces
1069 * @return String: HTML <td> tag
1071 protected function spacerIndent() {
1072 return '     ';
1076 * Enhanced RC ungrouped line.
1077 * @return String: a HTML formated line (generated using $r)
1079 protected function recentChangesBlockLine( $rcObj ) {
1080 global $wgRCShowChangedSize;
1082 wfProfileIn( __METHOD__
);
1084 # Extract fields from DB into the function scope (rc_xxxx variables)
1085 // FIXME: Would be good to replace this extract() call with something
1086 // that explicitly initializes variables.
1087 $classes = array(); // TODO implement
1088 extract( $rcObj->mAttribs
);
1089 $query['curid'] = $rc_cur_id;
1091 $r = '<table class="mw-enhanced-rc"><tr>';
1092 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . ' ';
1093 # Flag and Timestamp
1094 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
1095 $r .= '    '; // 4 flags -> 4 spaces
1097 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
1099 $r .= ' '.$rcObj->timestamp
.' </td><td style="padding:0px;">';
1100 # Article or log link
1101 if( $rc_log_type ) {
1102 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
1103 $logname = LogPage
::logName( $rc_log_type );
1104 $r .= '(' . $this->skin
->link(
1109 array( 'known', 'noclasses' )
1112 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1114 # Diff and hist links
1115 if ( $rc_type != RC_LOG
) {
1116 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1117 $query['action'] = 'history';
1118 $r .= $this->skin
->link(
1120 $this->message
['hist'],
1123 array( 'known', 'noclasses' )
1128 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1132 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1133 # Log action (if any)
1134 if( $rc_log_type ) {
1135 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1136 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1138 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1139 $this->skin
, LogPage
::extractParams($rc_params), true, true );
1142 $this->insertComment( $r, $rcObj );
1143 $this->insertRollback( $r, $rcObj );
1145 $this->insertTags( $r, $rcObj, $classes );
1146 # Show how many people are watching this if enabled
1147 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1149 $r .= "</td></tr></table>\n";
1151 wfProfileOut( __METHOD__
);
1157 * If enhanced RC is in use, this function takes the previously cached
1158 * RC lines, arranges them, and outputs the HTML
1160 protected function recentChangesBlock() {
1161 if( count ( $this->rc_cache
) == 0 ) {
1165 wfProfileIn( __METHOD__
);
1168 foreach( $this->rc_cache
as $block ) {
1169 if( count( $block ) < 2 ) {
1170 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1172 $blockOut .= $this->recentChangesBlockGroup( $block );
1176 wfProfileOut( __METHOD__
);
1178 return '<div>'.$blockOut.'</div>';
1182 * Returns text for the end of RC
1183 * If enhanced RC is in use, returns pretty much all the text
1185 public function endRecentChangesList() {
1186 return $this->recentChangesBlock() . parent
::endRecentChangesList();