thumb_handler.php doesn't seem to extract path_info correctly
[mediawiki.git] / includes / ChangesList.php
blob02c02e0d283a670239ba99d33ba110aa3ee88f7e
1 <?php
2 /**
3 * Classes to show lists of changes.
5 * These can be:
6 * - watchlist
7 * - related changes
8 * - recent changes
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @file
28 /**
29 * @todo document
31 class RCCacheEntry extends RecentChange {
32 var $secureName, $link;
33 var $curlink, $difflink, $lastlink, $usertalklink, $versionlink;
34 var $userlink, $timestamp, $watched;
36 /**
37 * @param $rc RecentChange
38 * @return RCCacheEntry
40 static function newFromParent( $rc ) {
41 $rc2 = new RCCacheEntry;
42 $rc2->mAttribs = $rc->mAttribs;
43 $rc2->mExtra = $rc->mExtra;
44 return $rc2;
48 /**
49 * Base class for all changes lists
51 class ChangesList extends ContextSource {
53 /**
54 * @var Skin
56 public $skin;
58 protected $watchlist = false;
60 protected $message;
62 /**
63 * Changeslist constructor
65 * @param $obj Skin or IContextSource
67 public function __construct( $obj ) {
68 if ( $obj instanceof IContextSource ) {
69 $this->setContext( $obj );
70 $this->skin = $obj->getSkin();
71 } else {
72 $this->setContext( $obj->getContext() );
73 $this->skin = $obj;
75 $this->preCacheMessages();
78 /**
79 * Fetch an appropriate changes list class for the main context
80 * This first argument used to be an User object.
82 * @deprecated in 1.18; use newFromContext() instead
83 * @param string|User $unused Unused
84 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
86 public static function newFromUser( $unused ) {
87 wfDeprecated( __METHOD__, '1.18' );
88 return self::newFromContext( RequestContext::getMain() );
91 /**
92 * Fetch an appropriate changes list class for the specified context
93 * Some users might want to use an enhanced list format, for instance
95 * @param $context IContextSource to use
96 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
98 public static function newFromContext( IContextSource $context ) {
99 $user = $context->getUser();
100 $sk = $context->getSkin();
101 $list = null;
102 if ( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
103 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
104 return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
105 } else {
106 return $list;
111 * Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag
112 * @param $value Boolean
114 public function setWatchlistDivs( $value = true ) {
115 $this->watchlist = $value;
119 * As we use the same small set of messages in various methods and that
120 * they are called often, we call them once and save them in $this->message
122 private function preCacheMessages() {
123 if ( !isset( $this->message ) ) {
124 foreach ( array(
125 'cur', 'diff', 'hist', 'last', 'blocklink', 'history',
126 'semicolon-separator', 'pipe-separator' ) as $msg
128 $this->message[$msg] = $this->msg( $msg )->escaped();
134 * Returns the appropriate flags for new page, minor change and patrolling
135 * @param array $flags Associative array of 'flag' => Bool
136 * @param string $nothing to use for empty space
137 * @return String
139 protected function recentChangesFlags( $flags, $nothing = '&#160;' ) {
140 $f = '';
141 foreach ( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ) {
142 $f .= isset( $flags[$flag] ) && $flags[$flag]
143 ? self::flag( $flag )
144 : $nothing;
146 return $f;
150 * Provide the "<abbr>" element appropriate to a given abbreviated flag,
151 * namely the flag indicating a new page, a minor edit, a bot edit, or an
152 * unpatrolled edit. By default in English it will contain "N", "m", "b",
153 * "!" respectively, plus it will have an appropriate title and class.
155 * @param string $flag 'newpage', 'unpatrolled', 'minor', or 'bot'
156 * @return String: Raw HTML
158 public static function flag( $flag ) {
159 static $messages = null;
160 if ( is_null( $messages ) ) {
161 $messages = array(
162 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
163 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
164 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
165 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
167 foreach ( $messages as &$value ) {
168 $value[0] = wfMessage( $value[0] )->escaped();
169 $value[1] = wfMessage( $value[1] )->escaped();
173 # Inconsistent naming, bleh
174 $map = array(
175 'newpage' => 'newpage',
176 'minor' => 'minoredit',
177 'bot' => 'botedit',
178 'unpatrolled' => 'unpatrolled',
179 'minoredit' => 'minoredit',
180 'botedit' => 'botedit',
182 $flag = $map[$flag];
184 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
188 * Returns text for the start of the tabular part of RC
189 * @return String
191 public function beginRecentChangesList() {
192 $this->rc_cache = array();
193 $this->rcMoveIndex = 0;
194 $this->rcCacheIndex = 0;
195 $this->lastdate = '';
196 $this->rclistOpen = false;
197 $this->getOutput()->addModules( 'mediawiki.special.changeslist' );
198 return '';
202 * Show formatted char difference
203 * @param $old Integer: bytes
204 * @param $new Integer: bytes
205 * @param $context IContextSource context to use
206 * @return String
208 public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
209 global $wgRCChangedSizeThreshold, $wgMiserMode;
211 if ( !$context ) {
212 $context = RequestContext::getMain();
215 $new = (int)$new;
216 $old = (int)$old;
217 $szdiff = $new - $old;
219 $lang = $context->getLanguage();
220 $code = $lang->getCode();
221 static $fastCharDiff = array();
222 if ( !isset( $fastCharDiff[$code] ) ) {
223 $fastCharDiff[$code] = $wgMiserMode || $context->msg( 'rc-change-size' )->plain() === '$1';
226 $formattedSize = $lang->formatNum( $szdiff );
228 if ( !$fastCharDiff[$code] ) {
229 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
232 if ( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
233 $tag = 'strong';
234 } else {
235 $tag = 'span';
238 if ( $szdiff === 0 ) {
239 $formattedSizeClass = 'mw-plusminus-null';
241 if ( $szdiff > 0 ) {
242 $formattedSize = '+' . $formattedSize;
243 $formattedSizeClass = 'mw-plusminus-pos';
245 if ( $szdiff < 0 ) {
246 $formattedSizeClass = 'mw-plusminus-neg';
249 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
251 return Html::element( $tag,
252 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
253 $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
257 * Format the character difference of one or several changes.
259 * @param $old RecentChange
260 * @param $new RecentChange last change to use, if not provided, $old will be used
261 * @return string HTML fragment
263 public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
264 $oldlen = $old->mAttribs['rc_old_len'];
266 if ( $new ) {
267 $newlen = $new->mAttribs['rc_new_len'];
268 } else {
269 $newlen = $old->mAttribs['rc_new_len'];
272 if ( $oldlen === null || $newlen === null ) {
273 return '';
276 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
280 * Returns text for the end of RC
281 * @return String
283 public function endRecentChangesList() {
284 if ( $this->rclistOpen ) {
285 return "</ul>\n";
286 } else {
287 return '';
292 * @param string $s HTML to update
293 * @param $rc_timestamp mixed
295 public function insertDateHeader( &$s, $rc_timestamp ) {
296 # Make date header if necessary
297 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
298 if ( $date != $this->lastdate ) {
299 if ( $this->lastdate != '' ) {
300 $s .= "</ul>\n";
302 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
303 $this->lastdate = $date;
304 $this->rclistOpen = true;
309 * @param string $s HTML to update
310 * @param $title Title
311 * @param $logtype string
313 public function insertLog( &$s, $title, $logtype ) {
314 $page = new LogPage( $logtype );
315 $logname = $page->getName()->escaped();
316 $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
320 * @param string $s HTML to update
321 * @param $rc RecentChange
322 * @param $unpatrolled
324 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
325 # Diff link
326 if ( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
327 $diffLink = $this->message['diff'];
328 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
329 $diffLink = $this->message['diff'];
330 } else {
331 $query = array(
332 'curid' => $rc->mAttribs['rc_cur_id'],
333 'diff' => $rc->mAttribs['rc_this_oldid'],
334 'oldid' => $rc->mAttribs['rc_last_oldid']
337 $diffLink = Linker::linkKnown(
338 $rc->getTitle(),
339 $this->message['diff'],
340 array( 'tabindex' => $rc->counter ),
341 $query
344 $diffhist = $diffLink . $this->message['pipe-separator'];
345 # History link
346 $diffhist .= Linker::linkKnown(
347 $rc->getTitle(),
348 $this->message['hist'],
349 array(),
350 array(
351 'curid' => $rc->mAttribs['rc_cur_id'],
352 'action' => 'history'
355 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' <span class="mw-changeslist-separator">. .</span> ';
359 * @param string $s HTML to update
360 * @param $rc RecentChange
361 * @param $unpatrolled
362 * @param $watched
364 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
365 global $wgUseRCPatrol;
367 $params = array();
369 $articlelink = Linker::linkKnown(
370 $rc->getTitle(),
371 null,
372 array( 'class' => 'mw-changeslist-title' ),
373 $params
375 if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
376 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
378 # To allow for boldening pages watched by this user
379 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
380 # RTL/LTR marker
381 $articlelink .= $this->getLanguage()->getDirMark();
383 wfRunHooks( 'ChangesListInsertArticleLink',
384 array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
386 $s .= " $articlelink";
390 * Get the timestamp from $rc formatted with current user's settings
391 * and a separator
393 * @param $rc RecentChange
394 * @return string HTML fragment
396 public function getTimestamp( $rc ) {
397 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
398 $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
402 * Insert time timestamp string from $rc into $s
404 * @param string $s HTML to update
405 * @param $rc RecentChange
407 public function insertTimestamp( &$s, $rc ) {
408 $s .= $this->getTimestamp( $rc );
412 * Insert links to user page, user talk page and eventually a blocking link
414 * @param &$s String HTML to update
415 * @param &$rc RecentChange
417 public function insertUserRelatedLinks( &$s, &$rc ) {
418 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
419 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
420 } else {
421 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
422 $rc->mAttribs['rc_user_text'] );
423 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
428 * Insert a formatted action
430 * @param $rc RecentChange
431 * @return string
433 public function insertLogEntry( $rc ) {
434 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
435 $formatter->setContext( $this->getContext() );
436 $formatter->setShowUserToolLinks( true );
437 $mark = $this->getLanguage()->getDirMark();
438 return $formatter->getActionText() . " $mark" . $formatter->getComment();
442 * Insert a formatted comment
443 * @param $rc RecentChange
444 * @return string
446 public function insertComment( $rc ) {
447 if ( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
448 if ( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
449 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
450 } else {
451 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
454 return '';
458 * Check whether to enable recent changes patrol features
459 * @return Boolean
461 public static function usePatrol() {
462 global $wgUser;
463 return $wgUser->useRCPatrol();
467 * Returns the string which indicates the number of watching users
468 * @return string
470 protected function numberofWatchingusers( $count ) {
471 static $cache = array();
472 if ( $count > 0 ) {
473 if ( !isset( $cache[$count] ) ) {
474 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
476 return $cache[$count];
477 } else {
478 return '';
483 * Determine if said field of a revision is hidden
484 * @param $rc RCCacheEntry
485 * @param $field Integer: one of DELETED_* bitfield constants
486 * @return Boolean
488 public static function isDeleted( $rc, $field ) {
489 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
493 * Determine if the current user is allowed to view a particular
494 * field of this revision, if it's marked as deleted.
495 * @param $rc RCCacheEntry
496 * @param $field Integer
497 * @param $user User object to check, or null to use $wgUser
498 * @return Boolean
500 public static function userCan( $rc, $field, User $user = null ) {
501 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
502 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
503 } else {
504 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
509 * @param $link string
510 * @param $watched bool
511 * @return string
513 protected function maybeWatchedLink( $link, $watched = false ) {
514 if ( $watched ) {
515 return '<strong class="mw-watched">' . $link . '</strong>';
516 } else {
517 return '<span class="mw-rc-unwatched">' . $link . '</span>';
521 /** Inserts a rollback link
523 * @param $s string
524 * @param $rc RecentChange
526 public function insertRollback( &$s, &$rc ) {
527 if ( $rc->mAttribs['rc_type'] == RC_EDIT && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
528 $page = $rc->getTitle();
529 /** Check for rollback and edit permissions, disallow special pages, and only
530 * show a link on the top-most revision */
531 if ( $this->getUser()->isAllowed( 'rollback' ) && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
533 $rev = new Revision( array(
534 'title' => $page,
535 'id' => $rc->mAttribs['rc_this_oldid'],
536 'user' => $rc->mAttribs['rc_user'],
537 'user_text' => $rc->mAttribs['rc_user_text'],
538 'deleted' => $rc->mAttribs['rc_deleted']
539 ) );
540 $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
546 * @param $s string
547 * @param $rc RecentChange
548 * @param $classes
550 public function insertTags( &$s, &$rc, &$classes ) {
551 if ( empty( $rc->mAttribs['ts_tags'] ) ) {
552 return;
555 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
556 $classes = array_merge( $classes, $newClasses );
557 $s .= ' ' . $tagSummary;
560 public function insertExtra( &$s, &$rc, &$classes ) {
561 // Empty, used for subclasses to add anything special.
564 protected function showAsUnpatrolled( RecentChange $rc ) {
565 $unpatrolled = false;
566 if ( !$rc->mAttribs['rc_patrolled'] ) {
567 if ( $this->getUser()->useRCPatrol() ) {
568 $unpatrolled = true;
569 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_type'] == RC_NEW ) {
570 $unpatrolled = true;
573 return $unpatrolled;
578 * Generate a list of changes using the good old system (no javascript)
580 class OldChangesList extends ChangesList {
582 * Format a line using the old system (aka without any javascript).
584 * @param $rc RecentChange, passed by reference
585 * @param bool $watched (default false)
586 * @param int $linenumber (default null)
588 * @return string|bool
590 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
591 global $wgRCShowChangedSize;
592 wfProfileIn( __METHOD__ );
594 # Should patrol-related stuff be shown?
595 $unpatrolled = $this->showAsUnpatrolled( $rc );
597 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
598 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
600 $s = '';
601 $classes = array();
602 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
603 if ( $linenumber ) {
604 if ( $linenumber & 1 ) {
605 $classes[] = 'mw-line-odd';
606 } else {
607 $classes[] = 'mw-line-even';
611 // Indicate watched status on the line to allow for more
612 // comprehensive styling.
613 $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
614 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
616 // Moved pages (very very old, not supported anymore)
617 if ( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
618 // Log entries
619 } elseif ( $rc->mAttribs['rc_log_type'] ) {
620 $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
621 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
622 // Log entries (old format) or log targets, and special pages
623 } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
624 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
625 if ( $name == 'Log' ) {
626 $this->insertLog( $s, $rc->getTitle(), $subpage );
628 // Regular entries
629 } else {
630 $this->insertDiffHist( $s, $rc, $unpatrolled );
631 # M, N, b and ! (minor, new, bot and unpatrolled)
632 $s .= $this->recentChangesFlags(
633 array(
634 'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
635 'minor' => $rc->mAttribs['rc_minor'],
636 'unpatrolled' => $unpatrolled,
637 'bot' => $rc->mAttribs['rc_bot']
641 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
643 # Edit/log timestamp
644 $this->insertTimestamp( $s, $rc );
645 # Bytes added or removed
646 if ( $wgRCShowChangedSize ) {
647 $cd = $this->formatCharacterDifference( $rc );
648 if ( $cd !== '' ) {
649 $s .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
653 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
654 $s .= $this->insertLogEntry( $rc );
655 } else {
656 # User tool links
657 $this->insertUserRelatedLinks( $s, $rc );
658 # LTR/RTL direction mark
659 $s .= $this->getLanguage()->getDirMark();
660 $s .= $this->insertComment( $rc );
663 # Tags
664 $this->insertTags( $s, $rc, $classes );
665 # Rollback
666 $this->insertRollback( $s, $rc );
667 # For subclasses
668 $this->insertExtra( $s, $rc, $classes );
670 # How many users watch this page
671 if ( $rc->numberofWatchingusers > 0 ) {
672 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
675 if ( $this->watchlist ) {
676 $classes[] = Sanitizer::escapeClass( 'watchlist-' . $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
679 if ( !wfRunHooks( 'OldChangesListRecentChangesLine', array( &$this, &$s, $rc, &$classes ) ) ) {
680 wfProfileOut( __METHOD__ );
681 return false;
684 wfProfileOut( __METHOD__ );
685 return "$dateheader<li class=\"" . implode( ' ', $classes ) . "\">" . $s . "</li>\n";
690 * Generate a list of changes using an Enhanced system (uses javascript).
692 class EnhancedChangesList extends ChangesList {
694 protected $rc_cache;
697 * Add the JavaScript file for enhanced changeslist
698 * @return String
700 public function beginRecentChangesList() {
701 $this->rc_cache = array();
702 $this->rcMoveIndex = 0;
703 $this->rcCacheIndex = 0;
704 $this->lastdate = '';
705 $this->rclistOpen = false;
706 $this->getOutput()->addModules( 'mediawiki.special.changeslist' );
707 return '';
710 * Format a line for enhanced recentchange (aka with javascript and block of lines).
712 * @param $baseRC RecentChange
713 * @param $watched bool
715 * @return string
717 public function recentChangesLine( &$baseRC, $watched = false ) {
718 wfProfileIn( __METHOD__ );
720 # Create a specialised object
721 $rc = RCCacheEntry::newFromParent( $baseRC );
723 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
725 # If it's a new day, add the headline and flush the cache
726 $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() );
727 $ret = '';
728 if ( $date != $this->lastdate ) {
729 # Process current cache
730 $ret = $this->recentChangesBlock();
731 $this->rc_cache = array();
732 $ret .= Xml::element( 'h4', null, $date ) . "\n";
733 $this->lastdate = $date;
736 # Should patrol-related stuff be shown?
737 $rc->unpatrolled = $this->showAsUnpatrolled( $rc );
739 $showdifflinks = true;
740 # Make article link
741 $type = $rc->mAttribs['rc_type'];
742 $logType = $rc->mAttribs['rc_log_type'];
743 // Page moves, very old style, not supported anymore
744 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
745 // New unpatrolled pages
746 } elseif ( $rc->unpatrolled && $type == RC_NEW ) {
747 $clink = Linker::linkKnown( $rc->getTitle() );
748 // Log entries
749 } elseif ( $type == RC_LOG ) {
750 if ( $logType ) {
751 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
752 $logpage = new LogPage( $logType );
753 $logname = $logpage->getName()->escaped();
754 $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
755 } else {
756 $clink = Linker::link( $rc->getTitle() );
758 $watched = false;
759 // Log entries (old format) and special pages
760 } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
761 wfDebug( "Unexpected special page in recentchanges\n" );
762 $clink = '';
763 // Edits
764 } else {
765 $clink = Linker::linkKnown( $rc->getTitle() );
768 # Don't show unusable diff links
769 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
770 $showdifflinks = false;
773 $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() );
774 $rc->watched = $watched;
775 $rc->link = $clink;
776 $rc->timestamp = $time;
777 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
779 # Make "cur" and "diff" links. Do not use link(), it is too slow if
780 # called too many times (50% of CPU time on RecentChanges!).
781 $thisOldid = $rc->mAttribs['rc_this_oldid'];
782 $lastOldid = $rc->mAttribs['rc_last_oldid'];
784 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
785 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
787 if ( !$showdifflinks ) {
788 $curLink = $this->message['cur'];
789 $diffLink = $this->message['diff'];
790 } elseif ( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
791 if ( $type != RC_NEW ) {
792 $curLink = $this->message['cur'];
793 } else {
794 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
795 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
797 $diffLink = $this->message['diff'];
798 } else {
799 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
800 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
801 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
802 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
805 # Make "last" link
806 if ( !$showdifflinks || !$lastOldid ) {
807 $lastLink = $this->message['last'];
808 } elseif ( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
809 $lastLink = $this->message['last'];
810 } else {
811 $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'],
812 array(), $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
815 # Make user links
816 if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
817 $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
818 } else {
819 $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
820 $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
823 $rc->lastlink = $lastLink;
824 $rc->curlink = $curLink;
825 $rc->difflink = $diffLink;
827 # Put accumulated information into the cache, for later display
828 # Page moves go on their own line
829 $title = $rc->getTitle();
830 $secureName = $title->getPrefixedDBkey();
831 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
832 # Use an @ character to prevent collision with page names
833 $this->rc_cache['@@' . ( $this->rcMoveIndex++ )] = array( $rc );
834 } else {
835 # Logs are grouped by type
836 if ( $type == RC_LOG ) {
837 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
839 if ( !isset( $this->rc_cache[$secureName] ) ) {
840 $this->rc_cache[$secureName] = array();
843 array_push( $this->rc_cache[$secureName], $rc );
846 wfProfileOut( __METHOD__ );
848 return $ret;
852 * Enhanced RC group
853 * @return string
855 protected function recentChangesBlockGroup( $block ) {
856 global $wgRCShowChangedSize;
858 wfProfileIn( __METHOD__ );
860 # Add the namespace and title of the block as part of the class
861 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
862 if ( $block[0]->mAttribs['rc_log_type'] ) {
863 # Log entry
864 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
865 . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
866 } else {
867 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
868 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
870 $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
871 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
872 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
873 Html::openElement( 'tr' );
875 # Collate list of users
876 $userlinks = array();
877 # Other properties
878 $unpatrolled = false;
879 $isnew = false;
880 $allBots = true;
881 $allMinors = true;
882 $curId = $currentRevision = 0;
883 # Some catalyst variables...
884 $namehidden = true;
885 $allLogs = true;
886 foreach ( $block as $rcObj ) {
887 $oldid = $rcObj->mAttribs['rc_last_oldid'];
888 if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
889 $isnew = true;
891 // If all log actions to this page were hidden, then don't
892 // give the name of the affected page for this block!
893 if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
894 $namehidden = false;
896 $u = $rcObj->userlink;
897 if ( !isset( $userlinks[$u] ) ) {
898 $userlinks[$u] = 0;
900 if ( $rcObj->unpatrolled ) {
901 $unpatrolled = true;
903 if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
904 $allLogs = false;
906 # Get the latest entry with a page_id and oldid
907 # since logs may not have these.
908 if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
909 $curId = $rcObj->mAttribs['rc_cur_id'];
911 if ( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
912 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
915 if ( !$rcObj->mAttribs['rc_bot'] ) {
916 $allBots = false;
918 if ( !$rcObj->mAttribs['rc_minor'] ) {
919 $allMinors = false;
922 $userlinks[$u]++;
925 # Sort the list and convert to text
926 krsort( $userlinks );
927 asort( $userlinks );
928 $users = array();
929 foreach ( $userlinks as $userlink => $count ) {
930 $text = $userlink;
931 $text .= $this->getLanguage()->getDirMark();
932 if ( $count > 1 ) {
933 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
935 array_push( $users, $text );
938 $users = ' <span class="changedby">'
939 . $this->msg( 'brackets' )->rawParams(
940 implode( $this->message['semicolon-separator'], $users )
941 )->escaped() . '</span>';
943 $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
944 $r .= "<td>$tl</td>";
946 # Main line
947 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
948 'newpage' => $isnew, # show, when one have this flag
949 'minor' => $allMinors, # show only, when all have this flag
950 'unpatrolled' => $unpatrolled, # show, when one have this flag
951 'bot' => $allBots, # show only, when all have this flag
952 ) );
954 # Timestamp
955 $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
957 # Article link
958 if ( $namehidden ) {
959 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
960 } elseif ( $allLogs ) {
961 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
962 } else {
963 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
966 $r .= $this->getLanguage()->getDirMark();
968 $queryParams['curid'] = $curId;
969 # Changes message
970 $n = count( $block );
971 static $nchanges = array();
972 if ( !isset( $nchanges[$n] ) ) {
973 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
975 # Total change link
976 $r .= ' ';
977 $logtext = '';
978 if ( !$allLogs ) {
979 if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
980 $logtext .= $nchanges[$n];
981 } elseif ( $isnew ) {
982 $logtext .= $nchanges[$n];
983 } else {
984 $params = $queryParams;
985 $params['diff'] = $currentRevision;
986 $params['oldid'] = $oldid;
988 $logtext .= Linker::link(
989 $block[0]->getTitle(),
990 $nchanges[$n],
991 array(),
992 $params,
993 array( 'known', 'noclasses' )
998 # History
999 if ( $allLogs ) {
1000 // don't show history link for logs
1001 } elseif ( $namehidden || !$block[0]->getTitle()->exists() ) {
1002 $logtext .= $this->message['pipe-separator'] . $this->message['hist'];
1003 } else {
1004 $params = $queryParams;
1005 $params['action'] = 'history';
1007 $logtext .= $this->message['pipe-separator'] .
1008 Linker::linkKnown(
1009 $block[0]->getTitle(),
1010 $this->message['hist'],
1011 array(),
1012 $params
1016 if ( $logtext !== '' ) {
1017 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
1020 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1022 # Character difference (does not apply if only log items)
1023 if ( $wgRCShowChangedSize && !$allLogs ) {
1024 $last = 0;
1025 $first = count( $block ) - 1;
1026 # Some events (like logs) have an "empty" size, so we need to skip those...
1027 while ( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
1028 $last++;
1030 while ( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
1031 $first--;
1033 # Get net change
1034 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
1036 if ( $chardiff == '' ) {
1037 $r .= ' ';
1038 } else {
1039 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
1043 $r .= $users;
1044 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
1046 # Sub-entries
1047 foreach ( $block as $rcObj ) {
1048 # Classes to apply -- TODO implement
1049 $classes = array();
1050 $type = $rcObj->mAttribs['rc_type'];
1052 $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
1053 ? ' class="mw-enhanced-watched"' : '';
1055 $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
1056 $r .= $this->recentChangesFlags( array(
1057 'newpage' => $type == RC_NEW,
1058 'minor' => $rcObj->mAttribs['rc_minor'],
1059 'unpatrolled' => $rcObj->unpatrolled,
1060 'bot' => $rcObj->mAttribs['rc_bot'],
1061 ) );
1062 $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1064 $params = $queryParams;
1066 if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
1067 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
1070 # Log timestamp
1071 if ( $type == RC_LOG ) {
1072 $link = $rcObj->timestamp;
1073 # Revision link
1074 } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
1075 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
1076 } else {
1078 $link = Linker::linkKnown(
1079 $rcObj->getTitle(),
1080 $rcObj->timestamp,
1081 array(),
1082 $params
1084 if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
1085 $link = '<span class="history-deleted">' . $link . '</span> ';
1088 $r .= $link . '</span>';
1090 if ( !$type == RC_LOG || $type == RC_NEW ) {
1091 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
1093 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1095 # Character diff
1096 if ( $wgRCShowChangedSize ) {
1097 $cd = $this->formatCharacterDifference( $rcObj );
1098 if ( $cd !== '' ) {
1099 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1103 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
1104 $r .= $this->insertLogEntry( $rcObj );
1105 } else {
1106 # User links
1107 $r .= $rcObj->userlink;
1108 $r .= $rcObj->usertalklink;
1109 $r .= $this->insertComment( $rcObj );
1112 # Rollback
1113 $this->insertRollback( $r, $rcObj );
1114 # Tags
1115 $this->insertTags( $r, $rcObj, $classes );
1117 $r .= "</td></tr>\n";
1119 $r .= "</table>\n";
1121 $this->rcCacheIndex++;
1123 wfProfileOut( __METHOD__ );
1125 return $r;
1129 * Generate HTML for an arrow or placeholder graphic
1130 * @param string $dir one of '', 'd', 'l', 'r'
1131 * @param string $alt text
1132 * @param string $title text
1133 * @return String: HTML "<img>" tag
1135 protected function arrow( $dir, $alt = '', $title = '' ) {
1136 global $wgStylePath;
1137 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1138 $encAlt = htmlspecialchars( $alt );
1139 $encTitle = htmlspecialchars( $title );
1140 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1144 * Generate HTML for a right- or left-facing arrow,
1145 * depending on language direction.
1146 * @return String: HTML "<img>" tag
1148 protected function sideArrow() {
1149 $dir = $this->getLanguage()->isRTL() ? 'l' : 'r';
1150 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
1154 * Generate HTML for a down-facing arrow
1155 * depending on language direction.
1156 * @return String: HTML "<img>" tag
1158 protected function downArrow() {
1159 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
1163 * Generate HTML for a spacer image
1164 * @return String: HTML "<img>" tag
1166 protected function spacerArrow() {
1167 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1171 * Enhanced RC ungrouped line.
1173 * @param $rcObj RecentChange
1174 * @return String: a HTML formatted line (generated using $r)
1176 protected function recentChangesBlockLine( $rcObj ) {
1177 global $wgRCShowChangedSize;
1179 wfProfileIn( __METHOD__ );
1180 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
1182 $type = $rcObj->mAttribs['rc_type'];
1183 $logType = $rcObj->mAttribs['rc_log_type'];
1184 $classes = array( 'mw-enhanced-rc' );
1185 if ( $logType ) {
1186 # Log entry
1187 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
1188 . $logType . '-' . $rcObj->mAttribs['rc_title'] );
1189 } else {
1190 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
1191 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
1193 $classes[] = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
1194 ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
1195 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
1196 Html::openElement( 'tr' );
1198 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
1199 # Flag and Timestamp
1200 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
1201 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1202 } else {
1203 $r .= $this->recentChangesFlags( array(
1204 'newpage' => $type == RC_NEW,
1205 'minor' => $rcObj->mAttribs['rc_minor'],
1206 'unpatrolled' => $rcObj->unpatrolled,
1207 'bot' => $rcObj->mAttribs['rc_bot'],
1208 ) );
1210 $r .= '&#160;' . $rcObj->timestamp . '&#160;</td><td>';
1211 # Article or log link
1212 if ( $logType ) {
1213 $logPage = new LogPage( $logType );
1214 $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
1215 $logName = $logPage->getName()->escaped();
1216 $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
1217 } else {
1218 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1220 # Diff and hist links
1221 if ( $type != RC_LOG ) {
1222 $query['action'] = 'history';
1223 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
1224 $rcObj->getTitle(),
1225 $this->message['hist'],
1226 array(),
1227 $query
1228 ) )->escaped();
1230 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1231 # Character diff
1232 if ( $wgRCShowChangedSize ) {
1233 $cd = $this->formatCharacterDifference( $rcObj );
1234 if ( $cd !== '' ) {
1235 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1239 if ( $type == RC_LOG ) {
1240 $r .= $this->insertLogEntry( $rcObj );
1241 } else {
1242 $r .= ' ' . $rcObj->userlink . $rcObj->usertalklink;
1243 $r .= $this->insertComment( $rcObj );
1244 $this->insertRollback( $r, $rcObj );
1247 # Tags
1248 $this->insertTags( $r, $rcObj, $classes );
1249 # Show how many people are watching this if enabled
1250 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
1252 $r .= "</td></tr></table>\n";
1254 wfProfileOut( __METHOD__ );
1256 return $r;
1260 * If enhanced RC is in use, this function takes the previously cached
1261 * RC lines, arranges them, and outputs the HTML
1263 * @return string
1265 protected function recentChangesBlock() {
1266 if ( count ( $this->rc_cache ) == 0 ) {
1267 return '';
1270 wfProfileIn( __METHOD__ );
1272 $blockOut = '';
1273 foreach ( $this->rc_cache as $block ) {
1274 if ( count( $block ) < 2 ) {
1275 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1276 } else {
1277 $blockOut .= $this->recentChangesBlockGroup( $block );
1281 wfProfileOut( __METHOD__ );
1283 return '<div>' . $blockOut . '</div>';
1287 * Returns text for the end of RC
1288 * If enhanced RC is in use, returns pretty much all the text
1289 * @return string
1291 public function endRecentChangesList() {
1292 return $this->recentChangesBlock() . parent::endRecentChangesList();