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