6 class RCCacheEntry
extends RecentChange
8 var $secureName, $link;
9 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
10 var $userlink, $timestamp, $watched;
12 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 );
174 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
176 $articlelink .= $wgContLang->getDirMark();
178 $s .= ' '.$articlelink;
181 function insertTimestamp(&$s, $rc) {
184 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
187 /** Insert links to user page, user talk page and eventually a blocking link */
188 function insertUserRelatedLinks(&$s, &$rc) {
189 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
190 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
193 /** insert a formatted comment */
194 function insertComment(&$s, &$rc) {
196 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
197 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
202 * Check whether to enable recent changes patrol features
205 function usePatrol() {
206 global $wgUseRCPatrol, $wgUser;
207 return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
211 * Returns the string which indicates the number of watching users
213 function numberofWatchingusers( $count ) {
215 static $cache = array();
217 if ( !isset( $cache[$count] ) ) {
218 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
219 array('parsemag', 'escape'), $wgLang->formatNum($count));
221 return $cache[$count];
230 * Generate a list of changes using the good old system (no javascript)
232 class OldChangesList
extends ChangesList
{
234 * Format a line using the old system (aka without any javascript).
236 function recentChangesLine( &$rc, $watched = false ) {
237 global $wgContLang, $wgRCShowChangedSize;
239 $fname = 'ChangesList::recentChangesLineOld';
240 wfProfileIn( $fname );
242 # Extract DB fields into local scope
243 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
244 extract( $rc->mAttribs
);
246 # Should patrol-related stuff be shown?
247 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
249 $this->insertDateHeader($s,$rc_timestamp);
254 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
255 $this->insertMove( $s, $rc );
257 } elseif ( $rc_namespace == NS_SPECIAL
) {
258 list( $specialName, $specialSubpage ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
259 if ( $specialName == 'Log' ) {
260 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
262 wfDebug( "Unexpected special page in recentchanges\n" );
266 wfProfileIn($fname.'-page');
268 $this->insertDiffHist($s, $rc, $unpatrolled);
270 # M, N, b and ! (minor, new, bot and unpatrolled)
271 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '', $rc_bot );
272 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
274 wfProfileOut($fname.'-page');
277 wfProfileIn( $fname.'-rest' );
279 $this->insertTimestamp($s,$rc);
281 if( $wgRCShowChangedSize ) {
282 $s .= ( $rc->getCharacterDifference() == '' ?
'' : $rc->getCharacterDifference() . ' . . ' );
285 $this->insertUserRelatedLinks($s,$rc);
286 $this->insertComment($s, $rc);
288 $s .= rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers
));
292 wfProfileOut( $fname.'-rest' );
294 wfProfileOut( $fname );
301 * Generate a list of changes using an Enhanced system (use javascript).
303 class EnhancedChangesList
extends ChangesList
{
305 * Format a line for enhanced recentchange (aka with javascript and block of lines).
307 function recentChangesLine( &$baseRC, $watched = false ) {
308 global $wgLang, $wgContLang;
310 # Create a specialised object
311 $rc = RCCacheEntry
::newFromParent( $baseRC );
313 # Extract fields from DB into the function scope (rc_xxxx variables)
314 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
315 extract( $rc->mAttribs
);
316 $curIdEq = 'curid=' . $rc_cur_id;
318 # If it's a new day, add the headline and flush the cache
319 $date = $wgLang->date( $rc_timestamp, true);
321 if( $date != $this->lastdate
) {
322 # Process current cache
323 $ret = $this->recentChangesBlock();
324 $this->rc_cache
= array();
325 $ret .= "<h4>{$date}</h4>\n";
326 $this->lastdate
= $date;
329 # Should patrol-related stuff be shown?
330 if( $this->usePatrol() ) {
331 $rc->unpatrolled
= !$rc_patrolled;
333 $rc->unpatrolled
= false;
337 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
338 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
339 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
340 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
341 } elseif( $rc_namespace == NS_SPECIAL
) {
342 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
343 if ( $specialName == 'Log' ) {
345 $logname = LogPage
::logName( $logtype );
346 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
348 wfDebug( "Unexpected special page in recentchanges\n" );
351 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
352 # Unpatrolled new page, give rc_id in query
353 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
355 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
358 $time = $wgContLang->time( $rc_timestamp, true, true );
359 $rc->watched
= $watched;
361 $rc->timestamp
= $time;
362 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
364 # Make "cur" and "diff" links
365 if( $rc->unpatrolled
) {
366 $rcIdQuery = "&rcid={$rc_id}";
370 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
371 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
372 $aprops = ' tabindex="'.$baseRC->counter
.'"';
373 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
374 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
375 if( $rc_type != RC_NEW
) {
376 $curLink = $this->message
['cur'];
378 $diffLink = $this->message
['diff'];
380 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
384 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
385 $lastLink = $this->message
['last'];
387 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
388 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
391 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
393 $rc->lastlink
= $lastLink;
394 $rc->curlink
= $curLink;
395 $rc->difflink
= $diffLink;
397 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
399 # Put accumulated information into the cache, for later display
400 # Page moves go on their own line
401 $title = $rc->getTitle();
402 $secureName = $title->getPrefixedDBkey();
403 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
404 # Use an @ character to prevent collision with page names
405 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
407 if( !isset ( $this->rc_cache
[$secureName] ) ) {
408 $this->rc_cache
[$secureName] = array();
410 array_push( $this->rc_cache
[$secureName], $rc );
418 function recentChangesBlockGroup( $block ) {
419 global $wgLang, $wgContLang, $wgRCShowChangedSize;
422 # Collate list of users
424 $unpatrolled = false;
425 $userlinks = array();
426 foreach( $block as $rcObj ) {
427 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
428 if( $rcObj->mAttribs
['rc_new'] ) {
431 $u = $rcObj->userlink
;
432 if( !isset( $userlinks[$u] ) ) {
435 if( $rcObj->unpatrolled
) {
438 $bot = $rcObj->mAttribs
['rc_bot'];
442 # Sort the list and convert to text
443 krsort( $userlinks );
446 foreach( $userlinks as $userlink => $count) {
448 $text .= $wgContLang->getDirMark();
450 $text .= ' ('.$count.'×)';
452 array_push( $users, $text );
455 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
458 $rci = 'RCI'.$this->rcCacheIndex
;
459 $rcl = 'RCL'.$this->rcCacheIndex
;
460 $rcm = 'RCM'.$this->rcCacheIndex
;
461 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
462 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
463 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
468 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
471 $r .= ' '.$block[0]->timestamp
.' </tt>';
474 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
475 $r .= $wgContLang->getDirMark();
477 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
478 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
479 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
483 static $nchanges = array();
484 if ( !isset( $nchanges[$n] ) ) {
485 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'),
486 $wgLang->formatNum( $n ) );
494 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
495 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
500 # Character difference
501 $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs
['rc_old_len'],
502 $block[0]->mAttribs
['rc_new_len'] );
503 if( $chardiff == '' ) {
506 $r .= ' ' . $chardiff. ' . . (';
511 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
512 $this->message
['history'], $curIdEq.'&action=history' );
518 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
522 $r .= '<div id="'.$rci.'" style="display:none">';
523 foreach( $block as $rcObj ) {
524 # Get rc_xxxx variables
525 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
526 extract( $rcObj->mAttribs
);
528 $r .= $this->spacerArrow();
529 $r .= '<tt> ';
530 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
534 if( $rc_this_oldid != 0 ) {
535 $o = 'oldid='.$rc_this_oldid;
537 if( $rc_type == RC_LOG
) {
538 $link = $rcObj->timestamp
;
540 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
542 $link = '<tt>'.$link.'</tt>';
546 $r .= $rcObj->curlink
;
548 $r .= $rcObj->lastlink
;
552 if( $wgRCShowChangedSize ) {
553 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
556 $r .= $rcObj->userlink
;
557 $r .= $rcObj->usertalklink
;
558 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
563 $this->rcCacheIndex++
;
567 function maybeWatchedLink( $link, $watched=false ) {
569 // FIXME: css style might be more appropriate
570 return '<strong>' . $link . '</strong>';
577 * Generate HTML for an arrow or placeholder graphic
578 * @param string $dir one of '', 'd', 'l', 'r'
579 * @param string $alt text
580 * @return string HTML <img> tag
583 function arrow( $dir, $alt='' ) {
585 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
586 $encAlt = htmlspecialchars( $alt );
587 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
591 * Generate HTML for a right- or left-facing arrow,
592 * depending on language direction.
593 * @return string HTML <img> tag
596 function sideArrow() {
598 $dir = $wgContLang->isRTL() ?
'l' : 'r';
599 return $this->arrow( $dir, '+' );
603 * Generate HTML for a down-facing arrow
604 * depending on language direction.
605 * @return string HTML <img> tag
608 function downArrow() {
609 return $this->arrow( 'd', '-' );
613 * Generate HTML for a spacer image
614 * @return string HTML <img> tag
617 function spacerArrow() {
618 return $this->arrow( '', ' ' );
622 * Enhanced RC ungrouped line.
623 * @return string a HTML formated line (generated using $r)
625 function recentChangesBlockLine( $rcObj ) {
626 global $wgContLang, $wgRCShowChangedSize;
628 # Get rc_xxxx variables
629 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
630 extract( $rcObj->mAttribs
);
631 $curIdEq = 'curid='.$rc_cur_id;
636 $r .= $this->spacerArrow();
641 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
642 $r .= ' ';
644 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
646 $r .= ' '.$rcObj->timestamp
.' </tt>';
649 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
652 $r .= ' ('. $rcObj->difflink
.'; ';
655 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ') . . ';
658 if( $wgRCShowChangedSize ) {
659 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : ' ' . $rcObj->getCharacterDifference() . ' . . ' ) ;
663 $r .= $rcObj->userlink
. $rcObj->usertalklink
;
666 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
667 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
670 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
677 * If enhanced RC is in use, this function takes the previously cached
678 * RC lines, arranges them, and outputs the HTML
680 function recentChangesBlock() {
681 if( count ( $this->rc_cache
) == 0 ) {
685 foreach( $this->rc_cache
as $block ) {
686 if( count( $block ) < 2 ) {
687 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
689 $blockOut .= $this->recentChangesBlockGroup( $block );
693 return '<div>'.$blockOut.'</div>';
697 * Returns text for the end of RC
698 * If enhanced RC is in use, returns pretty much all the text
700 function endRecentChangesList() {
701 return $this->recentChangesBlock() . parent
::endRecentChangesList();