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