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