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' ) );
217 * Returns the string which indicates the number of watching users
219 function numberofWatchingusers( $count ) {
221 static $cache = array();
223 if ( !isset( $cache[$count] ) ) {
224 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
225 array('parsemag', 'escape'), $wgLang->formatNum($count));
227 return $cache[$count];
236 * Generate a list of changes using the good old system (no javascript)
238 class OldChangesList
extends ChangesList
{
240 * Format a line using the old system (aka without any javascript).
242 function recentChangesLine( &$rc, $watched = false ) {
243 global $wgContLang, $wgRCShowChangedSize;
245 $fname = 'ChangesList::recentChangesLineOld';
246 wfProfileIn( $fname );
248 # Extract DB fields into local scope
249 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
250 extract( $rc->mAttribs
);
252 # Should patrol-related stuff be shown?
253 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
255 $this->insertDateHeader($s,$rc_timestamp);
260 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
261 $this->insertMove( $s, $rc );
263 } elseif ( $rc_namespace == NS_SPECIAL
) {
264 list( $specialName, $specialSubpage ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
265 if ( $specialName == 'Log' ) {
266 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
268 wfDebug( "Unexpected special page in recentchanges\n" );
272 wfProfileIn($fname.'-page');
274 $this->insertDiffHist($s, $rc, $unpatrolled);
276 # M, N, b and ! (minor, new, bot and unpatrolled)
277 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '', $rc_bot );
278 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
280 wfProfileOut($fname.'-page');
283 wfProfileIn( $fname.'-rest' );
285 $this->insertTimestamp($s,$rc);
287 if( $wgRCShowChangedSize ) {
288 $s .= ( $rc->getCharacterDifference() == '' ?
'' : $rc->getCharacterDifference() . ' . . ' );
291 $this->insertUserRelatedLinks($s,$rc);
292 $this->insertComment($s, $rc);
294 $s .= rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers
));
298 wfProfileOut( $fname.'-rest' );
300 wfProfileOut( $fname );
307 * Generate a list of changes using an Enhanced system (use javascript).
309 class EnhancedChangesList
extends ChangesList
{
311 * Format a line for enhanced recentchange (aka with javascript and block of lines).
313 function recentChangesLine( &$baseRC, $watched = false ) {
314 global $wgLang, $wgContLang;
316 # Create a specialised object
317 $rc = RCCacheEntry
::newFromParent( $baseRC );
319 # Extract fields from DB into the function scope (rc_xxxx variables)
320 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
321 extract( $rc->mAttribs
);
322 $curIdEq = 'curid=' . $rc_cur_id;
324 # If it's a new day, add the headline and flush the cache
325 $date = $wgLang->date( $rc_timestamp, true);
327 if( $date != $this->lastdate
) {
328 # Process current cache
329 $ret = $this->recentChangesBlock();
330 $this->rc_cache
= array();
331 $ret .= "<h4>{$date}</h4>\n";
332 $this->lastdate
= $date;
335 # Should patrol-related stuff be shown?
336 if( $this->usePatrol() ) {
337 $rc->unpatrolled
= !$rc_patrolled;
339 $rc->unpatrolled
= false;
343 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
344 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
345 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
346 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
347 } elseif( $rc_namespace == NS_SPECIAL
) {
348 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
349 if ( $specialName == 'Log' ) {
351 $logname = LogPage
::logName( $logtype );
352 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
354 wfDebug( "Unexpected special page in recentchanges\n" );
357 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
358 # Unpatrolled new page, give rc_id in query
359 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
361 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
364 $time = $wgContLang->time( $rc_timestamp, true, true );
365 $rc->watched
= $watched;
367 $rc->timestamp
= $time;
368 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
370 # Make "cur" and "diff" links
371 if( $rc->unpatrolled
) {
372 $rcIdQuery = "&rcid={$rc_id}";
376 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
377 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
378 $aprops = ' tabindex="'.$baseRC->counter
.'"';
379 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
380 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
381 if( $rc_type != RC_NEW
) {
382 $curLink = $this->message
['cur'];
384 $diffLink = $this->message
['diff'];
386 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
390 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
391 $lastLink = $this->message
['last'];
393 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
394 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
397 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
399 $rc->lastlink
= $lastLink;
400 $rc->curlink
= $curLink;
401 $rc->difflink
= $diffLink;
403 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
405 # Put accumulated information into the cache, for later display
406 # Page moves go on their own line
407 $title = $rc->getTitle();
408 $secureName = $title->getPrefixedDBkey();
409 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
410 # Use an @ character to prevent collision with page names
411 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
413 if( !isset ( $this->rc_cache
[$secureName] ) ) {
414 $this->rc_cache
[$secureName] = array();
416 array_push( $this->rc_cache
[$secureName], $rc );
424 function recentChangesBlockGroup( $block ) {
425 global $wgContLang, $wgRCShowChangedSize;
428 # Collate list of users
430 $unpatrolled = false;
431 $userlinks = array();
432 foreach( $block as $rcObj ) {
433 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
434 if( $rcObj->mAttribs
['rc_new'] ) {
437 $u = $rcObj->userlink
;
438 if( !isset( $userlinks[$u] ) ) {
441 if( $rcObj->unpatrolled
) {
444 $bot = $rcObj->mAttribs
['rc_bot'];
448 # Sort the list and convert to text
449 krsort( $userlinks );
452 foreach( $userlinks as $userlink => $count) {
454 $text .= $wgContLang->getDirMark();
456 $text .= ' ('.$count.'×)';
458 array_push( $users, $text );
461 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
464 $rci = 'RCI'.$this->rcCacheIndex
;
465 $rcl = 'RCL'.$this->rcCacheIndex
;
466 $rcm = 'RCM'.$this->rcCacheIndex
;
467 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
468 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
469 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
474 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
477 $r .= ' '.$block[0]->timestamp
.' </tt>';
480 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
481 $r .= $wgContLang->getDirMark();
483 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
484 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
485 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
487 $r .= ' ('.count($block).' ';
490 $r .= $this->message
['changes'];
492 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
493 $this->message
['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
498 # Character difference
499 $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs
['rc_old_len'],
500 $block[0]->mAttribs
['rc_new_len'] );
501 if( $chardiff == '' ) {
504 $r .= ' ' . $chardiff. ' . . (';
509 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
510 $this->message
['history'], $curIdEq.'&action=history' );
516 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
520 $r .= '<div id="'.$rci.'" style="display:none">';
521 foreach( $block as $rcObj ) {
522 # Get rc_xxxx variables
523 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
524 extract( $rcObj->mAttribs
);
526 $r .= $this->spacerArrow();
527 $r .= '<tt> ';
528 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
532 if( $rc_this_oldid != 0 ) {
533 $o = 'oldid='.$rc_this_oldid;
535 if( $rc_type == RC_LOG
) {
536 $link = $rcObj->timestamp
;
538 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
540 $link = '<tt>'.$link.'</tt>';
544 $r .= $rcObj->curlink
;
546 $r .= $rcObj->lastlink
;
550 if( $wgRCShowChangedSize ) {
551 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
554 $r .= $rcObj->userlink
;
555 $r .= $rcObj->usertalklink
;
556 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
561 $this->rcCacheIndex++
;
565 function maybeWatchedLink( $link, $watched=false ) {
567 // FIXME: css style might be more appropriate
568 return '<strong>' . $link . '</strong>';
575 * Generate HTML for an arrow or placeholder graphic
576 * @param string $dir one of '', 'd', 'l', 'r'
577 * @param string $alt text
578 * @return string HTML <img> tag
581 function arrow( $dir, $alt='' ) {
583 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
584 $encAlt = htmlspecialchars( $alt );
585 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
589 * Generate HTML for a right- or left-facing arrow,
590 * depending on language direction.
591 * @return string HTML <img> tag
594 function sideArrow() {
596 $dir = $wgContLang->isRTL() ?
'l' : 'r';
597 return $this->arrow( $dir, '+' );
601 * Generate HTML for a down-facing arrow
602 * depending on language direction.
603 * @return string HTML <img> tag
606 function downArrow() {
607 return $this->arrow( 'd', '-' );
611 * Generate HTML for a spacer image
612 * @return string HTML <img> tag
615 function spacerArrow() {
616 return $this->arrow( '', ' ' );
620 * Enhanced RC ungrouped line.
621 * @return string a HTML formated line (generated using $r)
623 function recentChangesBlockLine( $rcObj ) {
624 global $wgContLang, $wgRCShowChangedSize;
626 # Get rc_xxxx variables
627 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
628 extract( $rcObj->mAttribs
);
629 $curIdEq = 'curid='.$rc_cur_id;
634 $r .= $this->spacerArrow();
639 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
640 $r .= ' ';
642 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
644 $r .= ' '.$rcObj->timestamp
.' </tt>';
647 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
650 $r .= ' ('. $rcObj->difflink
.'; ';
653 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ') . . ';
656 if( $wgRCShowChangedSize ) {
657 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : ' ' . $rcObj->getCharacterDifference() . ' . . ' ) ;
661 $r .= $rcObj->userlink
. $rcObj->usertalklink
;
664 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
665 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
668 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
675 * If enhanced RC is in use, this function takes the previously cached
676 * RC lines, arranges them, and outputs the HTML
678 function recentChangesBlock() {
679 if( count ( $this->rc_cache
) == 0 ) {
683 foreach( $this->rc_cache
as $block ) {
684 if( count( $block ) < 2 ) {
685 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
687 $blockOut .= $this->recentChangesBlockGroup( $block );
691 return '<div>'.$blockOut.'</div>';
695 * Returns text for the end of RC
696 * If enhanced RC is in use, returns pretty much all the text
698 function endRecentChangesList() {
699 return $this->recentChangesBlock() . parent
::endRecentChangesList();