Fix for r44775: remove debug line
[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 // New unpatrolled pages
466 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
467 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
468 // Log entries
469 } else if( $rc_type == RC_LOG ) {
470 if( $rc_log_type ) {
471 $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
472 $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle, LogPage::logName($rc_log_type) ) . ')';
473 } else {
474 $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
475 }
476 $watched = false;
477 // Log entries (old format) and special pages
478 } elseif( $rc_namespace == NS_SPECIAL ) {
479 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
480 if ( $specialName == 'Log' ) {
481 # Log updates, etc
482 $logname = LogPage::logName( $logtype );
483 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
484 } else {
485 wfDebug( "Unexpected special page in recentchanges\n" );
486 $clink = '';
487 }
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 if( $allLogs ) {
656 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
657 } else {
658 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
659 }
660
661 $r .= $wgContLang->getDirMark();
662
663 $curIdEq = 'curid=' . $curId;
664 # Changes message
665 $n = count($block);
666 static $nchanges = array();
667 if ( !isset( $nchanges[$n] ) ) {
668 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
669 }
670 # Total change link
671 $r .= ' ';
672 if( !$allLogs ) {
673 $r .= '(';
674 if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
675 $r .= $nchanges[$n];
676 } else if( $isnew ) {
677 $r .= $nchanges[$n];
678 } else {
679 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
680 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
681 }
682 }
683
684 # History
685 if( $allLogs ) {
686 // don't show history link for logs
687 } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
688 $r .= $this->message['semicolon-separator'] . $this->message['hist'] . ')';
689 } else {
690 $r .= $this->message['semicolon-separator'] . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
691 $this->message['hist'], $curIdEq . '&action=history' ) . ')';
692 }
693 $r .= ' . . ';
694
695 # Character difference (does not apply if only log items)
696 if( $wgRCShowChangedSize && !$allLogs ) {
697 $last = 0;
698 $first = count($block) - 1;
699 # Some events (like logs) have an "empty" size, so we need to skip those...
700 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
701 $last++;
702 }
703 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
704 $first--;
705 }
706 # Get net change
707 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
708 $block[$last]->mAttribs['rc_new_len'] );
709
710 if( $chardiff == '' ) {
711 $r .= ' ';
712 } else {
713 $r .= ' ' . $chardiff. ' . . ';
714 }
715 }
716
717 $r .= $users;
718 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
719
720 $r .= "</td></tr></table>\n";
721
722 # Sub-entries
723 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
724 $r .= '<table cellpadding="0" cellspacing="0" border="0" style="background: none">';
725 foreach( $block as $rcObj ) {
726 # Get rc_xxxx variables
727 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
728 extract( $rcObj->mAttribs );
729
730 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
731 $r .= '<tr><td valign="top">';
732 $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
733 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
734 $r .= '&nbsp;</tt></td><td valign="top">';
735
736 $o = '';
737 if( $rc_this_oldid != 0 ) {
738 $o = 'oldid='.$rc_this_oldid;
739 }
740 # Log timestamp
741 if( $rc_type == RC_LOG ) {
742 $link = '<tt>'.$rcObj->timestamp.'</tt> ';
743 # Revision link
744 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
745 $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
746 } else {
747 $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ?
748 '&rcid='.$rcObj->mAttribs['rc_id'] : '';
749 $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(),
750 $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).'</tt>';
751 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
752 $link = '<span class="history-deleted">'.$link.'</span> ';
753 }
754 $r .= $link;
755
756 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
757 $r .= ' (';
758 $r .= $rcObj->curlink;
759 $r .= $this->message['semicolon-separator'];
760 $r .= $rcObj->lastlink;
761 $r .= ')';
762 }
763 $r .= ' . . ';
764
765 # Character diff
766 if( $wgRCShowChangedSize ) {
767 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
768 }
769 # User links
770 $r .= $rcObj->userlink;
771 $r .= $rcObj->usertalklink;
772 // log action
773 parent::insertAction( $r, $rcObj );
774 // log comment
775 parent::insertComment( $r, $rcObj );
776 # Mark revision as deleted
777 if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
778 $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
779 }
780
781 $r .= "</td></tr>\n";
782 }
783 $r .= "</table></div>\n";
784
785 $this->rcCacheIndex++;
786 return $r;
787 }
788
789 /**
790 * Generate HTML for an arrow or placeholder graphic
791 * @param string $dir one of '', 'd', 'l', 'r'
792 * @param string $alt text
793 * @param string $title text
794 * @return string HTML <img> tag
795 */
796 protected function arrow( $dir, $alt='', $title='' ) {
797 global $wgStylePath;
798 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
799 $encAlt = htmlspecialchars( $alt );
800 $encTitle = htmlspecialchars( $title );
801 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
802 }
803
804 /**
805 * Generate HTML for a right- or left-facing arrow,
806 * depending on language direction.
807 * @return string HTML <img> tag
808 */
809 protected function sideArrow() {
810 global $wgContLang;
811 $dir = $wgContLang->isRTL() ? 'l' : 'r';
812 return $this->arrow( $dir, '+', wfMsg('rc-enhanced-expand') );
813 }
814
815 /**
816 * Generate HTML for a down-facing arrow
817 * depending on language direction.
818 * @return string HTML <img> tag
819 */
820 protected function downArrow() {
821 return $this->arrow( 'd', '-', wfMsg('rc-enhanced-hide') );
822 }
823
824 /**
825 * Generate HTML for a spacer image
826 * @return string HTML <img> tag
827 */
828 protected function spacerArrow() {
829 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
830 }
831
832 /**
833 * Add a set of spaces
834 * @return string HTML <td> tag
835 */
836 protected function spacerIndent() {
837 return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
838 }
839
840 /**
841 * Enhanced RC ungrouped line.
842 * @return string a HTML formated line (generated using $r)
843 */
844 protected function recentChangesBlockLine( $rcObj ) {
845 global $wgContLang, $wgRCShowChangedSize;
846 # Get rc_xxxx variables
847 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
848 extract( $rcObj->mAttribs );
849 $curIdEq = "curid={$rc_cur_id}";
850
851 $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
852 $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
853 # Flag and Timestamp
854 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
855 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
856 } else {
857 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
858 }
859 $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
860 # Article or log link
861 if( $rc_log_type ) {
862 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
863 $logname = LogPage::logName( $rc_log_type );
864 $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
865 } else {
866 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
867 }
868 # Diff and hist links
869 if ( $rc_type != RC_LOG ) {
870 $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'];
871 $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
872 }
873 $r .= ' . . ';
874 # Character diff
875 if( $wgRCShowChangedSize ) {
876 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
877 }
878 # User/talk
879 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
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 # Edit or log comment
890 if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
891 // log comment
892 if ( $this->isDeleted($rcObj,LogPage::DELETED_COMMENT) ) {
893 $r .= ' <span class="history-deleted">' . wfMsg('rev-deleted-comment') . '</span>';
894 } else {
895 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
896 }
897 }
898 # Show how many people are watching this if enabled
899 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
900
901 $r .= "</td></tr></table>\n";
902 return $r;
903 }
904
905 /**
906 * If enhanced RC is in use, this function takes the previously cached
907 * RC lines, arranges them, and outputs the HTML
908 */
909 protected function recentChangesBlock() {
910 if( count ( $this->rc_cache ) == 0 ) {
911 return '';
912 }
913 $blockOut = '';
914 foreach( $this->rc_cache as $block ) {
915 if( count( $block ) < 2 ) {
916 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
917 } else {
918 $blockOut .= $this->recentChangesBlockGroup( $block );
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 }