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();
42 function newFromUser( &$user ) {
43 $sk =& $user->getSkin();
44 if( $user->getOption('usenewrc') ) {
45 return new EnhancedChangesList( $sk );
47 return new OldChangesList( $sk );
52 * As we use the same small set of messages in various methods and that
53 * they are called often, we call them once and save them in $this->message
55 function preCacheMessages() {
56 // Precache various messages
57 if( !isset( $this->message
) ) {
58 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
59 'blocklink changes history boteditletter' ) as $msg ) {
60 $this->message
[$msg] = wfMsgExt( $msg, array( 'escape') );
67 * Returns the appropriate flags for new page, minor change and patrolling
69 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
70 $f = $new ?
'<span class="newpage">' . $this->message
['newpageletter'] . '</span>'
72 $f .= $minor ?
'<span class="minor">' . $this->message
['minoreditletter'] . '</span>'
74 $f .= $bot ?
'<span class="bot">' . $this->message
['boteditletter'] . '</span>' : $nothing;
75 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
80 * Returns text for the start of the tabular part of RC
82 function beginRecentChangesList() {
83 $this->rc_cache
= array();
84 $this->rcMoveIndex
= 0;
85 $this->rcCacheIndex
= 0;
87 $this->rclistOpen
= false;
92 * Returns text for the end of RC
94 function endRecentChangesList() {
95 if( $this->rclistOpen
) {
103 function insertMove( &$s, $rc ) {
105 $s .= '(' . $this->message
['diff'] . ') (';
107 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
110 # "[[x]] moved to [[y]]"
111 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
112 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
113 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
116 function insertDateHeader(&$s, $rc_timestamp) {
119 # Make date header if necessary
120 $date = $wgLang->date( $rc_timestamp, true, true );
122 if( $date != $this->lastdate
) {
123 if( '' != $this->lastdate
) {
126 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
127 $this->lastdate
= $date;
128 $this->rclistOpen
= true;
132 function insertLog(&$s, $title, $logtype) {
133 $logname = LogPage
::logName( $logtype );
134 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
138 function insertDiffHist(&$s, &$rc, $unpatrolled) {
140 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
141 $diffLink = $this->message
['diff'];
143 $rcidparam = $unpatrolled
144 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
146 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
148 'curid' => $rc->mAttribs
['rc_cur_id'],
149 'diff' => $rc->mAttribs
['rc_this_oldid'],
150 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
152 '', '', ' tabindex="'.$rc->counter
.'"');
154 $s .= '('.$diffLink.') (';
157 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
159 'curid' => $rc->mAttribs
['rc_cur_id'],
160 'action' => 'history' ) ) );
164 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
166 # If it's a new article, there is no diff link, but if it hasn't been
167 # patrolled yet, we need to give users a way to do so
168 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
169 ?
'rcid='.$rc->mAttribs
['rc_id']
171 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
172 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
174 $articlelink .= $wgContLang->getDirMark();
176 $s .= ' '.$articlelink;
179 function insertTimestamp(&$s, &$rc) {
182 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
185 /** Insert links to user page, user talk page and eventually a blocking link */
186 function insertUserRelatedLinks(&$s, &$rc) {
187 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
188 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
191 /** insert a formatted comment */
192 function insertComment(&$s, &$rc) {
194 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
195 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
200 * Check whether to enable recent changes patrol features
203 function usePatrol() {
204 global $wgUseRCPatrol, $wgUser;
205 return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
213 * Generate a list of changes using the good old system (no javascript)
215 class OldChangesList
extends ChangesList
{
217 * Format a line using the old system (aka without any javascript).
219 function recentChangesLine( &$rc, $watched = false ) {
222 $fname = 'ChangesList::recentChangesLineOld';
223 wfProfileIn( $fname );
226 # Extract DB fields into local scope
227 extract( $rc->mAttribs
);
228 $curIdEq = 'curid=' . $rc_cur_id;
230 # Should patrol-related stuff be shown?
231 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
233 $this->insertDateHeader($s,$rc_timestamp);
238 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
239 $this->insertMove( $s, $rc );
241 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
242 $this->insertLog($s, $rc->getTitle(), $matches[1]);
245 wfProfileIn($fname.'-page');
247 $this->insertDiffHist($s, $rc, $unpatrolled);
249 # M, N, b and ! (minor, new, bot and unpatrolled)
250 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '', $rc_bot );
251 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
253 wfProfileOut($fname.'-page');
256 wfProfileIn( $fname.'-rest' );
258 $this->insertTimestamp($s,$rc);
259 $this->insertUserRelatedLinks($s,$rc);
260 $this->insertComment($s, $rc);
262 if($rc->numberofWatchingusers
> 0) {
263 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
268 wfProfileOut( $fname.'-rest' );
270 wfProfileOut( $fname );
277 * Generate a list of changes using an Enhanced system (use javascript).
279 class EnhancedChangesList
extends ChangesList
{
281 * Format a line for enhanced recentchange (aka with javascript and block of lines).
283 function recentChangesLine( &$baseRC, $watched = false ) {
284 global $wgLang, $wgContLang;
286 # Create a specialised object
287 $rc = RCCacheEntry
::newFromParent( $baseRC );
289 # Extract fields from DB into the function scope (rc_xxxx variables)
290 extract( $rc->mAttribs
);
291 $curIdEq = 'curid=' . $rc_cur_id;
293 # If it's a new day, add the headline and flush the cache
294 $date = $wgLang->date( $rc_timestamp, true);
296 if( $date != $this->lastdate
) {
297 # Process current cache
298 $ret = $this->recentChangesBlock();
299 $this->rc_cache
= array();
300 $ret .= "<h4>{$date}</h4>\n";
301 $this->lastdate
= $date;
304 # Should patrol-related stuff be shown?
305 if( $this->usePatrol() ) {
306 $rc->unpatrolled
= !$rc_patrolled;
308 $rc->unpatrolled
= false;
312 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
313 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
314 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
315 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
316 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
318 $logtype = $matches[1];
319 $logname = LogPage
::logName( $logtype );
320 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
321 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
322 # Unpatrolled new page, give rc_id in query
323 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
325 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
328 $time = $wgContLang->time( $rc_timestamp, true, true );
329 $rc->watched
= $watched;
331 $rc->timestamp
= $time;
332 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
334 # Make "cur" and "diff" links
335 if( $rc->unpatrolled
) {
336 $rcIdQuery = "&rcid={$rc_id}";
340 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
341 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
342 $aprops = ' tabindex="'.$baseRC->counter
.'"';
343 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
344 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
345 if( $rc_type != RC_NEW
) {
346 $curLink = $this->message
['cur'];
348 $diffLink = $this->message
['diff'];
350 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
354 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
355 $lastLink = $this->message
['last'];
357 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
358 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
361 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
363 $rc->lastlink
= $lastLink;
364 $rc->curlink
= $curLink;
365 $rc->difflink
= $diffLink;
367 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
369 # Put accumulated information into the cache, for later display
370 # Page moves go on their own line
371 $title = $rc->getTitle();
372 $secureName = $title->getPrefixedDBkey();
373 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
374 # Use an @ character to prevent collision with page names
375 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
377 if( !isset ( $this->rc_cache
[$secureName] ) ) {
378 $this->rc_cache
[$secureName] = array();
380 array_push( $this->rc_cache
[$secureName], $rc );
388 function recentChangesBlockGroup( $block ) {
391 # Collate list of users
393 $unpatrolled = false;
394 $userlinks = array();
395 foreach( $block as $rcObj ) {
396 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
397 $newid = $rcObj->mAttribs
['rc_this_oldid'];
398 if( $rcObj->mAttribs
['rc_new'] ) {
401 $u = $rcObj->userlink
;
402 if( !isset( $userlinks[$u] ) ) {
405 if( $rcObj->unpatrolled
) {
408 $bot = $rcObj->mAttribs
['rc_bot'];
412 # Sort the list and convert to text
413 krsort( $userlinks );
416 foreach( $userlinks as $userlink => $count) {
419 $text .= ' ('.$count.'×)';
421 array_push( $users, $text );
424 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
427 $rci = 'RCI'.$this->rcCacheIndex
;
428 $rcl = 'RCL'.$this->rcCacheIndex
;
429 $rcm = 'RCM'.$this->rcCacheIndex
;
430 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
431 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
432 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
437 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
440 $r .= ' '.$block[0]->timestamp
.' ';
444 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
446 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
447 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
448 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
450 $r .= ' ('.count($block).' ';
452 $r .= $this->message
['changes'];
454 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
455 $this->message
['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
460 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
461 $this->message
['history'], $curIdEq.'&action=history' );
467 if($block[0]->numberofWatchingusers
> 0) {
469 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
474 $r .= '<div id="'.$rci.'" style="display:none">';
475 foreach( $block as $rcObj ) {
476 # Get rc_xxxx variables
477 extract( $rcObj->mAttribs
);
479 $r .= $this->spacerArrow();
480 $r .= '<tt> ';
481 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
485 if( $rc_this_oldid != 0 ) {
486 $o = 'oldid='.$rc_this_oldid;
488 if( $rc_type == RC_LOG
) {
489 $link = $rcObj->timestamp
;
491 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
493 $link = '<tt>'.$link.'</tt>';
497 $r .= $rcObj->curlink
;
499 $r .= $rcObj->lastlink
;
500 $r .= ') . . '.$rcObj->userlink
;
501 $r .= $rcObj->usertalklink
;
502 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
507 $this->rcCacheIndex++
;
511 function maybeWatchedLink( $link, $watched=false ) {
513 // FIXME: css style might be more appropriate
514 return '<strong>' . $link . '</strong>';
521 * Generate HTML for an arrow or placeholder graphic
522 * @param string $dir one of '', 'd', 'l', 'r'
523 * @param string $alt text
524 * @return string HTML <img> tag
527 function arrow( $dir, $alt='' ) {
529 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
530 $encAlt = htmlspecialchars( $alt );
531 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
535 * Generate HTML for a right- or left-facing arrow,
536 * depending on language direction.
537 * @return string HTML <img> tag
540 function sideArrow() {
542 $dir = $wgContLang->isRTL() ?
'l' : 'r';
543 return $this->arrow( $dir, '+' );
547 * Generate HTML for a down-facing arrow
548 * depending on language direction.
549 * @return string HTML <img> tag
552 function downArrow() {
553 return $this->arrow( 'd', '-' );
557 * Generate HTML for a spacer image
558 * @return string HTML <img> tag
561 function spacerArrow() {
562 return $this->arrow( '', ' ' );
566 * Enhanced RC ungrouped line.
567 * @return string a HTML formated line (generated using $r)
569 function recentChangesBlockLine( $rcObj ) {
572 # Get rc_xxxx variables
573 extract( $rcObj->mAttribs
);
574 $curIdEq = 'curid='.$rc_cur_id;
579 $r .= $this->spacerArrow();
584 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
585 $r .= ' ';
587 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
589 $r .= ' '.$rcObj->timestamp
.' </tt>';
592 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
595 $r .= ' ('. $rcObj->difflink
.'; ';
598 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
601 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
604 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
605 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
608 if( $rcObj->numberofWatchingusers
> 0 ) {
609 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
617 * If enhanced RC is in use, this function takes the previously cached
618 * RC lines, arranges them, and outputs the HTML
620 function recentChangesBlock() {
621 if( count ( $this->rc_cache
) == 0 ) {
625 foreach( $this->rc_cache
as $secureName => $block ) {
626 if( count( $block ) < 2 ) {
627 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
629 $blockOut .= $this->recentChangesBlockGroup( $block );
633 return '<div>'.$blockOut.'</div>';
637 * Returns text for the end of RC
638 * If enhanced RC is in use, returns pretty much all the text
640 function endRecentChangesList() {
641 return $this->recentChangesBlock() . parent
::endRecentChangesList();