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 blocklink' ) as $msg ) {
60 $this->message
[$msg] = wfMsg( $msg );
67 * Returns the appropiate flags for new page, minor change and patrolling
69 function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ' ) {
70 $f = $new ?
'<span class="newpage">' . wfMsgHtml( 'newpageletter' ) . '</span>'
72 $f .= $minor ?
'<span class="minor">' . wfMsgHtml( 'minoreditletter' ) . '</span>'
74 $f .= $patrolled ?
'<span class="unpatrolled">!</span>' : $nothing;
79 * Returns text for the start of the tabular part of RC
81 function beginRecentChangesList() {
82 $this->rc_cache
= array();
83 $this->rcMoveIndex
= 0;
84 $this->rcCacheIndex
= 0;
86 $this->rclistOpen
= false;
91 * Returns text for the end of RC
93 function endRecentChangesList() {
94 if( $this->rclistOpen
) {
102 function insertMove( &$s, $rc ) {
104 $s .= '(' . $this->message
['diff'] . ') (';
106 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
109 # "[[x]] moved to [[y]]"
110 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
111 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
112 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
115 function insertDateHeader(&$s, $rc_timestamp) {
118 # Make date header if necessary
119 $date = $wgLang->date( $rc_timestamp, true, true );
121 if( $date != $this->lastdate
) {
122 if( '' != $this->lastdate
) {
125 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
126 $this->lastdate
= $date;
127 $this->rclistOpen
= true;
131 function insertLog(&$s, $title, $logtype) {
132 $logname = LogPage
::logName( $logtype );
133 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
137 function insertDiffHist(&$s, &$rc, $unpatrolled) {
139 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
140 $diffLink = $this->message
['diff'];
142 $rcidparam = $unpatrolled
143 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
145 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
147 'curid' => $rc->mAttribs
['rc_cur_id'],
148 'diff' => $rc->mAttribs
['rc_this_oldid'],
149 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
151 '', '', ' tabindex="'.$rc->counter
.'"');
153 $s .= '('.$diffLink.') (';
156 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
158 'curid' => $rc->mAttribs
['rc_cur_id'],
159 'action' => 'history' ) ) );
163 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
165 # If it's a new article, there is no diff link, but if it hasn't been
166 # patrolled yet, we need to give users a way to do so
167 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
168 ?
'rcid='.$rc->mAttribs
['rc_id']
170 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
171 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
173 $s .= ' '.$articlelink;
176 function insertTimestamp(&$s, &$rc) {
179 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
182 /** Insert links to user page, user talk page and eventually a blocking link */
183 function insertUserRelatedLinks(&$s, &$rc) {
184 $s .= $this->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
185 $s .= $this->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
188 /** insert a formatted comment */
189 function insertComment(&$s, &$rc) {
191 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
192 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
197 * Check whether to enable RC-Patrol features
200 function usePatrol() {
201 global $wgUseRCPatrol, $wgOnlySysopsCanPatrol, $wgUser;
202 return $wgUseRCPatrol && $wgUser->isLoggedIn() &&
203 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed( 'patrol' ) );
207 * Make user link (or user contributions for unregistered users)
209 * @param string $userText
210 * @return string HTML fragment
213 function userLink( $userId, $userText ) {
214 $encName = htmlspecialchars( $userText );
216 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
217 return $this->skin
->makeKnownLinkObj( $contribsPage,
218 $encName, 'target=' . urlencode( $userText ) );
220 $userPage = Title
::makeTitle( NS_USER
, $userText );
221 return $this->skin
->makeLinkObj( $userPage, $encName );
227 * @param string $userText
228 * @return string HTML fragment with talk and/or block links
231 function userToolLinks( $userId, $userText ) {
232 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
233 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
234 $blockable = ( $wgSysopUserBans ||
0 == $userId );
238 $items[] = $this->userTalkLink( $userId, $userText );
240 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
241 $items[] = $this->blockLink( $userId, $userText );
245 return ' (' . implode( ' | ', $items ) . ')';
253 * @param string $userText
254 * @return string HTML fragment with user talk link
257 function userTalkLink( $userId, $userText ) {
259 $talkname = $wgContLang->getNsText( NS_TALK
); # use the shorter name
261 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
262 $userTalkLink = $this->skin
->makeLinkObj( $userTalkPage, $talkname );
263 return $userTalkLink;
268 * @param string $userText
269 * @return string HTML fragment with block link
272 function blockLink( $userId, $userText ) {
273 $blockPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
274 $blockLink = $this->skin
->makeKnownLinkObj( $blockPage,
275 $this->message
['blocklink'], 'ip=' . urlencode( $userText ) );
283 * Generate a list of changes using the good old system (no javascript)
285 class OldChangesList
extends ChangesList
{
287 * Format a line using the old system (aka without any javascript).
289 function recentChangesLine( &$rc, $watched = false ) {
290 global $wgLang, $wgContLang, $wgUser, $wgSysopUserBans;
292 $fname = 'ChangesList::recentChangesLineOld';
293 wfProfileIn( $fname );
296 # Extract DB fields into local scope
297 extract( $rc->mAttribs
);
298 $curIdEq = 'curid=' . $rc_cur_id;
300 # Should patrol-related stuff be shown?
301 $unpatrolled = $this->usePatrol() && $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, $rc );
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 $wgLang, $wgContLang, $wgUser, $wgSysopUserBans;
356 # Create a specialised object
357 $rc = RCCacheEntry
::newFromParent( $baseRC );
359 # Extract fields from DB into the function scope (rc_xxxx variables)
360 extract( $rc->mAttribs
);
361 $curIdEq = 'curid=' . $rc_cur_id;
363 # If it's a new day, add the headline and flush the cache
364 $date = $wgLang->date( $rc_timestamp, true);
366 if( $date != $this->lastdate
) {
367 # Process current cache
368 $ret = $this->recentChangesBlock();
369 $this->rc_cache
= array();
370 $ret .= "<h4>{$date}</h4>\n";
371 $this->lastdate
= $date;
374 # Should patrol-related stuff be shown?
375 if( $this->usePatrol() ) {
376 $rc->unpatrolled
= !$rc_patrolled;
378 $rc->unpatrolled
= false;
382 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
383 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
384 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
385 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
386 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
388 $logtype = $matches[1];
389 $logname = LogPage
::logName( $logtype );
390 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
391 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
392 # Unpatrolled new page, give rc_id in query
393 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
395 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
398 $time = $wgContLang->time( $rc_timestamp, true, true );
399 $rc->watched
= $watched;
401 $rc->timestamp
= $time;
402 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
404 # Make "cur" and "diff" links
405 $titleObj = $rc->getTitle();
406 if( $rc->unpatrolled
) {
407 $rcIdQuery = "&rcid={$rc_id}";
411 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
412 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
413 $aprops = ' tabindex="'.$baseRC->counter
.'"';
414 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
415 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
416 if( $rc_type != RC_NEW
) {
417 $curLink = $this->message
['cur'];
419 $diffLink = $this->message
['diff'];
421 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
425 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
426 $lastLink = $this->message
['last'];
428 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
429 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
432 $rc->userlink
= $this->userLink( $rc_user, $rc_user_text );
434 $rc->lastlink
= $lastLink;
435 $rc->curlink
= $curLink;
436 $rc->difflink
= $diffLink;
438 $rc->usertalklink
= $this->userToolLinks( $rc_user, $rc_user_text );
440 # Put accumulated information into the cache, for later display
441 # Page moves go on their own line
442 $title = $rc->getTitle();
443 $secureName = $title->getPrefixedDBkey();
444 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
445 # Use an @ character to prevent collision with page names
446 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
448 if( !isset ( $this->rc_cache
[$secureName] ) ) {
449 $this->rc_cache
[$secureName] = array();
451 array_push( $this->rc_cache
[$secureName], $rc );
459 function recentChangesBlockGroup( $block ) {
462 # Collate list of users
464 $unpatrolled = false;
465 $userlinks = array();
466 foreach( $block as $rcObj ) {
467 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
468 $newid = $rcObj->mAttribs
['rc_this_oldid'];
469 if( $rcObj->mAttribs
['rc_new'] ) {
472 $u = $rcObj->userlink
;
473 if( !isset( $userlinks[$u] ) ) {
476 if( $rcObj->unpatrolled
) {
482 # Sort the list and convert to text
483 krsort( $userlinks );
486 foreach( $userlinks as $userlink => $count) {
489 $text .= ' ('.$count.'×)';
491 array_push( $users, $text );
494 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
497 $rci = 'RCI'.$this->rcCacheIndex
;
498 $rcl = 'RCL'.$this->rcCacheIndex
;
499 $rcm = 'RCM'.$this->rcCacheIndex
;
500 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
501 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
502 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
507 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
510 $r .= ' '.$block[0]->timestamp
.' ';
514 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
516 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
517 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
518 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
520 $r .= ' ('.count($block).' ';
522 $r .= wfMsg('changes');
524 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg('changes'),
525 $curIdEq."&diff=$currentRevision&oldid=$oldid" );
530 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
536 if($block[0]->numberofWatchingusers
> 0) {
537 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
542 $r .= '<div id="'.$rci.'" style="display:none">';
543 foreach( $block as $rcObj ) {
544 # Get rc_xxxx variables
545 extract( $rcObj->mAttribs
);
547 $r .= $this->spacerArrow();
548 $r .= '<tt> ';
549 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
);
553 if( $rc_this_oldid != 0 ) {
554 $o = 'oldid='.$rc_this_oldid;
556 if( $rc_type == RC_LOG
) {
557 $link = $rcObj->timestamp
;
559 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
561 $link = '<tt>'.$link.'</tt>';
565 $r .= $rcObj->curlink
;
567 $r .= $rcObj->lastlink
;
568 $r .= ') . . '.$rcObj->userlink
;
569 $r .= $rcObj->usertalklink
;
570 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
575 $this->rcCacheIndex++
;
579 function maybeWatchedLink( $link, $watched=false ) {
581 // FIXME: css style might be more appropriate
582 return '<strong>' . $link . '</strong>';
589 * Generate HTML for an arrow or placeholder graphic
590 * @param string $dir one of '', 'd', 'l', 'r'
591 * @param string $alt text
592 * @return string HTML <img> tag
595 function arrow( $dir, $alt='' ) {
597 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
598 $encAlt = htmlspecialchars( $alt );
599 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
603 * Generate HTML for a right- or left-facing arrow,
604 * depending on language direction.
605 * @return string HTML <img> tag
608 function sideArrow() {
610 $dir = $wgContLang->isRTL() ?
'l' : 'r';
611 return $this->arrow( $dir, '+' );
615 * Generate HTML for a down-facing arrow
616 * depending on language direction.
617 * @return string HTML <img> tag
620 function downArrow() {
621 return $this->arrow( 'd', '-' );
625 * Generate HTML for a spacer image
626 * @return string HTML <img> tag
629 function spacerArrow() {
630 return $this->arrow( '', ' ' );
634 * Enhanced RC ungrouped line.
635 * @return string a HTML formated line (generated using $r)
637 function recentChangesBlockLine( $rcObj ) {
640 # Get rc_xxxx variables
641 extract( $rcObj->mAttribs
);
642 $curIdEq = 'curid='.$rc_cur_id;
647 $r .= $this->spacerArrow();
652 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
653 $r .= ' ';
655 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
);
657 $r .= ' '.$rcObj->timestamp
.' </tt>';
660 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
663 $r .= ' ('. $rcObj->difflink
.'; ';
666 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
669 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
672 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
673 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
676 if( $rcObj->numberofWatchingusers
> 0 ) {
677 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
685 * If enhanced RC is in use, this function takes the previously cached
686 * RC lines, arranges them, and outputs the HTML
688 function recentChangesBlock() {
689 if( count ( $this->rc_cache
) == 0 ) {
693 foreach( $this->rc_cache
as $secureName => $block ) {
694 if( count( $block ) < 2 ) {
695 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
697 $blockOut .= $this->recentChangesBlockGroup( $block );
701 return '<div>'.$blockOut.'</div>';
705 * Returns text for the end of RC
706 * If enhanced RC is in use, returns pretty much all the text
708 function endRecentChangesList() {
709 return $this->recentChangesBlock() . parent
::endRecentChangesList();