6 class RCCacheEntry
extends RecentChange
8 var $secureName, $link;
9 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
10 var $userlink, $timestamp, $watched;
12 static function newFromParent( $rc ) {
13 $rc2 = new RCCacheEntry
;
14 $rc2->mAttribs
= $rc->mAttribs
;
15 $rc2->mExtra
= $rc->mExtra
;
21 * Class to show various lists of changes:
27 # Called by history lists and recent changes
31 function __construct( &$skin ) {
33 $this->preCacheMessages();
37 * Fetch an appropriate changes list class for the specified user
38 * Some users might want to use an enhanced list format, for instance
40 * @param $user User to fetch the list class for
41 * @return ChangesList derivative
43 public static function newFromUser( &$user ) {
44 $sk = $user->getSkin();
46 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
47 return $user->getOption( 'usenewrc' ) ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
54 * As we use the same small set of messages in various methods and that
55 * they are called often, we call them once and save them in $this->message
57 function preCacheMessages() {
58 // Precache various messages
59 if( !isset( $this->message
) ) {
60 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
61 'blocklink history boteditletter' ) as $msg ) {
62 $this->message
[$msg] = wfMsgExt( $msg, array( 'escape') );
69 * Returns the appropriate flags for new page, minor change and patrolling
71 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
72 $f = $new ?
'<span class="newpage">' . $this->message
['newpageletter'] . '</span>'
74 $f .= $minor ?
'<span class="minor">' . $this->message
['minoreditletter'] . '</span>'
76 $f .= $bot ?
'<span class="bot">' . $this->message
['boteditletter'] . '</span>' : $nothing;
77 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
82 * Returns text for the start of the tabular part of RC
84 function beginRecentChangesList() {
85 $this->rc_cache
= array();
86 $this->rcMoveIndex
= 0;
87 $this->rcCacheIndex
= 0;
89 $this->rclistOpen
= false;
94 * Returns text for the end of RC
96 function endRecentChangesList() {
97 if( $this->rclistOpen
) {
105 function insertMove( &$s, $rc ) {
107 $s .= '(' . $this->message
['diff'] . ') (';
109 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
112 # "[[x]] moved to [[y]]"
113 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
114 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
115 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
118 function insertDateHeader(&$s, $rc_timestamp) {
121 # Make date header if necessary
122 $date = $wgLang->date( $rc_timestamp, true, true );
124 if( $date != $this->lastdate
) {
125 if( '' != $this->lastdate
) {
128 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
129 $this->lastdate
= $date;
130 $this->rclistOpen
= true;
134 function insertLog(&$s, $title, $logtype) {
135 $logname = LogPage
::logName( $logtype );
136 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
140 function insertDiffHist(&$s, &$rc, $unpatrolled) {
142 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
143 $diffLink = $this->message
['diff'];
145 $rcidparam = $unpatrolled
146 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
148 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
150 'curid' => $rc->mAttribs
['rc_cur_id'],
151 'diff' => $rc->mAttribs
['rc_this_oldid'],
152 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
154 '', '', ' tabindex="'.$rc->counter
.'"');
156 $s .= '('.$diffLink.') (';
159 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
161 'curid' => $rc->mAttribs
['rc_cur_id'],
162 'action' => 'history' ) ) );
166 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
168 # If it's a new article, there is no diff link, but if it hasn't been
169 # patrolled yet, we need to give users a way to do so
170 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
171 ?
'rcid='.$rc->mAttribs
['rc_id']
173 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
175 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
177 $articlelink .= $wgContLang->getDirMark();
179 $s .= ' '.$articlelink;
182 function insertTimestamp(&$s, $rc) {
185 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
188 /** Insert links to user page, user talk page and eventually a blocking link */
189 function insertUserRelatedLinks(&$s, &$rc) {
190 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
191 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
194 /** insert a formatted comment */
195 function insertComment(&$s, &$rc) {
197 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
198 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
203 * Check whether to enable recent changes patrol features
206 function usePatrol() {
207 global $wgUseRCPatrol, $wgUser;
208 return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') ||
$wgUser->isAllowed('patrolmarks')) );
212 * Returns the string which indicates the number of watching users
214 function numberofWatchingusers( $count ) {
216 static $cache = array();
218 if ( !isset( $cache[$count] ) ) {
219 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
220 array('parsemag', 'escape'), $wgLang->formatNum($count));
222 return $cache[$count];
231 * Generate a list of changes using the good old system (no javascript)
233 class OldChangesList
extends ChangesList
{
235 * Format a line using the old system (aka without any javascript).
237 function recentChangesLine( &$rc, $watched = false ) {
238 global $wgContLang, $wgRCShowChangedSize;
240 $fname = 'ChangesList::recentChangesLineOld';
241 wfProfileIn( $fname );
243 # Extract DB fields into local scope
244 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
245 extract( $rc->mAttribs
);
247 # Should patrol-related stuff be shown?
248 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
250 $this->insertDateHeader($s,$rc_timestamp);
255 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
256 $this->insertMove( $s, $rc );
258 } elseif ( $rc_namespace == NS_SPECIAL
) {
259 list( $specialName, $specialSubpage ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
260 if ( $specialName == 'Log' ) {
261 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
263 wfDebug( "Unexpected special page in recentchanges\n" );
267 wfProfileIn($fname.'-page');
269 $this->insertDiffHist($s, $rc, $unpatrolled);
271 # M, N, b and ! (minor, new, bot and unpatrolled)
272 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '', $rc_bot );
273 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
275 wfProfileOut($fname.'-page');
278 wfProfileIn( $fname.'-rest' );
280 $this->insertTimestamp($s,$rc);
282 if( $wgRCShowChangedSize ) {
283 $s .= ( $rc->getCharacterDifference() == '' ?
'' : $rc->getCharacterDifference() . ' . . ' );
286 $this->insertUserRelatedLinks($s,$rc);
287 $this->insertComment($s, $rc);
289 $s .= rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers
));
293 wfProfileOut( $fname.'-rest' );
295 wfProfileOut( $fname );
302 * Generate a list of changes using an Enhanced system (use javascript).
304 class EnhancedChangesList
extends ChangesList
{
306 * Format a line for enhanced recentchange (aka with javascript and block of lines).
308 function recentChangesLine( &$baseRC, $watched = false ) {
309 global $wgLang, $wgContLang;
311 # Create a specialised object
312 $rc = RCCacheEntry
::newFromParent( $baseRC );
314 # Extract fields from DB into the function scope (rc_xxxx variables)
315 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
316 extract( $rc->mAttribs
);
317 $curIdEq = 'curid=' . $rc_cur_id;
319 # If it's a new day, add the headline and flush the cache
320 $date = $wgLang->date( $rc_timestamp, true);
322 if( $date != $this->lastdate
) {
323 # Process current cache
324 $ret = $this->recentChangesBlock();
325 $this->rc_cache
= array();
326 $ret .= "<h4>{$date}</h4>\n";
327 $this->lastdate
= $date;
330 # Should patrol-related stuff be shown?
331 if( $this->usePatrol() ) {
332 $rc->unpatrolled
= !$rc_patrolled;
334 $rc->unpatrolled
= false;
338 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
339 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
340 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
341 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
342 } elseif( $rc_namespace == NS_SPECIAL
) {
343 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
344 if ( $specialName == 'Log' ) {
346 $logname = LogPage
::logName( $logtype );
347 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
349 wfDebug( "Unexpected special page in recentchanges\n" );
352 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
353 # Unpatrolled new page, give rc_id in query
354 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
356 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
359 $time = $wgContLang->time( $rc_timestamp, true, true );
360 $rc->watched
= $watched;
362 $rc->timestamp
= $time;
363 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
365 # Make "cur" and "diff" links
366 if( $rc->unpatrolled
) {
367 $rcIdQuery = "&rcid={$rc_id}";
371 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
372 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
373 $aprops = ' tabindex="'.$baseRC->counter
.'"';
374 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
375 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
376 if( $rc_type != RC_NEW
) {
377 $curLink = $this->message
['cur'];
379 $diffLink = $this->message
['diff'];
381 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
385 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
386 $lastLink = $this->message
['last'];
388 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
389 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
392 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
394 $rc->lastlink
= $lastLink;
395 $rc->curlink
= $curLink;
396 $rc->difflink
= $diffLink;
398 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
400 # Put accumulated information into the cache, for later display
401 # Page moves go on their own line
402 $title = $rc->getTitle();
403 $secureName = $title->getPrefixedDBkey();
404 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
405 # Use an @ character to prevent collision with page names
406 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
408 if( !isset ( $this->rc_cache
[$secureName] ) ) {
409 $this->rc_cache
[$secureName] = array();
411 array_push( $this->rc_cache
[$secureName], $rc );
419 function recentChangesBlockGroup( $block ) {
420 global $wgLang, $wgContLang, $wgRCShowChangedSize;
423 # Collate list of users
425 $unpatrolled = false;
426 $userlinks = array();
427 foreach( $block as $rcObj ) {
428 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
429 if( $rcObj->mAttribs
['rc_new'] ) {
432 $u = $rcObj->userlink
;
433 if( !isset( $userlinks[$u] ) ) {
436 if( $rcObj->unpatrolled
) {
439 $bot = $rcObj->mAttribs
['rc_bot'];
443 # Sort the list and convert to text
444 krsort( $userlinks );
447 foreach( $userlinks as $userlink => $count) {
449 $text .= $wgContLang->getDirMark();
451 $text .= ' ('.$count.'×)';
453 array_push( $users, $text );
456 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
459 $rci = 'RCI'.$this->rcCacheIndex
;
460 $rcl = 'RCL'.$this->rcCacheIndex
;
461 $rcm = 'RCM'.$this->rcCacheIndex
;
462 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
463 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
464 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
469 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
472 $r .= ' '.$block[0]->timestamp
.' </tt>';
475 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
476 $r .= $wgContLang->getDirMark();
478 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
479 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
480 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
484 static $nchanges = array();
485 if ( !isset( $nchanges[$n] ) ) {
486 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'),
487 $wgLang->formatNum( $n ) );
495 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
496 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
501 if( $wgRCShowChangedSize ) {
502 # Character difference
503 $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs
['rc_old_len'],
504 $block[0]->mAttribs
['rc_new_len'] );
505 if( $chardiff == '' ) {
508 $r .= ' ' . $chardiff. ' . . ';
513 $r .= '(' . $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
514 $this->message
['history'], $curIdEq.'&action=history' );
520 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
524 $r .= '<div id="'.$rci.'" style="display:none">';
525 foreach( $block as $rcObj ) {
526 # Get rc_xxxx variables
527 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
528 extract( $rcObj->mAttribs
);
530 $r .= $this->spacerArrow();
531 $r .= '<tt> ';
532 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
536 if( $rc_this_oldid != 0 ) {
537 $o = 'oldid='.$rc_this_oldid;
539 if( $rc_type == RC_LOG
) {
540 $link = $rcObj->timestamp
;
542 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
544 $link = '<tt>'.$link.'</tt>';
548 $r .= $rcObj->curlink
;
550 $r .= $rcObj->lastlink
;
554 if( $wgRCShowChangedSize ) {
555 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
558 $r .= $rcObj->userlink
;
559 $r .= $rcObj->usertalklink
;
560 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
565 $this->rcCacheIndex++
;
569 function maybeWatchedLink( $link, $watched=false ) {
571 // FIXME: css style might be more appropriate
572 return '<strong class="mw-watched">' . $link . '</strong>';
579 * Generate HTML for an arrow or placeholder graphic
580 * @param string $dir one of '', 'd', 'l', 'r'
581 * @param string $alt text
582 * @return string HTML <img> tag
585 function arrow( $dir, $alt='' ) {
587 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
588 $encAlt = htmlspecialchars( $alt );
589 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
593 * Generate HTML for a right- or left-facing arrow,
594 * depending on language direction.
595 * @return string HTML <img> tag
598 function sideArrow() {
600 $dir = $wgContLang->isRTL() ?
'l' : 'r';
601 return $this->arrow( $dir, '+' );
605 * Generate HTML for a down-facing arrow
606 * depending on language direction.
607 * @return string HTML <img> tag
610 function downArrow() {
611 return $this->arrow( 'd', '-' );
615 * Generate HTML for a spacer image
616 * @return string HTML <img> tag
619 function spacerArrow() {
620 return $this->arrow( '', ' ' );
624 * Enhanced RC ungrouped line.
625 * @return string a HTML formated line (generated using $r)
627 function recentChangesBlockLine( $rcObj ) {
628 global $wgContLang, $wgRCShowChangedSize;
630 # Get rc_xxxx variables
631 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
632 extract( $rcObj->mAttribs
);
633 $curIdEq = 'curid='.$rc_cur_id;
638 $r .= $this->spacerArrow();
643 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
644 $r .= ' ';
646 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
648 $r .= ' '.$rcObj->timestamp
.' </tt>';
651 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
654 $r .= ' ('. $rcObj->difflink
.'; ';
657 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ') . . ';
660 if( $wgRCShowChangedSize ) {
661 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : ' ' . $rcObj->getCharacterDifference() . ' . . ' ) ;
665 $r .= $rcObj->userlink
. $rcObj->usertalklink
;
668 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
669 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
672 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
679 * If enhanced RC is in use, this function takes the previously cached
680 * RC lines, arranges them, and outputs the HTML
682 function recentChangesBlock() {
683 if( count ( $this->rc_cache
) == 0 ) {
687 foreach( $this->rc_cache
as $block ) {
688 if( count( $block ) < 2 ) {
689 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
691 $blockOut .= $this->recentChangesBlockGroup( $block );
695 return '<div>'.$blockOut.'</div>';
699 * Returns text for the end of RC
700 * If enhanced RC is in use, returns pretty much all the text
702 function endRecentChangesList() {
703 return $this->recentChangesBlock() . parent
::endRecentChangesList();