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
73 function endRecentChangesList() {
74 if( $this->rclistOpen
) {
82 function insertMove( &$s, $rc ) {
84 $s .= '(' . $this->message
['diff'] . ') (';
86 $s .= $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message
['hist'], 'action=history' ) .
89 # "[[x]] moved to [[y]]"
90 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
91 $s .= wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
92 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
95 function insertDateHeader(&$s, $rc_timestamp) {
98 # Make date header if necessary
99 $date = $wgLang->date( $rc_timestamp, true, true );
101 if( $date != $this->lastdate
) {
102 if( '' != $this->lastdate
) {
105 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
106 $this->lastdate
= $date;
107 $this->rclistOpen
= true;
111 function insertLog(&$s, $title, $logtype) {
112 $logname = LogPage
::logName( $logtype );
113 $s .= '(' . $this->skin
->makeKnownLinkObj($title, $logname ) . ')';
117 function insertDiffHist(&$s, &$rc, $unpatrolled) {
119 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
120 $diffLink = $this->message
['diff'];
122 $rcidparam = $unpatrolled
123 ?
array( 'rcid' => $rc->mAttribs
['rc_id'] )
125 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'],
127 'curid' => $rc->mAttribs
['rc_cur_id'],
128 'diff' => $rc->mAttribs
['rc_this_oldid'],
129 'oldid' => $rc->mAttribs
['rc_last_oldid'] ),
131 '', '', ' tabindex="'.$rc->counter
.'"');
133 $s .= '('.$diffLink.') (';
136 $s .= $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['hist'],
138 'curid' => $rc->mAttribs
['rc_cur_id'],
139 'action' => 'history' ) ) );
143 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
145 # If it's a new article, there is no diff link, but if it hasn't been
146 # patrolled yet, we need to give users a way to do so
147 $params = ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
)
148 ?
'rcid='.$rc->mAttribs
['rc_id']
150 $articlelink = ' '. $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', $params );
151 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
153 $s .= ' '.$articlelink;
156 function insertTimestamp(&$s, &$rc) {
159 $s .= '; ' . $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
162 /** Insert links to user page, user talk page and eventually a blocking link */
163 function insertUserRelatedLinks(&$s, &$rc) {
164 $s .= $this->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
165 $s .= $this->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
168 /** insert a formatted comment */
169 function insertComment(&$s, &$rc) {
171 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
172 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
177 * Check whether to enable RC-Patrol features
180 function usePatrol() {
181 global $wgUseRCPatrol, $wgOnlySysopsCanPatrol, $wgUser;
182 return $wgUseRCPatrol && $wgUser->isLoggedIn() &&
183 ( !$wgOnlySysopsCanPatrol ||
$wgUser->isAllowed( 'patrol' ) );
187 * Make user link (or user contributions for unregistered users)
189 * @param string $userText
190 * @return string HTML fragment
193 function userLink( $userId, $userText ) {
194 $encName = htmlspecialchars( $userText );
196 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
197 return $this->skin
->makeKnownLinkObj( $contribsPage,
198 $encName, 'target=' . urlencode( $userText ) );
200 $userPage = Title
::makeTitle( NS_USER
, $userText );
201 return $this->skin
->makeLinkObj( $userPage, $encName );
207 * @param string $userText
208 * @return string HTML fragment with talk and/or block links
211 function userToolLinks( $userId, $userText ) {
212 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
213 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
214 $blockable = ( $wgSysopUserBans ||
0 == $userId );
218 $items[] = $this->userTalkLink( $userId, $userText );
220 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
221 $items[] = $this->blockLink( $userId, $userText );
225 return ' (' . implode( ' | ', $items ) . ')';
233 * @param string $userText
234 * @return string HTML fragment with user talk link
237 function userTalkLink( $userId, $userText ) {
239 $talkname = $wgContLang->getNsText( NS_TALK
); # use the shorter name
241 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
242 $userTalkLink = $this->skin
->makeLinkObj( $userTalkPage, $talkname );
243 return $userTalkLink;
248 * @param string $userText
249 * @return string HTML fragment with block link
252 function blockLink( $userId, $userText ) {
253 $blockPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
254 $blockLink = $this->skin
->makeKnownLinkObj( $blockPage,
255 $this->message
['blocklink'], 'ip=' . urlencode( $userText ) );
263 * Generate a list of changes using the good old system (no javascript)
265 class OldChangesList
extends ChangesList
{
267 * Format a line using the old system (aka without any javascript).
269 function recentChangesLine( &$rc, $watched = false ) {
270 global $wgLang, $wgContLang, $wgUser, $wgSysopUserBans;
272 $fname = 'ChangesList::recentChangesLineOld';
273 wfProfileIn( $fname );
276 # Extract DB fields into local scope
277 extract( $rc->mAttribs
);
278 $curIdEq = 'curid=' . $rc_cur_id;
280 # Should patrol-related stuff be shown?
281 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
283 $this->insertDateHeader($s,$rc_timestamp);
288 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
289 $this->insertMove( $s, $rc );
291 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
292 $this->insertLog($s, $rc->getTitle(), $matches[1]);
295 wfProfileIn($fname.'-page');
297 $this->insertDiffHist($s, $rc, $unpatrolled);
299 # M, N and ! (minor, new and unpatrolled)
300 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $unpatrolled, '' );
301 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
303 wfProfileOut($fname.'-page');
306 wfProfileIn( $fname.'-rest' );
308 $this->insertTimestamp($s,$rc);
309 $this->insertUserRelatedLinks($s,$rc);
310 $this->insertComment($s, $rc);
312 if($rc->numberofWatchingusers
> 0) {
313 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers
));
318 wfProfileOut( $fname.'-rest' );
320 wfProfileOut( $fname );
327 * Generate a list of changes using an Enhanced system (use javascript).
329 class EnhancedChangesList
extends ChangesList
{
331 * Format a line for enhanced recentchange (aka with javascript and block of lines).
333 function recentChangesLine( &$baseRC, $watched = false ) {
334 global $wgLang, $wgContLang, $wgUser, $wgSysopUserBans;
336 # Create a specialised object
337 $rc = RCCacheEntry
::newFromParent( $baseRC );
339 # Extract fields from DB into the function scope (rc_xxxx variables)
340 extract( $rc->mAttribs
);
341 $curIdEq = 'curid=' . $rc_cur_id;
343 # If it's a new day, add the headline and flush the cache
344 $date = $wgLang->date( $rc_timestamp, true);
346 if( $date != $this->lastdate
) {
347 # Process current cache
348 $ret = $this->recentChangesBlock();
349 $this->rc_cache
= array();
350 $ret .= "<h4>{$date}</h4>\n";
351 $this->lastdate
= $date;
354 # Should patrol-related stuff be shown?
355 if( $this->usePatrol() ) {
356 $rc->unpatrolled
= !$rc_patrolled;
358 $rc->unpatrolled
= false;
362 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
363 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
364 $clink = wfMsg( $msg, $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
365 $this->skin
->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
366 } elseif( $rc_namespace == NS_SPECIAL
&& preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
368 $logtype = $matches[1];
369 $logname = LogPage
::logName( $logtype );
370 $clink = '(' . $this->skin
->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
371 } elseif( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
372 # Unpatrolled new page, give rc_id in query
373 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
375 $clink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), '' );
378 $time = $wgContLang->time( $rc_timestamp, true, true );
379 $rc->watched
= $watched;
381 $rc->timestamp
= $time;
382 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
384 # Make "cur" and "diff" links
385 $titleObj = $rc->getTitle();
386 if( $rc->unpatrolled
) {
387 $rcIdQuery = "&rcid={$rc_id}";
391 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
392 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
393 $aprops = ' tabindex="'.$baseRC->counter
.'"';
394 $curLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['cur'], $querycur, '' ,'', $aprops );
395 if( $rc_type == RC_NEW ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
396 if( $rc_type != RC_NEW
) {
397 $curLink = $this->message
['cur'];
399 $diffLink = $this->message
['diff'];
401 $diffLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['diff'], $querydiff, '' ,'', $aprops );
405 if( $rc_last_oldid == 0 ||
$rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
406 $lastLink = $this->message
['last'];
408 $lastLink = $this->skin
->makeKnownLinkObj( $rc->getTitle(), $this->message
['last'],
409 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
412 $rc->userlink
= $this->userLink( $rc_user, $rc_user_text );
414 $rc->lastlink
= $lastLink;
415 $rc->curlink
= $curLink;
416 $rc->difflink
= $diffLink;
418 $rc->usertalklink
= $this->userToolLinks( $rc_user, $rc_user_text );
420 # Put accumulated information into the cache, for later display
421 # Page moves go on their own line
422 $title = $rc->getTitle();
423 $secureName = $title->getPrefixedDBkey();
424 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
425 # Use an @ character to prevent collision with page names
426 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
428 if( !isset ( $this->rc_cache
[$secureName] ) ) {
429 $this->rc_cache
[$secureName] = array();
431 array_push( $this->rc_cache
[$secureName], $rc );
439 function recentChangesBlockGroup( $block ) {
442 # Collate list of users
444 $unpatrolled = false;
445 $userlinks = array();
446 foreach( $block as $rcObj ) {
447 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
448 $newid = $rcObj->mAttribs
['rc_this_oldid'];
449 if( $rcObj->mAttribs
['rc_new'] ) {
452 $u = $rcObj->userlink
;
453 if( !isset( $userlinks[$u] ) ) {
456 if( $rcObj->unpatrolled
) {
462 # Sort the list and convert to text
463 krsort( $userlinks );
466 foreach( $userlinks as $userlink => $count) {
469 $text .= ' ('.$count.'×)';
471 array_push( $users, $text );
474 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
477 $rci = 'RCI'.$this->rcCacheIndex
;
478 $rcl = 'RCL'.$this->rcCacheIndex
;
479 $rcm = 'RCM'.$this->rcCacheIndex
;
480 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
481 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
482 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
487 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
490 $r .= ' '.$block[0]->timestamp
.' ';
494 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
496 $curIdEq = 'curid=' . $block[0]->mAttribs
['rc_cur_id'];
497 $currentRevision = $block[0]->mAttribs
['rc_this_oldid'];
498 if( $block[0]->mAttribs
['rc_type'] != RC_LOG
) {
500 $r .= ' ('.count($block).' ';
502 $r .= wfMsg('changes');
504 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg('changes'),
505 $curIdEq."&diff=$currentRevision&oldid=$oldid" );
510 $r .= $this->skin
->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
516 if($block[0]->numberofWatchingusers
> 0) {
517 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers
));
522 $r .= '<div id="'.$rci.'" style="display:none">';
523 foreach( $block as $rcObj ) {
524 # Get rc_xxxx variables
525 extract( $rcObj->mAttribs
);
527 $r .= $this->spacerArrow();
528 $r .= '<tt> ';
529 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
);
533 if( $rc_this_oldid != 0 ) {
534 $o = 'oldid='.$rc_this_oldid;
536 if( $rc_type == RC_LOG
) {
537 $link = $rcObj->timestamp
;
539 $link = $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp
, $curIdEq.'&'.$o );
541 $link = '<tt>'.$link.'</tt>';
545 $r .= $rcObj->curlink
;
547 $r .= $rcObj->lastlink
;
548 $r .= ') . . '.$rcObj->userlink
;
549 $r .= $rcObj->usertalklink
;
550 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
555 $this->rcCacheIndex++
;
559 function maybeWatchedLink( $link, $watched=false ) {
561 // FIXME: css style might be more appropriate
562 return '<strong>' . $link . '</strong>';
569 * Generate HTML for an arrow or placeholder graphic
570 * @param string $dir one of '', 'd', 'l', 'r'
571 * @param string $alt text
572 * @return string HTML <img> tag
575 function arrow( $dir, $alt='' ) {
577 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
578 $encAlt = htmlspecialchars( $alt );
579 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
583 * Generate HTML for a right- or left-facing arrow,
584 * depending on language direction.
585 * @return string HTML <img> tag
588 function sideArrow() {
590 $dir = $wgContLang->isRTL() ?
'l' : 'r';
591 return $this->arrow( $dir, '+' );
595 * Generate HTML for a down-facing arrow
596 * depending on language direction.
597 * @return string HTML <img> tag
600 function downArrow() {
601 return $this->arrow( 'd', '-' );
605 * Generate HTML for a spacer image
606 * @return string HTML <img> tag
609 function spacerArrow() {
610 return $this->arrow( '', ' ' );
614 * Enhanced RC ungrouped line.
615 * @return string a HTML formated line (generated using $r)
617 function recentChangesBlockLine( $rcObj ) {
620 # Get rc_xxxx variables
621 extract( $rcObj->mAttribs
);
622 $curIdEq = 'curid='.$rc_cur_id;
627 $r .= $this->spacerArrow();
632 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
633 $r .= ' ';
635 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
);
637 $r .= ' '.$rcObj->timestamp
.' </tt>';
640 $r .= $this->maybeWatchedLink( $rcObj->link
, $rcObj->watched
);
643 $r .= ' ('. $rcObj->difflink
.'; ';
646 $r .= $this->skin
->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
649 $r .= ') . . '.$rcObj->userlink
. $rcObj->usertalklink
;
652 if( $rc_type != RC_MOVE
&& $rc_type != RC_MOVE_OVER_REDIRECT
) {
653 $r .= $this->skin
->commentBlock( $rc_comment, $rcObj->getTitle() );
656 if( $rcObj->numberofWatchingusers
> 0 ) {
657 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers
));
665 * If enhanced RC is in use, this function takes the previously cached
666 * RC lines, arranges them, and outputs the HTML
668 function recentChangesBlock() {
669 if( count ( $this->rc_cache
) == 0 ) {
673 foreach( $this->rc_cache
as $secureName => $block ) {
674 if( count( $block ) < 2 ) {
675 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
677 $blockOut .= $this->recentChangesBlockGroup( $block );
681 return '<div>'.$blockOut.'</div>';
685 * Returns text for the end of RC
686 * If enhanced RC is in use, returns pretty much all the text
688 function endRecentChangesList() {
689 return $this->recentChangesBlock() . parent
::endRecentChangesList();