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