3 * Classes to show lists of 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
31 class RCCacheEntry
extends RecentChange
{
32 var $secureName, $link;
33 var $curlink, $difflink, $lastlink, $usertalklink, $versionlink;
34 var $userlink, $timestamp, $watched;
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
;
49 * Base class for all changes lists
51 class ChangesList
extends ContextSource
{
58 protected $watchlist = false;
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();
72 $this->setContext( $obj->getContext() );
75 $this->preCacheMessages();
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() );
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();
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 );
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 ( explode( ' ', 'cur diff hist last blocklink history ' .
125 'semicolon-separator pipe-separator' ) as $msg ) {
126 $this->message
[$msg] = $this->msg( $msg )->escaped();
132 * Returns the appropriate flags for new page, minor change and patrolling
133 * @param array $flags Associative array of 'flag' => Bool
134 * @param string $nothing to use for empty space
137 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
139 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ) {
140 $f .= isset( $flags[$flag] ) && $flags[$flag]
141 ? self
::flag( $flag )
148 * Provide the "<abbr>" element appropriate to a given abbreviated flag,
149 * namely the flag indicating a new page, a minor edit, a bot edit, or an
150 * unpatrolled edit. By default in English it will contain "N", "m", "b",
151 * "!" respectively, plus it will have an appropriate title and class.
153 * @param string $flag 'newpage', 'unpatrolled', 'minor', or 'bot'
154 * @return String: Raw HTML
156 public static function flag( $flag ) {
157 static $messages = null;
158 if ( is_null( $messages ) ) {
160 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
161 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
162 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
163 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
165 foreach( $messages as &$value ) {
166 $value[0] = wfMessage( $value[0] )->escaped();
167 $value[1] = wfMessage( $value[1] )->escaped();
171 # Inconsistent naming, bleh
173 'newpage' => 'newpage',
174 'minor' => 'minoredit',
176 'unpatrolled' => 'unpatrolled',
177 'minoredit' => 'minoredit',
178 'botedit' => 'botedit',
182 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
186 * Returns text for the start of the tabular part of RC
189 public function beginRecentChangesList() {
190 $this->rc_cache
= array();
191 $this->rcMoveIndex
= 0;
192 $this->rcCacheIndex
= 0;
193 $this->lastdate
= '';
194 $this->rclistOpen
= false;
195 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
200 * Show formatted char difference
201 * @param $old Integer: bytes
202 * @param $new Integer: bytes
203 * @param $context IContextSource context to use
206 public static function showCharacterDifference( $old, $new, IContextSource
$context = null ) {
207 global $wgRCChangedSizeThreshold, $wgMiserMode;
210 $context = RequestContext
::getMain();
215 $szdiff = $new - $old;
217 $lang = $context->getLanguage();
218 $code = $lang->getCode();
219 static $fastCharDiff = array();
220 if ( !isset( $fastCharDiff[$code] ) ) {
221 $fastCharDiff[$code] = $wgMiserMode ||
$context->msg( 'rc-change-size' )->plain() === '$1';
224 $formattedSize = $lang->formatNum( $szdiff );
226 if ( !$fastCharDiff[$code] ) {
227 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
230 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
236 if ( $szdiff === 0 ) {
237 $formattedSizeClass = 'mw-plusminus-null';
240 $formattedSize = '+' . $formattedSize;
241 $formattedSizeClass = 'mw-plusminus-pos';
244 $formattedSizeClass = 'mw-plusminus-neg';
247 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
249 return Html
::element( $tag,
250 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
251 $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
255 * Format the character difference of one or several changes.
257 * @param $old RecentChange
258 * @param $new RecentChange last change to use, if not provided, $old will be used
259 * @return string HTML fragment
261 public function formatCharacterDifference( RecentChange
$old, RecentChange
$new = null ) {
262 $oldlen = $old->mAttribs
['rc_old_len'];
265 $newlen = $new->mAttribs
['rc_new_len'];
267 $newlen = $old->mAttribs
['rc_new_len'];
270 if( $oldlen === null ||
$newlen === null ) {
274 return self
::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
278 * Returns text for the end of RC
281 public function endRecentChangesList() {
282 if( $this->rclistOpen
) {
290 * @param string $s HTML to update
291 * @param $rc_timestamp mixed
293 public function insertDateHeader( &$s, $rc_timestamp ) {
294 # Make date header if necessary
295 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
296 if( $date != $this->lastdate
) {
297 if( $this->lastdate
!= '' ) {
300 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
301 $this->lastdate
= $date;
302 $this->rclistOpen
= true;
307 * @param string $s HTML to update
308 * @param $title Title
309 * @param $logtype string
311 public function insertLog( &$s, $title, $logtype ) {
312 $page = new LogPage( $logtype );
313 $logname = $page->getName()->escaped();
314 $s .= $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $title, $logname ) )->escaped();
318 * @param string $s HTML to update
319 * @param $rc RecentChange
320 * @param $unpatrolled
322 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
324 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
325 $diffLink = $this->message
['diff'];
326 } elseif ( !self
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
327 $diffLink = $this->message
['diff'];
330 'curid' => $rc->mAttribs
['rc_cur_id'],
331 'diff' => $rc->mAttribs
['rc_this_oldid'],
332 'oldid' => $rc->mAttribs
['rc_last_oldid']
336 $query['rcid'] = $rc->mAttribs
['rc_id'];
339 $diffLink = Linker
::linkKnown(
341 $this->message
['diff'],
342 array( 'tabindex' => $rc->counter
),
346 $diffhist = $diffLink . $this->message
['pipe-separator'];
348 $diffhist .= Linker
::linkKnown(
350 $this->message
['hist'],
353 'curid' => $rc->mAttribs
['rc_cur_id'],
354 'action' => 'history'
357 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' <span class="mw-changeslist-separator">. .</span> ';
361 * @param string $s HTML to update
362 * @param $rc RecentChange
363 * @param $unpatrolled
366 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
367 # If it's a new article, there is no diff link, but if it hasn't been
368 # patrolled yet, we need to give users a way to do so
371 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
372 $params['rcid'] = $rc->mAttribs
['rc_id'];
375 $articlelink = Linker
::linkKnown(
378 array( 'class' => 'mw-changeslist-title' ),
381 if( $this->isDeleted( $rc, Revision
::DELETED_TEXT
) ) {
382 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
384 # To allow for boldening pages watched by this user
385 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
387 $articlelink .= $this->getLanguage()->getDirMark();
389 wfRunHooks( 'ChangesListInsertArticleLink',
390 array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
392 $s .= " $articlelink";
396 * Get the timestamp from $rc formatted with current user's settings
399 * @param $rc RecentChange
400 * @return string HTML fragment
402 public function getTimestamp( $rc ) {
403 return $this->message
['semicolon-separator'] . '<span class="mw-changeslist-date">' .
404 $this->getLanguage()->userTime( $rc->mAttribs
['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
408 * Insert time timestamp string from $rc into $s
410 * @param string $s HTML to update
411 * @param $rc RecentChange
413 public function insertTimestamp( &$s, $rc ) {
414 $s .= $this->getTimestamp( $rc );
418 * Insert links to user page, user talk page and eventually a blocking link
420 * @param &$s String HTML to update
421 * @param &$rc RecentChange
423 public function insertUserRelatedLinks( &$s, &$rc ) {
424 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
425 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
427 $s .= $this->getLanguage()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'],
428 $rc->mAttribs
['rc_user_text'] );
429 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
434 * Insert a formatted action
436 * @param $rc RecentChange
439 public function insertLogEntry( $rc ) {
440 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
441 $formatter->setContext( $this->getContext() );
442 $formatter->setShowUserToolLinks( true );
443 $mark = $this->getLanguage()->getDirMark();
444 return $formatter->getActionText() . " $mark" . $formatter->getComment();
448 * Insert a formatted comment
449 * @param $rc RecentChange
452 public function insertComment( $rc ) {
453 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
454 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
455 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
457 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
464 * Check whether to enable recent changes patrol features
467 public static function usePatrol() {
469 return $wgUser->useRCPatrol();
473 * Returns the string which indicates the number of watching users
476 protected function numberofWatchingusers( $count ) {
477 static $cache = array();
479 if( !isset( $cache[$count] ) ) {
480 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
482 return $cache[$count];
489 * Determine if said field of a revision is hidden
490 * @param $rc RCCacheEntry
491 * @param $field Integer: one of DELETED_* bitfield constants
494 public static function isDeleted( $rc, $field ) {
495 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
499 * Determine if the current user is allowed to view a particular
500 * field of this revision, if it's marked as deleted.
501 * @param $rc RCCacheEntry
502 * @param $field Integer
503 * @param $user User object to check, or null to use $wgUser
506 public static function userCan( $rc, $field, User
$user = null ) {
507 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
508 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
510 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
515 * @param $link string
516 * @param $watched bool
519 protected function maybeWatchedLink( $link, $watched = false ) {
521 return '<strong class="mw-watched">' . $link . '</strong>';
523 return '<span class="mw-rc-unwatched">' . $link . '</span>';
527 /** Inserts a rollback link
530 * @param $rc RecentChange
532 public function insertRollback( &$s, &$rc ) {
533 if( $rc->mAttribs
['rc_type'] != RC_NEW
&& $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
534 $page = $rc->getTitle();
535 /** Check for rollback and edit permissions, disallow special pages, and only
536 * show a link on the top-most revision */
537 if ( $this->getUser()->isAllowed( 'rollback' ) && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
539 $rev = new Revision( array(
541 'id' => $rc->mAttribs
['rc_this_oldid'],
542 'user' => $rc->mAttribs
['rc_user'],
543 'user_text' => $rc->mAttribs
['rc_user_text'],
544 'deleted' => $rc->mAttribs
['rc_deleted']
546 $s .= ' ' . Linker
::generateRollback( $rev, $this->getContext() );
553 * @param $rc RecentChange
556 public function insertTags( &$s, &$rc, &$classes ) {
557 if ( empty( $rc->mAttribs
['ts_tags'] ) )
560 list( $tagSummary, $newClasses ) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
561 $classes = array_merge( $classes, $newClasses );
562 $s .= ' ' . $tagSummary;
565 public function insertExtra( &$s, &$rc, &$classes ) {
566 // Empty, used for subclasses to add anything special.
569 protected function showAsUnpatrolled( RecentChange
$rc ) {
570 $unpatrolled = false;
571 if ( !$rc->mAttribs
['rc_patrolled'] ) {
572 if ( $this->getUser()->useRCPatrol() ) {
574 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs
['rc_type'] == RC_NEW
) {
583 * Generate a list of changes using the good old system (no javascript)
585 class OldChangesList
extends ChangesList
{
587 * Format a line using the old system (aka without any javascript).
589 * @param $rc RecentChange, passed by reference
590 * @param bool $watched (default false)
591 * @param int $linenumber (default null)
593 * @return string|bool
595 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
596 global $wgRCShowChangedSize;
597 wfProfileIn( __METHOD__
);
599 # Should patrol-related stuff be shown?
600 $unpatrolled = $this->showAsUnpatrolled( $rc );
602 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
603 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
607 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
609 if( $linenumber & 1 ) {
610 $classes[] = 'mw-line-odd';
613 $classes[] = 'mw-line-even';
617 // Indicate watched status on the line to allow for more
618 // comprehensive styling.
619 $classes[] = $watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
621 // Moved pages (very very old, not supported anymore)
622 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
624 } elseif( $rc->mAttribs
['rc_log_type'] ) {
625 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
626 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
627 // Log entries (old format) or log targets, and special pages
628 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
629 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
630 if( $name == 'Log' ) {
631 $this->insertLog( $s, $rc->getTitle(), $subpage );
635 $this->insertDiffHist( $s, $rc, $unpatrolled );
636 # M, N, b and ! (minor, new, bot and unpatrolled)
637 $s .= $this->recentChangesFlags(
639 'newpage' => $rc->mAttribs
['rc_type'] == RC_NEW
,
640 'minor' => $rc->mAttribs
['rc_minor'],
641 'unpatrolled' => $unpatrolled,
642 'bot' => $rc->mAttribs
['rc_bot']
646 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
649 $this->insertTimestamp( $s, $rc );
650 # Bytes added or removed
651 if ( $wgRCShowChangedSize ) {
652 $cd = $this->formatCharacterDifference( $rc );
654 $s .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
658 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
659 $s .= $this->insertLogEntry( $rc );
662 $this->insertUserRelatedLinks( $s, $rc );
663 # LTR/RTL direction mark
664 $s .= $this->getLanguage()->getDirMark();
665 $s .= $this->insertComment( $rc );
669 $this->insertTags( $s, $rc, $classes );
671 $this->insertRollback( $s, $rc );
673 $this->insertExtra( $s, $rc, $classes );
675 # How many users watch this page
676 if( $rc->numberofWatchingusers
> 0 ) {
677 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers
);
680 if( $this->watchlist
) {
681 $classes[] = Sanitizer
::escapeClass( 'watchlist-' . $rc->mAttribs
['rc_namespace'] . '-' . $rc->mAttribs
['rc_title'] );
684 if ( !wfRunHooks( 'OldChangesListRecentChangesLine', array( &$this, &$s, $rc, &$classes ) ) ) {
685 wfProfileOut( __METHOD__
);
689 wfProfileOut( __METHOD__
);
690 return "$dateheader<li class=\"" . implode( ' ', $classes ) . "\">" . $s . "</li>\n";
695 * Generate a list of changes using an Enhanced system (uses javascript).
697 class EnhancedChangesList
extends ChangesList
{
702 * Add the JavaScript file for enhanced changeslist
705 public function beginRecentChangesList() {
706 $this->rc_cache
= array();
707 $this->rcMoveIndex
= 0;
708 $this->rcCacheIndex
= 0;
709 $this->lastdate
= '';
710 $this->rclistOpen
= false;
711 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
715 * Format a line for enhanced recentchange (aka with javascript and block of lines).
717 * @param $baseRC RecentChange
718 * @param $watched bool
722 public function recentChangesLine( &$baseRC, $watched = false ) {
723 wfProfileIn( __METHOD__
);
725 # Create a specialised object
726 $rc = RCCacheEntry
::newFromParent( $baseRC );
728 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
730 # If it's a new day, add the headline and flush the cache
731 $date = $this->getLanguage()->userDate( $rc->mAttribs
['rc_timestamp'], $this->getUser() );
733 if( $date != $this->lastdate
) {
734 # Process current cache
735 $ret = $this->recentChangesBlock();
736 $this->rc_cache
= array();
737 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
738 $this->lastdate
= $date;
741 # Should patrol-related stuff be shown?
742 $rc->unpatrolled
= $this->showAsUnpatrolled( $rc );
744 $showdifflinks = true;
746 $type = $rc->mAttribs
['rc_type'];
747 $logType = $rc->mAttribs
['rc_log_type'];
748 // Page moves, very old style, not supported anymore
749 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
750 // New unpatrolled pages
751 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
752 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
753 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
755 } elseif( $type == RC_LOG
) {
757 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
758 $logpage = new LogPage( $logType );
759 $logname = $logpage->getName()->escaped();
760 $clink = $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $logtitle, $logname ) )->escaped();
762 $clink = Linker
::link( $rc->getTitle() );
765 // Log entries (old format) and special pages
766 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
767 wfDebug( "Unexpected special page in recentchanges\n" );
771 $clink = Linker
::linkKnown( $rc->getTitle() );
774 # Don't show unusable diff links
775 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
776 $showdifflinks = false;
779 $time = $this->getLanguage()->userTime( $rc->mAttribs
['rc_timestamp'], $this->getUser() );
780 $rc->watched
= $watched;
782 $rc->timestamp
= $time;
783 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
785 # Make "cur" and "diff" links. Do not use link(), it is too slow if
786 # called too many times (50% of CPU time on RecentChanges!).
787 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
788 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
789 if( $rc->unpatrolled
) {
790 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
792 $rcIdQuery = array();
794 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
795 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
796 $lastOldid ) +
$rcIdQuery;
798 if( !$showdifflinks ) {
799 $curLink = $this->message
['cur'];
800 $diffLink = $this->message
['diff'];
801 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
802 if ( $type != RC_NEW
) {
803 $curLink = $this->message
['cur'];
805 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
806 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
808 $diffLink = $this->message
['diff'];
810 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
811 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
812 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
813 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
817 if( !$showdifflinks ||
!$lastOldid ) {
818 $lastLink = $this->message
['last'];
819 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
820 $lastLink = $this->message
['last'];
822 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
823 array(), $curIdEq +
array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) +
$rcIdQuery );
827 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
828 $rc->userlink
= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
830 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
831 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
834 $rc->lastlink
= $lastLink;
835 $rc->curlink
= $curLink;
836 $rc->difflink
= $diffLink;
838 # Put accumulated information into the cache, for later display
839 # Page moves go on their own line
840 $title = $rc->getTitle();
841 $secureName = $title->getPrefixedDBkey();
842 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
843 # Use an @ character to prevent collision with page names
844 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array( $rc );
846 # Logs are grouped by type
847 if( $type == RC_LOG
) {
848 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
850 if( !isset( $this->rc_cache
[$secureName] ) ) {
851 $this->rc_cache
[$secureName] = array();
854 array_push( $this->rc_cache
[$secureName], $rc );
857 wfProfileOut( __METHOD__
);
866 protected function recentChangesBlockGroup( $block ) {
867 global $wgRCShowChangedSize;
869 wfProfileIn( __METHOD__
);
871 # Add the namespace and title of the block as part of the class
872 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
873 if ( $block[0]->mAttribs
['rc_log_type'] ) {
875 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
876 . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
878 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
879 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
881 $classes[] = $block[0]->watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
882 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
883 Html
::openElement( 'tr' );
885 # Collate list of users
886 $userlinks = array();
888 $unpatrolled = false;
892 $curId = $currentRevision = 0;
893 # Some catalyst variables...
896 foreach( $block as $rcObj ) {
897 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
898 if( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
901 // If all log actions to this page were hidden, then don't
902 // give the name of the affected page for this block!
903 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
906 $u = $rcObj->userlink
;
907 if( !isset( $userlinks[$u] ) ) {
910 if( $rcObj->unpatrolled
) {
913 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
916 # Get the latest entry with a page_id and oldid
917 # since logs may not have these.
918 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
919 $curId = $rcObj->mAttribs
['rc_cur_id'];
921 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
922 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
925 if( !$rcObj->mAttribs
['rc_bot'] ) {
928 if( !$rcObj->mAttribs
['rc_minor'] ) {
935 # Sort the list and convert to text
936 krsort( $userlinks );
939 foreach( $userlinks as $userlink => $count ) {
941 $text .= $this->getLanguage()->getDirMark();
943 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
945 array_push( $users, $text );
948 $users = ' <span class="changedby">'
949 . $this->msg( 'brackets' )->rawParams(
950 implode( $this->message
['semicolon-separator'], $users )
951 )->escaped() . '</span>';
953 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
954 $r .= "<td>$tl</td>";
957 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
958 'newpage' => $isnew, # show, when one have this flag
959 'minor' => $allMinors, # show only, when all have this flag
960 'unpatrolled' => $unpatrolled, # show, when one have this flag
961 'bot' => $allBots, # show only, when all have this flag
965 $r .= ' ' . $block[0]->timestamp
. ' </td><td>';
969 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
970 } elseif( $allLogs ) {
971 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
973 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
976 $r .= $this->getLanguage()->getDirMark();
978 $queryParams['curid'] = $curId;
980 $n = count( $block );
981 static $nchanges = array();
982 if ( !isset( $nchanges[$n] ) ) {
983 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
989 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
990 $logtext .= $nchanges[$n];
992 $logtext .= $nchanges[$n];
994 $params = $queryParams;
995 $params['diff'] = $currentRevision;
996 $params['oldid'] = $oldid;
998 $logtext .= Linker
::link(
999 $block[0]->getTitle(),
1003 array( 'known', 'noclasses' )
1010 // don't show history link for logs
1011 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
1012 $logtext .= $this->message
['pipe-separator'] . $this->message
['hist'];
1014 $params = $queryParams;
1015 $params['action'] = 'history';
1017 $logtext .= $this->message
['pipe-separator'] .
1019 $block[0]->getTitle(),
1020 $this->message
['hist'],
1026 if( $logtext !== '' ) {
1027 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
1030 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1032 # Character difference (does not apply if only log items)
1033 if( $wgRCShowChangedSize && !$allLogs ) {
1035 $first = count( $block ) - 1;
1036 # Some events (like logs) have an "empty" size, so we need to skip those...
1037 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
1040 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
1044 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
1046 if( $chardiff == '' ) {
1049 $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
1054 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers
);
1057 foreach( $block as $rcObj ) {
1058 # Classes to apply -- TODO implement
1060 $type = $rcObj->mAttribs
['rc_type'];
1062 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
1063 $r .= $this->recentChangesFlags( array(
1064 'newpage' => $type == RC_NEW
,
1065 'minor' => $rcObj->mAttribs
['rc_minor'],
1066 'unpatrolled' => $rcObj->unpatrolled
,
1067 'bot' => $rcObj->mAttribs
['rc_bot'],
1069 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1071 $params = $queryParams;
1073 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1074 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1078 if( $type == RC_LOG
) {
1079 $link = $rcObj->timestamp
;
1081 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
1082 $link = '<span class="history-deleted">' . $rcObj->timestamp
. '</span> ';
1084 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1085 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1088 $link = Linker
::linkKnown(
1094 if( $this->isDeleted( $rcObj, Revision
::DELETED_TEXT
) ) {
1095 $link = '<span class="history-deleted">' . $link . '</span> ';
1098 $r .= $link . '</span>';
1100 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1101 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink
. $this->message
['pipe-separator'] . $rcObj->lastlink
)->escaped();
1103 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1106 if ( $wgRCShowChangedSize ) {
1107 $cd = $this->formatCharacterDifference( $rcObj );
1109 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1113 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1114 $r .= $this->insertLogEntry( $rcObj );
1117 $r .= $rcObj->userlink
;
1118 $r .= $rcObj->usertalklink
;
1119 $r .= $this->insertComment( $rcObj );
1123 $this->insertRollback( $r, $rcObj );
1125 $this->insertTags( $r, $rcObj, $classes );
1127 $r .= "</td></tr>\n";
1131 $this->rcCacheIndex++
;
1133 wfProfileOut( __METHOD__
);
1139 * Generate HTML for an arrow or placeholder graphic
1140 * @param string $dir one of '', 'd', 'l', 'r'
1141 * @param string $alt text
1142 * @param string $title text
1143 * @return String: HTML "<img>" tag
1145 protected function arrow( $dir, $alt = '', $title = '' ) {
1146 global $wgStylePath;
1147 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1148 $encAlt = htmlspecialchars( $alt );
1149 $encTitle = htmlspecialchars( $title );
1150 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1154 * Generate HTML for a right- or left-facing arrow,
1155 * depending on language direction.
1156 * @return String: HTML "<img>" tag
1158 protected function sideArrow() {
1159 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
1160 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
1164 * Generate HTML for a down-facing arrow
1165 * depending on language direction.
1166 * @return String: HTML "<img>" tag
1168 protected function downArrow() {
1169 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
1173 * Generate HTML for a spacer image
1174 * @return String: HTML "<img>" tag
1176 protected function spacerArrow() {
1177 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1181 * Enhanced RC ungrouped line.
1183 * @param $rcObj RecentChange
1184 * @return String: a HTML formatted line (generated using $r)
1186 protected function recentChangesBlockLine( $rcObj ) {
1187 global $wgRCShowChangedSize;
1189 wfProfileIn( __METHOD__
);
1190 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1192 $type = $rcObj->mAttribs
['rc_type'];
1193 $logType = $rcObj->mAttribs
['rc_log_type'];
1194 $classes = array( 'mw-enhanced-rc' );
1197 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
1198 . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1200 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
1201 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1203 $classes[] = $rcObj->watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
1204 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1205 Html
::openElement( 'tr' );
1207 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
1208 # Flag and Timestamp
1209 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1210 $r .= '    '; // 4 flags -> 4 spaces
1212 $r .= $this->recentChangesFlags( array(
1213 'newpage' => $type == RC_NEW
,
1214 'minor' => $rcObj->mAttribs
['rc_minor'],
1215 'unpatrolled' => $rcObj->unpatrolled
,
1216 'bot' => $rcObj->mAttribs
['rc_bot'],
1219 $r .= ' ' . $rcObj->timestamp
. ' </td><td>';
1220 # Article or log link
1222 $logPage = new LogPage( $logType );
1223 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
1224 $logName = $logPage->getName()->escaped();
1225 $r .= $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
1227 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1229 # Diff and hist links
1230 if ( $type != RC_LOG
) {
1231 $query['action'] = 'history';
1232 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
1234 $this->message
['hist'],
1239 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1241 if ( $wgRCShowChangedSize ) {
1242 $cd = $this->formatCharacterDifference( $rcObj );
1244 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1248 if ( $type == RC_LOG
) {
1249 $r .= $this->insertLogEntry( $rcObj );
1251 $r .= ' ' . $rcObj->userlink
. $rcObj->usertalklink
;
1252 $r .= $this->insertComment( $rcObj );
1253 $this->insertRollback( $r, $rcObj );
1257 $this->insertTags( $r, $rcObj, $classes );
1258 # Show how many people are watching this if enabled
1259 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers
);
1261 $r .= "</td></tr></table>\n";
1263 wfProfileOut( __METHOD__
);
1269 * If enhanced RC is in use, this function takes the previously cached
1270 * RC lines, arranges them, and outputs the HTML
1274 protected function recentChangesBlock() {
1275 if( count ( $this->rc_cache
) == 0 ) {
1279 wfProfileIn( __METHOD__
);
1282 foreach( $this->rc_cache
as $block ) {
1283 if( count( $block ) < 2 ) {
1284 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1286 $blockOut .= $this->recentChangesBlockGroup( $block );
1290 wfProfileOut( __METHOD__
);
1292 return '<div>' . $blockOut . '</div>';
1296 * Returns text for the end of RC
1297 * If enhanced RC is in use, returns pretty much all the text
1300 public function endRecentChangesList() {
1301 return $this->recentChangesBlock() . parent
::endRecentChangesList();