Fix warning from r72349, $script is no longer used.
[lhc/web/wiklou.git] / includes / ChangesList.php
1 <?php
2 /**
3 * Classes to show various lists of changes:
4 * - what links here
5 * - related changes
6 * - recent changes
7 *
8 * @file
9 */
10
11 /**
12 * @todo document
13 */
14 class RCCacheEntry extends RecentChange {
15 var $secureName, $link;
16 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
17 var $userlink, $timestamp, $watched;
18
19 static function newFromParent( $rc ) {
20 $rc2 = new RCCacheEntry;
21 $rc2->mAttribs = $rc->mAttribs;
22 $rc2->mExtra = $rc->mExtra;
23 return $rc2;
24 }
25 }
26
27 /**
28 * Base class for all changes lists
29 */
30 class ChangesList {
31 public $skin;
32 protected $watchlist = false;
33
34 /**
35 * Changeslist contructor
36 * @param $skin Skin
37 */
38 public function __construct( $skin ) {
39 $this->skin = $skin;
40 $this->preCacheMessages();
41 }
42
43 /**
44 * Fetch an appropriate changes list class for the specified user
45 * Some users might want to use an enhanced list format, for instance
46 *
47 * @param $user User to fetch the list class for
48 * @return ChangesList derivative
49 */
50 public static function newFromUser( &$user ) {
51 global $wgRequest;
52
53 $sk = $user->getSkin();
54 $list = null;
55 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
56 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
57 return $new ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
58 } else {
59 return $list;
60 }
61 }
62
63 /**
64 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
65 * @param $value Boolean
66 */
67 public function setWatchlistDivs( $value = true ) {
68 $this->watchlist = $value;
69 }
70
71 /**
72 * As we use the same small set of messages in various methods and that
73 * they are called often, we call them once and save them in $this->message
74 */
75 private function preCacheMessages() {
76 if( !isset( $this->message ) ) {
77 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
78 'semicolon-separator pipe-separator' ) as $msg ) {
79 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
80 }
81 }
82 }
83
84
85 /**
86 * Returns the appropriate flags for new page, minor change and patrolling
87 * @param $new Boolean
88 * @param $minor Boolean
89 * @param $patrolled Boolean
90 * @param $nothing String to use for empty space
91 * @param $bot Boolean
92 * @return String
93 */
94 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&#160;', $bot = false ) {
95 $f = $new ? self::flag( 'newpage' ) : $nothing;
96 $f .= $minor ? self::flag( 'minor' ) : $nothing;
97 $f .= $bot ? self::flag( 'bot' ) : $nothing;
98 $f .= $patrolled ? self::flag( 'unpatrolled' ) : $nothing;
99 return $f;
100 }
101
102 /**
103 * Provide the <abbr> element appropriate to a given abbreviated flag,
104 * namely the flag indicating a new page, a minor edit, a bot edit, or an
105 * unpatrolled edit. By default in English it will contain "N", "m", "b",
106 * "!" respectively, plus it will have an appropriate title and class.
107 *
108 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
109 * @return String: Raw HTML
110 */
111 public static function flag( $key ) {
112 static $messages = null;
113 if ( is_null( $messages ) ) {
114 foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' .
115 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' .
116 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) {
117 $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' );
118 }
119 }
120 # Inconsistent naming, bleh
121 if ( $key == 'newpage' || $key == 'unpatrolled' ) {
122 $key2 = $key;
123 } else {
124 $key2 = $key . 'edit';
125 }
126 return "<abbr class=\"$key\" title=\""
127 . $messages["recentchanges-label-$key"] . "\">"
128 . $messages["${key2}letter"]
129 . '</abbr>';
130 }
131
132 /**
133 * Some explanatory wrapper text for the given flag, to be used in a legend
134 * explaining what the flags mean. For instance, "N - new page". See
135 * also flag().
136 *
137 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
138 * @return String: Raw HTML
139 */
140 private static function flagLine( $key ) {
141 return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities',
142 'replaceafter' ), self::flag( $key ) );
143 }
144
145 /**
146 * A handy legend to tell users what the little "m", "b", and so on mean.
147 *
148 * @return String: Raw HTML
149 */
150 public static function flagLegend() {
151 global $wgGroupPermissions, $wgLang;
152
153 $flags = array( self::flagLine( 'newpage' ),
154 self::flagLine( 'minor' ) );
155
156 # Don't show info on bot edits unless there's a bot group of some kind
157 foreach ( $wgGroupPermissions as $rights ) {
158 if ( isset( $rights['bot'] ) && $rights['bot'] ) {
159 $flags[] = self::flagLine( 'bot' );
160 break;
161 }
162 }
163
164 if ( self::usePatrol() ) {
165 $flags[] = self::flagLine( 'unpatrolled' );
166 }
167
168 return '<div class="mw-rc-label-legend">' .
169 wfMsgExt( 'recentchanges-label-legend', 'parseinline',
170 $wgLang->commaList( $flags ) ) . '</div>';
171 }
172
173 /**
174 * Returns text for the start of the tabular part of RC
175 * @return String
176 */
177 public function beginRecentChangesList() {
178 $this->rc_cache = array();
179 $this->rcMoveIndex = 0;
180 $this->rcCacheIndex = 0;
181 $this->lastdate = '';
182 $this->rclistOpen = false;
183 return '';
184 }
185
186 /**
187 * Show formatted char difference
188 * @param $old Integer: bytes
189 * @param $new Integer: bytes
190 * @returns String
191 */
192 public static function showCharacterDifference( $old, $new ) {
193 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
194 $szdiff = $new - $old;
195
196 $code = $wgLang->getCode();
197 static $fastCharDiff = array();
198 if ( !isset($fastCharDiff[$code]) ) {
199 $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1';
200 }
201
202 $formatedSize = $wgLang->formatNum($szdiff);
203
204 if ( !$fastCharDiff[$code] ) {
205 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
206 }
207
208 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
209 $tag = 'strong';
210 } else {
211 $tag = 'span';
212 }
213 if( $szdiff === 0 ) {
214 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
215 } elseif( $szdiff > 0 ) {
216 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
217 } else {
218 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
219 }
220 }
221
222 /**
223 * Returns text for the end of RC
224 * @return String
225 */
226 public function endRecentChangesList() {
227 if( $this->rclistOpen ) {
228 return "</ul>\n";
229 } else {
230 return '';
231 }
232 }
233
234 public function insertMove( &$s, $rc ) {
235 # Diff
236 $s .= '(' . $this->message['diff'] . ') (';
237 # Hist
238 $s .= $this->skin->link(
239 $rc->getMovedToTitle(),
240 $this->message['hist'],
241 array(),
242 array( 'action' => 'history' ),
243 array( 'known', 'noclasses' )
244 ) . ') . . ';
245 # "[[x]] moved to [[y]]"
246 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
247 $s .= wfMsg(
248 $msg,
249 $this->skin->link(
250 $rc->getTitle(),
251 null,
252 array(),
253 array( 'redirect' => 'no' ),
254 array( 'known', 'noclasses' )
255 ),
256 $this->skin->link(
257 $rc->getMovedToTitle(),
258 null,
259 array(),
260 array(),
261 array( 'known', 'noclasses' )
262 )
263 );
264 }
265
266 public function insertDateHeader( &$s, $rc_timestamp ) {
267 global $wgLang;
268 # Make date header if necessary
269 $date = $wgLang->date( $rc_timestamp, true, true );
270 if( $date != $this->lastdate ) {
271 if( $this->lastdate != '' ) {
272 $s .= "</ul>\n";
273 }
274 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
275 $this->lastdate = $date;
276 $this->rclistOpen = true;
277 }
278 }
279
280 public function insertLog( &$s, $title, $logtype ) {
281 $logname = LogPage::logName( $logtype );
282 $s .= '(' . $this->skin->link(
283 $title,
284 $logname,
285 array(),
286 array(),
287 array( 'known', 'noclasses' )
288 ) . ')';
289 }
290
291 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
292 # Diff link
293 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
294 $diffLink = $this->message['diff'];
295 } else if( !self::userCan($rc,Revision::DELETED_TEXT) ) {
296 $diffLink = $this->message['diff'];
297 } else {
298 $query = array(
299 'curid' => $rc->mAttribs['rc_cur_id'],
300 'diff' => $rc->mAttribs['rc_this_oldid'],
301 'oldid' => $rc->mAttribs['rc_last_oldid']
302 );
303
304 if( $unpatrolled ) {
305 $query['rcid'] = $rc->mAttribs['rc_id'];
306 };
307
308 $diffLink = $this->skin->link(
309 $rc->getTitle(),
310 $this->message['diff'],
311 array( 'tabindex' => $rc->counter ),
312 $query,
313 array( 'known', 'noclasses' )
314 );
315 }
316 $s .= '(' . $diffLink . $this->message['pipe-separator'];
317 # History link
318 $s .= $this->skin->link(
319 $rc->getTitle(),
320 $this->message['hist'],
321 array(),
322 array(
323 'curid' => $rc->mAttribs['rc_cur_id'],
324 'action' => 'history'
325 ),
326 array( 'known', 'noclasses' )
327 );
328 $s .= ') . . ';
329 }
330
331 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
332 global $wgContLang;
333 # If it's a new article, there is no diff link, but if it hasn't been
334 # patrolled yet, we need to give users a way to do so
335 $params = array();
336
337 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) {
338 $params['rcid'] = $rc->mAttribs['rc_id'];
339 }
340
341 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
342 $articlelink = $this->skin->link(
343 $rc->getTitle(),
344 null,
345 array(),
346 $params,
347 array( 'known', 'noclasses' )
348 );
349 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
350 } else {
351 $articlelink = ' '. $this->skin->link(
352 $rc->getTitle(),
353 null,
354 array(),
355 $params,
356 array( 'known', 'noclasses' )
357 );
358 }
359 # Bolden pages watched by this user
360 if( $watched ) {
361 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
362 }
363 # RTL/LTR marker
364 $articlelink .= $wgContLang->getDirMark();
365
366 wfRunHooks( 'ChangesListInsertArticleLink',
367 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
368
369 $s .= " $articlelink";
370 }
371
372 public function insertTimestamp( &$s, $rc ) {
373 global $wgLang;
374 $s .= $this->message['semicolon-separator'] .
375 $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
376 }
377
378 /** Insert links to user page, user talk page and eventually a blocking link */
379 public function insertUserRelatedLinks( &$s, &$rc ) {
380 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
381 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
382 } else {
383 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
384 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
385 }
386 }
387
388 /** insert a formatted action */
389 public function insertAction( &$s, &$rc ) {
390 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
391 if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) {
392 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
393 } else {
394 $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
395 $rc->getTitle(), $this->skin, LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true );
396 }
397 }
398 }
399
400 /** insert a formatted comment */
401 public function insertComment( &$s, &$rc ) {
402 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
403 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
404 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
405 } else {
406 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
407 }
408 }
409 }
410
411 /**
412 * Check whether to enable recent changes patrol features
413 * @return Boolean
414 */
415 public static function usePatrol() {
416 global $wgUser;
417 return $wgUser->useRCPatrol();
418 }
419
420 /**
421 * Returns the string which indicates the number of watching users
422 */
423 protected function numberofWatchingusers( $count ) {
424 global $wgLang;
425 static $cache = array();
426 if( $count > 0 ) {
427 if( !isset( $cache[$count] ) ) {
428 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
429 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
430 }
431 return $cache[$count];
432 } else {
433 return '';
434 }
435 }
436
437 /**
438 * Determine if said field of a revision is hidden
439 * @param $rc RCCacheEntry
440 * @param $field Integer: one of DELETED_* bitfield constants
441 * @return Boolean
442 */
443 public static function isDeleted( $rc, $field ) {
444 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
445 }
446
447 /**
448 * Determine if the current user is allowed to view a particular
449 * field of this revision, if it's marked as deleted.
450 * @param $rc RCCacheEntry
451 * @param $field Integer
452 * @return Boolean
453 */
454 public static function userCan( $rc, $field ) {
455 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
456 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field );
457 } else {
458 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field );
459 }
460 }
461
462 protected function maybeWatchedLink( $link, $watched = false ) {
463 if( $watched ) {
464 return '<strong class="mw-watched">' . $link . '</strong>';
465 } else {
466 return '<span class="mw-rc-unwatched">' . $link . '</span>';
467 }
468 }
469
470 /** Inserts a rollback link */
471 public function insertRollback( &$s, &$rc ) {
472 global $wgUser;
473 if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
474 $page = $rc->getTitle();
475 /** Check for rollback and edit permissions, disallow special pages, and only
476 * show a link on the top-most revision */
477 if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
478 {
479 $rev = new Revision( array(
480 'id' => $rc->mAttribs['rc_this_oldid'],
481 'user' => $rc->mAttribs['rc_user'],
482 'user_text' => $rc->mAttribs['rc_user_text'],
483 'deleted' => $rc->mAttribs['rc_deleted']
484 ) );
485 $rev->setTitle( $page );
486 $s .= ' '.$this->skin->generateRollback( $rev );
487 }
488 }
489 }
490
491 public function insertTags( &$s, &$rc, &$classes ) {
492 if ( empty($rc->mAttribs['ts_tags']) )
493 return;
494
495 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
496 $classes = array_merge( $classes, $newClasses );
497 $s .= ' ' . $tagSummary;
498 }
499
500 public function insertExtra( &$s, &$rc, &$classes ) {
501 ## Empty, used for subclassers to add anything special.
502 }
503 }
504
505
506 /**
507 * Generate a list of changes using the good old system (no javascript)
508 */
509 class OldChangesList extends ChangesList {
510 /**
511 * Format a line using the old system (aka without any javascript).
512 */
513 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
514 global $wgLang, $wgRCShowChangedSize, $wgUser;
515 wfProfileIn( __METHOD__ );
516 # Should patrol-related stuff be shown?
517 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
518
519 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
520 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
521
522 $s = '';
523 $classes = array();
524 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
525 if( $linenumber ) {
526 if( $linenumber & 1 ) {
527 $classes[] = 'mw-line-odd';
528 }
529 else {
530 $classes[] = 'mw-line-even';
531 }
532 }
533
534 // Moved pages
535 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
536 $this->insertMove( $s, $rc );
537 // Log entries
538 } elseif( $rc->mAttribs['rc_log_type'] ) {
539 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
540 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
541 // Log entries (old format) or log targets, and special pages
542 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
543 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] );
544 if( $name == 'Log' ) {
545 $this->insertLog( $s, $rc->getTitle(), $subpage );
546 }
547 // Regular entries
548 } else {
549 $this->insertDiffHist( $s, $rc, $unpatrolled );
550 # M, N, b and ! (minor, new, bot and unpatrolled)
551 $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'],
552 $unpatrolled, '', $rc->mAttribs['rc_bot'] );
553 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
554 }
555 # Edit/log timestamp
556 $this->insertTimestamp( $s, $rc );
557 # Bytes added or removed
558 if( $wgRCShowChangedSize ) {
559 $cd = $rc->getCharacterDifference();
560 if( $cd != '' ) {
561 $s .= "$cd . . ";
562 }
563 }
564 # User tool links
565 $this->insertUserRelatedLinks( $s, $rc );
566 # Log action text (if any)
567 $this->insertAction( $s, $rc );
568 # Edit or log comment
569 $this->insertComment( $s, $rc );
570 # Tags
571 $this->insertTags( $s, $rc, $classes );
572 # Rollback
573 $this->insertRollback( $s, $rc );
574 # For subclasses
575 $this->insertExtra( $s, $rc, $classes );
576
577 # How many users watch this page
578 if( $rc->numberofWatchingusers > 0 ) {
579 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
580 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
581 }
582
583 if( $this->watchlist ) {
584 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
585 }
586
587 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
588
589 wfProfileOut( __METHOD__ );
590 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
591 }
592 }
593
594
595 /**
596 * Generate a list of changes using an Enhanced system (uses javascript).
597 */
598 class EnhancedChangesList extends ChangesList {
599 /**
600 * Add the JavaScript file for enhanced changeslist
601 * @return String
602 */
603 public function beginRecentChangesList() {
604 global $wgOut;
605 $this->rc_cache = array();
606 $this->rcMoveIndex = 0;
607 $this->rcCacheIndex = 0;
608 $this->lastdate = '';
609 $this->rclistOpen = false;
610 $wgOut->addModules( 'mediawiki.legacy.enhancedchanges' );
611 return '';
612 }
613 /**
614 * Format a line for enhanced recentchange (aka with javascript and block of lines).
615 */
616 public function recentChangesLine( &$baseRC, $watched = false ) {
617 global $wgLang, $wgUser;
618
619 wfProfileIn( __METHOD__ );
620
621 # Create a specialised object
622 $rc = RCCacheEntry::newFromParent( $baseRC );
623
624 # Extract fields from DB into the function scope (rc_xxxx variables)
625 // FIXME: Would be good to replace this extract() call with something
626 // that explicitly initializes variables.
627 extract( $rc->mAttribs );
628 $curIdEq = array( 'curid' => $rc_cur_id );
629
630 # If it's a new day, add the headline and flush the cache
631 $date = $wgLang->date( $rc_timestamp, true );
632 $ret = '';
633 if( $date != $this->lastdate ) {
634 # Process current cache
635 $ret = $this->recentChangesBlock();
636 $this->rc_cache = array();
637 $ret .= Xml::element( 'h4', null, $date );
638 $this->lastdate = $date;
639 }
640
641 # Should patrol-related stuff be shown?
642 if( $wgUser->useRCPatrol() ) {
643 $rc->unpatrolled = !$rc_patrolled;
644 } else {
645 $rc->unpatrolled = false;
646 }
647
648 $showdifflinks = true;
649 # Make article link
650 // Page moves
651 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
652 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
653 $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null,
654 array(), array( 'redirect' => 'no' ) ),
655 $this->skin->linkKnown( $rc->getMovedToTitle() ) );
656 // New unpatrolled pages
657 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
658 $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(),
659 array( 'rcid' => $rc_id ) );
660 // Log entries
661 } else if( $rc_type == RC_LOG ) {
662 if( $rc_log_type ) {
663 $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
664 $clink = '(' . $this->skin->linkKnown( $logtitle,
665 LogPage::logName($rc_log_type) ) . ')';
666 } else {
667 $clink = $this->skin->link( $rc->getTitle() );
668 }
669 $watched = false;
670 // Log entries (old format) and special pages
671 } elseif( $rc_namespace == NS_SPECIAL ) {
672 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
673 if ( $specialName == 'Log' ) {
674 # Log updates, etc
675 $logname = LogPage::logName( $logtype );
676 $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')';
677 } else {
678 wfDebug( "Unexpected special page in recentchanges\n" );
679 $clink = '';
680 }
681 // Edits
682 } else {
683 $clink = $this->skin->linkKnown( $rc->getTitle() );
684 }
685
686 # Don't show unusable diff links
687 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
688 $showdifflinks = false;
689 }
690
691 $time = $wgLang->time( $rc_timestamp, true, true );
692 $rc->watched = $watched;
693 $rc->link = $clink;
694 $rc->timestamp = $time;
695 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
696
697 # Make "cur" and "diff" links. Do not use link(), it is too slow if
698 # called too many times (50% of CPU time on RecentChanges!).
699 if( $rc->unpatrolled ) {
700 $rcIdQuery = array( 'rcid' => $rc_id );
701 } else {
702 $rcIdQuery = array();
703 }
704 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $rc_this_oldid );
705 $querydiff = $curIdEq + array( 'diff' => $rc_this_oldid, 'oldid' =>
706 $rc_last_oldid ) + $rcIdQuery;
707
708 if( !$showdifflinks ) {
709 $curLink = $this->message['cur'];
710 $diffLink = $this->message['diff'];
711 } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) {
712 if ( $rc_type != RC_NEW ) {
713 $curLink = $this->message['cur'];
714 } else {
715 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
716 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
717 }
718 $diffLink = $this->message['diff'];
719 } else {
720 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
721 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
722 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
723 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
724 }
725
726 # Make "last" link
727 if( !$showdifflinks || !$rc_last_oldid ) {
728 $lastLink = $this->message['last'];
729 } else if( $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
730 $lastLink = $this->message['last'];
731 } else {
732 $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'],
733 array(), $curIdEq + array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) + $rcIdQuery );
734 }
735
736 # Make user links
737 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
738 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
739 } else {
740 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
741 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
742 }
743
744 $rc->lastlink = $lastLink;
745 $rc->curlink = $curLink;
746 $rc->difflink = $diffLink;
747
748 # Put accumulated information into the cache, for later display
749 # Page moves go on their own line
750 $title = $rc->getTitle();
751 $secureName = $title->getPrefixedDBkey();
752 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
753 # Use an @ character to prevent collision with page names
754 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
755 } else {
756 # Logs are grouped by type
757 if( $rc_type == RC_LOG ){
758 $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
759 }
760 if( !isset( $this->rc_cache[$secureName] ) ) {
761 $this->rc_cache[$secureName] = array();
762 }
763
764 array_push( $this->rc_cache[$secureName], $rc );
765 }
766
767 wfProfileOut( __METHOD__ );
768
769 return $ret;
770 }
771
772 /**
773 * Enhanced RC group
774 */
775 protected function recentChangesBlockGroup( $block ) {
776 global $wgLang, $wgContLang, $wgRCShowChangedSize;
777
778 wfProfileIn( __METHOD__ );
779
780 $r = '<table class="mw-enhanced-rc"><tr>';
781
782 # Collate list of users
783 $userlinks = array();
784 # Other properties
785 $unpatrolled = false;
786 $isnew = false;
787 $curId = $currentRevision = 0;
788 # Some catalyst variables...
789 $namehidden = true;
790 $allLogs = true;
791 foreach( $block as $rcObj ) {
792 $oldid = $rcObj->mAttribs['rc_last_oldid'];
793 if( $rcObj->mAttribs['rc_new'] ) {
794 $isnew = true;
795 }
796 // If all log actions to this page were hidden, then don't
797 // give the name of the affected page for this block!
798 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
799 $namehidden = false;
800 }
801 $u = $rcObj->userlink;
802 if( !isset( $userlinks[$u] ) ) {
803 $userlinks[$u] = 0;
804 }
805 if( $rcObj->unpatrolled ) {
806 $unpatrolled = true;
807 }
808 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
809 $allLogs = false;
810 }
811 # Get the latest entry with a page_id and oldid
812 # since logs may not have these.
813 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
814 $curId = $rcObj->mAttribs['rc_cur_id'];
815 }
816 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
817 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
818 }
819
820 $bot = $rcObj->mAttribs['rc_bot'];
821 $userlinks[$u]++;
822 }
823
824 # Sort the list and convert to text
825 krsort( $userlinks );
826 asort( $userlinks );
827 $users = array();
828 foreach( $userlinks as $userlink => $count) {
829 $text = $userlink;
830 $text .= $wgContLang->getDirMark();
831 if( $count > 1 ) {
832 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
833 }
834 array_push( $users, $text );
835 }
836
837 $users = ' <span class="changedby">[' .
838 implode( $this->message['semicolon-separator'], $users ) . ']</span>';
839
840 # ID for JS visibility toggle
841 $jsid = $this->rcCacheIndex;
842 # onclick handler to toggle hidden/expanded
843 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
844 # Title for <a> tags
845 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
846 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
847
848 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
849 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
850 $r .= '<td class="mw-enhanced-rc">'.$tl.'&#160;';
851
852 # Main line
853 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&#160;', $bot );
854
855 # Timestamp
856 $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td style="padding:0px;">';
857
858 # Article link
859 if( $namehidden ) {
860 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
861 } else if( $allLogs ) {
862 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
863 } else {
864 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
865 }
866
867 $r .= $wgContLang->getDirMark();
868
869 $queryParams['curid'] = $curId;
870 # Changes message
871 $n = count($block);
872 static $nchanges = array();
873 if ( !isset( $nchanges[$n] ) ) {
874 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
875 }
876 # Total change link
877 $r .= ' ';
878 if( !$allLogs ) {
879 $r .= '(';
880 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) {
881 $r .= $nchanges[$n];
882 } else if( $isnew ) {
883 $r .= $nchanges[$n];
884 } else {
885 $params = $queryParams;
886 $params['diff'] = $currentRevision;
887 $params['oldid'] = $oldid;
888
889 $r .= $this->skin->link(
890 $block[0]->getTitle(),
891 $nchanges[$n],
892 array(),
893 $params,
894 array( 'known', 'noclasses' )
895 );
896 }
897 }
898
899 # History
900 if( $allLogs ) {
901 // don't show history link for logs
902 } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
903 $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')';
904 } else {
905 $params = $queryParams;
906 $params['action'] = 'history';
907
908 $r .= $this->message['pipe-separator'] .
909 $this->skin->link(
910 $block[0]->getTitle(),
911 $this->message['hist'],
912 array(),
913 $params,
914 array( 'known', 'noclasses' )
915 ) . ')';
916 }
917 $r .= ' . . ';
918
919 # Character difference (does not apply if only log items)
920 if( $wgRCShowChangedSize && !$allLogs ) {
921 $last = 0;
922 $first = count($block) - 1;
923 # Some events (like logs) have an "empty" size, so we need to skip those...
924 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
925 $last++;
926 }
927 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
928 $first--;
929 }
930 # Get net change
931 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
932 $block[$last]->mAttribs['rc_new_len'] );
933
934 if( $chardiff == '' ) {
935 $r .= ' ';
936 } else {
937 $r .= ' ' . $chardiff. ' . . ';
938 }
939 }
940
941 $r .= $users;
942 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
943
944 $r .= "</td></tr></table>\n";
945
946 # Sub-entries
947 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
948 $r .= '<table class="mw-enhanced-rc">';
949 foreach( $block as $rcObj ) {
950 # Extract fields from DB into the function scope (rc_xxxx variables)
951 // FIXME: Would be good to replace this extract() call with something
952 // that explicitly initializes variables.
953 # Classes to apply -- TODO implement
954 $classes = array();
955 extract( $rcObj->mAttribs );
956
957 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
958 $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
959 $r .= $this->spacerIndent() . $this->spacerIndent();
960 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&#160;', $rc_bot );
961 $r .= '&#160;</td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
962
963 $params = $queryParams;
964
965 if( $rc_this_oldid != 0 ) {
966 $params['oldid'] = $rc_this_oldid;
967 }
968
969 # Log timestamp
970 if( $rc_type == RC_LOG ) {
971 $link = $rcObj->timestamp;
972 # Revision link
973 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
974 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
975 } else {
976 if ( $rcObj->unpatrolled && $rc_type == RC_NEW) {
977 $params['rcid'] = $rcObj->mAttribs['rc_id'];
978 }
979
980 $link = $this->skin->link(
981 $rcObj->getTitle(),
982 $rcObj->timestamp,
983 array(),
984 $params,
985 array( 'known', 'noclasses' )
986 );
987 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
988 $link = '<span class="history-deleted">'.$link.'</span> ';
989 }
990 $r .= $link . '</span>';
991
992 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
993 $r .= ' (';
994 $r .= $rcObj->curlink;
995 $r .= $this->message['pipe-separator'];
996 $r .= $rcObj->lastlink;
997 $r .= ')';
998 }
999 $r .= ' . . ';
1000
1001 # Character diff
1002 if( $wgRCShowChangedSize ) {
1003 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
1004 }
1005 # User links
1006 $r .= $rcObj->userlink;
1007 $r .= $rcObj->usertalklink;
1008 // log action
1009 $this->insertAction( $r, $rcObj );
1010 // log comment
1011 $this->insertComment( $r, $rcObj );
1012 # Rollback
1013 $this->insertRollback( $r, $rcObj );
1014 # Tags
1015 $this->insertTags( $r, $rcObj, $classes );
1016
1017 $r .= "</td></tr>\n";
1018 }
1019 $r .= "</table></div>\n";
1020
1021 $this->rcCacheIndex++;
1022
1023 wfProfileOut( __METHOD__ );
1024
1025 return $r;
1026 }
1027
1028 /**
1029 * Generate HTML for an arrow or placeholder graphic
1030 * @param $dir String: one of '', 'd', 'l', 'r'
1031 * @param $alt String: text
1032 * @param $title String: text
1033 * @return String: HTML <img> tag
1034 */
1035 protected function arrow( $dir, $alt='', $title='' ) {
1036 global $wgStylePath;
1037 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1038 $encAlt = htmlspecialchars( $alt );
1039 $encTitle = htmlspecialchars( $title );
1040 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1041 }
1042
1043 /**
1044 * Generate HTML for a right- or left-facing arrow,
1045 * depending on language direction.
1046 * @return String: HTML <img> tag
1047 */
1048 protected function sideArrow() {
1049 global $wgContLang;
1050 $dir = $wgContLang->isRTL() ? 'l' : 'r';
1051 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1052 }
1053
1054 /**
1055 * Generate HTML for a down-facing arrow
1056 * depending on language direction.
1057 * @return String: HTML <img> tag
1058 */
1059 protected function downArrow() {
1060 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1061 }
1062
1063 /**
1064 * Generate HTML for a spacer image
1065 * @return String: HTML <img> tag
1066 */
1067 protected function spacerArrow() {
1068 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1069 }
1070
1071 /**
1072 * Add a set of spaces
1073 * @return String: HTML <td> tag
1074 */
1075 protected function spacerIndent() {
1076 return '&#160;&#160;&#160;&#160;&#160;';
1077 }
1078
1079 /**
1080 * Enhanced RC ungrouped line.
1081 * @return String: a HTML formated line (generated using $r)
1082 */
1083 protected function recentChangesBlockLine( $rcObj ) {
1084 global $wgRCShowChangedSize;
1085
1086 wfProfileIn( __METHOD__ );
1087
1088 # Extract fields from DB into the function scope (rc_xxxx variables)
1089 // FIXME: Would be good to replace this extract() call with something
1090 // that explicitly initializes variables.
1091 $classes = array(); // TODO implement
1092 extract( $rcObj->mAttribs );
1093 $query['curid'] = $rc_cur_id;
1094
1095 $r = '<table class="mw-enhanced-rc"><tr>';
1096 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . '&#160;';
1097 # Flag and Timestamp
1098 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1099 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1100 } else {
1101 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&#160;', $rc_bot );
1102 }
1103 $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td style="padding:0px;">';
1104 # Article or log link
1105 if( $rc_log_type ) {
1106 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
1107 $logname = LogPage::logName( $rc_log_type );
1108 $r .= '(' . $this->skin->link(
1109 $logtitle,
1110 $logname,
1111 array(),
1112 array(),
1113 array( 'known', 'noclasses' )
1114 ) . ')';
1115 } else {
1116 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1117 }
1118 # Diff and hist links
1119 if ( $rc_type != RC_LOG ) {
1120 $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator'];
1121 $query['action'] = 'history';
1122 $r .= $this->skin->link(
1123 $rcObj->getTitle(),
1124 $this->message['hist'],
1125 array(),
1126 $query,
1127 array( 'known', 'noclasses' )
1128 ) . ')';
1129 }
1130 $r .= ' . . ';
1131 # Character diff
1132 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1133 $r .= "$cd . . ";
1134 }
1135 # User/talk
1136 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1137 # Log action (if any)
1138 if( $rc_log_type ) {
1139 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
1140 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1141 } else {
1142 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1143 $this->skin, LogPage::extractParams($rc_params), true, true );
1144 }
1145 }
1146 $this->insertComment( $r, $rcObj );
1147 $this->insertRollback( $r, $rcObj );
1148 # Tags
1149 $this->insertTags( $r, $rcObj, $classes );
1150 # Show how many people are watching this if enabled
1151 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
1152
1153 $r .= "</td></tr></table>\n";
1154
1155 wfProfileOut( __METHOD__ );
1156
1157 return $r;
1158 }
1159
1160 /**
1161 * If enhanced RC is in use, this function takes the previously cached
1162 * RC lines, arranges them, and outputs the HTML
1163 */
1164 protected function recentChangesBlock() {
1165 if( count ( $this->rc_cache ) == 0 ) {
1166 return '';
1167 }
1168
1169 wfProfileIn( __METHOD__ );
1170
1171 $blockOut = '';
1172 foreach( $this->rc_cache as $block ) {
1173 if( count( $block ) < 2 ) {
1174 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1175 } else {
1176 $blockOut .= $this->recentChangesBlockGroup( $block );
1177 }
1178 }
1179
1180 wfProfileOut( __METHOD__ );
1181
1182 return '<div>'.$blockOut.'</div>';
1183 }
1184
1185 /**
1186 * Returns text for the end of RC
1187 * If enhanced RC is in use, returns pretty much all the text
1188 */
1189 public function endRecentChangesList() {
1190 return $this->recentChangesBlock() . parent::endRecentChangesList();
1191 }
1192
1193 }