6e516d4f32c9db8bbdf070eb9c002b9a31451a57
[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 = '';
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 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
376
377 $s = "<li>$s</li>\n";
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 /**
393 * Add the JavaScript file for enhanced changeslist
394 * @ return string
395 */
396 public function beginRecentChangesList() {
397 global $wgStylePath, $wgStyleVersion;
398 $this->rc_cache = array();
399 $this->rcMoveIndex = 0;
400 $this->rcCacheIndex = 0;
401 $this->lastdate = '';
402 $this->rclistOpen = false;
403 $script = Xml::tags( 'script', array(
404 'type' => 'text/javascript',
405 'src' => $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" ), '' );
406 return $script;
407 }
408 /**
409 * Format a line for enhanced recentchange (aka with javascript and block of lines).
410 */
411 public function recentChangesLine( &$baseRC, $watched = false ) {
412 global $wgLang, $wgContLang, $wgUser;
413
414 # Create a specialised object
415 $rc = RCCacheEntry::newFromParent( $baseRC );
416
417 # Extract fields from DB into the function scope (rc_xxxx variables)
418 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
419 extract( $rc->mAttribs );
420 $curIdEq = 'curid=' . $rc_cur_id;
421
422 # If it's a new day, add the headline and flush the cache
423 $date = $wgLang->date( $rc_timestamp, true);
424 $ret = '';
425 if( $date != $this->lastdate ) {
426 # Process current cache
427 $ret = $this->recentChangesBlock();
428 $this->rc_cache = array();
429 $ret .= "<h4>{$date}</h4>\n";
430 $this->lastdate = $date;
431 }
432
433 # Should patrol-related stuff be shown?
434 if( $wgUser->useRCPatrol() ) {
435 $rc->unpatrolled = !$rc_patrolled;
436 } else {
437 $rc->unpatrolled = false;
438 }
439
440 $showdifflinks = true;
441 # Make article link
442 // Page moves
443 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
444 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
445 $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
446 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
447 // Log entries (old format) and special pages
448 } elseif( $rc_namespace == NS_SPECIAL ) {
449 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
450 if ( $specialName == 'Log' ) {
451 # Log updates, etc
452 $logname = LogPage::logName( $logtype );
453 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
454 } else {
455 wfDebug( "Unexpected special page in recentchanges\n" );
456 $clink = '';
457 }
458 // New unpatrolled pages
459 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
460 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
461 // Log entries
462 } else if( $rc_type == RC_LOG ) {
463 if( $rc_log_type ) {
464 $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
465 $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle, LogPage::logName($rc_log_type) ) . ')';
466 } else {
467 $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
468 }
469 $watched = false;
470 // Edits
471 } else {
472 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
473 }
474
475 # Don't show unusable diff links
476 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
477 $showdifflinks = false;
478 }
479
480 $time = $wgContLang->time( $rc_timestamp, true, true );
481 $rc->watched = $watched;
482 $rc->link = $clink;
483 $rc->timestamp = $time;
484 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
485
486 # Make "cur" and "diff" links
487 if( $rc->unpatrolled ) {
488 $rcIdQuery = "&rcid={$rc_id}";
489 } else {
490 $rcIdQuery = '';
491 }
492 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
493 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
494 $aprops = ' tabindex="'.$baseRC->counter.'"';
495 $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
496
497 # Make "diff" an "cur" links
498 if( !$showdifflinks ) {
499 $curLink = $this->message['cur'];
500 $diffLink = $this->message['diff'];
501 } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
502 if( $rc_type != RC_NEW ) {
503 $curLink = $this->message['cur'];
504 }
505 $diffLink = $this->message['diff'];
506 } else {
507 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
508 }
509
510 # Make "last" link
511 if( !$showdifflinks ) {
512 $lastLink = $this->message['last'];
513 } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
514 $lastLink = $this->message['last'];
515 } else {
516 $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
517 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
518 }
519
520 # Make user links
521 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
522 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
523 } else {
524 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
525 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
526 }
527
528 $rc->lastlink = $lastLink;
529 $rc->curlink = $curLink;
530 $rc->difflink = $diffLink;
531
532 # Put accumulated information into the cache, for later display
533 # Page moves go on their own line
534 $title = $rc->getTitle();
535 $secureName = $title->getPrefixedDBkey();
536 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
537 # Use an @ character to prevent collision with page names
538 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
539 } else {
540 # Logs are grouped by type
541 if( $rc_type == RC_LOG ){
542 $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
543 }
544 if( !isset( $this->rc_cache[$secureName] ) ) {
545 $this->rc_cache[$secureName] = array();
546 }
547 array_push( $this->rc_cache[$secureName], $rc );
548 }
549 return $ret;
550 }
551
552 /**
553 * Enhanced RC group
554 */
555 protected function recentChangesBlockGroup( $block ) {
556 global $wgLang, $wgContLang, $wgRCShowChangedSize;
557 $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
558
559 # Collate list of users
560 $userlinks = array();
561 # Other properties
562 $unpatrolled = false;
563 $isnew = false;
564 $curId = $currentRevision = 0;
565 # Some catalyst variables...
566 $namehidden = true;
567 $alllogs = true;
568 foreach( $block as $rcObj ) {
569 $oldid = $rcObj->mAttribs['rc_last_oldid'];
570 if( $rcObj->mAttribs['rc_new'] ) {
571 $isnew = true;
572 }
573 // If all log actions to this page were hidden, then don't
574 // give the name of the affected page for this block!
575 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
576 $namehidden = false;
577 }
578 $u = $rcObj->userlink;
579 if( !isset( $userlinks[$u] ) ) {
580 $userlinks[$u] = 0;
581 }
582 if( $rcObj->unpatrolled ) {
583 $unpatrolled = true;
584 }
585 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
586 $alllogs = false;
587 }
588 # Get the latest entry with a page_id and oldid
589 # since logs may not have these.
590 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
591 $curId = $rcObj->mAttribs['rc_cur_id'];
592 }
593 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
594 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
595 }
596
597 $bot = $rcObj->mAttribs['rc_bot'];
598 $userlinks[$u]++;
599 }
600
601 # Sort the list and convert to text
602 krsort( $userlinks );
603 asort( $userlinks );
604 $users = array();
605 foreach( $userlinks as $userlink => $count) {
606 $text = $userlink;
607 $text .= $wgContLang->getDirMark();
608 if( $count > 1 ) {
609 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
610 }
611 array_push( $users, $text );
612 }
613
614 $users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'], $users ) . ']</span>';
615
616 # ID for JS visibility toggle
617 $jsid = $this->rcCacheIndex;
618
619 $toggleLink = "onclick='toggleVisibility($jsid)'";
620 $tl = "<span id='mw-rc-openarrow-$jsid' style='display:inline;' $toggleLink>" . $this->sideArrow() . "</span>";
621 $tl .= "<span id='mw-rc-closearrow-$jsid' style='display:none;' class='mw-rc-jshidden' $toggleLink>" . $this->downArrow() . "</span>";
622 $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.'&nbsp;';
623
624 # Main line
625 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
626
627 # Timestamp
628 $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</tt></td><td>';
629
630 # Article link
631 if( $namehidden ) {
632 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
633 } else {
634 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
635 }
636
637 $r .= $wgContLang->getDirMark();
638
639 $curIdEq = 'curid=' . $curId;
640 # Changes message
641 $n = count($block);
642 static $nchanges = array();
643 if ( !isset( $nchanges[$n] ) ) {
644 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
645 }
646 # Total change link
647 $r .= ' ';
648 if( !$alllogs ) {
649 $r .= '(';
650 if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
651 $r .= $nchanges[$n];
652 } else if( $isnew ) {
653 $r .= $nchanges[$n];
654 } else {
655 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
656 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
657 }
658 $r .= ') . . ';
659 }
660
661 # Character difference (does not apply if only log items)
662 if( $wgRCShowChangedSize && !$alllogs ) {
663 $last = 0;
664 $first = count($block) - 1;
665 # Some events (like logs) have an "empty" size, so we need to skip those...
666 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
667 $last++;
668 }
669 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
670 $first--;
671 }
672 # Get net change
673 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
674 $block[$last]->mAttribs['rc_new_len'] );
675
676 if( $chardiff == '' ) {
677 $r .= ' ';
678 } else {
679 $r .= ' ' . $chardiff. ' . . ';
680 }
681 }
682
683 # History
684 if( $alllogs ) {
685 // don't show history link for logs
686 } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
687 $r .= '(' . $this->message['history'] . ')';
688 } else {
689 $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
690 $this->message['history'], $curIdEq.'&action=history' ) . ')';
691 }
692
693 $r .= $users;
694 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
695
696 $r .= "</td></tr></table>\n";
697
698 # Sub-entries
699 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-rc-jshidden"><table cellpadding="0" cellspacing="0" border="0" style="background: none">';
700 foreach( $block as $rcObj ) {
701 # Get rc_xxxx variables
702 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
703 extract( $rcObj->mAttribs );
704
705 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
706 $r .= '<tr><td valign="top">';
707 $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
708 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
709 $r .= '&nbsp;</tt></td><td valign="top">';
710
711 $o = '';
712 if( $rc_this_oldid != 0 ) {
713 $o = 'oldid='.$rc_this_oldid;
714 }
715 # Log timestamp
716 if( $rc_type == RC_LOG ) {
717 $link = '<tt>'.$rcObj->timestamp.'</tt> ';
718 # Revision link
719 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
720 $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
721 } else {
722 $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ? '&rcid='.$rcObj->mAttribs['rc_id'] : '';
723
724 $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).'</tt>';
725 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
726 $link = '<span class="history-deleted">'.$link.'</span> ';
727 }
728 $r .= $link;
729
730 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
731 $r .= ' (';
732 $r .= $rcObj->curlink;
733 $r .= $this->message['semicolon-separator'];
734 $r .= $rcObj->lastlink;
735 $r .= ')';
736 }
737 $r .= ' . . ';
738
739 # Character diff
740 if( $wgRCShowChangedSize ) {
741 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
742 }
743 # User links
744 $r .= $rcObj->userlink;
745 $r .= $rcObj->usertalklink;
746 // log action
747 parent::insertAction( $r, $rcObj );
748 // log comment
749 parent::insertComment( $r, $rcObj );
750 # Mark revision as deleted
751 if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
752 $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
753 }
754
755 $r .= "</td></tr>\n";
756 }
757 $r .= "</table></div>\n";
758
759 $this->rcCacheIndex++;
760 return $r;
761 }
762
763 protected function maybeWatchedLink( $link, $watched=false ) {
764 if( $watched ) {
765 // FIXME: css style might be more appropriate
766 return '<strong class="mw-watched">' . $link . '</strong>';
767 } else {
768 return $link;
769 }
770 }
771
772 /**
773 * Generate HTML for an arrow or placeholder graphic
774 * @param string $dir one of '', 'd', 'l', 'r'
775 * @param string $alt text
776 * @return string HTML <img> tag
777 */
778 protected function arrow( $dir, $alt='' ) {
779 global $wgStylePath;
780 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
781 $encAlt = htmlspecialchars( $alt );
782 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
783 }
784
785 /**
786 * Generate HTML for a right- or left-facing arrow,
787 * depending on language direction.
788 * @return string HTML <img> tag
789 */
790 protected function sideArrow() {
791 global $wgContLang;
792 $dir = $wgContLang->isRTL() ? 'l' : 'r';
793 return $this->arrow( $dir, '+' );
794 }
795
796 /**
797 * Generate HTML for a down-facing arrow
798 * depending on language direction.
799 * @return string HTML <img> tag
800 */
801 protected function downArrow() {
802 return $this->arrow( 'd', '-' );
803 }
804
805 /**
806 * Generate HTML for a spacer image
807 * @return string HTML <img> tag
808 */
809 protected function spacerArrow() {
810 return $this->arrow( '', ' ' );
811 }
812
813 /**
814 * Add a set of spaces
815 * @return string HTML <td> tag
816 */
817 protected function spacerIndent() {
818 return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
819 }
820
821 /**
822 * Enhanced RC ungrouped line.
823 * @return string a HTML formated line (generated using $r)
824 */
825 protected function recentChangesBlockLine( $rcObj ) {
826 global $wgContLang, $wgRCShowChangedSize;
827
828 # Get rc_xxxx variables
829 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
830 extract( $rcObj->mAttribs );
831 $curIdEq = 'curid='.$rc_cur_id;
832
833 $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
834
835 $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
836
837 # Flag and Timestamp
838 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
839 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
840 } else {
841 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
842 }
843 $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
844
845 # Article or log link
846 if( $rc_log_type ) {
847 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
848 $logname = LogPage::logName( $rc_log_type );
849 $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
850 } else if( !$this->userCan($rcObj,Revision::DELETED_TEXT) ) {
851 $r .= '<span class="history-deleted">' . $rcObj->link . '</span>';
852 } else {
853 $r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched );
854 }
855
856 # Diff and hist links
857 if ( $rc_type != RC_LOG ) {
858 $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'];
859 $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
860 }
861 $r .= ' . . ';
862
863 # Character diff
864 if( $wgRCShowChangedSize ) {
865 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : '&nbsp;' . $rcObj->getCharacterDifference() . ' . . ' ) ;
866 }
867
868 # User/talk
869 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
870
871 # Log action (if any)
872 if( $rc_log_type ) {
873 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
874 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
875 } else {
876 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
877 $this->skin, LogPage::extractParams($rc_params), true, true );
878 }
879 }
880
881 # Edit or log comment
882 if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
883 // log comment
884 if ( $this->isDeleted($rcObj,LogPage::DELETED_COMMENT) ) {
885 $r .= ' <span class="history-deleted">' . wfMsg('rev-deleted-comment') . '</span>';
886 } else {
887 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
888 }
889 }
890
891 # Show how many people are watching this if enabled
892 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
893
894 $r .= "</td></tr></table>\n";
895 return $r;
896 }
897
898 /**
899 * If enhanced RC is in use, this function takes the previously cached
900 * RC lines, arranges them, and outputs the HTML
901 */
902 protected function recentChangesBlock() {
903 if( count ( $this->rc_cache ) == 0 ) {
904 return '';
905 }
906 $blockOut = '';
907 foreach( $this->rc_cache as $block ) {
908 if( count( $block ) < 2 ) {
909 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
910 } else {
911 $blockOut .= $this->recentChangesBlockGroup( $block );
912 }
913 }
914
915 return '<div>'.$blockOut.'</div>';
916 }
917
918 /**
919 * Returns text for the end of RC
920 * If enhanced RC is in use, returns pretty much all the text
921 */
922 public function endRecentChangesList() {
923 return $this->recentChangesBlock() . parent::endRecentChangesList();
924 }
925
926 }