3 * Contain class to show various lists of change:
12 class RCCacheEntry
extends RecentChange
14 var $secureName, $link;
15 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
16 var $userlink, $timestamp, $watched;
18 function newFromParent( $rc ) {
19 $rc2 = new RCCacheEntry
;
20 $rc2->mAttribs
= $rc->mAttribs
;
21 $rc2->mExtra
= $rc->mExtra
;
29 # Called by history lists and recent changes
33 function __construct( &$skin ) {
35 $this->preCacheMessages();
39 * Fetch an appropriate changes list class for the specified user
40 * Some users might want to use an enhanced list format, for instance
42 * @param $user User to fetch the list class for
43 * @return ChangesList derivative
45 public static function newFromUser( &$user ) {
46 $sk = $user->getSkin();
48 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
49 return $user->getOption( 'usenewrc' ) ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
56 * As we use the same small set of messages in various methods and that
57 * they are called often, we call them once and save them in $this->message
59 function preCacheMessages() {
60 // Precache various messages
61 if( !isset( $this->message
) ) {
62 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
63 'blocklink history boteditletter' ) as $msg ) {
64 $this->message
[$msg] = wfMsgExt( $msg, array( 'escape') );
71 * Returns the appropriate flags for new page, minor change and patrolling
73 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
74 $f = $new ?
'<span class="newpage">' . $this->message
['newpageletter'] . '</span>'
76 $f .= $minor ?
'<span class="minor">' . $this->message
['minoreditletter'] . '</span>'
78 $f .= $bot ?
'<span class="bot">' . $this->message
['boteditletter'] . '</span>' : $nothing;
79 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
84 * Returns text for the start of the tabular part of RC
86 function beginRecentChangesList() {
87 $this->rc_cache
= array();
88 $this->rcMoveIndex
= 0;
89 $this->rcCacheIndex
= 0;
91 $this->rclistOpen
= false;
96 * Returns text for the end of RC
98 function endRecentChangesList() {
99 if( $this->rclistOpen
) {
107 function insertMove( &$s, $rc ) {
109 $s .= '(' . $this->message
['diff'] . ') (';
111 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
114 # "[[x]] moved to [[y]]"
115 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
116 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
117 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
120 function insertDateHeader(&$s, $rc_timestamp) {
123 # Make date header if necessary
124 $date = $wgLang->date( $rc_timestamp, true, true );
126 if( $date != $this->lastdate
) {
127 if( '' != $this->lastdate
) {
130 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
131 $this->lastdate
= $date;
132 $this->rclistOpen
= true;
136 function insertLog(&$s, $title, $logtype) {
137 $logname = LogPage
::logName( $logtype );
138 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
142 function insertDiffHist(&$s, &$rc, $unpatrolled) {
144 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
145 $diffLink = $this->message
['diff'];
147 $rcidparam = $unpatrolled
148 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
150 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
152 'curid' => $rc->mAttribs
['rc_cur_id'],
153 'diff' => $rc->mAttribs
['rc_this_oldid'],
154 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
156 '', '', ' tabindex="'.$rc->counter
.'"');
158 $s .= '('.$diffLink.') (';
161 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
163 'curid' => $rc->mAttribs
['rc_cur_id'],
164 'action' => 'history' ) ) );
168 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
170 # If it's a new article, there is no diff link, but if it hasn't been
171 # patrolled yet, we need to give users a way to do so
172 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
173 ?
'rcid='.$rc->mAttribs
['rc_id']
175 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
176 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
178 $articlelink .= $wgContLang->getDirMark();
180 $s .= ' '.$articlelink;
183 function insertTimestamp(&$s, $rc) {
186 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
189 /** Insert links to user page, user talk page and eventually a blocking link */
190 function insertUserRelatedLinks(&$s, &$rc) {
191 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
192 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
195 /** insert a formatted comment */
196 function insertComment(&$s, &$rc) {
198 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
199 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
204 * Check whether to enable recent changes patrol features
207 function usePatrol() {
208 global $wgUseRCPatrol, $wgUser;
209 return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
213 * Returns the string which indicates the number of watching users
215 function numberofWatchingusers( $count ) {
217 static $cache = array();
219 if ( !isset( $cache[$count] ) ) {
220 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
221 array('parsemag', 'escape'), $wgLang->formatNum($count));
223 return $cache[$count];
232 * Generate a list of changes using the good old system (no javascript)
234 class OldChangesList
extends ChangesList
{
236 * Format a line using the old system (aka without any javascript).
238 function recentChangesLine( &$rc, $watched = false ) {
239 global $wgContLang, $wgRCShowChangedSize;
241 $fname = 'ChangesList::recentChangesLineOld';
242 wfProfileIn( $fname );
244 # Extract DB fields into local scope
245 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
246 extract( $rc->mAttribs
);
248 # Should patrol-related stuff be shown?
249 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
251 $this->insertDateHeader($s,$rc_timestamp);
256 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
257 $this->insertMove( $s, $rc );
259 } elseif ( $rc_namespace == NS_SPECIAL
) {
260 list( $specialName, $specialSubpage ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
261 if ( $specialName == 'Log' ) {
262 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
264 wfDebug( "Unexpected special page in recentchanges\n" );
268 wfProfileIn($fname.'-page');
270 $this->insertDiffHist($s, $rc, $unpatrolled);
272 # M, N, b and ! (minor, new, bot and unpatrolled)
273 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '', $rc_bot );
274 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
276 wfProfileOut($fname.'-page');
279 wfProfileIn( $fname.'-rest' );
281 $this->insertTimestamp($s,$rc);
283 if( $wgRCShowChangedSize ) {
284 $s .= ( $rc->getCharacterDifference() == '' ?
'' : $rc->getCharacterDifference() . ' . . ' );
287 $this->insertUserRelatedLinks($s,$rc);
288 $this->insertComment($s, $rc);
290 $s .= rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers
));
294 wfProfileOut( $fname.'-rest' );
296 wfProfileOut( $fname );
303 * Generate a list of changes using an Enhanced system (use javascript).
305 class EnhancedChangesList
extends ChangesList
{
307 * Format a line for enhanced recentchange (aka with javascript and block of lines).
309 function recentChangesLine( &$baseRC, $watched = false ) {
310 global $wgLang, $wgContLang;
312 # Create a specialised object
313 $rc = RCCacheEntry
::newFromParent( $baseRC );
315 # Extract fields from DB into the function scope (rc_xxxx variables)
316 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
317 extract( $rc->mAttribs
);
318 $curIdEq = 'curid=' . $rc_cur_id;
320 # If it's a new day, add the headline and flush the cache
321 $date = $wgLang->date( $rc_timestamp, true);
323 if( $date != $this->lastdate
) {
324 # Process current cache
325 $ret = $this->recentChangesBlock();
326 $this->rc_cache
= array();
327 $ret .= "<h4>{$date}</h4>\n";
328 $this->lastdate
= $date;
331 # Should patrol-related stuff be shown?
332 if( $this->usePatrol() ) {
333 $rc->unpatrolled
= !$rc_patrolled;
335 $rc->unpatrolled
= false;
339 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
340 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
341 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
342 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
343 } elseif( $rc_namespace == NS_SPECIAL
) {
344 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
345 if ( $specialName == 'Log' ) {
347 $logname = LogPage
::logName( $logtype );
348 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
350 wfDebug( "Unexpected special page in recentchanges\n" );
353 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
354 # Unpatrolled new page, give rc_id in query
355 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
357 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
360 $time = $wgContLang->time( $rc_timestamp, true, true );
361 $rc->watched
= $watched;
363 $rc->timestamp
= $time;
364 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
366 # Make "cur" and "diff" links
367 if( $rc->unpatrolled
) {
368 $rcIdQuery = "&rcid={$rc_id}";
372 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
373 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
374 $aprops = ' tabindex="'.$baseRC->counter
.'"';
375 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
376 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
377 if( $rc_type != RC_NEW
) {
378 $curLink = $this->message
['cur'];
380 $diffLink = $this->message
['diff'];
382 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
386 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
387 $lastLink = $this->message
['last'];
389 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
390 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
393 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
395 $rc->lastlink
= $lastLink;
396 $rc->curlink
= $curLink;
397 $rc->difflink
= $diffLink;
399 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
401 # Put accumulated information into the cache, for later display
402 # Page moves go on their own line
403 $title = $rc->getTitle();
404 $secureName = $title->getPrefixedDBkey();
405 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
406 # Use an @ character to prevent collision with page names
407 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
409 if( !isset ( $this->rc_cache
[$secureName] ) ) {
410 $this->rc_cache
[$secureName] = array();
412 array_push( $this->rc_cache
[$secureName], $rc );
420 function recentChangesBlockGroup( $block ) {
421 global $wgLang, $wgContLang, $wgRCShowChangedSize;
424 # Collate list of users
426 $unpatrolled = false;
427 $userlinks = array();
428 foreach( $block as $rcObj ) {
429 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
430 if( $rcObj->mAttribs
['rc_new'] ) {
433 $u = $rcObj->userlink
;
434 if( !isset( $userlinks[$u] ) ) {
437 if( $rcObj->unpatrolled
) {
440 $bot = $rcObj->mAttribs
['rc_bot'];
444 # Sort the list and convert to text
445 krsort( $userlinks );
448 foreach( $userlinks as $userlink => $count) {
450 $text .= $wgContLang->getDirMark();
452 $text .= ' ('.$count.'×)';
454 array_push( $users, $text );
457 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
460 $rci = 'RCI'.$this->rcCacheIndex
;
461 $rcl = 'RCL'.$this->rcCacheIndex
;
462 $rcm = 'RCM'.$this->rcCacheIndex
;
463 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
464 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
465 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
470 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
473 $r .= ' '.$block[0]->timestamp
.' </tt>';
476 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
477 $r .= $wgContLang->getDirMark();
479 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
480 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
481 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
485 static $nchanges = array();
486 if ( !isset( $nchanges[$n] ) ) {
487 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'),
488 $wgLang->formatNum( $n ) );
496 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
497 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
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>' . $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();