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