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 ?
'&rcid='.$rc->mAttribs
['rc_id'] : '';
186 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
187 $curIdEq.'&diff='.$rc->mAttribs
['rc_this_oldid'].'&oldid='.$rc->mAttribs
['rc_last_oldid'].$rcidparam,
188 '', '', ' tabindex="'.$rc->counter
.'"');
190 $s .= '('.$diffLink.') (';
193 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'], 'curid='.$this->mAttribs
['rc_cur_id'].'&action=history' );
197 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
199 # If it's a new article, there is no diff link, but if it hasn't been
200 # patrolled yet, we need to give users a way to do so
201 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
202 $articlelink .= ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'rcid='.$this->mAttribs
['rc_id'] );
204 $articlelink .= ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
206 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
208 $s .= ' '.$articlelink;
211 function insertTimestamp(&$s, &$rc) {
214 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
217 /** Insert links to user page, user talk page and eventually a blocking link */
218 function insertUserRelatedLinks(&$s, &$rc) {
219 $this->insertUserLink($s,$rc);
220 $openParenthesis = false;
222 global $wgDisableAnonTalk;
223 if(!( 0 == $rc->mAttribs
['rc_user'] && $wgDisableAnonTalk)) {
224 $openParenthesis = true;
226 $this->insertUserTalkLink($s,$rc);
229 global $wgSysopUserBans, $wgUser;
230 if ( ( $wgSysopUserBans ||
0 == $rc->mAttribs
['rc_user'] ) && $wgUser->isAllowed('block') ) {
231 $s .= $openParenthesis ?
' | ' : '(';
232 $this->insertUserBlockLink($s,$rc);
234 $s .= $openParenthesis ?
' ) ' : '';
237 /** insert a formatted link to the user page */
238 function insertUserLink(&$s, &$rc) {
239 # User link (or contributions for unregistered users)
240 if ( 0 == $rc->mAttribs
['rc_user'] ) {
241 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
242 $userLink = $this->skin
->makeKnownLinkObj( $contribsPage,
243 $rc->mAttribs
['rc_user_text'], 'target=' . $rc->mAttribs
['rc_user_text'] );
245 $userPage =& Title
::makeTitle( NS_USER
, $rc->mAttribs
['rc_user_text'] );
246 $userLink = $this->skin
->makeLinkObj( $userPage, htmlspecialchars( $rc->mAttribs
['rc_user_text'] ) );
251 /** insert a formatted link to the user talk page */
252 function insertUserTalkLink(&$s, &$rc) {
255 $talkname = $wgContLang->getNsText(NS_TALK
); # use the shorter name
256 $userTalkPage =& Title
::makeTitle( NS_USER_TALK
, $rc->mAttribs
['rc_user_text'] );
257 $userTalkLink= $this->skin
->makeLinkObj( $userTalkPage, htmlspecialchars( $talkname ) );
261 /** insert a formatted link to block an user */
262 function insertUserBlockLink(&$s, &$rc) {
264 $blockLinkPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
265 $blockLink = $this->skin
->makeKnownLinkObj( $blockLinkPage,
266 htmlspecialchars( $this->message
['blocklink'] ), 'ip=' . urlencode( $rc->mAttribs
['user_text'] ) );
270 /** insert a formatted comment */
271 function insertComment(&$s, &$rc) {
273 if ( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
274 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
281 * Generate a list of changes using the good old system (no javascript)
283 class OldChangesList
extends ChangesList
{
285 * Format a line using the old system (aka without any javascript).
287 function recentChangesLine( &$rc, $watched = false ) {
288 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol,
289 $wgOnlySysopsCanPatrol, $wgSysopUserBans;
291 $fname = 'ChangesList::recentChangesLineOld';
292 wfProfileIn( $fname );
295 # Extract DB fields into local scope
296 extract( $rc->mAttribs
);
297 $curIdEq = 'curid=' . $rc_cur_id;
299 # Should patrol-related stuff be shown?
300 $unpatrolled = $wgUseRCPatrol && $wgUser->isLoggedIn() &&
301 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
303 $this->insertDateHeader($s,$rc_timestamp);
308 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
309 $this->insertMove($s);
311 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
312 $this->insertLog($s, $rc->getTitle(), $matches[1]);
315 wfProfileIn($fname.'-page');
317 $this->insertDiffHist($s, $rc, $unpatrolled);
319 # M, N and ! (minor, new and unpatrolled)
320 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '' );
321 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
323 wfProfileOut($fname.'-page');
326 wfProfileIn( $fname.'-rest' );
328 $this->insertTimestamp($s,$rc);
329 $this->insertUserRelatedLinks($s,$rc);
330 $this->insertComment($s, $rc);
332 if ($rc->numberofWatchingusers
> 0) {
333 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
338 wfProfileOut( $fname.'-rest' );
340 wfProfileOut( $fname );
347 * Generate a list of changes using an Enhanced system (use javascript).
349 class EnhancedChangesList
extends ChangesList
{
351 * Format a line for enhanced recentchange (aka with javascript and block of lines).
353 function recentChangesLine( &$baseRC, $watched = false ) {
354 global $wgTitle, $wgLang, $wgContLang, $wgUser,
355 $wgUseRCPatrol, $wgOnlySysopsCanPatrol, $wgSysopUserBans;
357 # Create a specialised object
358 $rc = RCCacheEntry
::newFromParent( $baseRC ) ;
360 # Extract fields from DB into the function scope (rc_xxxx variables)
361 extract( $rc->mAttribs
);
362 $curIdEq = 'curid=' . $rc_cur_id;
364 # If it's a new day, add the headline and flush the cache
365 $date = $wgLang->date( $rc_timestamp, true);
367 if ( $date != $this->lastdate
) {
368 # Process current cache
369 $ret = $this->recentChangesBlock () ;
370 $this->rc_cache
= array() ;
371 $ret .= "<h4>{$date}</h4>\n";
372 $this->lastdate
= $date;
375 # Should patrol-related stuff be shown?
376 if ( $wgUseRCPatrol && $wgUser->isLoggedIn() &&
377 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed('patrol') )) {
378 $rc->unpatrolled
= !$rc_patrolled;
380 $rc->unpatrolled
= false;
384 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
385 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
386 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
387 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
388 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
390 $logtype = $matches[1];
391 $logname = LogPage
::logName( $logtype );
392 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
393 } elseif ( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
394 # Unpatrolled new page, give rc_id in query
395 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
397 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' ) ;
400 $time = $wgContLang->time( $rc_timestamp, true, true );
401 $rc->watched
= $watched ;
403 $rc->timestamp
= $time;
404 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
406 # Make "cur" and "diff" links
407 $titleObj = $rc->getTitle();
408 if ( $rc->unpatrolled
) {
409 $rcIdQuery = "&rcid={$rc_id}";
413 $query = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid";
414 $aprops = ' tabindex="'.$baseRC->counter
.'"';
415 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $query, '' ,'' , $aprops );
416 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
417 if( $rc_type != RC_NEW
) {
418 $curLink = $this->message
['cur'];
420 $diffLink = $this->message
['diff'];
422 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $query . $rcIdQuery, '' ,'' , $aprops );
426 if ( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
427 $lastLink = $this->message
['last'];
429 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
430 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
433 # Make user link (or user contributions for unregistered users)
434 if ( $rc_user == 0 ) {
435 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
436 $userLink = $this->skin
->makeKnownLinkObj( $contribsPage,
437 $rc_user_text, 'target=' . $rc_user_text );
439 $userPage =& Title
::makeTitle( NS_USER
, $rc_user_text );
440 $userLink = $this->skin
->makeLinkObj( $userPage, $rc_user_text );
443 $rc->userlink
= $userLink;
444 $rc->lastlink
= $lastLink;
445 $rc->curlink
= $curLink;
446 $rc->difflink
= $diffLink;
448 # Make user talk link
449 $talkname = $wgContLang->getNsText( NS_TALK
); # use the shorter name
450 $userTalkPage =& Title
::makeTitle( NS_USER_TALK
, $rc_user_text );
451 $userTalkLink = $this->skin
->makeLinkObj( $userTalkPage, $talkname );
453 global $wgDisableAnonTalk;
454 if ( ( $wgSysopUserBans ||
0 == $rc_user ) && $wgUser->isAllowed('block') ) {
455 $blockPage =& Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
456 $blockLink = $this->skin
->makeKnownLinkObj( $blockPage,
457 $this->message
['blocklink'], 'ip='.$rc_user_text );
458 if( $wgDisableAnonTalk )
459 $rc->usertalklink
= ' ('.$blockLink.')';
461 $rc->usertalklink
= ' ('.$userTalkLink.' | '.$blockLink.')';
463 if( $wgDisableAnonTalk && ($rc_user == 0) )
464 $rc->usertalklink
= '';
466 $rc->usertalklink
= ' ('.$userTalkLink.')';
469 # Put accumulated information into the cache, for later display
470 # Page moves go on their own line
471 $title = $rc->getTitle();
472 $secureName = $title->getPrefixedDBkey();
473 if ( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
474 # Use an @ character to prevent collision with page names
475 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
477 if ( !isset ( $this->rc_cache
[$secureName] ) ) $this->rc_cache
[$secureName] = array() ;
478 array_push ( $this->rc_cache
[$secureName] , $rc ) ;
486 function recentChangesBlockGroup ( $block ) {
487 global $wgStylePath, $wgContLang ;
491 # Collate list of users
493 $unpatrolled = false;
494 $userlinks = array () ;
495 foreach ( $block AS $rcObj ) {
496 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
497 $newid = $rcObj->mAttribs
['rc_this_oldid'];
498 if ( $rcObj->mAttribs
['rc_new'] ) {
501 $u = $rcObj->userlink
;
502 if ( !isset ( $userlinks[$u] ) ) {
505 if ( $rcObj->unpatrolled
) {
511 # Sort the list and convert to text
512 krsort ( $userlinks ) ;
513 asort ( $userlinks ) ;
515 foreach ( $userlinks as $userlink => $count) {
517 if ( $count > 1 ) $text .= ' ('.$count.'×)' ;
518 array_push ( $users , $text ) ;
521 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
524 $rci = 'RCI'.$this->rcCacheIndex
;
525 $rcl = 'RCL'.$this->rcCacheIndex
;
526 $rcm = 'RCM'.$this->rcCacheIndex
;
527 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
528 $arrowdir = $wgContLang->isRTL() ?
'l' : 'r';
529 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
530 $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>' ;
535 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
538 $r .= ' '.$block[0]->timestamp
.' ' ;
542 $link = $block[0]->link
;
543 if ( $block[0]->watched
) $link = '<strong>'.$link.'</strong>' ;
546 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
547 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
548 if ( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
550 $r .= ' ('.count($block).' ' ;
551 if ( $isnew ) $r .= wfMsg('changes');
552 else $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
553 $curIdEq."&diff=$currentRevision&oldid=$oldid" ) ;
557 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
563 if ($block[0]->numberofWatchingusers
> 0) {
564 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
569 $r .= '<div id="'.$rci.'" style="display:none">' ;
570 foreach ( $block AS $rcObj ) {
571 # Get rc_xxxx variables
572 extract( $rcObj->mAttribs
);
574 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
575 $r .= '<tt> ' ;
576 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
);
577 $r .= ' </tt>' ;
580 if ( $rc_last_oldid != 0 ) {
581 $o = 'oldid='.$rc_last_oldid ;
583 if ( $rc_type == RC_LOG
) {
584 $link = $rcObj->timestamp
;
586 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
588 $link = '<tt>'.$link.'</tt>' ;
592 $r .= $rcObj->curlink
;
594 $r .= $rcObj->lastlink
;
595 $r .= ') . . '.$rcObj->userlink
;
596 $r .= $rcObj->usertalklink
;
597 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
602 $this->rcCacheIndex++
;