*Clean up deletion of revisions and remove some gaps
[lhc/web/wiklou.git] / includes / ChangesList.php
1 <?php
2
3 /**
4 * @todo document
5 */
6 class RCCacheEntry extends RecentChange
7 {
8 var $secureName, $link;
9 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
10 var $userlink, $timestamp, $watched;
11
12 static function newFromParent( $rc ) {
13 $rc2 = new RCCacheEntry;
14 $rc2->mAttribs = $rc->mAttribs;
15 $rc2->mExtra = $rc->mExtra;
16 return $rc2;
17 }
18 } ;
19
20 /**
21 * Class to show various lists of changes:
22 * - what links here
23 * - related changes
24 * - recent changes
25 */
26 class ChangesList {
27 # Called by history lists and recent changes
28 #
29
30 /** @todo document */
31 function __construct( &$skin ) {
32 $this->skin =& $skin;
33 $this->preCacheMessages();
34 }
35
36 /**
37 * Fetch an appropriate changes list class for the specified user
38 * Some users might want to use an enhanced list format, for instance
39 *
40 * @param $user User to fetch the list class for
41 * @return ChangesList derivative
42 */
43 public static function newFromUser( &$user ) {
44 $sk = $user->getSkin();
45 $list = NULL;
46 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
47 return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
48 } else {
49 return $list;
50 }
51 }
52
53 /**
54 * As we use the same small set of messages in various methods and that
55 * they are called often, we call them once and save them in $this->message
56 */
57 function preCacheMessages() {
58 // Precache various messages
59 if( !isset( $this->message ) ) {
60 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
61 'blocklink history boteditletter' ) as $msg ) {
62 $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
63 }
64 }
65 }
66
67
68 /**
69 * Returns the appropriate flags for new page, minor change and patrolling
70 */
71 function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
72 $f = $new ? '<span class="newpage">' . $this->message['newpageletter'] . '</span>'
73 : $nothing;
74 $f .= $minor ? '<span class="minor">' . $this->message['minoreditletter'] . '</span>'
75 : $nothing;
76 $f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
77 $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
78 return "<tt>$f</tt>";
79 }
80
81 /**
82 * Returns text for the start of the tabular part of RC
83 */
84 function beginRecentChangesList() {
85 $this->rc_cache = array();
86 $this->rcMoveIndex = 0;
87 $this->rcCacheIndex = 0;
88 $this->lastdate = '';
89 $this->rclistOpen = false;
90 return '';
91 }
92
93 /**
94 * Returns text for the end of RC
95 */
96 function endRecentChangesList() {
97 if( $this->rclistOpen ) {
98 return "</ul>\n";
99 } else {
100 return '';
101 }
102 }
103
104 /**
105 * int $field one of DELETED_* bitfield constants
106 * @return bool
107 */
108 function isDeleted( $rc, $field ) {
109 return ($rc->mAttribs['rc_deleted'] & $field) == $field;
110 }
111
112 /**
113 * Determine if the current user is allowed to view a particular
114 * field of this revision, if it's marked as deleted.
115 * @param int $field
116 * @return bool
117 */
118 function userCan( $rc, $field ) {
119 if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) {
120 global $wgUser;
121 $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED
122 ? 'hiderevision'
123 : 'deleterevision';
124 wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" );
125 return $wgUser->isAllowed( $permission );
126 } else {
127 return true;
128 }
129 }
130
131 function insertMove( &$s, $rc ) {
132 # Diff
133 $s .= '(' . $this->message['diff'] . ') (';
134 # Hist
135 $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) .
136 ') . . ';
137
138 # "[[x]] moved to [[y]]"
139 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
140 $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
141 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
142 }
143
144 function insertDateHeader(&$s, $rc_timestamp) {
145 global $wgLang;
146
147 # Make date header if necessary
148 $date = $wgLang->date( $rc_timestamp, true, true );
149 $s = '';
150 if( $date != $this->lastdate ) {
151 if( '' != $this->lastdate ) {
152 $s .= "</ul>\n";
153 }
154 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
155 $this->lastdate = $date;
156 $this->rclistOpen = true;
157 }
158 }
159
160 function insertLog(&$s, $title, $logtype) {
161 $logname = LogPage::logName( $logtype );
162 $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')';
163 }
164
165 function insertDiffHist(&$s, &$rc, $unpatrolled) {
166 # Diff link
167 if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
168 $diffLink = $this->message['diff'];
169 } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
170 $diffLink = $this->message['diff'];
171 } else {
172 $rcidparam = $unpatrolled
173 ? array( 'rcid' => $rc->mAttribs['rc_id'] )
174 : array();
175 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
176 wfArrayToCGI( array(
177 'curid' => $rc->mAttribs['rc_cur_id'],
178 'diff' => $rc->mAttribs['rc_this_oldid'],
179 'oldid' => $rc->mAttribs['rc_last_oldid'] ),
180 $rcidparam ),
181 '', '', ' tabindex="'.$rc->counter.'"');
182 }
183 $s .= '('.$diffLink.') (';
184
185 # History link
186 $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'],
187 wfArrayToCGI( array(
188 'curid' => $rc->mAttribs['rc_cur_id'],
189 'action' => 'history' ) ) );
190 $s .= ') . . ';
191 }
192
193 function insertArticleLink(&$s, &$rc, $unpatrolled, $watched) {
194 # Article link
195 # If it's a new article, there is no diff link, but if it hasn't been
196 # patrolled yet, we need to give users a way to do so
197 $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW )
198 ? 'rcid='.$rc->mAttribs['rc_id']
199 : '';
200 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
201 $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
202 $articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
203 } else {
204 $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
205 }
206 if( $watched )
207 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
208 global $wgContLang;
209 $articlelink .= $wgContLang->getDirMark();
210
211 $s .= ' '.$articlelink;
212 }
213
214 function insertTimestamp(&$s, $rc) {
215 global $wgLang;
216 # Timestamp
217 $s .= '; ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
218 }
219
220 /** Insert links to user page, user talk page and eventually a blocking link */
221 function insertUserRelatedLinks(&$s, &$rc) {
222 if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
223 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
224 } else {
225 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
226 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
227 }
228 }
229
230 /** insert a formatted action */
231 function insertAction(&$s, &$rc) {
232 # Add comment
233 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
234 // log action
235 if ( $this->isDeleted($rc,LogViewer::DELETED_ACTION) ) {
236 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
237 } else {
238 $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
239 $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true );
240 }
241 }
242 }
243
244 /** insert a formatted comment */
245 function insertComment(&$s, &$rc) {
246 # Add comment
247 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
248 // log comment
249 if ( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) {
250 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
251 } else {
252 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
253 }
254 }
255 }
256
257 /**
258 * Check whether to enable recent changes patrol features
259 * @return bool
260 */
261 function usePatrol() {
262 global $wgUseRCPatrol, $wgUser;
263 return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') || $wgUser->isAllowed('patrolmarks')) );
264 }
265
266 /**
267 * Returns the string which indicates the number of watching users
268 */
269 function numberofWatchingusers( $count ) {
270 global $wgLang;
271 static $cache = array();
272 if ( $count > 0 ) {
273 if ( !isset( $cache[$count] ) ) {
274 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
275 array('parsemag', 'escape'), $wgLang->formatNum($count));
276 }
277 return $cache[$count];
278 } else {
279 return '';
280 }
281 }
282 }
283
284
285 /**
286 * Generate a list of changes using the good old system (no javascript)
287 */
288 class OldChangesList extends ChangesList {
289 /**
290 * Format a line using the old system (aka without any javascript).
291 */
292 function recentChangesLine( &$rc, $watched = false ) {
293 global $wgContLang, $wgRCShowChangedSize;
294
295 $fname = 'ChangesList::recentChangesLineOld';
296 wfProfileIn( $fname );
297
298 # Extract DB fields into local scope
299 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
300 extract( $rc->mAttribs );
301
302 # Should patrol-related stuff be shown?
303 $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
304
305 $this->insertDateHeader($s,$rc_timestamp);
306
307 $s .= '<li>';
308
309 // Moved pages
310 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
311 $this->insertMove( $s, $rc );
312 // Log entries
313 } elseif( $rc_log_type !='' ) {
314 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
315 $this->insertLog( $s, $logtitle, $rc_log_type );
316 // Log entries (old format) or log targets, and special pages
317 } elseif( $rc_namespace == NS_SPECIAL ) {
318 list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
319 if ( $specialName == 'Log' ) {
320 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
321 } else {
322 wfDebug( "Unexpected special page in recentchanges\n" );
323 }
324 // Log entries
325 } else {
326 wfProfileIn($fname.'-page');
327
328 $this->insertDiffHist($s, $rc, $unpatrolled);
329
330 # M, N, b and ! (minor, new, bot and unpatrolled)
331 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
332 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
333
334 wfProfileOut($fname.'-page');
335 }
336
337 wfProfileIn( $fname.'-rest' );
338
339 $this->insertTimestamp($s,$rc);
340
341 if( $wgRCShowChangedSize ) {
342 $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' );
343 }
344
345 $this->insertUserRelatedLinks($s,$rc);
346 $this->insertAction($s, $rc);
347 $this->insertComment($s, $rc);
348
349 # Mark revision as deleted
350 if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) )
351 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
352 if($rc->numberofWatchingusers > 0) {
353 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers));
354 }
355
356 $s .= "</li>\n";
357
358 wfProfileOut( $fname.'-rest' );
359
360 wfProfileOut( $fname );
361 return $s;
362 }
363 }
364
365
366 /**
367 * Generate a list of changes using an Enhanced system (use javascript).
368 */
369 class EnhancedChangesList extends ChangesList {
370 /**
371 * Format a line for enhanced recentchange (aka with javascript and block of lines).
372 */
373 function recentChangesLine( &$baseRC, $watched = false ) {
374 global $wgLang, $wgContLang;
375
376 # Create a specialised object
377 $rc = RCCacheEntry::newFromParent( $baseRC );
378
379 # Extract fields from DB into the function scope (rc_xxxx variables)
380 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
381 extract( $rc->mAttribs );
382 $curIdEq = 'curid=' . $rc_cur_id;
383
384 # If it's a new day, add the headline and flush the cache
385 $date = $wgLang->date( $rc_timestamp, true);
386 $ret = '';
387 if( $date != $this->lastdate ) {
388 # Process current cache
389 $ret = $this->recentChangesBlock();
390 $this->rc_cache = array();
391 $ret .= "<h4>{$date}</h4>\n";
392 $this->lastdate = $date;
393 }
394
395 # Should patrol-related stuff be shown?
396 if( $this->usePatrol() ) {
397 $rc->unpatrolled = !$rc_patrolled;
398 } else {
399 $rc->unpatrolled = false;
400 }
401
402 $showrev=true;
403 # Make article link
404 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
405 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
406 $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
407 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
408 } else if( $rc_namespace == NS_SPECIAL ) {
409 // Log entries (old format) and special pages
410 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
411 if ( $specialName == 'Log' ) {
412 # Log updates, etc
413 $logname = LogPage::logName( $logtype );
414 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
415 } else {
416 wfDebug( "Unexpected special page in recentchanges\n" );
417 $clink = '';
418 }
419 } elseif ( $rc_log_type !='' ) {
420 // Log entries
421 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
422 $logname = LogPage::logName( $rc_log_type );
423 $clink = '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
424 } if ( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
425 $clink = '<span class="history-deleted">' . $this->skin->makeKnownLinkObj( $rc->getTitle(), '' ) . '</span>';
426 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) )
427 $showrev=false;
428 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
429 # Unpatrolled new page, give rc_id in query
430 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
431 } else {
432 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
433 }
434
435 $time = $wgContLang->time( $rc_timestamp, true, true );
436 $rc->watched = $watched;
437 $rc->link = $clink;
438 $rc->timestamp = $time;
439 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
440
441 # Make "cur" and "diff" links
442 if( $rc->unpatrolled ) {
443 $rcIdQuery = "&rcid={$rc_id}";
444 } else {
445 $rcIdQuery = '';
446 }
447 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
448 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
449 $aprops = ' tabindex="'.$baseRC->counter.'"';
450 $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
451 if ( !$showrev ) {
452 $curLink = $this->message['cur'];
453 $diffLink = $this->message['diff'];
454 } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
455 if( $rc_type != RC_NEW ) {
456 $curLink = $this->message['cur'];
457 }
458 $diffLink = $this->message['diff'];
459 } else {
460 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
461 }
462
463 # Make "last" link
464 if ( !$showrev ) {
465 $lastLink = $this->message['last'];
466 } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
467 $lastLink = $this->message['last'];
468 } else {
469 $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
470 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
471 }
472
473 # Make user links
474 if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
475 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
476 } else {
477 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
478 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
479 }
480
481 $rc->lastlink = $lastLink;
482 $rc->curlink = $curLink;
483 $rc->difflink = $diffLink;
484
485 # Put accumulated information into the cache, for later display
486 # Page moves go on their own line
487 $title = $rc->getTitle();
488 $secureName = $title->getPrefixedDBkey();
489 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
490 # Use an @ character to prevent collision with page names
491 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
492 } else {
493 if( !isset ( $this->rc_cache[$secureName] ) ) {
494 $this->rc_cache[$secureName] = array();
495 }
496 array_push( $this->rc_cache[$secureName], $rc );
497 }
498 return $ret;
499 }
500
501 /**
502 * Enhanced RC group
503 */
504 function recentChangesBlockGroup( $block ) {
505 global $wgLang, $wgContLang, $wgRCShowChangedSize;
506 $r = '<table cellpadding="0" cellspacing="0"><tr>';
507
508 # Collate list of users
509 $isnew = false;
510 $namehidden = true;
511 $unpatrolled = false;
512 $userlinks = array();
513 foreach( $block as $rcObj ) {
514 $oldid = $rcObj->mAttribs['rc_last_oldid'];
515 if( $rcObj->mAttribs['rc_new'] ) {
516 $isnew = true;
517 }
518 // if all log actions to this page were hidden, then don't
519 // give the name of the affected page for this block
520 if( !($rcObj->mAttribs['rc_deleted'] & LogViewer::DELETED_ACTION) ) {
521 $namehidden = false;
522 }
523 $u = $rcObj->userlink;
524 if( !isset( $userlinks[$u] ) ) {
525 $userlinks[$u] = 0;
526 }
527 if( $rcObj->unpatrolled ) {
528 $unpatrolled = true;
529 }
530 $bot = $rcObj->mAttribs['rc_bot'];
531 $userlinks[$u]++;
532 }
533
534 # Sort the list and convert to text
535 krsort( $userlinks );
536 asort( $userlinks );
537 $users = array();
538 foreach( $userlinks as $userlink => $count) {
539 $text = $userlink;
540 $text .= $wgContLang->getDirMark();
541 if( $count > 1 ) {
542 $text .= ' ('.$count.'&times;)';
543 }
544 array_push( $users, $text );
545 }
546
547 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
548
549 # Arrow
550 $rci = 'RCI'.$this->rcCacheIndex;
551 $rcl = 'RCL'.$this->rcCacheIndex;
552 $rcm = 'RCM'.$this->rcCacheIndex;
553 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
554 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
555 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
556 $r .= '<td valign="top">'.$tl;
557
558 # Main line
559 $r .= ' '.$this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
560
561 # Timestamp
562 $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;&nbsp;</td><td>';
563
564 # Article link
565 if ( $namehidden )
566 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
567 else
568 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
569 $r .= $wgContLang->getDirMark();
570
571 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
572 $currentRevision = $block[0]->mAttribs['rc_this_oldid'];
573 if( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
574 # Changes
575 $n = count($block);
576 static $nchanges = array();
577 if ( !isset( $nchanges[$n] ) ) {
578 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'),
579 $wgLang->formatNum( $n ) );
580 }
581
582 $r .= ' (';
583
584 if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
585 $r .= $nchanges[$n];
586 } else if( $isnew ) {
587 $r .= $nchanges[$n];
588 } else {
589 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
590 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
591 }
592
593 if( $wgRCShowChangedSize ) {
594 # Character difference
595 $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs['rc_old_len'],
596 $block[0]->mAttribs['rc_new_len'] );
597 if( $chardiff == '' ) {
598 $r .= ') ';
599 } else {
600 $r .= ' ' . $chardiff. ' . . ';
601 }
602 }
603
604 # History
605 $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
606 $this->message['history'], $curIdEq.'&action=history' );
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 class="mw-watched">' . $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