4 * Contain class to show various lists of change:
10 require_once("RecentChange.php");
15 class RCCacheEntry
extends RecentChange
17 var $secureName, $link;
18 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
19 var $userlink, $timestamp, $watched;
21 function newFromParent( $rc )
23 $rc2 = new RCCacheEntry
;
24 $rc2->mAttribs
= $rc->mAttribs
;
25 $rc2->mExtra
= $rc->mExtra
;
34 # Called by history lists and recent changes
38 function ChangesList( &$skin ) {
40 $this->preCacheMessages();
43 function newFromUser( &$user ) {
44 $sk =& $user->getSkin();
45 if( $user->getOption('usenewrc') ) {
46 return new EnhancedChangesList( $sk );
48 return new OldChangesList( $sk );
53 * As we use the same small set of messages in various methods and that
54 * they are called often, we call them once and save them in $this->message
56 function preCacheMessages() {
57 // Precache various messages
58 if( !isset( $this->message
) ) {
59 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
60 'blocklink changes history' ) as $msg ) {
61 $this->message
[$msg] = wfMsgExt( $msg, array( 'escape') );
68 * Returns the appropiate flags for new page, minor change and patrolling
70 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ' ) {
71 $f = $new ?
'<span class="newpage">' . $this->message
['newpageletter'] . '</span>'
73 $f .= $minor ?
'<span class="minor">' . $this->message
['minoreditletter'] . '</span>'
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 $s .= ' '.$articlelink;
177 function insertTimestamp(&$s, &$rc) {
180 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
183 /** Insert links to user page, user talk page and eventually a blocking link */
184 function insertUserRelatedLinks(&$s, &$rc) {
185 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
186 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
189 /** insert a formatted comment */
190 function insertComment(&$s, &$rc) {
192 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
193 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
198 * Check whether to enable recent changes patrol features
201 function usePatrol() {
202 global $wgUseRCPatrol, $wgUser;
203 return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
211 * Generate a list of changes using the good old system (no javascript)
213 class OldChangesList
extends ChangesList
{
215 * Format a line using the old system (aka without any javascript).
217 function recentChangesLine( &$rc, $watched = false ) {
220 $fname = 'ChangesList::recentChangesLineOld';
221 wfProfileIn( $fname );
224 # Extract DB fields into local scope
225 extract( $rc->mAttribs
);
226 $curIdEq = 'curid=' . $rc_cur_id;
228 # Should patrol-related stuff be shown?
229 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
231 $this->insertDateHeader($s,$rc_timestamp);
236 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
237 $this->insertMove( $s, $rc );
239 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
240 $this->insertLog($s, $rc->getTitle(), $matches[1]);
243 wfProfileIn($fname.'-page');
245 $this->insertDiffHist($s, $rc, $unpatrolled);
247 # M, N and ! (minor, new and unpatrolled)
248 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '' );
249 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
251 wfProfileOut($fname.'-page');
254 wfProfileIn( $fname.'-rest' );
256 $this->insertTimestamp($s,$rc);
257 $this->insertUserRelatedLinks($s,$rc);
258 $this->insertComment($s, $rc);
260 if($rc->numberofWatchingusers
> 0) {
261 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
266 wfProfileOut( $fname.'-rest' );
268 wfProfileOut( $fname );
275 * Generate a list of changes using an Enhanced system (use javascript).
277 class EnhancedChangesList
extends ChangesList
{
279 * Format a line for enhanced recentchange (aka with javascript and block of lines).
281 function recentChangesLine( &$baseRC, $watched = false ) {
282 global $wgLang, $wgContLang;
284 # Create a specialised object
285 $rc = RCCacheEntry
::newFromParent( $baseRC );
287 # Extract fields from DB into the function scope (rc_xxxx variables)
288 extract( $rc->mAttribs
);
289 $curIdEq = 'curid=' . $rc_cur_id;
291 # If it's a new day, add the headline and flush the cache
292 $date = $wgLang->date( $rc_timestamp, true);
294 if( $date != $this->lastdate
) {
295 # Process current cache
296 $ret = $this->recentChangesBlock();
297 $this->rc_cache
= array();
298 $ret .= "<h4>{$date}</h4>\n";
299 $this->lastdate
= $date;
302 # Should patrol-related stuff be shown?
303 if( $this->usePatrol() ) {
304 $rc->unpatrolled
= !$rc_patrolled;
306 $rc->unpatrolled
= false;
310 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
311 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
312 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
313 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
314 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
316 $logtype = $matches[1];
317 $logname = LogPage
::logName( $logtype );
318 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
319 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
320 # Unpatrolled new page, give rc_id in query
321 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
323 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
326 $time = $wgContLang->time( $rc_timestamp, true, true );
327 $rc->watched
= $watched;
329 $rc->timestamp
= $time;
330 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
332 # Make "cur" and "diff" links
333 $titleObj = $rc->getTitle();
334 if( $rc->unpatrolled
) {
335 $rcIdQuery = "&rcid={$rc_id}";
339 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
340 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
341 $aprops = ' tabindex="'.$baseRC->counter
.'"';
342 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
343 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
344 if( $rc_type != RC_NEW
) {
345 $curLink = $this->message
['cur'];
347 $diffLink = $this->message
['diff'];
349 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
353 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
354 $lastLink = $this->message
['last'];
356 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
357 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
360 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
362 $rc->lastlink
= $lastLink;
363 $rc->curlink
= $curLink;
364 $rc->difflink
= $diffLink;
366 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
368 # Put accumulated information into the cache, for later display
369 # Page moves go on their own line
370 $title = $rc->getTitle();
371 $secureName = $title->getPrefixedDBkey();
372 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
373 # Use an @ character to prevent collision with page names
374 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
376 if( !isset ( $this->rc_cache
[$secureName] ) ) {
377 $this->rc_cache
[$secureName] = array();
379 array_push( $this->rc_cache
[$secureName], $rc );
387 function recentChangesBlockGroup( $block ) {
390 # Collate list of users
392 $unpatrolled = false;
393 $userlinks = array();
394 foreach( $block as $rcObj ) {
395 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
396 $newid = $rcObj->mAttribs
['rc_this_oldid'];
397 if( $rcObj->mAttribs
['rc_new'] ) {
400 $u = $rcObj->userlink
;
401 if( !isset( $userlinks[$u] ) ) {
404 if( $rcObj->unpatrolled
) {
410 # Sort the list and convert to text
411 krsort( $userlinks );
414 foreach( $userlinks as $userlink => $count) {
417 $text .= ' ('.$count.'×)';
419 array_push( $users, $text );
422 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
425 $rci = 'RCI'.$this->rcCacheIndex
;
426 $rcl = 'RCL'.$this->rcCacheIndex
;
427 $rcm = 'RCM'.$this->rcCacheIndex
;
428 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
429 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
430 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
435 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
438 $r .= ' '.$block[0]->timestamp
.' ';
442 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
444 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
445 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
446 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
448 $r .= ' ('.count($block).' ';
450 $r .= $this->message
['changes'];
452 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
453 $this->message
['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
458 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(),
459 $this->message
['history'], $curIdEq.'&action=history' );
465 if($block[0]->numberofWatchingusers
> 0) {
467 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
472 $r .= '<div id="'.$rci.'" style="display:none">';
473 foreach( $block as $rcObj ) {
474 # Get rc_xxxx variables
475 extract( $rcObj->mAttribs
);
477 $r .= $this->spacerArrow();
478 $r .= '<tt> ';
479 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
);
483 if( $rc_this_oldid != 0 ) {
484 $o = 'oldid='.$rc_this_oldid;
486 if( $rc_type == RC_LOG
) {
487 $link = $rcObj->timestamp
;
489 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
491 $link = '<tt>'.$link.'</tt>';
495 $r .= $rcObj->curlink
;
497 $r .= $rcObj->lastlink
;
498 $r .= ') . . '.$rcObj->userlink
;
499 $r .= $rcObj->usertalklink
;
500 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
505 $this->rcCacheIndex++
;
509 function maybeWatchedLink( $link, $watched=false ) {
511 // FIXME: css style might be more appropriate
512 return '<strong>' . $link . '</strong>';
519 * Generate HTML for an arrow or placeholder graphic
520 * @param string $dir one of '', 'd', 'l', 'r'
521 * @param string $alt text
522 * @return string HTML <img> tag
525 function arrow( $dir, $alt='' ) {
527 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
528 $encAlt = htmlspecialchars( $alt );
529 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
533 * Generate HTML for a right- or left-facing arrow,
534 * depending on language direction.
535 * @return string HTML <img> tag
538 function sideArrow() {
540 $dir = $wgContLang->isRTL() ?
'l' : 'r';
541 return $this->arrow( $dir, '+' );
545 * Generate HTML for a down-facing arrow
546 * depending on language direction.
547 * @return string HTML <img> tag
550 function downArrow() {
551 return $this->arrow( 'd', '-' );
555 * Generate HTML for a spacer image
556 * @return string HTML <img> tag
559 function spacerArrow() {
560 return $this->arrow( '', ' ' );
564 * Enhanced RC ungrouped line.
565 * @return string a HTML formated line (generated using $r)
567 function recentChangesBlockLine( $rcObj ) {
570 # Get rc_xxxx variables
571 extract( $rcObj->mAttribs
);
572 $curIdEq = 'curid='.$rc_cur_id;
577 $r .= $this->spacerArrow();
582 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
583 $r .= ' ';
585 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
);
587 $r .= ' '.$rcObj->timestamp
.' </tt>';
590 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
593 $r .= ' ('. $rcObj->difflink
.'; ';
596 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
599 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
602 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
603 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
606 if( $rcObj->numberofWatchingusers
> 0 ) {
607 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
615 * If enhanced RC is in use, this function takes the previously cached
616 * RC lines, arranges them, and outputs the HTML
618 function recentChangesBlock() {
619 if( count ( $this->rc_cache
) == 0 ) {
623 foreach( $this->rc_cache
as $secureName => $block ) {
624 if( count( $block ) < 2 ) {
625 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
627 $blockOut .= $this->recentChangesBlockGroup( $block );
631 return '<div>'.$blockOut.'</div>';
635 * Returns text for the end of RC
636 * If enhanced RC is in use, returns pretty much all the text
638 function endRecentChangesList() {
639 return $this->recentChangesBlock() . parent
::endRecentChangesList();