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