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