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