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