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