4 * Contain class to show various lists of change:
14 class RCCacheEntry
extends RecentChange
16 var $secureName, $link;
17 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
18 var $userlink, $timestamp, $watched;
20 function newFromParent( $rc )
22 $rc2 = new RCCacheEntry
;
23 $rc2->mAttribs
= $rc->mAttribs
;
24 $rc2->mExtra
= $rc->mExtra
;
33 # Called by history lists and recent changes
37 function ChangesList( &$skin ) {
39 $this->preCacheMessages();
43 * Fetch an appropriate changes list class for the specified user
44 * Some users might want to use an enhanced list format, for instance
46 * @param $user User to fetch the list class for
47 * @return ChangesList derivative
49 public static function newFromUser( &$user ) {
50 $sk =& $user->getSkin();
52 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
53 return $user->getOption( 'usenewrc' ) ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
60 * As we use the same small set of messages in various methods and that
61 * they are called often, we call them once and save them in $this->message
63 function preCacheMessages() {
64 // Precache various messages
65 if( !isset( $this->message
) ) {
66 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
67 'blocklink changes history boteditletter' ) as $msg ) {
68 $this->message
[$msg] = wfMsgExt( $msg, array( 'escape') );
75 * Returns the appropriate flags for new page, minor change and patrolling
77 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
78 $f = $new ?
'<span class="newpage">' . $this->message
['newpageletter'] . '</span>'
80 $f .= $minor ?
'<span class="minor">' . $this->message
['minoreditletter'] . '</span>'
82 $f .= $bot ?
'<span class="bot">' . $this->message
['boteditletter'] . '</span>' : $nothing;
83 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
88 * Returns text for the start of the tabular part of RC
90 function beginRecentChangesList() {
91 $this->rc_cache
= array();
92 $this->rcMoveIndex
= 0;
93 $this->rcCacheIndex
= 0;
95 $this->rclistOpen
= false;
100 * Returns text for the end of RC
102 function endRecentChangesList() {
103 if( $this->rclistOpen
) {
111 function insertMove( &$s, $rc ) {
113 $s .= '(' . $this->message
['diff'] . ') (';
115 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
118 # "[[x]] moved to [[y]]"
119 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
120 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
121 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
124 function insertDateHeader(&$s, $rc_timestamp) {
127 # Make date header if necessary
128 $date = $wgLang->date( $rc_timestamp, true, true );
130 if( $date != $this->lastdate
) {
131 if( '' != $this->lastdate
) {
134 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
135 $this->lastdate
= $date;
136 $this->rclistOpen
= true;
140 function insertLog(&$s, $title, $logtype) {
141 $logname = LogPage
::logName( $logtype );
142 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
146 function insertDiffHist(&$s, &$rc, $unpatrolled) {
148 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
149 $diffLink = $this->message
['diff'];
151 $rcidparam = $unpatrolled
152 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
154 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
156 'curid' => $rc->mAttribs
['rc_cur_id'],
157 'diff' => $rc->mAttribs
['rc_this_oldid'],
158 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
160 '', '', ' tabindex="'.$rc->counter
.'"');
162 $s .= '('.$diffLink.') (';
165 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
167 'curid' => $rc->mAttribs
['rc_cur_id'],
168 'action' => 'history' ) ) );
172 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
174 # If it's a new article, there is no diff link, but if it hasn't been
175 # patrolled yet, we need to give users a way to do so
176 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
177 ?
'rcid='.$rc->mAttribs
['rc_id']
179 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
180 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
182 $articlelink .= $wgContLang->getDirMark();
184 $s .= ' '.$articlelink;
187 function insertTimestamp(&$s, $rc) {
190 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
193 /** Insert links to user page, user talk page and eventually a blocking link */
194 function insertUserRelatedLinks(&$s, &$rc) {
195 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
196 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
199 /** insert a formatted comment */
200 function insertComment(&$s, &$rc) {
202 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
203 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
208 * Check whether to enable recent changes patrol features
211 function usePatrol() {
212 global $wgUseRCPatrol, $wgUser;
213 return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
219 * Generate a list of changes using the good old system (no javascript)
221 class OldChangesList
extends ChangesList
{
223 * Format a line using the old system (aka without any javascript).
225 function recentChangesLine( &$rc, $watched = false ) {
226 global $wgContLang, $wgRCShowChangedSize;
228 $fname = 'ChangesList::recentChangesLineOld';
229 wfProfileIn( $fname );
231 # Extract DB fields into local scope
232 extract( $rc->mAttribs
);
234 # Should patrol-related stuff be shown?
235 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
237 $this->insertDateHeader($s,$rc_timestamp);
242 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
243 $this->insertMove( $s, $rc );
245 } elseif ( $rc_namespace == NS_SPECIAL
) {
246 list( $specialName, $specialSubpage ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
247 if ( $specialName == 'Log' ) {
248 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
250 wfDebug( "Unexpected special page in recentchanges\n" );
254 wfProfileIn($fname.'-page');
256 $this->insertDiffHist($s, $rc, $unpatrolled);
258 if( $wgRCShowChangedSize ) {
259 $s .= $rc->getCharacterDifference() . ' . . ';
262 # M, N, b and ! (minor, new, bot and unpatrolled)
263 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '', $rc_bot );
264 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
266 wfProfileOut($fname.'-page');
269 wfProfileIn( $fname.'-rest' );
271 $this->insertTimestamp($s,$rc);
272 $this->insertUserRelatedLinks($s,$rc);
273 $this->insertComment($s, $rc);
275 if($rc->numberofWatchingusers
> 0) {
276 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
281 wfProfileOut( $fname.'-rest' );
283 wfProfileOut( $fname );
290 * Generate a list of changes using an Enhanced system (use javascript).
292 class EnhancedChangesList
extends ChangesList
{
294 * Format a line for enhanced recentchange (aka with javascript and block of lines).
296 function recentChangesLine( &$baseRC, $watched = false ) {
297 global $wgLang, $wgContLang, $wgRCShowChangedSize;
299 # Create a specialised object
300 $rc = RCCacheEntry
::newFromParent( $baseRC );
302 # Extract fields from DB into the function scope (rc_xxxx variables)
303 extract( $rc->mAttribs
);
304 $curIdEq = 'curid=' . $rc_cur_id;
306 # If it's a new day, add the headline and flush the cache
307 $date = $wgLang->date( $rc_timestamp, true);
309 if( $date != $this->lastdate
) {
310 # Process current cache
311 $ret = $this->recentChangesBlock();
312 $this->rc_cache
= array();
313 $ret .= "<h4>{$date}</h4>\n";
314 $this->lastdate
= $date;
317 # Should patrol-related stuff be shown?
318 if( $this->usePatrol() ) {
319 $rc->unpatrolled
= !$rc_patrolled;
321 $rc->unpatrolled
= false;
325 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
326 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
327 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
328 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
329 } elseif( $rc_namespace == NS_SPECIAL
) {
330 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
331 if ( $specialName == 'Log' ) {
333 $logname = LogPage
::logName( $logtype );
334 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
336 wfDebug( "Unexpected special page in recentchanges\n" );
339 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
340 # Unpatrolled new page, give rc_id in query
341 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
343 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
346 $time = $wgContLang->time( $rc_timestamp, true, true );
348 if( $wgRCShowChangedSize ) {
349 $time .= ' ' . $rc->getCharacterDifference();
352 $rc->watched
= $watched;
354 $rc->timestamp
= $time;
355 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
357 # Make "cur" and "diff" links
358 if( $rc->unpatrolled
) {
359 $rcIdQuery = "&rcid={$rc_id}";
363 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
364 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
365 $aprops = ' tabindex="'.$baseRC->counter
.'"';
366 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
367 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
368 if( $rc_type != RC_NEW
) {
369 $curLink = $this->message
['cur'];
371 $diffLink = $this->message
['diff'];
373 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
377 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
378 $lastLink = $this->message
['last'];
380 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
381 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
384 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
386 $rc->lastlink
= $lastLink;
387 $rc->curlink
= $curLink;
388 $rc->difflink
= $diffLink;
390 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
392 # Put accumulated information into the cache, for later display
393 # Page moves go on their own line
394 $title = $rc->getTitle();
395 $secureName = $title->getPrefixedDBkey();
396 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
397 # Use an @ character to prevent collision with page names
398 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
400 if( !isset ( $this->rc_cache
[$secureName] ) ) {
401 $this->rc_cache
[$secureName] = array();
403 array_push( $this->rc_cache
[$secureName], $rc );
411 function recentChangesBlockGroup( $block ) {
412 global $wgContLang, $wgRCShowChangedSize;
415 # Collate list of users
417 $unpatrolled = false;
418 $userlinks = array();
419 foreach( $block as $rcObj ) {
420 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
421 if( $rcObj->mAttribs
['rc_new'] ) {
424 $u = $rcObj->userlink
;
425 if( !isset( $userlinks[$u] ) ) {
428 if( $rcObj->unpatrolled
) {
431 $bot = $rcObj->mAttribs
['rc_bot'];
435 # Sort the list and convert to text
436 krsort( $userlinks );
439 foreach( $userlinks as $userlink => $count) {
441 $text .= $wgContLang->getDirMark();
443 $text .= ' ('.$count.'×)';
445 array_push( $users, $text );
448 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
451 $rci = 'RCI'.$this->rcCacheIndex
;
452 $rcl = 'RCL'.$this->rcCacheIndex
;
453 $rcm = 'RCM'.$this->rcCacheIndex
;
454 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
455 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
456 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
461 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
464 $r .= ' '.$block[0]->timestamp
.' ';
467 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
468 $r .= $wgContLang->getDirMark();
470 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
471 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
472 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
474 $r .= ' ('.count($block).' ';
476 $r .= $this->message
['changes'];
478 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
479 $this->message
['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
484 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
485 $this->message
['history'], $curIdEq.'&action=history' );
491 if($block[0]->numberofWatchingusers
> 0) {
493 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
498 $r .= '<div id="'.$rci.'" style="display:none">';
499 foreach( $block as $rcObj ) {
500 # Get rc_xxxx variables
501 extract( $rcObj->mAttribs
);
503 $r .= $this->spacerArrow();
504 $r .= '<tt> ';
505 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
509 if( $rc_this_oldid != 0 ) {
510 $o = 'oldid='.$rc_this_oldid;
512 if( $rc_type == RC_LOG
) {
513 $link = $rcObj->timestamp
;
515 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
517 $link = '<tt>'.$link.'</tt>';
521 $r .= $rcObj->curlink
;
523 $r .= $rcObj->lastlink
;
524 $r .= ') . . '.$rcObj->userlink
;
525 $r .= $rcObj->usertalklink
;
526 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
531 $this->rcCacheIndex++
;
535 function maybeWatchedLink( $link, $watched=false ) {
537 // FIXME: css style might be more appropriate
538 return '<strong>' . $link . '</strong>';
545 * Generate HTML for an arrow or placeholder graphic
546 * @param string $dir one of '', 'd', 'l', 'r'
547 * @param string $alt text
548 * @return string HTML <img> tag
551 function arrow( $dir, $alt='' ) {
553 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
554 $encAlt = htmlspecialchars( $alt );
555 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
559 * Generate HTML for a right- or left-facing arrow,
560 * depending on language direction.
561 * @return string HTML <img> tag
564 function sideArrow() {
566 $dir = $wgContLang->isRTL() ?
'l' : 'r';
567 return $this->arrow( $dir, '+' );
571 * Generate HTML for a down-facing arrow
572 * depending on language direction.
573 * @return string HTML <img> tag
576 function downArrow() {
577 return $this->arrow( 'd', '-' );
581 * Generate HTML for a spacer image
582 * @return string HTML <img> tag
585 function spacerArrow() {
586 return $this->arrow( '', ' ' );
590 * Enhanced RC ungrouped line.
591 * @return string a HTML formated line (generated using $r)
593 function recentChangesBlockLine( $rcObj ) {
596 # Get rc_xxxx variables
597 extract( $rcObj->mAttribs
);
598 $curIdEq = 'curid='.$rc_cur_id;
603 $r .= $this->spacerArrow();
608 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
609 $r .= ' ';
611 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
613 $r .= ' '.$rcObj->timestamp
.' </tt>';
616 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
619 $r .= ' ('. $rcObj->difflink
.'; ';
622 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
625 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
628 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
629 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
632 if( $rcObj->numberofWatchingusers
> 0 ) {
633 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
641 * If enhanced RC is in use, this function takes the previously cached
642 * RC lines, arranges them, and outputs the HTML
644 function recentChangesBlock() {
645 if( count ( $this->rc_cache
) == 0 ) {
649 foreach( $this->rc_cache
as $block ) {
650 if( count( $block ) < 2 ) {
651 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
653 $blockOut .= $this->recentChangesBlockGroup( $block );
657 return '<div>'.$blockOut.'</div>';
661 * Returns text for the end of RC
662 * If enhanced RC is in use, returns pretty much all the text
664 function endRecentChangesList() {
665 return $this->recentChangesBlock() . parent
::endRecentChangesList();