a3361519aee07caaa5f5170da7b29223b0f692ab
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 );
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 if( $wgRCShowChangedSize ) {
501 # Character difference
502 $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs
['rc_old_len'],
503 $block[0]->mAttribs
['rc_new_len'] );
504 if( $chardiff == '' ) {
507 $r .= ' ' . $chardiff. ' . . ';
512 $r .= '(' . $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
513 $this->message
['history'], $curIdEq.'&action=history' );
519 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
523 $r .= '<div id="'.$rci.'" style="display:none">';
524 foreach( $block as $rcObj ) {
525 # Get rc_xxxx variables
526 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
527 extract( $rcObj->mAttribs
);
529 $r .= $this->spacerArrow();
530 $r .= '<tt> ';
531 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
535 if( $rc_this_oldid != 0 ) {
536 $o = 'oldid='.$rc_this_oldid;
538 if( $rc_type == RC_LOG
) {
539 $link = $rcObj->timestamp
;
541 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
543 $link = '<tt>'.$link.'</tt>';
547 $r .= $rcObj->curlink
;
549 $r .= $rcObj->lastlink
;
553 if( $wgRCShowChangedSize ) {
554 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
557 $r .= $rcObj->userlink
;
558 $r .= $rcObj->usertalklink
;
559 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
564 $this->rcCacheIndex++
;
568 function maybeWatchedLink( $link, $watched=false ) {
570 // FIXME: css style might be more appropriate
571 return '<strong>' . $link . '</strong>';
578 * Generate HTML for an arrow or placeholder graphic
579 * @param string $dir one of '', 'd', 'l', 'r'
580 * @param string $alt text
581 * @return string HTML <img> tag
584 function arrow( $dir, $alt='' ) {
586 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
587 $encAlt = htmlspecialchars( $alt );
588 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
592 * Generate HTML for a right- or left-facing arrow,
593 * depending on language direction.
594 * @return string HTML <img> tag
597 function sideArrow() {
599 $dir = $wgContLang->isRTL() ?
'l' : 'r';
600 return $this->arrow( $dir, '+' );
604 * Generate HTML for a down-facing arrow
605 * depending on language direction.
606 * @return string HTML <img> tag
609 function downArrow() {
610 return $this->arrow( 'd', '-' );
614 * Generate HTML for a spacer image
615 * @return string HTML <img> tag
618 function spacerArrow() {
619 return $this->arrow( '', ' ' );
623 * Enhanced RC ungrouped line.
624 * @return string a HTML formated line (generated using $r)
626 function recentChangesBlockLine( $rcObj ) {
627 global $wgContLang, $wgRCShowChangedSize;
629 # Get rc_xxxx variables
630 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
631 extract( $rcObj->mAttribs
);
632 $curIdEq = 'curid='.$rc_cur_id;
637 $r .= $this->spacerArrow();
642 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
643 $r .= ' ';
645 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
647 $r .= ' '.$rcObj->timestamp
.' </tt>';
650 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
653 $r .= ' ('. $rcObj->difflink
.'; ';
656 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ') . . ';
659 if( $wgRCShowChangedSize ) {
660 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : ' ' . $rcObj->getCharacterDifference() . ' . . ' ) ;
664 $r .= $rcObj->userlink
. $rcObj->usertalklink
;
667 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
668 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
671 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
678 * If enhanced RC is in use, this function takes the previously cached
679 * RC lines, arranges them, and outputs the HTML
681 function recentChangesBlock() {
682 if( count ( $this->rc_cache
) == 0 ) {
686 foreach( $this->rc_cache
as $block ) {
687 if( count( $block ) < 2 ) {
688 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
690 $blockOut .= $this->recentChangesBlockGroup( $block );
694 return '<div>'.$blockOut.'</div>';
698 * Returns text for the end of RC
699 * If enhanced RC is in use, returns pretty much all the text
701 function endRecentChangesList() {
702 return $this->recentChangesBlock() . parent
::endRecentChangesList();