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