(Bug 19725) Do not include suppressed edits in the "View X deleted edits" message...
[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 } elseif( !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 $wgLang;
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 .= $wgLang->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 # LTR/RTL direction mark
594 $s .= $wgLang->getDirMark();
595 # Log action text (if any)
596 $this->insertAction( $s, $rc );
597 # Edit or log comment
598 $this->insertComment( $s, $rc );
599 # Tags
600 $this->insertTags( $s, $rc, $classes );
601 # Rollback
602 $this->insertRollback( $s, $rc );
603 # For subclasses
604 $this->insertExtra( $s, $rc, $classes );
605
606 # How many users watch this page
607 if( $rc->numberofWatchingusers > 0 ) {
608 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
609 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
610 }
611
612 if( $this->watchlist ) {
613 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
614 }
615
616 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
617
618 wfProfileOut( __METHOD__ );
619 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
620 }
621 }
622
623
624 /**
625 * Generate a list of changes using an Enhanced system (uses javascript).
626 */
627 class EnhancedChangesList extends ChangesList {
628 /**
629 * Add the JavaScript file for enhanced changeslist
630 * @return String
631 */
632 public function beginRecentChangesList() {
633 global $wgOut;
634 $this->rc_cache = array();
635 $this->rcMoveIndex = 0;
636 $this->rcCacheIndex = 0;
637 $this->lastdate = '';
638 $this->rclistOpen = false;
639 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
640 return '';
641 }
642 /**
643 * Format a line for enhanced recentchange (aka with javascript and block of lines).
644 *
645 * @param $baseRC RecentChange
646 * @param $watched bool
647 *
648 * @return string
649 */
650 public function recentChangesLine( &$baseRC, $watched = false ) {
651 global $wgLang, $wgUser;
652
653 wfProfileIn( __METHOD__ );
654
655 # Create a specialised object
656 $rc = RCCacheEntry::newFromParent( $baseRC );
657
658 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
659
660 # If it's a new day, add the headline and flush the cache
661 $date = $wgLang->date( $rc->mAttribs['rc_timestamp'], true );
662 $ret = '';
663 if( $date != $this->lastdate ) {
664 # Process current cache
665 $ret = $this->recentChangesBlock();
666 $this->rc_cache = array();
667 $ret .= Xml::element( 'h4', null, $date ) . "\n";
668 $this->lastdate = $date;
669 }
670
671 # Should patrol-related stuff be shown?
672 if( $wgUser->useRCPatrol() ) {
673 $rc->unpatrolled = !$rc->mAttribs['rc_patrolled'];
674 } else {
675 $rc->unpatrolled = false;
676 }
677
678 $showdifflinks = true;
679 # Make article link
680 $type = $rc->mAttribs['rc_type'];
681 $logType = $rc->mAttribs['rc_log_type'];
682 // Page moves
683 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
684 $msg = ( $type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
685 $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null,
686 array(), array( 'redirect' => 'no' ) ),
687 $this->skin->linkKnown( $rc->getMovedToTitle() ) );
688 // New unpatrolled pages
689 } elseif( $rc->unpatrolled && $type == RC_NEW ) {
690 $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(),
691 array( 'rcid' => $rc->mAttribs['rc_id'] ) );
692 // Log entries
693 } elseif( $type == RC_LOG ) {
694 if( $logType ) {
695 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
696 $clink = '(' . $this->skin->linkKnown( $logtitle,
697 LogPage::logName( $logType ) ) . ')';
698 } else {
699 $clink = $this->skin->link( $rc->getTitle() );
700 }
701 $watched = false;
702 // Log entries (old format) and special pages
703 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
704 list( $specialName, $logtype ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
705 if ( $specialName == 'Log' ) {
706 # Log updates, etc
707 $logname = LogPage::logName( $logtype );
708 $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')';
709 } else {
710 wfDebug( "Unexpected special page in recentchanges\n" );
711 $clink = '';
712 }
713 // Edits
714 } else {
715 $clink = $this->skin->linkKnown( $rc->getTitle() );
716 }
717
718 # Don't show unusable diff links
719 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
720 $showdifflinks = false;
721 }
722
723 $time = $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true );
724 $rc->watched = $watched;
725 $rc->link = $clink;
726 $rc->timestamp = $time;
727 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
728
729 # Make "cur" and "diff" links. Do not use link(), it is too slow if
730 # called too many times (50% of CPU time on RecentChanges!).
731 $thisOldid = $rc->mAttribs['rc_this_oldid'];
732 $lastOldid = $rc->mAttribs['rc_last_oldid'];
733 if( $rc->unpatrolled ) {
734 $rcIdQuery = array( 'rcid' => $rc->mAttribs['rc_id'] );
735 } else {
736 $rcIdQuery = array();
737 }
738 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
739 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' =>
740 $lastOldid ) + $rcIdQuery;
741
742 if( !$showdifflinks ) {
743 $curLink = $this->message['cur'];
744 $diffLink = $this->message['diff'];
745 } elseif( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
746 if ( $type != RC_NEW ) {
747 $curLink = $this->message['cur'];
748 } else {
749 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
750 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
751 }
752 $diffLink = $this->message['diff'];
753 } else {
754 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
755 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
756 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
757 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
758 }
759
760 # Make "last" link
761 if( !$showdifflinks || !$lastOldid ) {
762 $lastLink = $this->message['last'];
763 } elseif( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
764 $lastLink = $this->message['last'];
765 } else {
766 $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'],
767 array(), $curIdEq + array('diff' => $thisOldid, 'oldid' => $lastOldid) + $rcIdQuery );
768 }
769
770 # Make user links
771 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
772 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
773 } else {
774 $rc->userlink = $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
775 $rc->usertalklink = $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
776 }
777
778 $rc->lastlink = $lastLink;
779 $rc->curlink = $curLink;
780 $rc->difflink = $diffLink;
781
782 # Put accumulated information into the cache, for later display
783 # Page moves go on their own line
784 $title = $rc->getTitle();
785 $secureName = $title->getPrefixedDBkey();
786 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
787 # Use an @ character to prevent collision with page names
788 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
789 } else {
790 # Logs are grouped by type
791 if( $type == RC_LOG ){
792 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
793 }
794 if( !isset( $this->rc_cache[$secureName] ) ) {
795 $this->rc_cache[$secureName] = array();
796 }
797
798 array_push( $this->rc_cache[$secureName], $rc );
799 }
800
801 wfProfileOut( __METHOD__ );
802
803 return $ret;
804 }
805
806 /**
807 * Enhanced RC group
808 */
809 protected function recentChangesBlockGroup( $block ) {
810 global $wgLang, $wgRCShowChangedSize;
811
812 wfProfileIn( __METHOD__ );
813
814 # Add the namespace and title of the block as part of the class
815 if ( $block[0]->mAttribs['rc_log_type'] ) {
816 # Log entry
817 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
818 } else {
819 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
820 }
821 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
822 Html::openElement( 'tr' );
823
824 # Collate list of users
825 $userlinks = array();
826 # Other properties
827 $unpatrolled = false;
828 $isnew = false;
829 $curId = $currentRevision = 0;
830 # Some catalyst variables...
831 $namehidden = true;
832 $allLogs = true;
833 foreach( $block as $rcObj ) {
834 $oldid = $rcObj->mAttribs['rc_last_oldid'];
835 if( $rcObj->mAttribs['rc_new'] ) {
836 $isnew = true;
837 }
838 // If all log actions to this page were hidden, then don't
839 // give the name of the affected page for this block!
840 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
841 $namehidden = false;
842 }
843 $u = $rcObj->userlink;
844 if( !isset( $userlinks[$u] ) ) {
845 $userlinks[$u] = 0;
846 }
847 if( $rcObj->unpatrolled ) {
848 $unpatrolled = true;
849 }
850 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
851 $allLogs = false;
852 }
853 # Get the latest entry with a page_id and oldid
854 # since logs may not have these.
855 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
856 $curId = $rcObj->mAttribs['rc_cur_id'];
857 }
858 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
859 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
860 }
861
862 $bot = $rcObj->mAttribs['rc_bot'];
863 $userlinks[$u]++;
864 }
865
866 # Sort the list and convert to text
867 krsort( $userlinks );
868 asort( $userlinks );
869 $users = array();
870 foreach( $userlinks as $userlink => $count) {
871 $text = $userlink;
872 $text .= $wgLang->getDirMark();
873 if( $count > 1 ) {
874 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
875 }
876 array_push( $users, $text );
877 }
878
879 $users = ' <span class="changedby">[' .
880 implode( $this->message['semicolon-separator'], $users ) . ']</span>';
881
882 # Title for <a> tags
883 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
884 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
885
886 $tl = "<span class='mw-collapsible-toggle'>"
887 . "<span class='mw-rc-openarrow'>"
888 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
889 . "</span><span class='mw-rc-closearrow'>"
890 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
891 . "</span></span>";
892 $r .= "<td>$tl</td>";
893
894 # Main line
895 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
896 'newpage' => $isnew,
897 'minor' => false,
898 'unpatrolled' => $unpatrolled,
899 'bot' => $bot ,
900 ) );
901
902 # Timestamp
903 $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td>';
904
905 # Article link
906 if( $namehidden ) {
907 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
908 } elseif( $allLogs ) {
909 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
910 } else {
911 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
912 }
913
914 $r .= $wgLang->getDirMark();
915
916 $queryParams['curid'] = $curId;
917 # Changes message
918 $n = count($block);
919 static $nchanges = array();
920 if ( !isset( $nchanges[$n] ) ) {
921 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
922 }
923 # Total change link
924 $r .= ' ';
925 if( !$allLogs ) {
926 $r .= '(';
927 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) {
928 $r .= $nchanges[$n];
929 } elseif( $isnew ) {
930 $r .= $nchanges[$n];
931 } else {
932 $params = $queryParams;
933 $params['diff'] = $currentRevision;
934 $params['oldid'] = $oldid;
935
936 $r .= $this->skin->link(
937 $block[0]->getTitle(),
938 $nchanges[$n],
939 array(),
940 $params,
941 array( 'known', 'noclasses' )
942 );
943 }
944 }
945
946 # History
947 if( $allLogs ) {
948 // don't show history link for logs
949 } elseif( $namehidden || !$block[0]->getTitle()->exists() ) {
950 $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')';
951 } else {
952 $params = $queryParams;
953 $params['action'] = 'history';
954
955 $r .= $this->message['pipe-separator'] .
956 $this->skin->link(
957 $block[0]->getTitle(),
958 $this->message['hist'],
959 array(),
960 $params,
961 array( 'known', 'noclasses' )
962 ) . ')';
963 }
964 $r .= ' . . ';
965
966 # Character difference (does not apply if only log items)
967 if( $wgRCShowChangedSize && !$allLogs ) {
968 $last = 0;
969 $first = count($block) - 1;
970 # Some events (like logs) have an "empty" size, so we need to skip those...
971 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
972 $last++;
973 }
974 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
975 $first--;
976 }
977 # Get net change
978 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
979 $block[$last]->mAttribs['rc_new_len'] );
980
981 if( $chardiff == '' ) {
982 $r .= ' ';
983 } else {
984 $r .= ' ' . $chardiff. ' . . ';
985 }
986 }
987
988 $r .= $users;
989 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
990
991 # Sub-entries
992 foreach( $block as $rcObj ) {
993 # Classes to apply -- TODO implement
994 $classes = array();
995 $type = $rcObj->mAttribs['rc_type'];
996
997 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
998 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
999 $r .= $this->recentChangesFlags( array(
1000 'newpage' => $rcObj->mAttribs['rc_new'],
1001 'minor' => $rcObj->mAttribs['rc_minor'],
1002 'unpatrolled' => $rcObj->unpatrolled,
1003 'bot' => $rcObj->mAttribs['rc_bot'],
1004 ) );
1005 $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1006
1007 $params = $queryParams;
1008
1009 if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
1010 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
1011 }
1012
1013 # Log timestamp
1014 if( $type == RC_LOG ) {
1015 $link = $rcObj->timestamp;
1016 # Revision link
1017 } elseif( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
1018 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
1019 } else {
1020 if ( $rcObj->unpatrolled && $type == RC_NEW) {
1021 $params['rcid'] = $rcObj->mAttribs['rc_id'];
1022 }
1023
1024 $link = $this->skin->link(
1025 $rcObj->getTitle(),
1026 $rcObj->timestamp,
1027 array(),
1028 $params,
1029 array( 'known', 'noclasses' )
1030 );
1031 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
1032 $link = '<span class="history-deleted">'.$link.'</span> ';
1033 }
1034 $r .= $link . '</span>';
1035
1036 if ( !$type == RC_LOG || $type == RC_NEW ) {
1037 $r .= ' (';
1038 $r .= $rcObj->curlink;
1039 $r .= $this->message['pipe-separator'];
1040 $r .= $rcObj->lastlink;
1041 $r .= ')';
1042 }
1043 $r .= ' . . ';
1044
1045 # Character diff
1046 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1047 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1048 }
1049
1050 # User links
1051 $r .= $rcObj->userlink;
1052 $r .= $rcObj->usertalklink;
1053 // log action
1054 $this->insertAction( $r, $rcObj );
1055 // log comment
1056 $this->insertComment( $r, $rcObj );
1057 # Rollback
1058 $this->insertRollback( $r, $rcObj );
1059 # Tags
1060 $this->insertTags( $r, $rcObj, $classes );
1061
1062 $r .= "</td></tr>\n";
1063 }
1064 $r .= "</table>\n";
1065
1066 $this->rcCacheIndex++;
1067
1068 wfProfileOut( __METHOD__ );
1069
1070 return $r;
1071 }
1072
1073 /**
1074 * Generate HTML for an arrow or placeholder graphic
1075 * @param $dir String: one of '', 'd', 'l', 'r'
1076 * @param $alt String: text
1077 * @param $title String: text
1078 * @return String: HTML <img> tag
1079 */
1080 protected function arrow( $dir, $alt='', $title='' ) {
1081 global $wgStylePath;
1082 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1083 $encAlt = htmlspecialchars( $alt );
1084 $encTitle = htmlspecialchars( $title );
1085 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1086 }
1087
1088 /**
1089 * Generate HTML for a right- or left-facing arrow,
1090 * depending on language direction.
1091 * @return String: HTML <img> tag
1092 */
1093 protected function sideArrow() {
1094 global $wgContLang;
1095 $dir = $wgContLang->isRTL() ? 'l' : 'r';
1096 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1097 }
1098
1099 /**
1100 * Generate HTML for a down-facing arrow
1101 * depending on language direction.
1102 * @return String: HTML <img> tag
1103 */
1104 protected function downArrow() {
1105 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1106 }
1107
1108 /**
1109 * Generate HTML for a spacer image
1110 * @return String: HTML <img> tag
1111 */
1112 protected function spacerArrow() {
1113 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1114 }
1115
1116 /**
1117 * Enhanced RC ungrouped line.
1118 *
1119 * @param $rcObj RecentChange
1120 * @return String: a HTML formated line (generated using $r)
1121 */
1122 protected function recentChangesBlockLine( $rcObj ) {
1123 global $wgRCShowChangedSize;
1124
1125 wfProfileIn( __METHOD__ );
1126 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
1127
1128 $type = $rcObj->mAttribs['rc_type'];
1129 $logType = $rcObj->mAttribs['rc_log_type'];
1130 if( $logType ) {
1131 # Log entry
1132 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs['rc_title'] );
1133 } else {
1134 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
1135 }
1136 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
1137 Html::openElement( 'tr' );
1138
1139 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1140 # Flag and Timestamp
1141 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
1142 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1143 } else {
1144 $r .= $this->recentChangesFlags( array(
1145 'newpage' => $type == RC_NEW,
1146 'mino' => $rcObj->mAttribs['rc_minor'],
1147 'unpatrolled' => $rcObj->unpatrolled,
1148 'bot' => $rcObj->mAttribs['rc_bot'],
1149 ) );
1150 }
1151 $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td>';
1152 # Article or log link
1153 if( $logType ) {
1154 $logtitle = Title::newFromText( "Log/$logType", NS_SPECIAL );
1155 $logname = LogPage::logName( $logType );
1156 $r .= '(' . $this->skin->link(
1157 $logtitle,
1158 $logname,
1159 array(),
1160 array(),
1161 array( 'known', 'noclasses' )
1162 ) . ')';
1163 } else {
1164 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1165 }
1166 # Diff and hist links
1167 if ( $type != RC_LOG ) {
1168 $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator'];
1169 $query['action'] = 'history';
1170 $r .= $this->skin->link(
1171 $rcObj->getTitle(),
1172 $this->message['hist'],
1173 array(),
1174 $query,
1175 array( 'known', 'noclasses' )
1176 ) . ')';
1177 }
1178 $r .= ' . . ';
1179 # Character diff
1180 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1181 $r .= "$cd . . ";
1182 }
1183 # User/talk
1184 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1185 # Log action (if any)
1186 if( $logType ) {
1187 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
1188 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1189 } else {
1190 $r .= ' ' . LogPage::actionText( $logType, $rcObj->mAttribs['rc_log_action'], $rcObj->getTitle(),
1191 $this->skin, LogPage::extractParams( $rcObj->mAttribs['rc_params'] ), true, true );
1192 }
1193 }
1194 $this->insertComment( $r, $rcObj );
1195 $this->insertRollback( $r, $rcObj );
1196 # Tags
1197 $classes = explode( ' ', $classes );
1198 $this->insertTags( $r, $rcObj, $classes );
1199 # Show how many people are watching this if enabled
1200 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
1201
1202 $r .= "</td></tr></table>\n";
1203
1204 wfProfileOut( __METHOD__ );
1205
1206 return $r;
1207 }
1208
1209 /**
1210 * If enhanced RC is in use, this function takes the previously cached
1211 * RC lines, arranges them, and outputs the HTML
1212 *
1213 * @return string
1214 */
1215 protected function recentChangesBlock() {
1216 if( count ( $this->rc_cache ) == 0 ) {
1217 return '';
1218 }
1219
1220 wfProfileIn( __METHOD__ );
1221
1222 $blockOut = '';
1223 foreach( $this->rc_cache as $block ) {
1224 if( count( $block ) < 2 ) {
1225 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1226 } else {
1227 $blockOut .= $this->recentChangesBlockGroup( $block );
1228 }
1229 }
1230
1231 wfProfileOut( __METHOD__ );
1232
1233 return '<div>'.$blockOut.'</div>';
1234 }
1235
1236 /**
1237 * Returns text for the end of RC
1238 * If enhanced RC is in use, returns pretty much all the text
1239 */
1240 public function endRecentChangesList() {
1241 return $this->recentChangesBlock() . parent::endRecentChangesList();
1242 }
1243
1244 }