4 * Contain class to show various lists of change:
14 # Called by history lists and recent changes
18 function ChangesList( &$skin ) {
20 $this->preCacheMessages();
24 * As we use the same small set of messages in various methods and that
25 * they are called often, we call them once and save them in $this->message
27 function preCacheMessages() {
28 // Precache various messages
29 if( !isset( $this->message
) ) {
30 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last blocklink' ) as $msg ) {
31 $this->message
[$msg] = wfMsg( $msg );
38 * Returns the appropiate flags for new page, minor change and patrolling
40 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ' ) {
41 $f = $new ?
'<span class="newpage">' . wfMsgHtml( 'newpageletter' ) . '</span>'
43 $f .= $minor ?
'<span class="minor">' . wfMsgHtml( 'minoreditletter' ) . '</span>'
45 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
50 * Returns text for the start of the tabular part of RC
52 function beginRecentChangesList() {
53 $this->rc_cache
= array() ;
54 $this->rcMoveIndex
= 0;
55 $this->rcCacheIndex
= 0 ;
57 $this->rclistOpen
= false;
62 * Returns text for the end of RC
63 * If enhanced RC is in use, returns pretty much all the text
65 function endRecentChangesList() {
66 $s = $this->recentChangesBlock() ;
67 if( $this->rclistOpen
) {
74 * Enhanced RC ungrouped line.
75 * @return string a HTML formated line (generated using $r)
77 function recentChangesBlockLine ( $rcObj ) {
78 global $wgStylePath, $wgContLang ;
80 # Get rc_xxxx variables
81 extract( $rcObj->mAttribs
) ;
82 $curIdEq = 'curid='.$rc_cur_id;
87 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
92 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
93 $r .= ' ';
95 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
);
97 $r .= ' '.$rcObj->timestamp
.' </tt>' ;
100 $link = $rcObj->link
;
101 // FIXME: should be handled with a css class
102 if ( $rcObj->watched
) $link = '<strong>'.$link.'</strong>' ;
106 $r .= ' ('. $rcObj->difflink
.'; ' ;
109 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
112 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
115 if ( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
116 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
119 if ($rcObj->numberofWatchingusers
> 0) {
120 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
128 * If enhanced RC is in use, this function takes the previously cached
129 * RC lines, arranges them, and outputs the HTML
131 function recentChangesBlock () {
132 global $wgStylePath ;
133 if ( count ( $this->rc_cache
) == 0 ) return '' ;
135 foreach ( $this->rc_cache
AS $secureName => $block ) {
136 if ( count ( $block ) < 2 ) {
137 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
139 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
143 return '<div>'.$blockOut.'</div>' ;
147 function insertMove(&$s) {
149 $s .= '(' . $this->message
['diff'] . ') (';
151 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
154 # "[[x]] moved to [[y]]"
155 $msg = ( $rc_type == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
156 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
157 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
160 function insertDateHeader(&$s, $rc_timestamp) {
163 # Make date header if necessary
164 $date = $wgLang->date( $rc_timestamp, true, true );
166 if ( $date != $this->lastdate
) {
167 if ( '' != $this->lastdate
) { $s .= "</ul>\n"; }
168 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
169 $this->lastdate
= $date;
170 $this->rclistOpen
= true;
174 function insertLog(&$s, $title, $logtype) {
175 $logname = LogPage
::logName( $logtype );
176 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
180 function insertDiffHist(&$s, &$rc, $unpatrolled) {
182 if ( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
183 $diffLink = $this->message
['diff'];
185 $rcidparam = $unpatrolled
186 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
188 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
190 'curid' => $rc->mAttribs
['rc_cur_id'],
191 'diff' => $rc->mAttribs
['rc_this_oldid'],
192 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
194 '', '', ' tabindex="'.$rc->counter
.'"');
196 $s .= '('.$diffLink.') (';
199 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
201 'curid' => $rc->mAttribs
['rc_cur_id'],
202 'action' => 'history' ) ) );
206 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
208 # If it's a new article, there is no diff link, but if it hasn't been
209 # patrolled yet, we need to give users a way to do so
210 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
211 ?
'rcid='.$rc->mAttribs
['rc_id']
213 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
214 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
216 $s .= ' '.$articlelink;
219 function insertTimestamp(&$s, &$rc) {
222 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
225 /** Insert links to user page, user talk page and eventually a blocking link */
226 function insertUserRelatedLinks(&$s, &$rc) {
227 $this->insertUserLink($s,$rc);
228 $openParenthesis = false;
230 global $wgDisableAnonTalk;
231 if(!( 0 == $rc->mAttribs
['rc_user'] && $wgDisableAnonTalk)) {
232 $openParenthesis = true;
234 $this->insertUserTalkLink($s,$rc);
237 global $wgSysopUserBans, $wgUser;
238 if ( ( $wgSysopUserBans ||
0 == $rc->mAttribs
['rc_user'] ) && $wgUser->isAllowed('block') ) {
239 $s .= $openParenthesis ?
' | ' : '(';
240 $this->insertUserBlockLink($s,$rc);
242 $s .= $openParenthesis ?
') ' : '';
245 /** insert a formatted link to the user page */
246 function insertUserLink(&$s, &$rc) {
247 # User link (or contributions for unregistered users)
248 if ( 0 == $rc->mAttribs
['rc_user'] ) {
249 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
250 $userLink = $this->skin
->makeKnownLinkObj( $contribsPage,
251 $rc->mAttribs
['rc_user_text'], 'target=' . $rc->mAttribs
['rc_user_text'] );
253 $userPage =& Title
::makeTitle( NS_USER
, $rc->mAttribs
['rc_user_text'] );
254 $userLink = $this->skin
->makeLinkObj( $userPage, htmlspecialchars( $rc->mAttribs
['rc_user_text'] ) );
259 /** insert a formatted link to the user talk page */
260 function insertUserTalkLink(&$s, &$rc) {
263 $talkname = $wgContLang->getNsText(NS_TALK
); # use the shorter name
264 $userTalkPage =& Title
::makeTitle( NS_USER_TALK
, $rc->mAttribs
['rc_user_text'] );
265 $userTalkLink= $this->skin
->makeLinkObj( $userTalkPage, htmlspecialchars( $talkname ) );
269 /** insert a formatted link to block an user */
270 function insertUserBlockLink(&$s, &$rc) {
272 $blockLinkPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
273 $blockLink = $this->skin
->makeKnownLinkObj( $blockLinkPage,
274 htmlspecialchars( $this->message
['blocklink'] ), 'ip=' . urlencode( $rc->mAttribs
['rc_user_text'] ) );
278 /** insert a formatted comment */
279 function insertComment(&$s, &$rc) {
281 if ( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
282 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
289 * Generate a list of changes using the good old system (no javascript)
291 class OldChangesList
extends ChangesList
{
293 * Format a line using the old system (aka without any javascript).
295 function recentChangesLine( &$rc, $watched = false ) {
296 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol,
297 $wgOnlySysopsCanPatrol, $wgSysopUserBans;
299 $fname = 'ChangesList::recentChangesLineOld';
300 wfProfileIn( $fname );
303 # Extract DB fields into local scope
304 extract( $rc->mAttribs
);
305 $curIdEq = 'curid=' . $rc_cur_id;
307 # Should patrol-related stuff be shown?
308 $unpatrolled = $wgUseRCPatrol && $wgUser->isLoggedIn() &&
309 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
311 $this->insertDateHeader($s,$rc_timestamp);
316 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
317 $this->insertMove($s);
319 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
320 $this->insertLog($s, $rc->getTitle(), $matches[1]);
323 wfProfileIn($fname.'-page');
325 $this->insertDiffHist($s, $rc, $unpatrolled);
327 # M, N and ! (minor, new and unpatrolled)
328 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '' );
329 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
331 wfProfileOut($fname.'-page');
334 wfProfileIn( $fname.'-rest' );
336 $this->insertTimestamp($s,$rc);
337 $this->insertUserRelatedLinks($s,$rc);
338 $this->insertComment($s, $rc);
340 if ($rc->numberofWatchingusers
> 0) {
341 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
346 wfProfileOut( $fname.'-rest' );
348 wfProfileOut( $fname );
355 * Generate a list of changes using an Enhanced system (use javascript).
357 class EnhancedChangesList
extends ChangesList
{
359 * Format a line for enhanced recentchange (aka with javascript and block of lines).
361 function recentChangesLine( &$baseRC, $watched = false ) {
362 global $wgTitle, $wgLang, $wgContLang, $wgUser,
363 $wgUseRCPatrol, $wgOnlySysopsCanPatrol, $wgSysopUserBans;
365 # Create a specialised object
366 $rc = RCCacheEntry
::newFromParent( $baseRC ) ;
368 # Extract fields from DB into the function scope (rc_xxxx variables)
369 extract( $rc->mAttribs
);
370 $curIdEq = 'curid=' . $rc_cur_id;
372 # If it's a new day, add the headline and flush the cache
373 $date = $wgLang->date( $rc_timestamp, true);
375 if ( $date != $this->lastdate
) {
376 # Process current cache
377 $ret = $this->recentChangesBlock () ;
378 $this->rc_cache
= array() ;
379 $ret .= "<h4>{$date}</h4>\n";
380 $this->lastdate
= $date;
383 # Should patrol-related stuff be shown?
384 if ( $wgUseRCPatrol && $wgUser->isLoggedIn() &&
385 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed('patrol') )) {
386 $rc->unpatrolled
= !$rc_patrolled;
388 $rc->unpatrolled
= false;
392 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
393 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
394 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
395 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
396 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
398 $logtype = $matches[1];
399 $logname = LogPage
::logName( $logtype );
400 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
401 } elseif ( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
402 # Unpatrolled new page, give rc_id in query
403 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
405 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' ) ;
408 $time = $wgContLang->time( $rc_timestamp, true, true );
409 $rc->watched
= $watched ;
411 $rc->timestamp
= $time;
412 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
414 # Make "cur" and "diff" links
415 $titleObj = $rc->getTitle();
416 if ( $rc->unpatrolled
) {
417 $rcIdQuery = "&rcid={$rc_id}";
421 $query = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid";
422 $aprops = ' tabindex="'.$baseRC->counter
.'"';
423 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $query, '' ,'' , $aprops );
424 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
425 if( $rc_type != RC_NEW
) {
426 $curLink = $this->message
['cur'];
428 $diffLink = $this->message
['diff'];
430 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $query . $rcIdQuery, '' ,'' , $aprops );
434 if ( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
435 $lastLink = $this->message
['last'];
437 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
438 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
441 # Make user link (or user contributions for unregistered users)
442 if ( $rc_user == 0 ) {
443 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
444 $userLink = $this->skin
->makeKnownLinkObj( $contribsPage,
445 $rc_user_text, 'target=' . $rc_user_text );
447 $userPage =& Title
::makeTitle( NS_USER
, $rc_user_text );
448 $userLink = $this->skin
->makeLinkObj( $userPage, $rc_user_text );
451 $rc->userlink
= $userLink;
452 $rc->lastlink
= $lastLink;
453 $rc->curlink
= $curLink;
454 $rc->difflink
= $diffLink;
456 # Make user talk link
457 $talkname = $wgContLang->getNsText( NS_TALK
); # use the shorter name
458 $userTalkPage =& Title
::makeTitle( NS_USER_TALK
, $rc_user_text );
459 $userTalkLink = $this->skin
->makeLinkObj( $userTalkPage, $talkname );
461 global $wgDisableAnonTalk;
462 if ( ( $wgSysopUserBans ||
0 == $rc_user ) && $wgUser->isAllowed('block') ) {
463 $blockPage =& Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
464 $blockLink = $this->skin
->makeKnownLinkObj( $blockPage,
465 $this->message
['blocklink'], 'ip='.$rc_user_text );
466 if( $wgDisableAnonTalk )
467 $rc->usertalklink
= ' ('.$blockLink.')';
469 $rc->usertalklink
= ' ('.$userTalkLink.' | '.$blockLink.')';
471 if( $wgDisableAnonTalk && ($rc_user == 0) )
472 $rc->usertalklink
= '';
474 $rc->usertalklink
= ' ('.$userTalkLink.')';
477 # Put accumulated information into the cache, for later display
478 # Page moves go on their own line
479 $title = $rc->getTitle();
480 $secureName = $title->getPrefixedDBkey();
481 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
482 # Use an @ character to prevent collision with page names
483 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
485 if ( !isset ( $this->rc_cache
[$secureName] ) ) $this->rc_cache
[$secureName] = array() ;
486 array_push ( $this->rc_cache
[$secureName] , $rc ) ;
494 function recentChangesBlockGroup ( $block ) {
495 global $wgStylePath, $wgContLang ;
499 # Collate list of users
501 $unpatrolled = false;
502 $userlinks = array () ;
503 foreach ( $block AS $rcObj ) {
504 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
505 $newid = $rcObj->mAttribs
['rc_this_oldid'];
506 if ( $rcObj->mAttribs
['rc_new'] ) {
509 $u = $rcObj->userlink
;
510 if ( !isset ( $userlinks[$u] ) ) {
513 if ( $rcObj->unpatrolled
) {
519 # Sort the list and convert to text
520 krsort ( $userlinks ) ;
521 asort ( $userlinks ) ;
523 foreach ( $userlinks as $userlink => $count) {
525 if ( $count > 1 ) $text .= ' ('.$count.'×)' ;
526 array_push ( $users , $text ) ;
529 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
532 $rci = 'RCI'.$this->rcCacheIndex
;
533 $rcl = 'RCL'.$this->rcCacheIndex
;
534 $rcm = 'RCM'.$this->rcCacheIndex
;
535 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
536 $arrowdir = $wgContLang->isRTL() ?
'l' : 'r';
537 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
538 $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>' ;
543 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
546 $r .= ' '.$block[0]->timestamp
.' ' ;
550 $link = $block[0]->link
;
551 if ( $block[0]->watched
) $link = '<strong>'.$link.'</strong>' ;
554 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
555 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
556 if ( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
558 $r .= ' ('.count($block).' ' ;
559 if ( $isnew ) $r .= wfMsg('changes');
560 else $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
561 $curIdEq."&diff=$currentRevision&oldid=$oldid" ) ;
565 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
571 if ($block[0]->numberofWatchingusers
> 0) {
572 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
577 $r .= '<div id="'.$rci.'" style="display:none">' ;
578 foreach ( $block AS $rcObj ) {
579 # Get rc_xxxx variables
580 extract( $rcObj->mAttribs
);
582 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
583 $r .= '<tt> ' ;
584 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
);
585 $r .= ' </tt>' ;
588 if ( $rc_last_oldid != 0 ) {
589 $o = 'oldid='.$rc_last_oldid ;
591 if ( $rc_type == RC_LOG
) {
592 $link = $rcObj->timestamp
;
594 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
596 $link = '<tt>'.$link.'</tt>' ;
600 $r .= $rcObj->curlink
;
602 $r .= $rcObj->lastlink
;
603 $r .= ') . . '.$rcObj->userlink
;
604 $r .= $rcObj->usertalklink
;
605 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
610 $this->rcCacheIndex++
;