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