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 contructor
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 $unused string|User 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 $flags Array Associative array of 'flag' => Bool
134 * @param $nothing String 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 $flag String: '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] = wfMsgExt( $value[0], 'escapenoentities' );
167 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
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();
213 $szdiff = $new - $old;
215 $lang = $context->getLanguage();
216 $code = $lang->getCode();
217 static $fastCharDiff = array();
218 if ( !isset($fastCharDiff[$code]) ) {
219 $fastCharDiff[$code] = $wgMiserMode ||
$context->msg( 'rc-change-size' )->plain() === '$1';
222 $formattedSize = $lang->formatNum( $szdiff );
224 if ( !$fastCharDiff[$code] ) {
225 $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
228 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
234 if ( $szdiff === 0 ) {
235 $formattedSizeClass = 'mw-plusminus-null';
238 $formattedSize = '+' . $formattedSize;
239 $formattedSizeClass = 'mw-plusminus-pos';
242 $formattedSizeClass = 'mw-plusminus-neg';
245 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
247 return Html
::element( $tag,
248 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
249 $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
253 * Format the character difference of one or several changes.
255 * @param $old RecentChange
256 * @param $new RecentChange last change to use, if not provided, $old will be used
257 * @return string HTML fragment
259 public function formatCharacterDifference( RecentChange
$old, RecentChange
$new = null ) {
260 $oldlen = $old->mAttribs
['rc_old_len'];
263 $newlen = $new->mAttribs
['rc_new_len'];
265 $newlen = $old->mAttribs
['rc_new_len'];
268 if( $oldlen === null ||
$newlen === null ) {
272 return self
::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
276 * Returns text for the end of RC
279 public function endRecentChangesList() {
280 if( $this->rclistOpen
) {
287 public function insertDateHeader( &$s, $rc_timestamp ) {
288 # Make date header if necessary
289 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
290 if( $date != $this->lastdate
) {
291 if( $this->lastdate
!= '' ) {
294 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
295 $this->lastdate
= $date;
296 $this->rclistOpen
= true;
300 public function insertLog( &$s, $title, $logtype ) {
301 $page = new LogPage( $logtype );
302 $logname = $page->getName()->escaped();
303 $s .= $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $title, $logname ) )->escaped();
308 * @param $rc RecentChange
309 * @param $unpatrolled
311 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
313 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
314 $diffLink = $this->message
['diff'];
315 } elseif ( !self
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
316 $diffLink = $this->message
['diff'];
319 'curid' => $rc->mAttribs
['rc_cur_id'],
320 'diff' => $rc->mAttribs
['rc_this_oldid'],
321 'oldid' => $rc->mAttribs
['rc_last_oldid']
325 $query['rcid'] = $rc->mAttribs
['rc_id'];
328 $diffLink = Linker
::linkKnown(
330 $this->message
['diff'],
331 array( 'tabindex' => $rc->counter
),
335 $diffhist = $diffLink . $this->message
['pipe-separator'];
337 $diffhist .= Linker
::linkKnown(
339 $this->message
['hist'],
342 'curid' => $rc->mAttribs
['rc_cur_id'],
343 'action' => 'history'
346 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' . . ';
351 * @param $rc RecentChange
352 * @param $unpatrolled
355 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
356 # If it's a new article, there is no diff link, but if it hasn't been
357 # patrolled yet, we need to give users a way to do so
360 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
361 $params['rcid'] = $rc->mAttribs
['rc_id'];
364 $articlelink = Linker
::linkKnown(
370 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
371 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
373 # To allow for boldening pages watched by this user
374 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
376 $articlelink .= $this->getLanguage()->getDirMark();
378 wfRunHooks( 'ChangesListInsertArticleLink',
379 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
381 $s .= " $articlelink";
386 * @param $rc RecentChange
388 public function insertTimestamp( &$s, $rc ) {
389 $s .= $this->message
['semicolon-separator'] .
390 $this->getLanguage()->userTime( $rc->mAttribs
['rc_timestamp'], $this->getUser() ) . ' . . ';
394 * Insert links to user page, user talk page and eventually a blocking link
396 * @param &$s String HTML to update
397 * @param &$rc RecentChange
399 public function insertUserRelatedLinks( &$s, &$rc ) {
400 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
401 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
403 $s .= $this->getLanguage()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'],
404 $rc->mAttribs
['rc_user_text'] );
405 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
410 * Insert a formatted action
412 * @param $rc RecentChange
415 public function insertLogEntry( $rc ) {
416 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
417 $formatter->setContext( $this->getContext() );
418 $formatter->setShowUserToolLinks( true );
419 $mark = $this->getLanguage()->getDirMark();
420 return $formatter->getActionText() . " $mark" . $formatter->getComment();
424 * Insert a formatted comment
425 * @param $rc RecentChange
428 public function insertComment( $rc ) {
429 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
430 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
431 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
433 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
439 * Check whether to enable recent changes patrol features
442 public static function usePatrol() {
444 return $wgUser->useRCPatrol();
448 * Returns the string which indicates the number of watching users
451 protected function numberofWatchingusers( $count ) {
452 static $cache = array();
454 if( !isset( $cache[$count] ) ) {
455 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
457 return $cache[$count];
464 * Determine if said field of a revision is hidden
465 * @param $rc RCCacheEntry
466 * @param $field Integer: one of DELETED_* bitfield constants
469 public static function isDeleted( $rc, $field ) {
470 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
474 * Determine if the current user is allowed to view a particular
475 * field of this revision, if it's marked as deleted.
476 * @param $rc RCCacheEntry
477 * @param $field Integer
478 * @param $user User object to check, or null to use $wgUser
481 public static function userCan( $rc, $field, User
$user = null ) {
482 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
483 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
485 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
490 * @param $link string
491 * @param $watched bool
494 protected function maybeWatchedLink( $link, $watched = false ) {
496 return '<strong class="mw-watched">' . $link . '</strong>';
498 return '<span class="mw-rc-unwatched">' . $link . '</span>';
502 /** Inserts a rollback link
505 * @param $rc RecentChange
507 public function insertRollback( &$s, &$rc ) {
508 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
509 $page = $rc->getTitle();
510 /** Check for rollback and edit permissions, disallow special pages, and only
511 * show a link on the top-most revision */
512 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
514 $rev = new Revision( array(
515 'id' => $rc->mAttribs
['rc_this_oldid'],
516 'user' => $rc->mAttribs
['rc_user'],
517 'user_text' => $rc->mAttribs
['rc_user_text'],
518 'deleted' => $rc->mAttribs
['rc_deleted']
520 $rev->setTitle( $page );
521 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
528 * @param $rc RecentChange
531 public function insertTags( &$s, &$rc, &$classes ) {
532 if ( empty($rc->mAttribs
['ts_tags']) )
535 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
536 $classes = array_merge( $classes, $newClasses );
537 $s .= ' ' . $tagSummary;
540 public function insertExtra( &$s, &$rc, &$classes ) {
541 ## Empty, used for subclassers to add anything special.
544 protected function showAsUnpatrolled( RecentChange
$rc ) {
545 $unpatrolled = false;
546 if ( !$rc->mAttribs
['rc_patrolled'] ) {
547 if ( $this->getUser()->useRCPatrol() ) {
549 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs
['rc_new'] ) {
559 * Generate a list of changes using the good old system (no javascript)
561 class OldChangesList
extends ChangesList
{
563 * Format a line using the old system (aka without any javascript).
565 * @param $rc RecentChange
568 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
569 global $wgRCShowChangedSize;
570 wfProfileIn( __METHOD__
);
572 # Should patrol-related stuff be shown?
573 $unpatrolled = $this->showAsUnpatrolled( $rc );
575 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
576 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
580 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
582 if( $linenumber & 1 ) {
583 $classes[] = 'mw-line-odd';
586 $classes[] = 'mw-line-even';
590 // Indicate watched status on the line to allow for more
591 // comprehensive styling.
592 $classes[] = $watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
594 // Moved pages (very very old, not supported anymore)
595 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
597 } elseif( $rc->mAttribs
['rc_log_type'] ) {
598 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
599 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
600 // Log entries (old format) or log targets, and special pages
601 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
602 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
603 if( $name == 'Log' ) {
604 $this->insertLog( $s, $rc->getTitle(), $subpage );
608 $this->insertDiffHist( $s, $rc, $unpatrolled );
609 # M, N, b and ! (minor, new, bot and unpatrolled)
610 $s .= $this->recentChangesFlags(
612 'newpage' => $rc->mAttribs
['rc_new'],
613 'minor' => $rc->mAttribs
['rc_minor'],
614 'unpatrolled' => $unpatrolled,
615 'bot' => $rc->mAttribs
['rc_bot']
619 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
622 $this->insertTimestamp( $s, $rc );
623 # Bytes added or removed
624 if ( $wgRCShowChangedSize ) {
625 $cd = $this->formatCharacterDifference( $rc );
631 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
632 $s .= $this->insertLogEntry( $rc );
635 $this->insertUserRelatedLinks( $s, $rc );
636 # LTR/RTL direction mark
637 $s .= $this->getLanguage()->getDirMark();
638 $s .= $this->insertComment( $rc );
642 $this->insertTags( $s, $rc, $classes );
644 $this->insertRollback( $s, $rc );
646 $this->insertExtra( $s, $rc, $classes );
648 # How many users watch this page
649 if( $rc->numberofWatchingusers
> 0 ) {
650 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers
);
653 if( $this->watchlist
) {
654 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
657 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
659 wfProfileOut( __METHOD__
);
660 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
666 * Generate a list of changes using an Enhanced system (uses javascript).
668 class EnhancedChangesList
extends ChangesList
{
673 * Add the JavaScript file for enhanced changeslist
676 public function beginRecentChangesList() {
677 $this->rc_cache
= array();
678 $this->rcMoveIndex
= 0;
679 $this->rcCacheIndex
= 0;
680 $this->lastdate
= '';
681 $this->rclistOpen
= false;
682 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
686 * Format a line for enhanced recentchange (aka with javascript and block of lines).
688 * @param $baseRC RecentChange
689 * @param $watched bool
693 public function recentChangesLine( &$baseRC, $watched = false ) {
694 wfProfileIn( __METHOD__
);
696 # Create a specialised object
697 $rc = RCCacheEntry
::newFromParent( $baseRC );
699 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
701 # If it's a new day, add the headline and flush the cache
702 $date = $this->getLanguage()->userDate( $rc->mAttribs
['rc_timestamp'], $this->getUser() );
704 if( $date != $this->lastdate
) {
705 # Process current cache
706 $ret = $this->recentChangesBlock();
707 $this->rc_cache
= array();
708 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
709 $this->lastdate
= $date;
712 # Should patrol-related stuff be shown?
713 $rc->unpatrolled
= $this->showAsUnpatrolled( $rc );
715 $showdifflinks = true;
717 $type = $rc->mAttribs
['rc_type'];
718 $logType = $rc->mAttribs
['rc_log_type'];
719 // Page moves, very old style, not supported anymore
720 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
721 // New unpatrolled pages
722 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
723 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
724 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
726 } elseif( $type == RC_LOG
) {
728 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
729 $logpage = new LogPage( $logType );
730 $logname = $logpage->getName()->escaped();
731 $clink = $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $logtitle, $logname ) )->escaped();
733 $clink = Linker
::link( $rc->getTitle() );
736 // Log entries (old format) and special pages
737 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
738 wfDebug( "Unexpected special page in recentchanges\n" );
742 $clink = Linker
::linkKnown( $rc->getTitle() );
745 # Don't show unusable diff links
746 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
747 $showdifflinks = false;
750 $time = $this->getLanguage()->userTime( $rc->mAttribs
['rc_timestamp'], $this->getUser() );
751 $rc->watched
= $watched;
753 $rc->timestamp
= $time;
754 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
756 # Make "cur" and "diff" links. Do not use link(), it is too slow if
757 # called too many times (50% of CPU time on RecentChanges!).
758 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
759 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
760 if( $rc->unpatrolled
) {
761 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
763 $rcIdQuery = array();
765 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
766 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
767 $lastOldid ) +
$rcIdQuery;
769 if( !$showdifflinks ) {
770 $curLink = $this->message
['cur'];
771 $diffLink = $this->message
['diff'];
772 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
773 if ( $type != RC_NEW
) {
774 $curLink = $this->message
['cur'];
776 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
777 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
779 $diffLink = $this->message
['diff'];
781 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
782 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
783 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
784 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
788 if( !$showdifflinks ||
!$lastOldid ) {
789 $lastLink = $this->message
['last'];
790 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
791 $lastLink = $this->message
['last'];
793 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
794 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
798 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
799 $rc->userlink
= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
801 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
802 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
805 $rc->lastlink
= $lastLink;
806 $rc->curlink
= $curLink;
807 $rc->difflink
= $diffLink;
809 # Put accumulated information into the cache, for later display
810 # Page moves go on their own line
811 $title = $rc->getTitle();
812 $secureName = $title->getPrefixedDBkey();
813 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
814 # Use an @ character to prevent collision with page names
815 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
817 # Logs are grouped by type
818 if( $type == RC_LOG
){
819 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
821 if( !isset( $this->rc_cache
[$secureName] ) ) {
822 $this->rc_cache
[$secureName] = array();
825 array_push( $this->rc_cache
[$secureName], $rc );
828 wfProfileOut( __METHOD__
);
837 protected function recentChangesBlockGroup( $block ) {
838 global $wgRCShowChangedSize;
840 wfProfileIn( __METHOD__
);
842 # Add the namespace and title of the block as part of the class
843 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
844 if ( $block[0]->mAttribs
['rc_log_type'] ) {
846 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
847 . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
849 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
850 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
852 $classes[] = $block[0]->watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
853 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
854 Html
::openElement( 'tr' );
856 # Collate list of users
857 $userlinks = array();
859 $unpatrolled = false;
861 $curId = $currentRevision = 0;
862 # Some catalyst variables...
865 foreach( $block as $rcObj ) {
866 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
867 if( $rcObj->mAttribs
['rc_new'] ) {
870 // If all log actions to this page were hidden, then don't
871 // give the name of the affected page for this block!
872 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
875 $u = $rcObj->userlink
;
876 if( !isset( $userlinks[$u] ) ) {
879 if( $rcObj->unpatrolled
) {
882 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
885 # Get the latest entry with a page_id and oldid
886 # since logs may not have these.
887 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
888 $curId = $rcObj->mAttribs
['rc_cur_id'];
890 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
891 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
894 $bot = $rcObj->mAttribs
['rc_bot'];
898 # Sort the list and convert to text
899 krsort( $userlinks );
902 foreach( $userlinks as $userlink => $count) {
904 $text .= $this->getLanguage()->getDirMark();
906 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
908 array_push( $users, $text );
911 $users = ' <span class="changedby">'
912 . $this->msg( 'brackets' )->rawParams(
913 implode( $this->message
['semicolon-separator'], $users )
914 )->escaped() . '</span>';
916 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow"></span>';
917 $r .= "<td>$tl</td>";
920 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
923 'unpatrolled' => $unpatrolled,
928 $r .= ' '.$block[0]->timestamp
.' </td><td>';
932 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
933 } elseif( $allLogs ) {
934 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
936 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
939 $r .= $this->getLanguage()->getDirMark();
941 $queryParams['curid'] = $curId;
944 static $nchanges = array();
945 if ( !isset( $nchanges[$n] ) ) {
946 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
952 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
953 $logtext .= $nchanges[$n];
955 $logtext .= $nchanges[$n];
957 $params = $queryParams;
958 $params['diff'] = $currentRevision;
959 $params['oldid'] = $oldid;
961 $logtext .= Linker
::link(
962 $block[0]->getTitle(),
966 array( 'known', 'noclasses' )
973 // don't show history link for logs
974 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
975 $logtext .= $this->message
['pipe-separator'] . $this->message
['hist'];
977 $params = $queryParams;
978 $params['action'] = 'history';
980 $logtext .= $this->message
['pipe-separator'] .
982 $block[0]->getTitle(),
983 $this->message
['hist'],
989 if( $logtext !== '' ) {
990 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
995 # Character difference (does not apply if only log items)
996 if( $wgRCShowChangedSize && !$allLogs ) {
998 $first = count($block) - 1;
999 # Some events (like logs) have an "empty" size, so we need to skip those...
1000 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
1003 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
1007 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
1009 if( $chardiff == '' ) {
1012 $r .= ' ' . $chardiff. ' . . ';
1017 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
1020 foreach( $block as $rcObj ) {
1021 # Classes to apply -- TODO implement
1023 $type = $rcObj->mAttribs
['rc_type'];
1025 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
1026 $r .= $this->recentChangesFlags( array(
1027 'newpage' => $rcObj->mAttribs
['rc_new'],
1028 'minor' => $rcObj->mAttribs
['rc_minor'],
1029 'unpatrolled' => $rcObj->unpatrolled
,
1030 'bot' => $rcObj->mAttribs
['rc_bot'],
1032 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1034 $params = $queryParams;
1036 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1037 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1041 if( $type == RC_LOG
) {
1042 $link = $rcObj->timestamp
;
1044 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
1045 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1047 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1048 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1051 $link = Linker
::linkKnown(
1057 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1058 $link = '<span class="history-deleted">'.$link.'</span> ';
1060 $r .= $link . '</span>';
1062 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1063 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink
. $this->message
['pipe-separator'] . $rcObj->lastlink
)->escaped();
1068 if ( $wgRCShowChangedSize ) {
1069 $cd = $this->formatCharacterDifference( $rcObj );
1075 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1076 $r .= $this->insertLogEntry( $rcObj );
1079 $r .= $rcObj->userlink
;
1080 $r .= $rcObj->usertalklink
;
1081 $r .= $this->insertComment( $rcObj );
1085 $this->insertRollback( $r, $rcObj );
1087 $this->insertTags( $r, $rcObj, $classes );
1089 $r .= "</td></tr>\n";
1093 $this->rcCacheIndex++
;
1095 wfProfileOut( __METHOD__
);
1101 * Generate HTML for an arrow or placeholder graphic
1102 * @param $dir String: one of '', 'd', 'l', 'r'
1103 * @param $alt String: text
1104 * @param $title String: text
1105 * @return String: HTML <img> tag
1107 protected function arrow( $dir, $alt='', $title='' ) {
1108 global $wgStylePath;
1109 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1110 $encAlt = htmlspecialchars( $alt );
1111 $encTitle = htmlspecialchars( $title );
1112 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1116 * Generate HTML for a right- or left-facing arrow,
1117 * depending on language direction.
1118 * @return String: HTML <img> tag
1120 protected function sideArrow() {
1121 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
1122 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
1126 * Generate HTML for a down-facing arrow
1127 * depending on language direction.
1128 * @return String: HTML <img> tag
1130 protected function downArrow() {
1131 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
1135 * Generate HTML for a spacer image
1136 * @return String: HTML <img> tag
1138 protected function spacerArrow() {
1139 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1143 * Enhanced RC ungrouped line.
1145 * @param $rcObj RecentChange
1146 * @return String: a HTML formatted line (generated using $r)
1148 protected function recentChangesBlockLine( $rcObj ) {
1149 global $wgRCShowChangedSize;
1151 wfProfileIn( __METHOD__
);
1152 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1154 $type = $rcObj->mAttribs
['rc_type'];
1155 $logType = $rcObj->mAttribs
['rc_log_type'];
1156 $classes = array( 'mw-enhanced-rc' );
1159 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
1160 . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1162 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
1163 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1165 $classes[] = $rcObj->watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
1166 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1167 Html
::openElement( 'tr' );
1169 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
1170 # Flag and Timestamp
1171 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1172 $r .= '    '; // 4 flags -> 4 spaces
1174 $r .= $this->recentChangesFlags( array(
1175 'newpage' => $type == RC_NEW
,
1176 'minor' => $rcObj->mAttribs
['rc_minor'],
1177 'unpatrolled' => $rcObj->unpatrolled
,
1178 'bot' => $rcObj->mAttribs
['rc_bot'],
1181 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1182 # Article or log link
1184 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1185 $logname = LogPage
::logName( $logType );
1186 $r .= $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) )->escaped();
1188 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1190 # Diff and hist links
1191 if ( $type != RC_LOG
) {
1192 $query['action'] = 'history';
1193 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
1195 $this->message
['hist'],
1202 if ( $wgRCShowChangedSize ) {
1203 $cd = $this->formatCharacterDifference( $rcObj );
1209 if ( $type == RC_LOG
) {
1210 $r .= $this->insertLogEntry( $rcObj );
1212 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1213 $r .= $this->insertComment( $rcObj );
1214 $this->insertRollback( $r, $rcObj );
1218 $classes = explode( ' ', $classes );
1219 $this->insertTags( $r, $rcObj, $classes );
1220 # Show how many people are watching this if enabled
1221 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1223 $r .= "</td></tr></table>\n";
1225 wfProfileOut( __METHOD__
);
1231 * If enhanced RC is in use, this function takes the previously cached
1232 * RC lines, arranges them, and outputs the HTML
1236 protected function recentChangesBlock() {
1237 if( count ( $this->rc_cache
) == 0 ) {
1241 wfProfileIn( __METHOD__
);
1244 foreach( $this->rc_cache
as $block ) {
1245 if( count( $block ) < 2 ) {
1246 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1248 $blockOut .= $this->recentChangesBlockGroup( $block );
1252 wfProfileOut( __METHOD__
);
1254 return '<div>'.$blockOut.'</div>';
1258 * Returns text for the end of RC
1259 * If enhanced RC is in use, returns pretty much all the text
1262 public function endRecentChangesList() {
1263 return $this->recentChangesBlock() . parent
::endRecentChangesList();