Remove unused global $wgContLang
[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 # If it's a new article, there is no diff link, but if it hasn't been
327 # patrolled yet, we need to give users a way to do so
328 $params = array();
329
330 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) {
331 $params['rcid'] = $rc->mAttribs['rc_id'];
332 }
333
334 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
335 $articlelink = $this->skin->link(
336 $rc->getTitle(),
337 null,
338 array(),
339 $params,
340 array( 'known', 'noclasses' )
341 );
342 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
343 } else {
344 $articlelink = ' '. $this->skin->link(
345 $rc->getTitle(),
346 null,
347 array(),
348 $params,
349 array( 'known', 'noclasses' )
350 );
351 }
352 # Bolden pages watched by this user
353 if( $watched ) {
354 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
355 }
356 # RTL/LTR marker
357 $articlelink .= wfUILang()->getDirMark();
358
359 wfRunHooks( 'ChangesListInsertArticleLink',
360 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
361
362 $s .= " $articlelink";
363 }
364
365 /**
366 * @param $s
367 * @param $rc RecentChange
368 * @return void
369 */
370 public function insertTimestamp( &$s, $rc ) {
371 global $wgLang;
372 $s .= $this->message['semicolon-separator'] .
373 $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
374 }
375
376 /** Insert links to user page, user talk page and eventually a blocking link
377 *
378 * @param $rc RecentChange
379 */
380 public function insertUserRelatedLinks( &$s, &$rc ) {
381 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
382 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
383 } else {
384 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
385 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
386 }
387 }
388
389 /** insert a formatted action
390 *
391 * @param $rc RecentChange
392 */
393 public function insertAction( &$s, &$rc ) {
394 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
395 if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) {
396 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
397 } else {
398 $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
399 $rc->getTitle(), $this->skin, LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true );
400 }
401 }
402 }
403
404 /** insert a formatted comment
405 *
406 * @param $rc RecentChange
407 */
408 public function insertComment( &$s, &$rc ) {
409 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
410 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
411 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
412 } else {
413 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
414 }
415 }
416 }
417
418 /**
419 * Check whether to enable recent changes patrol features
420 * @return Boolean
421 */
422 public static function usePatrol() {
423 global $wgUser;
424 return $wgUser->useRCPatrol();
425 }
426
427 /**
428 * Returns the string which indicates the number of watching users
429 */
430 protected function numberofWatchingusers( $count ) {
431 global $wgLang;
432 static $cache = array();
433 if( $count > 0 ) {
434 if( !isset( $cache[$count] ) ) {
435 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
436 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
437 }
438 return $cache[$count];
439 } else {
440 return '';
441 }
442 }
443
444 /**
445 * Determine if said field of a revision is hidden
446 * @param $rc RCCacheEntry
447 * @param $field Integer: one of DELETED_* bitfield constants
448 * @return Boolean
449 */
450 public static function isDeleted( $rc, $field ) {
451 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
452 }
453
454 /**
455 * Determine if the current user is allowed to view a particular
456 * field of this revision, if it's marked as deleted.
457 * @param $rc RCCacheEntry
458 * @param $field Integer
459 * @return Boolean
460 */
461 public static function userCan( $rc, $field ) {
462 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
463 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field );
464 } else {
465 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field );
466 }
467 }
468
469 protected function maybeWatchedLink( $link, $watched = false ) {
470 if( $watched ) {
471 return '<strong class="mw-watched">' . $link . '</strong>';
472 } else {
473 return '<span class="mw-rc-unwatched">' . $link . '</span>';
474 }
475 }
476
477 /** Inserts a rollback link
478 *
479 * @param $s
480 * @param $rc RecentChange
481 */
482 public function insertRollback( &$s, &$rc ) {
483 global $wgUser;
484 if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
485 $page = $rc->getTitle();
486 /** Check for rollback and edit permissions, disallow special pages, and only
487 * show a link on the top-most revision */
488 if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
489 {
490 $rev = new Revision( array(
491 'id' => $rc->mAttribs['rc_this_oldid'],
492 'user' => $rc->mAttribs['rc_user'],
493 'user_text' => $rc->mAttribs['rc_user_text'],
494 'deleted' => $rc->mAttribs['rc_deleted']
495 ) );
496 $rev->setTitle( $page );
497 $s .= ' '.$this->skin->generateRollback( $rev );
498 }
499 }
500 }
501
502 /**
503 * @param $s
504 * @param $rc RecentChange
505 * @param $classes
506 * @return
507 */
508 public function insertTags( &$s, &$rc, &$classes ) {
509 if ( empty($rc->mAttribs['ts_tags']) )
510 return;
511
512 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
513 $classes = array_merge( $classes, $newClasses );
514 $s .= ' ' . $tagSummary;
515 }
516
517 public function insertExtra( &$s, &$rc, &$classes ) {
518 ## Empty, used for subclassers to add anything special.
519 }
520 }
521
522
523 /**
524 * Generate a list of changes using the good old system (no javascript)
525 */
526 class OldChangesList extends ChangesList {
527 /**
528 * Format a line using the old system (aka without any javascript).
529 *
530 * @param $rc RecentChange
531 */
532 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
533 global $wgLang, $wgRCShowChangedSize, $wgUser;
534 wfProfileIn( __METHOD__ );
535 # Should patrol-related stuff be shown?
536 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
537
538 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
539 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
540
541 $s = '';
542 $classes = array();
543 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
544 if( $linenumber ) {
545 if( $linenumber & 1 ) {
546 $classes[] = 'mw-line-odd';
547 }
548 else {
549 $classes[] = 'mw-line-even';
550 }
551 }
552
553 // Moved pages
554 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
555 $this->insertMove( $s, $rc );
556 // Log entries
557 } elseif( $rc->mAttribs['rc_log_type'] ) {
558 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
559 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
560 // Log entries (old format) or log targets, and special pages
561 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
562 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
563 if( $name == 'Log' ) {
564 $this->insertLog( $s, $rc->getTitle(), $subpage );
565 }
566 // Regular entries
567 } else {
568 $this->insertDiffHist( $s, $rc, $unpatrolled );
569 # M, N, b and ! (minor, new, bot and unpatrolled)
570 $s .= $this->recentChangesFlags(
571 array(
572 'newpage' => $rc->mAttribs['rc_new'],
573 'minor' => $rc->mAttribs['rc_minor'],
574 'unpatrolled' => $unpatrolled,
575 'bot' => $rc->mAttribs['rc_bot']
576 ),
577 ''
578 );
579 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
580 }
581 # Edit/log timestamp
582 $this->insertTimestamp( $s, $rc );
583 # Bytes added or removed
584 if( $wgRCShowChangedSize ) {
585 $cd = $rc->getCharacterDifference();
586 if( $cd != '' ) {
587 $s .= "$cd . . ";
588 }
589 }
590 # User tool links
591 $this->insertUserRelatedLinks( $s, $rc );
592 # Log action text (if any)
593 $this->insertAction( $s, $rc );
594 # Edit or log comment
595 $this->insertComment( $s, $rc );
596 # Tags
597 $this->insertTags( $s, $rc, $classes );
598 # Rollback
599 $this->insertRollback( $s, $rc );
600 # For subclasses
601 $this->insertExtra( $s, $rc, $classes );
602
603 # How many users watch this page
604 if( $rc->numberofWatchingusers > 0 ) {
605 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
606 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
607 }
608
609 if( $this->watchlist ) {
610 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
611 }
612
613 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
614
615 wfProfileOut( __METHOD__ );
616 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
617 }
618 }
619
620
621 /**
622 * Generate a list of changes using an Enhanced system (uses javascript).
623 */
624 class EnhancedChangesList extends ChangesList {
625 /**
626 * Add the JavaScript file for enhanced changeslist
627 * @return String
628 */
629 public function beginRecentChangesList() {
630 global $wgOut;
631 $this->rc_cache = array();
632 $this->rcMoveIndex = 0;
633 $this->rcCacheIndex = 0;
634 $this->lastdate = '';
635 $this->rclistOpen = false;
636 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
637 return '';
638 }
639 /**
640 * Format a line for enhanced recentchange (aka with javascript and block of lines).
641 *
642 * @param $baseRC RecentChange
643 * @param $watched bool
644 *
645 * @return string
646 */
647 public function recentChangesLine( &$baseRC, $watched = false ) {
648 global $wgLang, $wgUser;
649
650 wfProfileIn( __METHOD__ );
651
652 # Create a specialised object
653 $rc = RCCacheEntry::newFromParent( $baseRC );
654
655 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
656
657 # If it's a new day, add the headline and flush the cache
658 $date = $wgLang->date( $rc->mAttribs['rc_timestamp'], true );
659 $ret = '';
660 if( $date != $this->lastdate ) {
661 # Process current cache
662 $ret = $this->recentChangesBlock();
663 $this->rc_cache = array();
664 $ret .= Xml::element( 'h4', null, $date ) . "\n";
665 $this->lastdate = $date;
666 }
667
668 # Should patrol-related stuff be shown?
669 if( $wgUser->useRCPatrol() ) {
670 $rc->unpatrolled = !$rc->mAttribs['rc_patrolled'];
671 } else {
672 $rc->unpatrolled = false;
673 }
674
675 $showdifflinks = true;
676 # Make article link
677 $type = $rc->mAttribs['rc_type'];
678 $logType = $rc->mAttribs['rc_log_type'];
679 // Page moves
680 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
681 $msg = ( $type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
682 $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null,
683 array(), array( 'redirect' => 'no' ) ),
684 $this->skin->linkKnown( $rc->getMovedToTitle() ) );
685 // New unpatrolled pages
686 } elseif( $rc->unpatrolled && $type == RC_NEW ) {
687 $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(),
688 array( 'rcid' => $rc->mAttribs['rc_id'] ) );
689 // Log entries
690 } elseif( $type == RC_LOG ) {
691 if( $logType ) {
692 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
693 $clink = '(' . $this->skin->linkKnown( $logtitle,
694 LogPage::logName( $logType ) ) . ')';
695 } else {
696 $clink = $this->skin->link( $rc->getTitle() );
697 }
698 $watched = false;
699 // Log entries (old format) and special pages
700 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
701 list( $specialName, $logtype ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
702 if ( $specialName == 'Log' ) {
703 # Log updates, etc
704 $logname = LogPage::logName( $logtype );
705 $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')';
706 } else {
707 wfDebug( "Unexpected special page in recentchanges\n" );
708 $clink = '';
709 }
710 // Edits
711 } else {
712 $clink = $this->skin->linkKnown( $rc->getTitle() );
713 }
714
715 # Don't show unusable diff links
716 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
717 $showdifflinks = false;
718 }
719
720 $time = $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true );
721 $rc->watched = $watched;
722 $rc->link = $clink;
723 $rc->timestamp = $time;
724 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
725
726 # Make "cur" and "diff" links. Do not use link(), it is too slow if
727 # called too many times (50% of CPU time on RecentChanges!).
728 $thisOldid = $rc->mAttribs['rc_this_oldid'];
729 $lastOldid = $rc->mAttribs['rc_last_oldid'];
730 if( $rc->unpatrolled ) {
731 $rcIdQuery = array( 'rcid' => $rc->mAttribs['rc_id'] );
732 } else {
733 $rcIdQuery = array();
734 }
735 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
736 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' =>
737 $lastOldid ) + $rcIdQuery;
738
739 if( !$showdifflinks ) {
740 $curLink = $this->message['cur'];
741 $diffLink = $this->message['diff'];
742 } elseif( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
743 if ( $type != RC_NEW ) {
744 $curLink = $this->message['cur'];
745 } else {
746 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
747 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
748 }
749 $diffLink = $this->message['diff'];
750 } else {
751 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
752 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
753 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
754 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
755 }
756
757 # Make "last" link
758 if( !$showdifflinks || !$lastOldid ) {
759 $lastLink = $this->message['last'];
760 } elseif( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
761 $lastLink = $this->message['last'];
762 } else {
763 $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'],
764 array(), $curIdEq + array('diff' => $thisOldid, 'oldid' => $lastOldid) + $rcIdQuery );
765 }
766
767 # Make user links
768 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
769 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
770 } else {
771 $rc->userlink = $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
772 $rc->usertalklink = $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
773 }
774
775 $rc->lastlink = $lastLink;
776 $rc->curlink = $curLink;
777 $rc->difflink = $diffLink;
778
779 # Put accumulated information into the cache, for later display
780 # Page moves go on their own line
781 $title = $rc->getTitle();
782 $secureName = $title->getPrefixedDBkey();
783 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
784 # Use an @ character to prevent collision with page names
785 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
786 } else {
787 # Logs are grouped by type
788 if( $type == RC_LOG ){
789 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
790 }
791 if( !isset( $this->rc_cache[$secureName] ) ) {
792 $this->rc_cache[$secureName] = array();
793 }
794
795 array_push( $this->rc_cache[$secureName], $rc );
796 }
797
798 wfProfileOut( __METHOD__ );
799
800 return $ret;
801 }
802
803 /**
804 * Enhanced RC group
805 */
806 protected function recentChangesBlockGroup( $block ) {
807 global $wgLang, $wgRCShowChangedSize;
808
809 wfProfileIn( __METHOD__ );
810
811 # Add the namespace and title of the block as part of the class
812 if ( $block[0]->mAttribs['rc_log_type'] ) {
813 # Log entry
814 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
815 } else {
816 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
817 }
818 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
819 Html::openElement( 'tr' );
820
821 # Collate list of users
822 $userlinks = array();
823 # Other properties
824 $unpatrolled = false;
825 $isnew = false;
826 $curId = $currentRevision = 0;
827 # Some catalyst variables...
828 $namehidden = true;
829 $allLogs = true;
830 foreach( $block as $rcObj ) {
831 $oldid = $rcObj->mAttribs['rc_last_oldid'];
832 if( $rcObj->mAttribs['rc_new'] ) {
833 $isnew = true;
834 }
835 // If all log actions to this page were hidden, then don't
836 // give the name of the affected page for this block!
837 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
838 $namehidden = false;
839 }
840 $u = $rcObj->userlink;
841 if( !isset( $userlinks[$u] ) ) {
842 $userlinks[$u] = 0;
843 }
844 if( $rcObj->unpatrolled ) {
845 $unpatrolled = true;
846 }
847 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
848 $allLogs = false;
849 }
850 # Get the latest entry with a page_id and oldid
851 # since logs may not have these.
852 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
853 $curId = $rcObj->mAttribs['rc_cur_id'];
854 }
855 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
856 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
857 }
858
859 $bot = $rcObj->mAttribs['rc_bot'];
860 $userlinks[$u]++;
861 }
862
863 # Sort the list and convert to text
864 krsort( $userlinks );
865 asort( $userlinks );
866 $users = array();
867 foreach( $userlinks as $userlink => $count) {
868 $text = $userlink;
869 $text .= wfUILang()->getDirMark();
870 if( $count > 1 ) {
871 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
872 }
873 array_push( $users, $text );
874 }
875
876 $users = ' <span class="changedby">[' .
877 implode( $this->message['semicolon-separator'], $users ) . ']</span>';
878
879 # Title for <a> tags
880 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
881 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
882
883 $tl = "<span class='mw-collapsible-toggle'>"
884 . "<span class='mw-rc-openarrow'>"
885 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
886 . "</span><span class='mw-rc-closearrow'>"
887 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
888 . "</span></span>";
889 $r .= "<td>$tl</td>";
890
891 # Main line
892 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
893 'newpage' => $isnew,
894 'minor' => false,
895 'unpatrolled' => $unpatrolled,
896 'bot' => $bot ,
897 ) );
898
899 # Timestamp
900 $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td>';
901
902 # Article link
903 if( $namehidden ) {
904 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
905 } elseif( $allLogs ) {
906 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
907 } else {
908 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
909 }
910
911 $r .= wfUILang()->getDirMark();
912
913 $queryParams['curid'] = $curId;
914 # Changes message
915 $n = count($block);
916 static $nchanges = array();
917 if ( !isset( $nchanges[$n] ) ) {
918 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
919 }
920 # Total change link
921 $r .= ' ';
922 if( !$allLogs ) {
923 $r .= '(';
924 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) {
925 $r .= $nchanges[$n];
926 } elseif( $isnew ) {
927 $r .= $nchanges[$n];
928 } else {
929 $params = $queryParams;
930 $params['diff'] = $currentRevision;
931 $params['oldid'] = $oldid;
932
933 $r .= $this->skin->link(
934 $block[0]->getTitle(),
935 $nchanges[$n],
936 array(),
937 $params,
938 array( 'known', 'noclasses' )
939 );
940 }
941 }
942
943 # History
944 if( $allLogs ) {
945 // don't show history link for logs
946 } elseif( $namehidden || !$block[0]->getTitle()->exists() ) {
947 $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')';
948 } else {
949 $params = $queryParams;
950 $params['action'] = 'history';
951
952 $r .= $this->message['pipe-separator'] .
953 $this->skin->link(
954 $block[0]->getTitle(),
955 $this->message['hist'],
956 array(),
957 $params,
958 array( 'known', 'noclasses' )
959 ) . ')';
960 }
961 $r .= ' . . ';
962
963 # Character difference (does not apply if only log items)
964 if( $wgRCShowChangedSize && !$allLogs ) {
965 $last = 0;
966 $first = count($block) - 1;
967 # Some events (like logs) have an "empty" size, so we need to skip those...
968 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
969 $last++;
970 }
971 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
972 $first--;
973 }
974 # Get net change
975 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
976 $block[$last]->mAttribs['rc_new_len'] );
977
978 if( $chardiff == '' ) {
979 $r .= ' ';
980 } else {
981 $r .= ' ' . $chardiff. ' . . ';
982 }
983 }
984
985 $r .= $users;
986 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
987
988 # Sub-entries
989 foreach( $block as $rcObj ) {
990 # Classes to apply -- TODO implement
991 $classes = array();
992 $type = $rcObj->mAttribs['rc_type'];
993
994 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
995 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
996 $r .= $this->recentChangesFlags( array(
997 'newpage' => $rcObj->mAttribs['rc_new'],
998 'minor' => $rcObj->mAttribs['rc_minor'],
999 'unpatrolled' => $rcObj->unpatrolled,
1000 'bot' => $rcObj->mAttribs['rc_bot'],
1001 ) );
1002 $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1003
1004 $params = $queryParams;
1005
1006 if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
1007 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
1008 }
1009
1010 # Log timestamp
1011 if( $type == RC_LOG ) {
1012 $link = $rcObj->timestamp;
1013 # Revision link
1014 } elseif( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
1015 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
1016 } else {
1017 if ( $rcObj->unpatrolled && $type == RC_NEW) {
1018 $params['rcid'] = $rcObj->mAttribs['rc_id'];
1019 }
1020
1021 $link = $this->skin->link(
1022 $rcObj->getTitle(),
1023 $rcObj->timestamp,
1024 array(),
1025 $params,
1026 array( 'known', 'noclasses' )
1027 );
1028 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
1029 $link = '<span class="history-deleted">'.$link.'</span> ';
1030 }
1031 $r .= $link . '</span>';
1032
1033 if ( !$type == RC_LOG || $type == RC_NEW ) {
1034 $r .= ' (';
1035 $r .= $rcObj->curlink;
1036 $r .= $this->message['pipe-separator'];
1037 $r .= $rcObj->lastlink;
1038 $r .= ')';
1039 }
1040 $r .= ' . . ';
1041
1042 # Character diff
1043 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1044 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1045 }
1046
1047 # User links
1048 $r .= $rcObj->userlink;
1049 $r .= $rcObj->usertalklink;
1050 // log action
1051 $this->insertAction( $r, $rcObj );
1052 // log comment
1053 $this->insertComment( $r, $rcObj );
1054 # Rollback
1055 $this->insertRollback( $r, $rcObj );
1056 # Tags
1057 $this->insertTags( $r, $rcObj, $classes );
1058
1059 $r .= "</td></tr>\n";
1060 }
1061 $r .= "</table>\n";
1062
1063 $this->rcCacheIndex++;
1064
1065 wfProfileOut( __METHOD__ );
1066
1067 return $r;
1068 }
1069
1070 /**
1071 * Generate HTML for an arrow or placeholder graphic
1072 * @param $dir String: one of '', 'd', 'l', 'r'
1073 * @param $alt String: text
1074 * @param $title String: text
1075 * @return String: HTML <img> tag
1076 */
1077 protected function arrow( $dir, $alt='', $title='' ) {
1078 global $wgStylePath;
1079 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1080 $encAlt = htmlspecialchars( $alt );
1081 $encTitle = htmlspecialchars( $title );
1082 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1083 }
1084
1085 /**
1086 * Generate HTML for a right- or left-facing arrow,
1087 * depending on language direction.
1088 * @return String: HTML <img> tag
1089 */
1090 protected function sideArrow() {
1091 global $wgContLang;
1092 $dir = $wgContLang->isRTL() ? 'l' : 'r';
1093 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1094 }
1095
1096 /**
1097 * Generate HTML for a down-facing arrow
1098 * depending on language direction.
1099 * @return String: HTML <img> tag
1100 */
1101 protected function downArrow() {
1102 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1103 }
1104
1105 /**
1106 * Generate HTML for a spacer image
1107 * @return String: HTML <img> tag
1108 */
1109 protected function spacerArrow() {
1110 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1111 }
1112
1113 /**
1114 * Enhanced RC ungrouped line.
1115 *
1116 * @param $rcObj RecentChange
1117 * @return String: a HTML formated line (generated using $r)
1118 */
1119 protected function recentChangesBlockLine( $rcObj ) {
1120 global $wgRCShowChangedSize;
1121
1122 wfProfileIn( __METHOD__ );
1123 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
1124
1125 $type = $rcObj->mAttribs['rc_type'];
1126 $logType = $rcObj->mAttribs['rc_log_type'];
1127 if( $logType ) {
1128 # Log entry
1129 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs['rc_title'] );
1130 } else {
1131 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
1132 }
1133 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
1134 Html::openElement( 'tr' );
1135
1136 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1137 # Flag and Timestamp
1138 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
1139 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1140 } else {
1141 $r .= $this->recentChangesFlags( array(
1142 'newpage' => $type == RC_NEW,
1143 'mino' => $rcObj->mAttribs['rc_minor'],
1144 'unpatrolled' => $rcObj->unpatrolled,
1145 'bot' => $rcObj->mAttribs['rc_bot'],
1146 ) );
1147 }
1148 $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td>';
1149 # Article or log link
1150 if( $logType ) {
1151 $logtitle = Title::newFromText( "Log/$logType", NS_SPECIAL );
1152 $logname = LogPage::logName( $logType );
1153 $r .= '(' . $this->skin->link(
1154 $logtitle,
1155 $logname,
1156 array(),
1157 array(),
1158 array( 'known', 'noclasses' )
1159 ) . ')';
1160 } else {
1161 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1162 }
1163 # Diff and hist links
1164 if ( $type != RC_LOG ) {
1165 $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator'];
1166 $query['action'] = 'history';
1167 $r .= $this->skin->link(
1168 $rcObj->getTitle(),
1169 $this->message['hist'],
1170 array(),
1171 $query,
1172 array( 'known', 'noclasses' )
1173 ) . ')';
1174 }
1175 $r .= ' . . ';
1176 # Character diff
1177 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1178 $r .= "$cd . . ";
1179 }
1180 # User/talk
1181 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1182 # Log action (if any)
1183 if( $logType ) {
1184 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
1185 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1186 } else {
1187 $r .= ' ' . LogPage::actionText( $logType, $rcObj->mAttribs['rc_log_action'], $rcObj->getTitle(),
1188 $this->skin, LogPage::extractParams( $rcObj->mAttribs['rc_params'] ), true, true );
1189 }
1190 }
1191 $this->insertComment( $r, $rcObj );
1192 $this->insertRollback( $r, $rcObj );
1193 # Tags
1194 $classes = explode( ' ', $classes );
1195 $this->insertTags( $r, $rcObj, $classes );
1196 # Show how many people are watching this if enabled
1197 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
1198
1199 $r .= "</td></tr></table>\n";
1200
1201 wfProfileOut( __METHOD__ );
1202
1203 return $r;
1204 }
1205
1206 /**
1207 * If enhanced RC is in use, this function takes the previously cached
1208 * RC lines, arranges them, and outputs the HTML
1209 *
1210 * @return string
1211 */
1212 protected function recentChangesBlock() {
1213 if( count ( $this->rc_cache ) == 0 ) {
1214 return '';
1215 }
1216
1217 wfProfileIn( __METHOD__ );
1218
1219 $blockOut = '';
1220 foreach( $this->rc_cache as $block ) {
1221 if( count( $block ) < 2 ) {
1222 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1223 } else {
1224 $blockOut .= $this->recentChangesBlockGroup( $block );
1225 }
1226 }
1227
1228 wfProfileOut( __METHOD__ );
1229
1230 return '<div>'.$blockOut.'</div>';
1231 }
1232
1233 /**
1234 * Returns text for the end of RC
1235 * If enhanced RC is in use, returns pretty much all the text
1236 */
1237 public function endRecentChangesList() {
1238 return $this->recentChangesBlock() . parent::endRecentChangesList();
1239 }
1240
1241 }