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 minoreditletter newpageletter last '.
72 'blocklink history boteditletter semicolon-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 ) {
90 '<span class="newpage">' . $this->message
['newpageletter'] . '</span>' : $nothing;
92 '<span class="minor">' . $this->message
['minoreditletter'] . '</span>' : $nothing;
93 $f .= $bot ?
'<span class="bot">' . $this->message
['boteditletter'] . '</span>' : $nothing;
94 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
99 * Returns text for the start of the tabular part of RC
102 public function beginRecentChangesList() {
103 $this->rc_cache
= array();
104 $this->rcMoveIndex
= 0;
105 $this->rcCacheIndex
= 0;
106 $this->lastdate
= '';
107 $this->rclistOpen
= false;
112 * Show formatted char difference
113 * @param int $old bytes
114 * @param int $new bytes
117 public static function showCharacterDifference( $old, $new ) {
118 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
119 $szdiff = $new - $old;
121 $code = $wgLang->getCode();
122 static $fastCharDiff = array();
123 if ( !isset($fastCharDiff[$code]) ) {
124 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
127 $formatedSize = $wgLang->formatNum($szdiff);
129 if ( !$fastCharDiff[$code] ) {
130 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
133 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
138 if( $szdiff === 0 ) {
139 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
140 } elseif( $szdiff > 0 ) {
141 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
143 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
148 * Returns text for the end of RC
151 public function endRecentChangesList() {
152 if( $this->rclistOpen
) {
159 protected function insertMove( &$s, $rc ) {
161 $s .= '(' . $this->message
['diff'] . ') (';
163 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'],
164 'action=history' ) . ') . . ';
165 # "[[x]] moved to [[y]]"
166 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
167 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
168 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
171 protected function insertDateHeader( &$s, $rc_timestamp ) {
173 # Make date header if necessary
174 $date = $wgLang->date( $rc_timestamp, true, true );
175 if( $date != $this->lastdate
) {
176 if( '' != $this->lastdate
) {
179 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
180 $this->lastdate
= $date;
181 $this->rclistOpen
= true;
185 protected function insertLog( &$s, $title, $logtype ) {
186 $logname = LogPage
::logName( $logtype );
187 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
190 protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
192 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
193 $diffLink = $this->message
['diff'];
194 } else if( !$this->userCan($rc,Revision
::DELETED_TEXT
) ) {
195 $diffLink = $this->message
['diff'];
197 $rcidparam = $unpatrolled ?
array( 'rcid' => $rc->mAttribs
['rc_id'] ) : array();
198 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
200 'curid' => $rc->mAttribs
['rc_cur_id'],
201 'diff' => $rc->mAttribs
['rc_this_oldid'],
202 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
204 '', '', ' tabindex="'.$rc->counter
.'"');
206 $s .= '('.$diffLink.') (';
208 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
210 'curid' => $rc->mAttribs
['rc_cur_id'],
211 'action' => 'history' ) ) );
215 protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
217 # If it's a new article, there is no diff link, but if it hasn't been
218 # patrolled yet, we need to give users a way to do so
219 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) ?
220 'rcid='.$rc->mAttribs
['rc_id'] : '';
221 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
222 $articlelink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
223 $articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
225 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
227 # Bolden pages watched by this user
229 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
232 $articlelink .= $wgContLang->getDirMark();
234 wfRunHooks( 'ChangesListInsertArticleLink',
235 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
237 $s .= " $articlelink";
240 protected function insertTimestamp( &$s, $rc ) {
242 $s .= $this->message
['semicolon-separator'] .
243 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
246 /** Insert links to user page, user talk page and eventually a blocking link */
247 public function insertUserRelatedLinks( &$s, &$rc ) {
248 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
249 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
251 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
252 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
256 /** insert a formatted action */
257 protected function insertAction( &$s, &$rc ) {
258 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
259 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
260 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
262 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
263 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
268 /** insert a formatted comment */
269 protected function insertComment( &$s, &$rc ) {
270 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
271 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
272 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
274 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
280 * Check whether to enable recent changes patrol features
283 public static function usePatrol() {
285 return $wgUser->useRCPatrol();
289 * Returns the string which indicates the number of watching users
291 protected function numberofWatchingusers( $count ) {
293 static $cache = array();
295 if( !isset( $cache[$count] ) ) {
296 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
297 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
299 return $cache[$count];
306 * Determine if said field of a revision is hidden
307 * @param RCCacheEntry $rc
308 * @param int $field one of DELETED_* bitfield constants
311 public static function isDeleted( $rc, $field ) {
312 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
316 * Determine if the current user is allowed to view a particular
317 * field of this revision, if it's marked as deleted.
318 * @param RCCacheEntry $rc
322 public static function userCan( $rc, $field ) {
323 if( ( $rc->mAttribs
['rc_deleted'] & $field ) == $field ) {
325 $permission = ( $rc->mAttribs
['rc_deleted'] & Revision
::DELETED_RESTRICTED
) == Revision
::DELETED_RESTRICTED
328 wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" );
329 return $wgUser->isAllowed( $permission );
335 protected function maybeWatchedLink( $link, $watched=false ) {
337 return '<strong class="mw-watched">' . $link . '</strong>';
339 return '<span class="mw-rc-unwatched">' . $link . '</span>';
343 /** Inserts a rollback link */
344 protected function insertRollback( &$s, &$rc ) {
346 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
347 $page = $rc->getTitle();
348 /** Check for rollback and edit permissions, disallow special pages, and only
349 * show a link on the top-most revision */
350 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
352 $rev = new Revision( array(
353 'id' => $rc->mAttribs
['rc_this_oldid'],
354 'user' => $rc->mAttribs
['rc_user'],
355 'user_text' => $rc->mAttribs
['rc_user_text'],
356 'deleted' => $rc->mAttribs
['rc_deleted']
358 $rev->setTitle( $page );
359 $s .= ' '.$this->skin
->generateRollback( $rev );
364 protected function insertTags( &$s, &$rc, &$classes ) {
365 if ( empty($rc->mAttribs
['ts_tags']) )
368 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
369 $classes = array_merge( $classes, $newClasses );
370 $s .= ' ' . $tagSummary;
373 protected function insertExtra( &$s, &$rc, &$classes ) {
374 ## Empty, used for subclassers to add anything special.
380 * Generate a list of changes using the good old system (no javascript)
382 class OldChangesList
extends ChangesList
{
384 * Format a line using the old system (aka without any javascript).
386 public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) {
387 global $wgLang, $wgRCShowChangedSize, $wgUser;
388 wfProfileIn( __METHOD__
);
389 # Should patrol-related stuff be shown?
390 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
392 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
393 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
397 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
399 if( $linenumber & 1 ) {
400 $classes[] = 'mw-line-odd';
403 $classes[] = 'mw-line-even';
408 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
409 $this->insertMove( $s, $rc );
411 } elseif( $rc->mAttribs
['rc_log_type'] ) {
412 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
413 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
414 // Log entries (old format) or log targets, and special pages
415 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
416 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
417 if( $name == 'Log' ) {
418 $this->insertLog( $s, $rc->getTitle(), $subpage );
422 $this->insertDiffHist( $s, $rc, $unpatrolled );
423 # M, N, b and ! (minor, new, bot and unpatrolled)
424 $s .= $this->recentChangesFlags( $rc->mAttribs
['rc_new'], $rc->mAttribs
['rc_minor'],
425 $unpatrolled, '', $rc->mAttribs
['rc_bot'] );
426 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
429 $this->insertTimestamp( $s, $rc );
430 # Bytes added or removed
431 if( $wgRCShowChangedSize ) {
432 $cd = $rc->getCharacterDifference();
438 $this->insertUserRelatedLinks( $s, $rc );
439 # Log action text (if any)
440 $this->insertAction( $s, $rc );
441 # Edit or log comment
442 $this->insertComment( $s, $rc );
444 $this->insertTags( $s, $rc, $classes );
446 $this->insertRollback( $s, $rc );
448 $this->insertExtra( $s, $rc, $classes );
450 # Mark revision as deleted if so
451 if( !$rc->mAttribs
['rc_log_type'] && $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
452 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
454 # How many users watch this page
455 if( $rc->numberofWatchingusers
> 0 ) {
456 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
457 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
460 if( $this->watchlist
) {
461 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
464 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
466 wfProfileOut( __METHOD__
);
467 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
473 * Generate a list of changes using an Enhanced system (uses javascript).
475 class EnhancedChangesList
extends ChangesList
{
477 * Add the JavaScript file for enhanced changeslist
480 public function beginRecentChangesList() {
481 global $wgStylePath, $wgJsMimeType, $wgStyleVersion;
482 $this->rc_cache
= array();
483 $this->rcMoveIndex
= 0;
484 $this->rcCacheIndex
= 0;
485 $this->lastdate
= '';
486 $this->rclistOpen
= false;
487 $script = Xml
::tags( 'script', array(
488 'type' => $wgJsMimeType,
489 'src' => $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" ), '' );
493 * Format a line for enhanced recentchange (aka with javascript and block of lines).
495 public function recentChangesLine( &$baseRC, $watched = false ) {
496 global $wgLang, $wgUser;
498 wfProfileIn( __METHOD__
);
500 # Create a specialised object
501 $rc = RCCacheEntry
::newFromParent( $baseRC );
503 # Extract fields from DB into the function scope (rc_xxxx variables)
504 // FIXME: Would be good to replace this extract() call with something
505 // that explicitly initializes variables.
506 extract( $rc->mAttribs
);
507 $curIdEq = array( 'curid' => $rc_cur_id );
509 # If it's a new day, add the headline and flush the cache
510 $date = $wgLang->date( $rc_timestamp, true );
512 if( $date != $this->lastdate
) {
513 # Process current cache
514 $ret = $this->recentChangesBlock();
515 $this->rc_cache
= array();
516 $ret .= Xml
::element( 'h4', null, $date );
517 $this->lastdate
= $date;
520 # Should patrol-related stuff be shown?
521 if( $wgUser->useRCPatrol() ) {
522 $rc->unpatrolled
= !$rc_patrolled;
524 $rc->unpatrolled
= false;
527 $showdifflinks = true;
530 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
531 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
532 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
533 array(), array( 'redirect' => 'no' ) ),
534 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
535 // New unpatrolled pages
536 } else if( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
537 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
538 array( 'rcid' => $rc_id ) );
540 } else if( $rc_type == RC_LOG
) {
542 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc_log_type );
543 $clink = '(' . $this->skin
->linkKnown( $logtitle,
544 LogPage
::logName($rc_log_type) ) . ')';
546 $clink = $this->skin
->link( $rc->getTitle() );
549 // Log entries (old format) and special pages
550 } elseif( $rc_namespace == NS_SPECIAL
) {
551 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
552 if ( $specialName == 'Log' ) {
554 $logname = LogPage
::logName( $logtype );
555 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
557 wfDebug( "Unexpected special page in recentchanges\n" );
562 $clink = $this->skin
->linkKnown( $rc->getTitle() );
565 # Don't show unusable diff links
566 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
567 $showdifflinks = false;
570 $time = $wgLang->time( $rc_timestamp, true, true );
571 $rc->watched
= $watched;
573 $rc->timestamp
= $time;
574 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
576 # Make "cur" and "diff" links. Don't use link(), it's too slow if
577 # called too many times (50% of CPU time on RecentChanges!).
578 if( $rc->unpatrolled
) {
579 $rcIdQuery = array( 'rcid' => $rc_id );
581 $rcIdQuery = array();
583 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $rc_this_oldid );
584 $querydiff = $curIdEq +
array( 'diff' => $rc_this_oldid, 'oldid' =>
585 $rc_last_oldid ) +
$rcIdQuery;
587 if( !$showdifflinks ) {
588 $curLink = $this->message
['cur'];
589 $diffLink = $this->message
['diff'];
590 } else if( in_array( $rc_type, array(RC_NEW
,RC_LOG
,RC_MOVE
,RC_MOVE_OVER_REDIRECT
) ) ) {
591 if ( $rc_type != RC_NEW
) {
592 $curLink = $this->message
['cur'];
594 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
595 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
597 $diffLink = $this->message
['diff'];
599 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
600 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
601 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
602 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
606 if( !$showdifflinks ||
!$rc_last_oldid ) {
607 $lastLink = $this->message
['last'];
608 } else if( $rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
609 $lastLink = $this->message
['last'];
611 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
612 array(), $curIdEq +
array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) +
$rcIdQuery );
616 if( $this->isDeleted($rc,Revision
::DELETED_USER
) ) {
617 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
619 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
620 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
623 $rc->lastlink
= $lastLink;
624 $rc->curlink
= $curLink;
625 $rc->difflink
= $diffLink;
627 # Put accumulated information into the cache, for later display
628 # Page moves go on their own line
629 $title = $rc->getTitle();
630 $secureName = $title->getPrefixedDBkey();
631 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
632 # Use an @ character to prevent collision with page names
633 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
635 # Logs are grouped by type
636 if( $rc_type == RC_LOG
){
637 $secureName = SpecialPage
::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
639 if( !isset( $this->rc_cache
[$secureName] ) ) {
640 $this->rc_cache
[$secureName] = array();
643 array_push( $this->rc_cache
[$secureName], $rc );
646 wfProfileOut( __METHOD__
);
654 protected function recentChangesBlockGroup( $block ) {
655 global $wgLang, $wgContLang, $wgRCShowChangedSize;
657 wfProfileIn( __METHOD__
);
659 $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
661 # Collate list of users
662 $userlinks = array();
664 $unpatrolled = false;
666 $curId = $currentRevision = 0;
667 # Some catalyst variables...
670 foreach( $block as $rcObj ) {
671 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
672 if( $rcObj->mAttribs
['rc_new'] ) {
675 // If all log actions to this page were hidden, then don't
676 // give the name of the affected page for this block!
677 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
680 $u = $rcObj->userlink
;
681 if( !isset( $userlinks[$u] ) ) {
684 if( $rcObj->unpatrolled
) {
687 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
690 # Get the latest entry with a page_id and oldid
691 # since logs may not have these.
692 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
693 $curId = $rcObj->mAttribs
['rc_cur_id'];
695 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
696 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
699 $bot = $rcObj->mAttribs
['rc_bot'];
703 # Sort the list and convert to text
704 krsort( $userlinks );
707 foreach( $userlinks as $userlink => $count) {
709 $text .= $wgContLang->getDirMark();
711 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
713 array_push( $users, $text );
716 $users = ' <span class="changedby">[' .
717 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
719 # ID for JS visibility toggle
720 $jsid = $this->rcCacheIndex
;
721 # onclick handler to toggle hidden/expanded
722 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
724 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
725 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
727 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
728 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
729 $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.' ';
732 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
735 $r .= ' '.$block[0]->timestamp
.' </tt></td><td>';
739 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
740 } else if( $allLogs ) {
741 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
743 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
746 $r .= $wgContLang->getDirMark();
748 $curIdEq = 'curid=' . $curId;
751 static $nchanges = array();
752 if ( !isset( $nchanges[$n] ) ) {
753 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
759 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
761 } else if( $isnew ) {
764 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
765 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
771 // don't show history link for logs
772 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
773 $r .= $this->message
['semicolon-separator'] . $this->message
['hist'] . ')';
775 $r .= $this->message
['semicolon-separator'] . $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
776 $this->message
['hist'], $curIdEq . '&action=history' ) . ')';
780 # Character difference (does not apply if only log items)
781 if( $wgRCShowChangedSize && !$allLogs ) {
783 $first = count($block) - 1;
784 # Some events (like logs) have an "empty" size, so we need to skip those...
785 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === NULL ) {
788 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === NULL ) {
792 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
793 $block[$last]->mAttribs
['rc_new_len'] );
795 if( $chardiff == '' ) {
798 $r .= ' ' . $chardiff. ' . . ';
803 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
805 $r .= "</td></tr></table>\n";
808 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
809 $r .= '<table cellpadding="0" cellspacing="0" border="0" style="background: none">';
810 foreach( $block as $rcObj ) {
811 # Extract fields from DB into the function scope (rc_xxxx variables)
812 // FIXME: Would be good to replace this extract() call with something
813 // that explicitly initializes variables.
814 # Classes to apply -- TODO implement
816 extract( $rcObj->mAttribs
);
818 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
819 $r .= '<tr><td valign="top">';
820 $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
821 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
822 $r .= ' </tt></td><td valign="top">';
825 if( $rc_this_oldid != 0 ) {
826 $o = 'oldid='.$rc_this_oldid;
829 if( $rc_type == RC_LOG
) {
830 $link = '<tt>'.$rcObj->timestamp
.'</tt> ';
832 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
833 $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp
.'</tt></span> ';
835 $rcIdEq = ($rcObj->unpatrolled
&& $rc_type == RC_NEW
) ?
836 '&rcid='.$rcObj->mAttribs
['rc_id'] : '';
837 $link = '<tt>'.$this->skin
->makeKnownLinkObj( $rcObj->getTitle(),
838 $rcObj->timestamp
, $curIdEq.'&'.$o.$rcIdEq ).'</tt>';
839 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
840 $link = '<span class="history-deleted">'.$link.'</span> ';
844 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
846 $r .= $rcObj->curlink
;
847 $r .= $this->message
['semicolon-separator'];
848 $r .= $rcObj->lastlink
;
854 if( $wgRCShowChangedSize ) {
855 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
858 $r .= $rcObj->userlink
;
859 $r .= $rcObj->usertalklink
;
861 $this->insertAction( $r, $rcObj );
863 $this->insertComment( $r, $rcObj );
865 $this->insertRollback( $r, $rcObj );
867 $this->insertTags( $r, $rcObj, $classes );
869 # Mark revision as deleted
870 if( !$rc_log_type && $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) ) {
871 $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
874 $r .= "</td></tr>\n";
876 $r .= "</table></div>\n";
878 $this->rcCacheIndex++
;
880 wfProfileOut( __METHOD__
);
886 * Generate HTML for an arrow or placeholder graphic
887 * @param string $dir one of '', 'd', 'l', 'r'
888 * @param string $alt text
889 * @param string $title text
890 * @return string HTML <img> tag
892 protected function arrow( $dir, $alt='', $title='' ) {
894 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
895 $encAlt = htmlspecialchars( $alt );
896 $encTitle = htmlspecialchars( $title );
897 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
901 * Generate HTML for a right- or left-facing arrow,
902 * depending on language direction.
903 * @return string HTML <img> tag
905 protected function sideArrow() {
907 $dir = $wgContLang->isRTL() ?
'l' : 'r';
908 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
912 * Generate HTML for a down-facing arrow
913 * depending on language direction.
914 * @return string HTML <img> tag
916 protected function downArrow() {
917 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
921 * Generate HTML for a spacer image
922 * @return string HTML <img> tag
924 protected function spacerArrow() {
925 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
929 * Add a set of spaces
930 * @return string HTML <td> tag
932 protected function spacerIndent() {
933 return ' ';
937 * Enhanced RC ungrouped line.
938 * @return string a HTML formated line (generated using $r)
940 protected function recentChangesBlockLine( $rcObj ) {
941 global $wgRCShowChangedSize;
943 wfProfileIn( __METHOD__
);
945 # Extract fields from DB into the function scope (rc_xxxx variables)
946 // FIXME: Would be good to replace this extract() call with something
947 // that explicitly initializes variables.
948 $classes = array(); // TODO implement
949 extract( $rcObj->mAttribs
);
950 $curIdEq = "curid={$rc_cur_id}";
952 $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
953 $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . ' ';
955 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
956 $r .= ' '; // 4 flags -> 4 spaces
958 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
960 $r .= ' '.$rcObj->timestamp
.' </tt></td><td>';
961 # Article or log link
963 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
964 $logname = LogPage
::logName( $rc_log_type );
965 $r .= '(' . $this->skin
->makeKnownLinkObj($logtitle, $logname ) . ')';
967 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
969 # Diff and hist links
970 if ( $rc_type != RC_LOG
) {
971 $r .= ' ('. $rcObj->difflink
. $this->message
['semicolon-separator'];
972 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $this->message
['hist'],
973 $curIdEq.'&action=history' ) . ')';
977 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
981 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
982 # Log action (if any)
984 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
985 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
987 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
988 $this->skin
, LogPage
::extractParams($rc_params), true, true );
991 $this->insertComment( $r, $rcObj );
992 $this->insertRollback( $r, $rcObj );
994 $this->insertTags( $r, $rcObj, $classes );
995 # Show how many people are watching this if enabled
996 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
998 $r .= "</td></tr></table>\n";
1000 wfProfileOut( __METHOD__
);
1006 * If enhanced RC is in use, this function takes the previously cached
1007 * RC lines, arranges them, and outputs the HTML
1009 protected function recentChangesBlock() {
1010 if( count ( $this->rc_cache
) == 0 ) {
1014 wfProfileIn( __METHOD__
);
1017 foreach( $this->rc_cache
as $block ) {
1018 if( count( $block ) < 2 ) {
1019 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1021 $blockOut .= $this->recentChangesBlockGroup( $block );
1025 wfProfileOut( __METHOD__
);
1027 return '<div>'.$blockOut.'</div>';
1031 * Returns text for the end of RC
1032 * If enhanced RC is in use, returns pretty much all the text
1034 public function endRecentChangesList() {
1035 return $this->recentChangesBlock() . parent
::endRecentChangesList();