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] = 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
) {
289 public function insertDateHeader( &$s, $rc_timestamp ) {
290 # Make date header if necessary
291 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
292 if( $date != $this->lastdate
) {
293 if( $this->lastdate
!= '' ) {
296 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
297 $this->lastdate
= $date;
298 $this->rclistOpen
= true;
302 public function insertLog( &$s, $title, $logtype ) {
303 $page = new LogPage( $logtype );
304 $logname = $page->getName()->escaped();
305 $s .= $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $title, $logname ) )->escaped();
310 * @param $rc RecentChange
311 * @param $unpatrolled
313 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
315 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
316 $diffLink = $this->message
['diff'];
317 } elseif ( !self
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
318 $diffLink = $this->message
['diff'];
321 'curid' => $rc->mAttribs
['rc_cur_id'],
322 'diff' => $rc->mAttribs
['rc_this_oldid'],
323 'oldid' => $rc->mAttribs
['rc_last_oldid']
327 $query['rcid'] = $rc->mAttribs
['rc_id'];
330 $diffLink = Linker
::linkKnown(
332 $this->message
['diff'],
333 array( 'tabindex' => $rc->counter
),
337 $diffhist = $diffLink . $this->message
['pipe-separator'];
339 $diffhist .= Linker
::linkKnown(
341 $this->message
['hist'],
344 'curid' => $rc->mAttribs
['rc_cur_id'],
345 'action' => 'history'
348 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' <span class="mw-changeslist-separator">. .</span> ';
353 * @param $rc RecentChange
354 * @param $unpatrolled
357 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
358 # If it's a new article, there is no diff link, but if it hasn't been
359 # patrolled yet, we need to give users a way to do so
362 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
363 $params['rcid'] = $rc->mAttribs
['rc_id'];
366 $articlelink = Linker
::linkKnown(
369 array( 'class' => 'mw-changeslist-title' ),
372 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
373 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
375 # To allow for boldening pages watched by this user
376 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
378 $articlelink .= $this->getLanguage()->getDirMark();
380 wfRunHooks( 'ChangesListInsertArticleLink',
381 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
383 $s .= " $articlelink";
388 * @param $rc RecentChange
390 public function insertTimestamp( &$s, $rc ) {
391 $s .= $this->message
['semicolon-separator'] . '<span class="mw-changeslist-date">' .
392 $this->getLanguage()->userTime( $rc->mAttribs
['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
396 * Insert links to user page, user talk page and eventually a blocking link
398 * @param &$s String HTML to update
399 * @param &$rc RecentChange
401 public function insertUserRelatedLinks( &$s, &$rc ) {
402 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
403 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
405 $s .= $this->getLanguage()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'],
406 $rc->mAttribs
['rc_user_text'] );
407 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
412 * Insert a formatted action
414 * @param $rc RecentChange
417 public function insertLogEntry( $rc ) {
418 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
419 $formatter->setContext( $this->getContext() );
420 $formatter->setShowUserToolLinks( true );
421 $mark = $this->getLanguage()->getDirMark();
422 return $formatter->getActionText() . " $mark" . $formatter->getComment();
426 * Insert a formatted comment
427 * @param $rc RecentChange
430 public function insertComment( $rc ) {
431 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
432 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
433 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
435 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
441 * Check whether to enable recent changes patrol features
444 public static function usePatrol() {
446 return $wgUser->useRCPatrol();
450 * Returns the string which indicates the number of watching users
453 protected function numberofWatchingusers( $count ) {
454 static $cache = array();
456 if( !isset( $cache[$count] ) ) {
457 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
459 return $cache[$count];
466 * Determine if said field of a revision is hidden
467 * @param $rc RCCacheEntry
468 * @param $field Integer: one of DELETED_* bitfield constants
471 public static function isDeleted( $rc, $field ) {
472 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
476 * Determine if the current user is allowed to view a particular
477 * field of this revision, if it's marked as deleted.
478 * @param $rc RCCacheEntry
479 * @param $field Integer
480 * @param $user User object to check, or null to use $wgUser
483 public static function userCan( $rc, $field, User
$user = null ) {
484 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
485 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
487 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field, $user );
492 * @param $link string
493 * @param $watched bool
496 protected function maybeWatchedLink( $link, $watched = false ) {
498 return '<strong class="mw-watched">' . $link . '</strong>';
500 return '<span class="mw-rc-unwatched">' . $link . '</span>';
504 /** Inserts a rollback link
507 * @param $rc RecentChange
509 public function insertRollback( &$s, &$rc ) {
510 if( $rc->mAttribs
['rc_type'] != RC_NEW
&& $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
511 $page = $rc->getTitle();
512 /** Check for rollback and edit permissions, disallow special pages, and only
513 * show a link on the top-most revision */
514 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
516 $rev = new Revision( array(
517 'id' => $rc->mAttribs
['rc_this_oldid'],
518 'user' => $rc->mAttribs
['rc_user'],
519 'user_text' => $rc->mAttribs
['rc_user_text'],
520 'deleted' => $rc->mAttribs
['rc_deleted']
522 $rev->setTitle( $page );
523 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
530 * @param $rc RecentChange
533 public function insertTags( &$s, &$rc, &$classes ) {
534 if ( empty($rc->mAttribs
['ts_tags']) )
537 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
538 $classes = array_merge( $classes, $newClasses );
539 $s .= ' ' . $tagSummary;
542 public function insertExtra( &$s, &$rc, &$classes ) {
543 ## Empty, used for subclassers to add anything special.
546 protected function showAsUnpatrolled( RecentChange
$rc ) {
547 $unpatrolled = false;
548 if ( !$rc->mAttribs
['rc_patrolled'] ) {
549 if ( $this->getUser()->useRCPatrol() ) {
551 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs
['rc_type'] == RC_NEW
) {
561 * Generate a list of changes using the good old system (no javascript)
563 class OldChangesList
extends ChangesList
{
565 * Format a line using the old system (aka without any javascript).
567 * @param $rc RecentChange, passed by reference
568 * @param $watched Bool (default false)
569 * @param $linenumber Int (default null)
572 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
573 global $wgRCShowChangedSize;
574 wfProfileIn( __METHOD__
);
576 # Should patrol-related stuff be shown?
577 $unpatrolled = $this->showAsUnpatrolled( $rc );
579 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
580 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
584 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
586 if( $linenumber & 1 ) {
587 $classes[] = 'mw-line-odd';
590 $classes[] = 'mw-line-even';
594 // Indicate watched status on the line to allow for more
595 // comprehensive styling.
596 $classes[] = $watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
598 // Moved pages (very very old, not supported anymore)
599 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
601 } elseif( $rc->mAttribs
['rc_log_type'] ) {
602 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
603 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
604 // Log entries (old format) or log targets, and special pages
605 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
606 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
607 if( $name == 'Log' ) {
608 $this->insertLog( $s, $rc->getTitle(), $subpage );
612 $this->insertDiffHist( $s, $rc, $unpatrolled );
613 # M, N, b and ! (minor, new, bot and unpatrolled)
614 $s .= $this->recentChangesFlags(
616 'newpage' => $rc->mAttribs
['rc_type'] == RC_NEW
,
617 'minor' => $rc->mAttribs
['rc_minor'],
618 'unpatrolled' => $unpatrolled,
619 'bot' => $rc->mAttribs
['rc_bot']
623 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
626 $this->insertTimestamp( $s, $rc );
627 # Bytes added or removed
628 if ( $wgRCShowChangedSize ) {
629 $cd = $this->formatCharacterDifference( $rc );
631 $s .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
635 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
636 $s .= $this->insertLogEntry( $rc );
639 $this->insertUserRelatedLinks( $s, $rc );
640 # LTR/RTL direction mark
641 $s .= $this->getLanguage()->getDirMark();
642 $s .= $this->insertComment( $rc );
646 $this->insertTags( $s, $rc, $classes );
648 $this->insertRollback( $s, $rc );
650 $this->insertExtra( $s, $rc, $classes );
652 # How many users watch this page
653 if( $rc->numberofWatchingusers
> 0 ) {
654 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers
);
657 if( $this->watchlist
) {
658 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
661 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
663 wfProfileOut( __METHOD__
);
664 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
670 * Generate a list of changes using an Enhanced system (uses javascript).
672 class EnhancedChangesList
extends ChangesList
{
677 * Add the JavaScript file for enhanced changeslist
680 public function beginRecentChangesList() {
681 $this->rc_cache
= array();
682 $this->rcMoveIndex
= 0;
683 $this->rcCacheIndex
= 0;
684 $this->lastdate
= '';
685 $this->rclistOpen
= false;
686 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
690 * Format a line for enhanced recentchange (aka with javascript and block of lines).
692 * @param $baseRC RecentChange
693 * @param $watched bool
697 public function recentChangesLine( &$baseRC, $watched = false ) {
698 wfProfileIn( __METHOD__
);
700 # Create a specialised object
701 $rc = RCCacheEntry
::newFromParent( $baseRC );
703 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
705 # If it's a new day, add the headline and flush the cache
706 $date = $this->getLanguage()->userDate( $rc->mAttribs
['rc_timestamp'], $this->getUser() );
708 if( $date != $this->lastdate
) {
709 # Process current cache
710 $ret = $this->recentChangesBlock();
711 $this->rc_cache
= array();
712 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
713 $this->lastdate
= $date;
716 # Should patrol-related stuff be shown?
717 $rc->unpatrolled
= $this->showAsUnpatrolled( $rc );
719 $showdifflinks = true;
721 $type = $rc->mAttribs
['rc_type'];
722 $logType = $rc->mAttribs
['rc_log_type'];
723 // Page moves, very old style, not supported anymore
724 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
725 // New unpatrolled pages
726 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
727 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
728 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
730 } elseif( $type == RC_LOG
) {
732 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
733 $logpage = new LogPage( $logType );
734 $logname = $logpage->getName()->escaped();
735 $clink = $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $logtitle, $logname ) )->escaped();
737 $clink = Linker
::link( $rc->getTitle() );
740 // Log entries (old format) and special pages
741 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
742 wfDebug( "Unexpected special page in recentchanges\n" );
746 $clink = Linker
::linkKnown( $rc->getTitle() );
749 # Don't show unusable diff links
750 if ( !ChangesList
::userCan( $rc, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
751 $showdifflinks = false;
754 $time = $this->getLanguage()->userTime( $rc->mAttribs
['rc_timestamp'], $this->getUser() );
755 $rc->watched
= $watched;
757 $rc->timestamp
= $time;
758 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
760 # Make "cur" and "diff" links. Do not use link(), it is too slow if
761 # called too many times (50% of CPU time on RecentChanges!).
762 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
763 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
764 if( $rc->unpatrolled
) {
765 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
767 $rcIdQuery = array();
769 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
770 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
771 $lastOldid ) +
$rcIdQuery;
773 if( !$showdifflinks ) {
774 $curLink = $this->message
['cur'];
775 $diffLink = $this->message
['diff'];
776 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
777 if ( $type != RC_NEW
) {
778 $curLink = $this->message
['cur'];
780 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
781 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
783 $diffLink = $this->message
['diff'];
785 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
786 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
787 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
788 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
792 if( !$showdifflinks ||
!$lastOldid ) {
793 $lastLink = $this->message
['last'];
794 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
795 $lastLink = $this->message
['last'];
797 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
798 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
802 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
803 $rc->userlink
= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
805 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
806 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
809 $rc->lastlink
= $lastLink;
810 $rc->curlink
= $curLink;
811 $rc->difflink
= $diffLink;
813 # Put accumulated information into the cache, for later display
814 # Page moves go on their own line
815 $title = $rc->getTitle();
816 $secureName = $title->getPrefixedDBkey();
817 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
818 # Use an @ character to prevent collision with page names
819 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
821 # Logs are grouped by type
822 if( $type == RC_LOG
){
823 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
825 if( !isset( $this->rc_cache
[$secureName] ) ) {
826 $this->rc_cache
[$secureName] = array();
829 array_push( $this->rc_cache
[$secureName], $rc );
832 wfProfileOut( __METHOD__
);
841 protected function recentChangesBlockGroup( $block ) {
842 global $wgRCShowChangedSize;
844 wfProfileIn( __METHOD__
);
846 # Add the namespace and title of the block as part of the class
847 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
848 if ( $block[0]->mAttribs
['rc_log_type'] ) {
850 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
851 . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
853 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns'
854 . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
856 $classes[] = $block[0]->watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
857 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
858 Html
::openElement( 'tr' );
860 # Collate list of users
861 $userlinks = array();
863 $unpatrolled = false;
865 $curId = $currentRevision = 0;
866 # Some catalyst variables...
869 foreach( $block as $rcObj ) {
870 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
871 if( $rcObj->mAttribs
['rc_type'] == RC_NEW
) {
874 // If all log actions to this page were hidden, then don't
875 // give the name of the affected page for this block!
876 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
879 $u = $rcObj->userlink
;
880 if( !isset( $userlinks[$u] ) ) {
883 if( $rcObj->unpatrolled
) {
886 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
889 # Get the latest entry with a page_id and oldid
890 # since logs may not have these.
891 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
892 $curId = $rcObj->mAttribs
['rc_cur_id'];
894 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
895 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
898 $bot = $rcObj->mAttribs
['rc_bot'];
902 # Sort the list and convert to text
903 krsort( $userlinks );
906 foreach( $userlinks as $userlink => $count) {
908 $text .= $this->getLanguage()->getDirMark();
910 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
912 array_push( $users, $text );
915 $users = ' <span class="changedby">'
916 . $this->msg( 'brackets' )->rawParams(
917 implode( $this->message
['semicolon-separator'], $users )
918 )->escaped() . '</span>';
920 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow"></span>';
921 $r .= "<td>$tl</td>";
924 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
927 'unpatrolled' => $unpatrolled,
932 $r .= ' '.$block[0]->timestamp
.' </td><td>';
936 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
937 } elseif( $allLogs ) {
938 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
940 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
943 $r .= $this->getLanguage()->getDirMark();
945 $queryParams['curid'] = $curId;
948 static $nchanges = array();
949 if ( !isset( $nchanges[$n] ) ) {
950 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
956 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
957 $logtext .= $nchanges[$n];
959 $logtext .= $nchanges[$n];
961 $params = $queryParams;
962 $params['diff'] = $currentRevision;
963 $params['oldid'] = $oldid;
965 $logtext .= Linker
::link(
966 $block[0]->getTitle(),
970 array( 'known', 'noclasses' )
977 // don't show history link for logs
978 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
979 $logtext .= $this->message
['pipe-separator'] . $this->message
['hist'];
981 $params = $queryParams;
982 $params['action'] = 'history';
984 $logtext .= $this->message
['pipe-separator'] .
986 $block[0]->getTitle(),
987 $this->message
['hist'],
993 if( $logtext !== '' ) {
994 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
997 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
999 # Character difference (does not apply if only log items)
1000 if( $wgRCShowChangedSize && !$allLogs ) {
1002 $first = count($block) - 1;
1003 # Some events (like logs) have an "empty" size, so we need to skip those...
1004 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
1007 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
1011 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
1013 if( $chardiff == '' ) {
1016 $r .= ' ' . $chardiff. ' <span class="mw-changeslist-separator">. .</span> ';
1021 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
1024 foreach( $block as $rcObj ) {
1025 # Classes to apply -- TODO implement
1027 $type = $rcObj->mAttribs
['rc_type'];
1029 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
1030 $r .= $this->recentChangesFlags( array(
1031 'newpage' => $type == RC_NEW
,
1032 'minor' => $rcObj->mAttribs
['rc_minor'],
1033 'unpatrolled' => $rcObj->unpatrolled
,
1034 'bot' => $rcObj->mAttribs
['rc_bot'],
1036 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1038 $params = $queryParams;
1040 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1041 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1045 if( $type == RC_LOG
) {
1046 $link = $rcObj->timestamp
;
1048 } elseif( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
, $this->getUser() ) ) {
1049 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1051 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1052 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1055 $link = Linker
::linkKnown(
1061 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1062 $link = '<span class="history-deleted">'.$link.'</span> ';
1064 $r .= $link . '</span>';
1066 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1067 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink
. $this->message
['pipe-separator'] . $rcObj->lastlink
)->escaped();
1069 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1072 if ( $wgRCShowChangedSize ) {
1073 $cd = $this->formatCharacterDifference( $rcObj );
1075 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1079 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1080 $r .= $this->insertLogEntry( $rcObj );
1083 $r .= $rcObj->userlink
;
1084 $r .= $rcObj->usertalklink
;
1085 $r .= $this->insertComment( $rcObj );
1089 $this->insertRollback( $r, $rcObj );
1091 $this->insertTags( $r, $rcObj, $classes );
1093 $r .= "</td></tr>\n";
1097 $this->rcCacheIndex++
;
1099 wfProfileOut( __METHOD__
);
1105 * Generate HTML for an arrow or placeholder graphic
1106 * @param $dir String: one of '', 'd', 'l', 'r'
1107 * @param $alt String: text
1108 * @param $title String: text
1109 * @return String: HTML "<img>" tag
1111 protected function arrow( $dir, $alt='', $title='' ) {
1112 global $wgStylePath;
1113 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1114 $encAlt = htmlspecialchars( $alt );
1115 $encTitle = htmlspecialchars( $title );
1116 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1120 * Generate HTML for a right- or left-facing arrow,
1121 * depending on language direction.
1122 * @return String: HTML "<img>" tag
1124 protected function sideArrow() {
1125 $dir = $this->getLanguage()->isRTL() ?
'l' : 'r';
1126 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
1130 * Generate HTML for a down-facing arrow
1131 * depending on language direction.
1132 * @return String: HTML "<img>" tag
1134 protected function downArrow() {
1135 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
1139 * Generate HTML for a spacer image
1140 * @return String: HTML "<img>" tag
1142 protected function spacerArrow() {
1143 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1147 * Enhanced RC ungrouped line.
1149 * @param $rcObj RecentChange
1150 * @return String: a HTML formatted line (generated using $r)
1152 protected function recentChangesBlockLine( $rcObj ) {
1153 global $wgRCShowChangedSize;
1155 wfProfileIn( __METHOD__
);
1156 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1158 $type = $rcObj->mAttribs
['rc_type'];
1159 $logType = $rcObj->mAttribs
['rc_log_type'];
1160 $classes = array( 'mw-enhanced-rc' );
1163 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-log-'
1164 . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1166 $classes[] = Sanitizer
::escapeClass( 'mw-changeslist-ns' .
1167 $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1169 $classes[] = $rcObj->watched ?
'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
1170 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1171 Html
::openElement( 'tr' );
1173 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
1174 # Flag and Timestamp
1175 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1176 $r .= '    '; // 4 flags -> 4 spaces
1178 $r .= $this->recentChangesFlags( array(
1179 'newpage' => $type == RC_NEW
,
1180 'minor' => $rcObj->mAttribs
['rc_minor'],
1181 'unpatrolled' => $rcObj->unpatrolled
,
1182 'bot' => $rcObj->mAttribs
['rc_bot'],
1185 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1186 # Article or log link
1188 $logPage = new LogPage( $logType );
1189 $logTitle = SpecialPage
::getTitleFor( 'Log', $logType );
1190 $logName = $logPage->getName()->escaped();
1191 $r .= $this->msg( 'parentheses' )->rawParams( Linker
::linkKnown( $logTitle, $logName ) )->escaped();
1193 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1195 # Diff and hist links
1196 if ( $type != RC_LOG
) {
1197 $query['action'] = 'history';
1198 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink
. $this->message
['pipe-separator'] . Linker
::linkKnown(
1200 $this->message
['hist'],
1205 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
1207 if ( $wgRCShowChangedSize ) {
1208 $cd = $this->formatCharacterDifference( $rcObj );
1210 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
1214 if ( $type == RC_LOG
) {
1215 $r .= $this->insertLogEntry( $rcObj );
1217 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1218 $r .= $this->insertComment( $rcObj );
1219 $this->insertRollback( $r, $rcObj );
1223 $this->insertTags( $r, $rcObj, $classes );
1224 # Show how many people are watching this if enabled
1225 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1227 $r .= "</td></tr></table>\n";
1229 wfProfileOut( __METHOD__
);
1235 * If enhanced RC is in use, this function takes the previously cached
1236 * RC lines, arranges them, and outputs the HTML
1240 protected function recentChangesBlock() {
1241 if( count ( $this->rc_cache
) == 0 ) {
1245 wfProfileIn( __METHOD__
);
1248 foreach( $this->rc_cache
as $block ) {
1249 if( count( $block ) < 2 ) {
1250 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1252 $blockOut .= $this->recentChangesBlockGroup( $block );
1256 wfProfileOut( __METHOD__
);
1258 return '<div>'.$blockOut.'</div>';
1262 * Returns text for the end of RC
1263 * If enhanced RC is in use, returns pretty much all the text
1266 public function endRecentChangesList() {
1267 return $this->recentChangesBlock() . parent
::endRecentChangesList();