4 * Contain class to show various lists of change:
14 # Called by history lists and recent changes
18 function ChangesList( &$skin ) {
20 $this->preCacheMessages();
23 function newFromUser( &$user ) {
24 $sk =& $user->getSkin();
25 if ( $user->getOption('usenewrc') ) {
26 return new EnhancedChangesList( $sk );
28 return new OldChangesList( $sk );
33 * As we use the same small set of messages in various methods and that
34 * they are called often, we call them once and save them in $this->message
36 function preCacheMessages() {
37 // Precache various messages
38 if( !isset( $this->message
) ) {
39 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last blocklink' ) as $msg ) {
40 $this->message
[$msg] = wfMsg( $msg );
47 * Returns the appropiate flags for new page, minor change and patrolling
49 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ' ) {
50 $f = $new ?
'<span class="newpage">' . wfMsgHtml( 'newpageletter' ) . '</span>'
52 $f .= $minor ?
'<span class="minor">' . wfMsgHtml( 'minoreditletter' ) . '</span>'
54 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
59 * Returns text for the start of the tabular part of RC
61 function beginRecentChangesList() {
62 $this->rc_cache
= array() ;
63 $this->rcMoveIndex
= 0;
64 $this->rcCacheIndex
= 0 ;
66 $this->rclistOpen
= false;
71 * Returns text for the end of RC
72 * If enhanced RC is in use, returns pretty much all the text
74 function endRecentChangesList() {
75 $s = $this->recentChangesBlock() ;
76 if( $this->rclistOpen
) {
83 * Enhanced RC ungrouped line.
84 * @return string a HTML formated line (generated using $r)
86 function recentChangesBlockLine ( $rcObj ) {
87 global $wgStylePath, $wgContLang ;
89 # Get rc_xxxx variables
90 extract( $rcObj->mAttribs
) ;
91 $curIdEq = 'curid='.$rc_cur_id;
96 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
101 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
102 $r .= ' ';
104 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
);
106 $r .= ' '.$rcObj->timestamp
.' </tt>' ;
109 $link = $rcObj->link
;
110 // FIXME: should be handled with a css class
111 if ( $rcObj->watched
) $link = '<strong>'.$link.'</strong>' ;
115 $r .= ' ('. $rcObj->difflink
.'; ' ;
118 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
121 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
124 if ( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
125 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
128 if ($rcObj->numberofWatchingusers
> 0) {
129 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
137 * If enhanced RC is in use, this function takes the previously cached
138 * RC lines, arranges them, and outputs the HTML
140 function recentChangesBlock () {
141 global $wgStylePath ;
142 if ( count ( $this->rc_cache
) == 0 ) return '' ;
144 foreach ( $this->rc_cache
AS $secureName => $block ) {
145 if ( count ( $block ) < 2 ) {
146 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
148 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
152 return '<div>'.$blockOut.'</div>' ;
156 function insertMove(&$s) {
158 $s .= '(' . $this->message
['diff'] . ') (';
160 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
163 # "[[x]] moved to [[y]]"
164 $msg = ( $rc_type == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
165 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
166 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
169 function insertDateHeader(&$s, $rc_timestamp) {
172 # Make date header if necessary
173 $date = $wgLang->date( $rc_timestamp, true, true );
175 if ( $date != $this->lastdate
) {
176 if ( '' != $this->lastdate
) { $s .= "</ul>\n"; }
177 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
178 $this->lastdate
= $date;
179 $this->rclistOpen
= true;
183 function insertLog(&$s, $title, $logtype) {
184 $logname = LogPage
::logName( $logtype );
185 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
189 function insertDiffHist(&$s, &$rc, $unpatrolled) {
191 if ( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
192 $diffLink = $this->message
['diff'];
194 $rcidparam = $unpatrolled
195 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
197 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
199 'curid' => $rc->mAttribs
['rc_cur_id'],
200 'diff' => $rc->mAttribs
['rc_this_oldid'],
201 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
203 '', '', ' tabindex="'.$rc->counter
.'"');
205 $s .= '('.$diffLink.') (';
208 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
210 'curid' => $rc->mAttribs
['rc_cur_id'],
211 'action' => 'history' ) ) );
215 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
217 # If it's a new article, there is no diff link, but if it hasn't been
218 # patrolled yet, we need to give users a way to do so
219 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
220 ?
'rcid='.$rc->mAttribs
['rc_id']
222 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
223 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
225 $s .= ' '.$articlelink;
228 function insertTimestamp(&$s, &$rc) {
231 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
234 /** Insert links to user page, user talk page and eventually a blocking link */
235 function insertUserRelatedLinks(&$s, &$rc) {
236 $this->insertUserLink($s,$rc);
237 $openParenthesis = false;
239 global $wgDisableAnonTalk;
240 if(!( 0 == $rc->mAttribs
['rc_user'] && $wgDisableAnonTalk)) {
241 $openParenthesis = true;
243 $this->insertUserTalkLink($s,$rc);
246 global $wgSysopUserBans, $wgUser;
247 if ( ( $wgSysopUserBans ||
0 == $rc->mAttribs
['rc_user'] ) && $wgUser->isAllowed('block') ) {
248 $s .= $openParenthesis ?
' | ' : '(';
249 $this->insertUserBlockLink($s,$rc);
251 $s .= $openParenthesis ?
') ' : '';
254 /** insert a formatted link to the user page */
255 function insertUserLink(&$s, &$rc) {
256 # User link (or contributions for unregistered users)
257 if ( 0 == $rc->mAttribs
['rc_user'] ) {
258 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
259 $userLink = $this->skin
->makeKnownLinkObj( $contribsPage,
260 $rc->mAttribs
['rc_user_text'], 'target=' . $rc->mAttribs
['rc_user_text'] );
262 $userPage =& Title
::makeTitle( NS_USER
, $rc->mAttribs
['rc_user_text'] );
263 $userLink = $this->skin
->makeLinkObj( $userPage, htmlspecialchars( $rc->mAttribs
['rc_user_text'] ) );
268 /** insert a formatted link to the user talk page */
269 function insertUserTalkLink(&$s, &$rc) {
272 $talkname = $wgContLang->getNsText(NS_TALK
); # use the shorter name
273 $userTalkPage =& Title
::makeTitle( NS_USER_TALK
, $rc->mAttribs
['rc_user_text'] );
274 $userTalkLink= $this->skin
->makeLinkObj( $userTalkPage, htmlspecialchars( $talkname ) );
278 /** insert a formatted link to block an user */
279 function insertUserBlockLink(&$s, &$rc) {
281 $blockLinkPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
282 $blockLink = $this->skin
->makeKnownLinkObj( $blockLinkPage,
283 htmlspecialchars( $this->message
['blocklink'] ), 'ip=' . urlencode( $rc->mAttribs
['rc_user_text'] ) );
287 /** insert a formatted comment */
288 function insertComment(&$s, &$rc) {
290 if ( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
291 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
298 * Generate a list of changes using the good old system (no javascript)
300 class OldChangesList
extends ChangesList
{
302 * Format a line using the old system (aka without any javascript).
304 function recentChangesLine( &$rc, $watched = false ) {
305 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol,
306 $wgOnlySysopsCanPatrol, $wgSysopUserBans;
308 $fname = 'ChangesList::recentChangesLineOld';
309 wfProfileIn( $fname );
312 # Extract DB fields into local scope
313 extract( $rc->mAttribs
);
314 $curIdEq = 'curid=' . $rc_cur_id;
316 # Should patrol-related stuff be shown?
317 $unpatrolled = $wgUseRCPatrol && $wgUser->isLoggedIn() &&
318 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
320 $this->insertDateHeader($s,$rc_timestamp);
325 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
326 $this->insertMove($s);
328 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
329 $this->insertLog($s, $rc->getTitle(), $matches[1]);
332 wfProfileIn($fname.'-page');
334 $this->insertDiffHist($s, $rc, $unpatrolled);
336 # M, N and ! (minor, new and unpatrolled)
337 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '' );
338 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
340 wfProfileOut($fname.'-page');
343 wfProfileIn( $fname.'-rest' );
345 $this->insertTimestamp($s,$rc);
346 $this->insertUserRelatedLinks($s,$rc);
347 $this->insertComment($s, $rc);
349 if ($rc->numberofWatchingusers
> 0) {
350 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
355 wfProfileOut( $fname.'-rest' );
357 wfProfileOut( $fname );
364 * Generate a list of changes using an Enhanced system (use javascript).
366 class EnhancedChangesList
extends ChangesList
{
368 * Format a line for enhanced recentchange (aka with javascript and block of lines).
370 function recentChangesLine( &$baseRC, $watched = false ) {
371 global $wgTitle, $wgLang, $wgContLang, $wgUser,
372 $wgUseRCPatrol, $wgOnlySysopsCanPatrol, $wgSysopUserBans;
374 # Create a specialised object
375 $rc = RCCacheEntry
::newFromParent( $baseRC ) ;
377 # Extract fields from DB into the function scope (rc_xxxx variables)
378 extract( $rc->mAttribs
);
379 $curIdEq = 'curid=' . $rc_cur_id;
381 # If it's a new day, add the headline and flush the cache
382 $date = $wgLang->date( $rc_timestamp, true);
384 if ( $date != $this->lastdate
) {
385 # Process current cache
386 $ret = $this->recentChangesBlock () ;
387 $this->rc_cache
= array() ;
388 $ret .= "<h4>{$date}</h4>\n";
389 $this->lastdate
= $date;
392 # Should patrol-related stuff be shown?
393 if ( $wgUseRCPatrol && $wgUser->isLoggedIn() &&
394 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed('patrol') )) {
395 $rc->unpatrolled
= !$rc_patrolled;
397 $rc->unpatrolled
= false;
401 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
402 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
403 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
404 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
405 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
407 $logtype = $matches[1];
408 $logname = LogPage
::logName( $logtype );
409 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
410 } elseif ( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
411 # Unpatrolled new page, give rc_id in query
412 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
414 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' ) ;
417 $time = $wgContLang->time( $rc_timestamp, true, true );
418 $rc->watched
= $watched ;
420 $rc->timestamp
= $time;
421 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
423 # Make "cur" and "diff" links
424 $titleObj = $rc->getTitle();
425 if ( $rc->unpatrolled
) {
426 $rcIdQuery = "&rcid={$rc_id}";
430 $query = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid";
431 $aprops = ' tabindex="'.$baseRC->counter
.'"';
432 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $query, '' ,'' , $aprops );
433 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
434 if( $rc_type != RC_NEW
) {
435 $curLink = $this->message
['cur'];
437 $diffLink = $this->message
['diff'];
439 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $query . $rcIdQuery, '' ,'' , $aprops );
443 if ( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
444 $lastLink = $this->message
['last'];
446 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
447 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
450 # Make user link (or user contributions for unregistered users)
451 if ( $rc_user == 0 ) {
452 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
453 $userLink = $this->skin
->makeKnownLinkObj( $contribsPage,
454 $rc_user_text, 'target=' . $rc_user_text );
456 $userPage =& Title
::makeTitle( NS_USER
, $rc_user_text );
457 $userLink = $this->skin
->makeLinkObj( $userPage, $rc_user_text );
460 $rc->userlink
= $userLink;
461 $rc->lastlink
= $lastLink;
462 $rc->curlink
= $curLink;
463 $rc->difflink
= $diffLink;
465 # Make user talk link
466 $talkname = $wgContLang->getNsText( NS_TALK
); # use the shorter name
467 $userTalkPage =& Title
::makeTitle( NS_USER_TALK
, $rc_user_text );
468 $userTalkLink = $this->skin
->makeLinkObj( $userTalkPage, $talkname );
470 global $wgDisableAnonTalk;
471 if ( ( $wgSysopUserBans ||
0 == $rc_user ) && $wgUser->isAllowed('block') ) {
472 $blockPage =& Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
473 $blockLink = $this->skin
->makeKnownLinkObj( $blockPage,
474 $this->message
['blocklink'], 'ip='.$rc_user_text );
475 if( $wgDisableAnonTalk )
476 $rc->usertalklink
= ' ('.$blockLink.')';
478 $rc->usertalklink
= ' ('.$userTalkLink.' | '.$blockLink.')';
480 if( $wgDisableAnonTalk && ($rc_user == 0) )
481 $rc->usertalklink
= '';
483 $rc->usertalklink
= ' ('.$userTalkLink.')';
486 # Put accumulated information into the cache, for later display
487 # Page moves go on their own line
488 $title = $rc->getTitle();
489 $secureName = $title->getPrefixedDBkey();
490 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
491 # Use an @ character to prevent collision with page names
492 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
494 if ( !isset ( $this->rc_cache
[$secureName] ) ) $this->rc_cache
[$secureName] = array() ;
495 array_push ( $this->rc_cache
[$secureName] , $rc ) ;
503 function recentChangesBlockGroup ( $block ) {
504 global $wgStylePath, $wgContLang ;
508 # Collate list of users
510 $unpatrolled = false;
511 $userlinks = array () ;
512 foreach ( $block AS $rcObj ) {
513 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
514 $newid = $rcObj->mAttribs
['rc_this_oldid'];
515 if ( $rcObj->mAttribs
['rc_new'] ) {
518 $u = $rcObj->userlink
;
519 if ( !isset ( $userlinks[$u] ) ) {
522 if ( $rcObj->unpatrolled
) {
528 # Sort the list and convert to text
529 krsort ( $userlinks ) ;
530 asort ( $userlinks ) ;
532 foreach ( $userlinks as $userlink => $count) {
534 if ( $count > 1 ) $text .= ' ('.$count.'×)' ;
535 array_push ( $users , $text ) ;
538 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
541 $rci = 'RCI'.$this->rcCacheIndex
;
542 $rcl = 'RCL'.$this->rcCacheIndex
;
543 $rcm = 'RCM'.$this->rcCacheIndex
;
544 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
545 $arrowdir = $wgContLang->isRTL() ?
'l' : 'r';
546 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
547 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" alt="-" /></a></span>' ;
552 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
555 $r .= ' '.$block[0]->timestamp
.' ' ;
559 $link = $block[0]->link
;
560 if ( $block[0]->watched
) $link = '<strong>'.$link.'</strong>' ;
563 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
564 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
565 if ( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
567 $r .= ' ('.count($block).' ' ;
568 if ( $isnew ) $r .= wfMsg('changes');
569 else $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
570 $curIdEq."&diff=$currentRevision&oldid=$oldid" ) ;
574 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
580 if ($block[0]->numberofWatchingusers
> 0) {
581 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
586 $r .= '<div id="'.$rci.'" style="display:none">' ;
587 foreach ( $block AS $rcObj ) {
588 # Get rc_xxxx variables
589 extract( $rcObj->mAttribs
);
591 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
592 $r .= '<tt> ' ;
593 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
);
594 $r .= ' </tt>' ;
597 if ( $rc_last_oldid != 0 ) {
598 $o = 'oldid='.$rc_last_oldid ;
600 if ( $rc_type == RC_LOG
) {
601 $link = $rcObj->timestamp
;
603 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
605 $link = '<tt>'.$link.'</tt>' ;
609 $r .= $rcObj->curlink
;
611 $r .= $rcObj->lastlink
;
612 $r .= ') . . '.$rcObj->userlink
;
613 $r .= $rcObj->usertalklink
;
614 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
619 $this->rcCacheIndex++
;