*Fix syntax bugs on line 669
[lhc/web/wiklou.git] / includes / ChangesList.php
1 <?php
2 /**
3 * Contain class to show various lists of change:
4 * - what's link here
5 * - related changes
6 * - recent changes
7 */
8
9 /**
10 * @todo document
11 */
12 class RCCacheEntry extends RecentChange
13 {
14 var $secureName, $link;
15 var $curlinks, $difflink, $lastlink , $usertalklink , $versionlink ;
16 var $userlink, $timestamp, $watched;
17
18 function newFromParent( $rc )
19 {
20 $rc2 = new RCCacheEntry;
21 $rc2->mAttribs = $rc->mAttribs;
22 $rc2->mExtra = $rc->mExtra;
23 return $rc2;
24 }
25 } ;
26
27 /**
28 * @package MediaWiki
29 */
30 class ChangesList {
31 # Called by history lists and recent changes
32 #
33
34 /** @todo document */
35 function __construct( &$skin ) {
36 $this->skin =& $skin;
37 $this->preCacheMessages();
38 }
39
40 /**
41 * Fetch an appropriate changes list class for the specified user
42 * Some users might want to use an enhanced list format, for instance
43 *
44 * @param $user User to fetch the list class for
45 * @return ChangesList derivative
46 */
47 public static function newFromUser( &$user ) {
48 $sk = $user->getSkin();
49 $list = NULL;
50 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
51 return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
52 } else {
53 return $list;
54 }
55 }
56
57 /**
58 * As we use the same small set of messages in various methods and that
59 * they are called often, we call them once and save them in $this->message
60 */
61 function preCacheMessages() {
62 // Precache various messages
63 if( !isset( $this->message ) ) {
64 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
65 'blocklink history boteditletter' ) as $msg ) {
66 $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
67 }
68 }
69 }
70
71
72 /**
73 * Returns the appropriate flags for new page, minor change and patrolling
74 */
75 function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
76 $f = $new ? '<span class="newpage">' . $this->message['newpageletter'] . '</span>'
77 : $nothing;
78 $f .= $minor ? '<span class="minor">' . $this->message['minoreditletter'] . '</span>'
79 : $nothing;
80 $f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
81 $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
82 return "<tt>$f</tt>";
83 }
84
85 /**
86 * Returns text for the start of the tabular part of RC
87 */
88 function beginRecentChangesList() {
89 $this->rc_cache = array();
90 $this->rcMoveIndex = 0;
91 $this->rcCacheIndex = 0;
92 $this->lastdate = '';
93 $this->rclistOpen = false;
94 return '';
95 }
96
97 /**
98 * Returns text for the end of RC
99 */
100 function endRecentChangesList() {
101 if( $this->rclistOpen ) {
102 return "</ul>\n";
103 } else {
104 return '';
105 }
106 }
107
108 /**
109 * int $field one of DELETED_* bitfield constants
110 * @return bool
111 */
112 function isDeleted( $rc, $field ) {
113 return ($rc->mAttribs['rc_deleted'] & $field) == $field;
114 }
115
116 /**
117 * Determine if the current user is allowed to view a particular
118 * field of this revision, if it's marked as deleted.
119 * @param int $field
120 * @return bool
121 */
122 function userCan( $rc, $field ) {
123 if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) {
124 global $wgUser;
125 $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED
126 ? 'hiderevision'
127 : 'deleterevision';
128 wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" );
129 return $wgUser->isAllowed( $permission );
130 } else {
131 return true;
132 }
133 }
134
135 function insertMove( &$s, $rc ) {
136 # Diff
137 $s .= '(' . $this->message['diff'] . ') (';
138 # Hist
139 $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) .
140 ') . . ';
141
142 # "[[x]] moved to [[y]]"
143 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
144 $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
145 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
146 }
147
148 function insertDateHeader(&$s, $rc_timestamp) {
149 global $wgLang;
150
151 # Make date header if necessary
152 $date = $wgLang->date( $rc_timestamp, true, true );
153 $s = '';
154 if( $date != $this->lastdate ) {
155 if( '' != $this->lastdate ) {
156 $s .= "</ul>\n";
157 }
158 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
159 $this->lastdate = $date;
160 $this->rclistOpen = true;
161 }
162 }
163
164 function insertLog(&$s, $title, $logtype) {
165 $logname = LogPage::logName( $logtype );
166 $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')';
167 }
168
169 function insertDiffHist(&$s, &$rc, $unpatrolled) {
170 # Diff link
171 if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
172 $diffLink = $this->message['diff'];
173 } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG) {
174 $diffLink = $this->message['diff'];
175 } else {
176 $rcidparam = $unpatrolled
177 ? array( 'rcid' => $rc->mAttribs['rc_id'] )
178 : array();
179 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
180 wfArrayToCGI( array(
181 'curid' => $rc->mAttribs['rc_cur_id'],
182 'diff' => $rc->mAttribs['rc_this_oldid'],
183 'oldid' => $rc->mAttribs['rc_last_oldid'] ),
184 $rcidparam ),
185 '', '', ' tabindex="'.$rc->counter.'"');
186 }
187 $s .= '('.$diffLink.') (';
188
189 # History link
190 $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'],
191 wfArrayToCGI( array(
192 'curid' => $rc->mAttribs['rc_cur_id'],
193 'action' => 'history' ) ) );
194 $s .= ') . . ';
195 }
196
197 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
198 # Article link
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 $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW )
202 ? 'rcid='.$rc->mAttribs['rc_id']
203 : '';
204 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
205 $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
206 $articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
207 } else {
208 $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
209 }
210 if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
211 global $wgContLang;
212 $articlelink .= $wgContLang->getDirMark();
213
214 $s .= ' '.$articlelink;
215 }
216
217 function insertTimestamp(&$s, $rc) {
218 global $wgLang;
219 # Timestamp
220 $s .= '; ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
221 }
222
223 /** Insert links to user page, user talk page and eventually a blocking link */
224 function insertUserRelatedLinks(&$s, &$rc) {
225 if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
226 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
227 } else {
228 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
229 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
230 }
231 }
232
233 /** insert a formatted action */
234 function insertAction(&$s, &$rc) {
235 # Add comment
236 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
237 // log action
238 if ( $this->isDeleted($rc,LogViewer::DELETED_ACTION) ) {
239 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
240 } else {
241 $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'], $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true );
242 }
243 }
244 }
245
246 /** insert a formatted comment */
247 function insertComment(&$s, &$rc) {
248 # Add comment
249 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
250 // log comment
251 if ( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) {
252 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
253 } else {
254 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
255 }
256 }
257 }
258
259 /**
260 * Check whether to enable recent changes patrol features
261 * @return bool
262 */
263 function usePatrol() {
264 global $wgUseRCPatrol, $wgUser;
265 return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
266 }
267
268 /**
269 * Returns the string which indicates the number of watching users
270 */
271 function numberofWatchingusers( $count ) {
272 global $wgLang;
273 static $cache = array();
274 if ( $count > 0 ) {
275 if ( !isset( $cache[$count] ) ) {
276 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
277 array('parsemag', 'escape'), $wgLang->formatNum($count));
278 }
279 return $cache[$count];
280 } else {
281 return '';
282 }
283 }
284 }
285
286
287 /**
288 * Generate a list of changes using the good old system (no javascript)
289 */
290 class OldChangesList extends ChangesList {
291 /**
292 * Format a line using the old system (aka without any javascript).
293 */
294 function recentChangesLine( &$rc, $watched = false ) {
295 global $wgContLang, $wgRCShowChangedSize;
296
297 $fname = 'ChangesList::recentChangesLineOld';
298 wfProfileIn( $fname );
299
300 # Extract DB fields into local scope
301 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
302 extract( $rc->mAttribs );
303
304 # Should patrol-related stuff be shown?
305 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
306
307 $this->insertDateHeader($s,$rc_timestamp);
308
309 $s .= '<li>';
310
311 // Moved pages
312 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
313 $this->insertMove( $s, $rc );
314 // Log entries (old format) or log targets, and special pages
315 } elseif( $rc_namespace == NS_SPECIAL ) {
316 list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
317 if ( $specialName == 'Log' ) {
318 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
319 } else {
320 wfDebug( "Unexpected special page in recentchanges\n" );
321 }
322 // Log entries
323 } elseif( $rc_log_type !='' ) {
324 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
325 $this->insertLog( $s, $logtitle, $rc_log_type );
326 // All other stuff
327 } else {
328 wfProfileIn($fname.'-page');
329
330 $this->insertDiffHist($s, $rc, $unpatrolled);
331
332 # M, N, b and ! (minor, new, bot and unpatrolled)
333 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
334 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
335
336 wfProfileOut($fname.'-page');
337 }
338
339 wfProfileIn( $fname.'-rest' );
340
341 $this->insertTimestamp($s,$rc);
342
343 if( $wgRCShowChangedSize ) {
344 $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' );
345 }
346
347 $this->insertUserRelatedLinks($s,$rc);
348 $this->insertAction($s, $rc);
349 $this->insertComment($s, $rc);
350
351 # Mark revision as deleted
352 if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) )
353 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
354 if($rc->numberofWatchingusers > 0) {
355 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers));
356 }
357
358 $s .= "</li>\n";
359
360 wfProfileOut( $fname.'-rest' );
361
362 wfProfileOut( $fname );
363 return $s;
364 }
365 }
366
367
368 /**
369 * Generate a list of changes using an Enhanced system (use javascript).
370 */
371 class EnhancedChangesList extends ChangesList {
372 /**
373 * Format a line for enhanced recentchange (aka with javascript and block of lines).
374 */
375 function recentChangesLine( &$baseRC, $watched = false ) {
376 global $wgLang, $wgContLang;
377
378 # Create a specialised object
379 $rc = RCCacheEntry::newFromParent( $baseRC );
380
381 # Extract fields from DB into the function scope (rc_xxxx variables)
382 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
383 extract( $rc->mAttribs );
384 $curIdEq = 'curid=' . $rc_cur_id;
385
386 # If it's a new day, add the headline and flush the cache
387 $date = $wgLang->date( $rc_timestamp, true);
388 $ret = '';
389 if( $date != $this->lastdate ) {
390 # Process current cache
391 $ret = $this->recentChangesBlock();
392 $this->rc_cache = array();
393 $ret .= "<h4>{$date}</h4>\n";
394 $this->lastdate = $date;
395 }
396
397 # Should patrol-related stuff be shown?
398 if( $this->usePatrol() ) {
399 $rc->unpatrolled = !$rc_patrolled;
400 } else {
401 $rc->unpatrolled = false;
402 }
403
404 $showrev=true;
405 # Make article link
406 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
407 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
408 $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
409 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
410 } else if( $rc_namespace == NS_SPECIAL ) {
411 // Log entries (old format) and special pages
412 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
413 if ( $specialName == 'Log' ) {
414 # Log updates, etc
415 $logname = LogPage::logName( $logtype );
416 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
417 } else {
418 wfDebug( "Unexpected special page in recentchanges\n" );
419 $clink = '';
420 }
421 } elseif ( $rc_log_type !='' ) {
422 // Log entries
423 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
424 $logname = LogPage::logName( $rc_log_type );
425 $clink = '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
426 } if ( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
427 $clink = '<span class="history-deleted">' . $this->skin->makeKnownLinkObj( $rc->getTitle(), '' ) . '</span>';
428 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) )
429 $showrev=false;
430 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
431 # Unpatrolled new page, give rc_id in query
432 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
433 } else {
434 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
435 }
436
437 $time = $wgContLang->time( $rc_timestamp, true, true );
438 $rc->watched = $watched;
439 $rc->link = $clink;
440 $rc->timestamp = $time;
441 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
442
443 # Make "cur" and "diff" links
444 if( $rc->unpatrolled ) {
445 $rcIdQuery = "&rcid={$rc_id}";
446 } else {
447 $rcIdQuery = '';
448 }
449 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
450 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
451 $aprops = ' tabindex="'.$baseRC->counter.'"';
452 $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
453 if ( !$showrev ) {
454 $curLink = $this->message['cur'];
455 $diffLink = $this->message['diff'];
456 } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
457 if( $rc_type != RC_NEW ) {
458 $curLink = $this->message['cur'];
459 }
460 $diffLink = $this->message['diff'];
461 } else {
462 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
463 }
464
465 # Make "last" link
466 if ( !$showrev ) {
467 $lastLink = $this->message['last'];
468 } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
469 $lastLink = $this->message['last'];
470 } else {
471 $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
472 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
473 }
474
475 # Make user links
476 if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
477 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
478 } else {
479 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
480 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
481 }
482
483 $rc->lastlink = $lastLink;
484 $rc->curlink = $curLink;
485 $rc->difflink = $diffLink;
486
487 # Put accumulated information into the cache, for later display
488 # Page moves go on their own line
489 $title = $rc->getTitle();
490 $secureName = $title->getPrefixedDBkey();
491 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
492 # Use an @ character to prevent collision with page names
493 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
494 } else {
495 if( !isset ( $this->rc_cache[$secureName] ) ) {
496 $this->rc_cache[$secureName] = array();
497 }
498 array_push( $this->rc_cache[$secureName], $rc );
499 }
500 return $ret;
501 }
502
503 /**
504 * Enhanced RC group
505 */
506 function recentChangesBlockGroup( $block ) {
507 global $wgLang, $wgContLang, $wgRCShowChangedSize;
508 $r = '<table cellpadding="0" cellspacing="0"><tr>';
509
510 # Collate list of users
511 $isnew = false;
512 $namehidden = true;
513 $unpatrolled = false;
514 $userlinks = array();
515 foreach( $block as $rcObj ) {
516 $oldid = $rcObj->mAttribs['rc_last_oldid'];
517 if( $rcObj->mAttribs['rc_new'] ) {
518 $isnew = true;
519 }
520 // if all log actions to this page were hidden, then don't
521 // give the name of the affected page for this block
522 if( !($rcObj->mAttribs['rc_deleted'] & LogViewer::DELETED_ACTION) ) {
523 $namehidden = false;
524 }
525 $u = $rcObj->userlink;
526 if( !isset( $userlinks[$u] ) ) {
527 $userlinks[$u] = 0;
528 }
529 if( $rcObj->unpatrolled ) {
530 $unpatrolled = true;
531 }
532 $bot = $rcObj->mAttribs['rc_bot'];
533 $userlinks[$u]++;
534 }
535
536 # Sort the list and convert to text
537 krsort( $userlinks );
538 asort( $userlinks );
539 $users = array();
540 foreach( $userlinks as $userlink => $count) {
541 $text = $userlink;
542 $text .= $wgContLang->getDirMark();
543 if( $count > 1 ) {
544 $text .= ' ('.$count.'&times;)';
545 }
546 array_push( $users, $text );
547 }
548
549 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
550
551 # Arrow
552 $rci = 'RCI'.$this->rcCacheIndex;
553 $rcl = 'RCL'.$this->rcCacheIndex;
554 $rcm = 'RCM'.$this->rcCacheIndex;
555 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
556 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
557 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
558 $r .= '<td valign="top">'.$tl;
559
560 # Main line
561 $r .= ' '.$this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
562
563 # Timestamp
564 $r .= ' '.$block[0]->timestamp.'&nbsp;&nbsp;</td><td>';
565
566 # Article link
567 if ( $namehidden )
568 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
569 else
570 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
571 $r .= $wgContLang->getDirMark();
572
573 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
574 $currentRevision = $block[0]->mAttribs['rc_this_oldid'];
575 if( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
576 # Changes
577 $n = count($block);
578 static $nchanges = array();
579 if ( !isset( $nchanges[$n] ) ) {
580 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'),
581 $wgLang->formatNum( $n ) );
582 }
583
584 $r .= ' (';
585
586 if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
587 $r .= $nchanges[$n];
588 } else if( $isnew ) {
589 $r .= $nchanges[$n];
590 } else {
591 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
592 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
593 }
594
595 # Character difference
596 $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs['rc_old_len'],
597 $block[0]->mAttribs['rc_new_len'] );
598 if( $chardiff == '' ) {
599 $r .= '; ';
600 } else {
601 $r .= '; ' . $chardiff . ' ';
602 }
603
604 # History
605 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), $this->message['history'], $curIdEq.'&action=history' );
606
607 $r .= ')';
608 }
609
610 $r .= $users;
611 $r .=$this->numberofWatchingusers($block[0]->numberofWatchingusers);
612
613 $r .= "</td></tr></table>\n";
614
615 # Sub-entries
616 $r .= '<div id="'.$rci.'" style="display:none; font-size:95%;"><table cellpadding="0" cellspacing="0">';
617 foreach( $block as $rcObj ) {
618 # Get rc_xxxx variables
619 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
620 extract( $rcObj->mAttribs );
621
622 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
623 $r .= '<tr><td valign="top">'.$this->spacerIndent();
624 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
625 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
626 $r .= '&nbsp;&nbsp;</td><td valign="top">';
627
628 $o = '';
629 if( $rc_this_oldid != 0 ) {
630 $o = 'oldid='.$rc_this_oldid;
631 }
632 # Revision link
633 if( $rc_type == RC_LOG ) {
634 $link = $rcObj->timestamp.' ';
635 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
636 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
637 } else {
638 $link = $this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o );
639 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
640 $link = '<span class="history-deleted">'.$link.'</span> ';
641 }
642 $r .= $link;
643
644 if ( !$rc_log_type ) {
645 $r .= ' (';
646 $r .= $rcObj->curlink;
647 $r .= '; ';
648 $r .= $rcObj->lastlink;
649 $r .= ')';
650 } else {
651 $logname = LogPage::logName( $rc_log_type );
652 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
653 $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
654 }
655 $r .= ' . . ';
656
657 # Character diff
658 if( $wgRCShowChangedSize ) {
659 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
660 }
661 # User links
662 $r .= $rcObj->userlink;
663 $r .= $rcObj->usertalklink;
664 // log action
665 parent::insertAction($r, $rcObj);
666 // log comment
667 parent::insertComment($r, $rcObj);
668 # Mark revision as deleted
669 if ( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
670 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
671
672 $r .= "</td></tr>\n";
673 }
674 $r .= "</table></div>\n";
675
676 $this->rcCacheIndex++;
677 return $r;
678 }
679
680 function maybeWatchedLink( $link, $watched=false ) {
681 if( $watched ) {
682 // FIXME: css style might be more appropriate
683 return '<strong>' . $link . '</strong>';
684 } else {
685 return $link;
686 }
687 }
688
689 /**
690 * Generate HTML for an arrow or placeholder graphic
691 * @param string $dir one of '', 'd', 'l', 'r'
692 * @param string $alt text
693 * @return string HTML <img> tag
694 * @access private
695 */
696 function arrow( $dir, $alt='' ) {
697 global $wgStylePath;
698 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
699 $encAlt = htmlspecialchars( $alt );
700 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
701 }
702
703 /**
704 * Generate HTML for a right- or left-facing arrow,
705 * depending on language direction.
706 * @return string HTML <img> tag
707 * @access private
708 */
709 function sideArrow() {
710 global $wgContLang;
711 $dir = $wgContLang->isRTL() ? 'l' : 'r';
712 return $this->arrow( $dir, '+' );
713 }
714
715 /**
716 * Generate HTML for a down-facing arrow
717 * depending on language direction.
718 * @return string HTML <img> tag
719 * @access private
720 */
721 function downArrow() {
722 return $this->arrow( 'd', '-' );
723 }
724
725 /**
726 * Generate HTML for a spacer image
727 * @return string HTML <img> tag
728 * @access private
729 */
730 function spacerArrow() {
731 //FIXME: problems with FF 1.5x
732 return $this->arrow( '', ' ' );
733 }
734
735 /**
736 * Generate HTML for the equivilant of a spacer image for tables
737 * @return string HTML <td> tag
738 * @access private
739 */
740 function spacerColumn() {
741 return '<td width="12"></td>';
742 }
743
744 // Adds a few spaces
745 function spacerIndent() {
746 return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
747 }
748
749 /**
750 * Enhanced RC ungrouped line.
751 * @return string a HTML formated line (generated using $r)
752 */
753 function recentChangesBlockLine( $rcObj ) {
754 global $wgContLang, $wgRCShowChangedSize;
755
756 # Get rc_xxxx variables
757 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
758 extract( $rcObj->mAttribs );
759 $curIdEq = 'curid='.$rc_cur_id;
760
761 $r = '<table cellspacing="0" cellpadding="0"><tr><td>';
762
763 # spacerArrow() causes issues in FF
764 $r .= $this->spacerColumn();
765 $r .= '<td valign="top">';
766
767 # Flag and Timestamp
768 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
769 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;';
770 } else {
771 $r .= '&nbsp;'.$this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
772 }
773 $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;&nbsp;</td><td>';
774
775 # Article link
776 if ( $rc_log_type !='' ) {
777 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
778 $logname = LogPage::logName( $rc_log_type );
779 $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
780 // All other stuff
781 } else {
782 $r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched );
783 }
784 if ( $rc_type != RC_LOG ) {
785 # Diff
786 $r .= ' ('. $rcObj->difflink .'; ';
787 # Hist
788 $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
789 }
790 $r .= ' . . ';
791
792 # Character diff
793 if( $wgRCShowChangedSize ) {
794 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : '&nbsp;' . $rcObj->getCharacterDifference() . ' . . ' ) ;
795 }
796
797 # User/talk
798 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
799
800 # Comment
801 if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
802 // log action
803 if ( $this->isDeleted($rcObj,LogViewer::DELETED_ACTION) ) {
804 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
805 } else {
806 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(), $this->skin, LogPage::extractParams($rc_params), true, true );
807 }
808 // log comment
809 if ( $this->isDeleted($rcObj,LogViewer::DELETED_COMMENT) ) {
810 $r .= ' <span class="history-deleted">' . wfMsg('rev-deleted-comment') . '</span>';
811 } else {
812 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
813 }
814 }
815
816 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
817
818 $r .= "</td></tr></table>\n";
819 return $r;
820 }
821
822 /**
823 * If enhanced RC is in use, this function takes the previously cached
824 * RC lines, arranges them, and outputs the HTML
825 */
826 function recentChangesBlock() {
827 if( count ( $this->rc_cache ) == 0 ) {
828 return '';
829 }
830 $blockOut = '';
831 foreach( $this->rc_cache as $block ) {
832 if( count( $block ) < 2 ) {
833 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
834 } else {
835 $blockOut .= $this->recentChangesBlockGroup( $block );
836 }
837 }
838
839 return '<div>'.$blockOut.'</div>';
840 }
841
842 /**
843 * Returns text for the end of RC
844 * If enhanced RC is in use, returns pretty much all the text
845 */
846 function endRecentChangesList() {
847 return $this->recentChangesBlock() . parent::endRecentChangesList();
848 }
849
850 }
851 ?>