3 * Classes to show various lists of changes:
14 class RCCacheEntry
extends RecentChange
{
15 var $secureName, $link;
16 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
17 var $userlink, $timestamp, $watched;
20 * @param $rc RecentChange
21 * @return RCCacheEntry
23 static function newFromParent( $rc ) {
24 $rc2 = new RCCacheEntry
;
25 $rc2->mAttribs
= $rc->mAttribs
;
26 $rc2->mExtra
= $rc->mExtra
;
32 * Base class for all changes lists
34 class ChangesList
extends ContextSource
{
41 protected $watchlist = false;
46 * Changeslist contructor
48 * @param $obj Skin or RequestContext
50 public function __construct( $obj ) {
51 if ( $obj instanceof RequestContext
) {
52 $this->setContext( $obj );
53 $this->skin
= $obj->getSkin();
55 $this->setContext( $obj->getContext() );
58 $this->preCacheMessages();
62 * Fetch an appropriate changes list class for the main context
63 * This first argument used to be an User object.
65 * @deprecated in 1.18; use newFromContext() instead
66 * @param $unused Unused
67 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
69 public static function newFromUser( $unused ) {
70 return self
::newFromContext( RequestContext
::getMain() );
74 * Fetch an appropriate changes list class for the specified context
75 * Some users might want to use an enhanced list format, for instance
77 * @param $context RequestContext to use
78 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
80 public static function newFromContext( RequestContext
$context ) {
81 $user = $context->getUser();
82 $sk = $context->getSkin();
84 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
85 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
86 return $new ?
new EnhancedChangesList( $context ) : new OldChangesList( $context );
93 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
94 * @param $value Boolean
96 public function setWatchlistDivs( $value = true ) {
97 $this->watchlist
= $value;
101 * As we use the same small set of messages in various methods and that
102 * they are called often, we call them once and save them in $this->message
104 private function preCacheMessages() {
105 if( !isset( $this->message
) ) {
106 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
107 'semicolon-separator pipe-separator' ) as $msg ) {
108 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
114 * Returns the appropriate flags for new page, minor change and patrolling
115 * @param $flags Array Associative array of 'flag' => Bool
116 * @param $nothing String to use for empty space
119 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
121 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
122 $f .= isset( $flags[$flag] ) && $flags[$flag]
123 ? self
::flag( $flag )
130 * Provide the <abbr> element appropriate to a given abbreviated flag,
131 * namely the flag indicating a new page, a minor edit, a bot edit, or an
132 * unpatrolled edit. By default in English it will contain "N", "m", "b",
133 * "!" respectively, plus it will have an appropriate title and class.
135 * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot'
136 * @return String: Raw HTML
138 public static function flag( $flag ) {
139 static $messages = null;
140 if ( is_null( $messages ) ) {
142 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
143 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
144 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
145 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
147 foreach( $messages as &$value ) {
148 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
149 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
153 # Inconsistent naming, bleh
155 'newpage' => 'newpage',
156 'minor' => 'minoredit',
158 'unpatrolled' => 'unpatrolled',
159 'minoredit' => 'minoredit',
160 'botedit' => 'botedit',
164 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
168 * Returns text for the start of the tabular part of RC
171 public function beginRecentChangesList() {
172 $this->rc_cache
= array();
173 $this->rcMoveIndex
= 0;
174 $this->rcCacheIndex
= 0;
175 $this->lastdate
= '';
176 $this->rclistOpen
= false;
181 * Show formatted char difference
182 * @param $old Integer: bytes
183 * @param $new Integer: bytes
186 public static function showCharacterDifference( $old, $new ) {
187 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
188 $szdiff = $new - $old;
190 $code = $wgLang->getCode();
191 static $fastCharDiff = array();
192 if ( !isset($fastCharDiff[$code]) ) {
193 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
196 $formatedSize = $wgLang->formatNum($szdiff);
198 if ( !$fastCharDiff[$code] ) {
199 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
202 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
207 if( $szdiff === 0 ) {
208 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
209 } elseif( $szdiff > 0 ) {
210 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
212 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
217 * Returns text for the end of RC
220 public function endRecentChangesList() {
221 if( $this->rclistOpen
) {
228 public function insertDateHeader( &$s, $rc_timestamp ) {
229 # Make date header if necessary
230 $date = $this->getLang()->date( $rc_timestamp, true, true );
231 if( $date != $this->lastdate
) {
232 if( $this->lastdate
!= '' ) {
235 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
236 $this->lastdate
= $date;
237 $this->rclistOpen
= true;
241 public function insertLog( &$s, $title, $logtype ) {
242 $page = new LogPage( $logtype );
243 $logname = $page->getName()->escaped();
244 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
249 * @param $rc RecentChange
250 * @param $unpatrolled
253 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
255 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
256 $diffLink = $this->message
['diff'];
257 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
258 $diffLink = $this->message
['diff'];
261 'curid' => $rc->mAttribs
['rc_cur_id'],
262 'diff' => $rc->mAttribs
['rc_this_oldid'],
263 'oldid' => $rc->mAttribs
['rc_last_oldid']
267 $query['rcid'] = $rc->mAttribs
['rc_id'];
270 $diffLink = Linker
::linkKnown(
272 $this->message
['diff'],
273 array( 'tabindex' => $rc->counter
),
277 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
279 $s .= Linker
::linkKnown(
281 $this->message
['hist'],
284 'curid' => $rc->mAttribs
['rc_cur_id'],
285 'action' => 'history'
293 * @param $rc RecentChange
294 * @param $unpatrolled
298 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
299 # If it's a new article, there is no diff link, but if it hasn't been
300 # patrolled yet, we need to give users a way to do so
303 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
304 $params['rcid'] = $rc->mAttribs
['rc_id'];
307 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
308 $articlelink = Linker
::linkKnown(
314 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
316 $articlelink = ' '. Linker
::linkKnown(
323 # Bolden pages watched by this user
325 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
328 $articlelink .= $this->getLang()->getDirMark();
330 wfRunHooks( 'ChangesListInsertArticleLink',
331 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
333 $s .= " $articlelink";
338 * @param $rc RecentChange
341 public function insertTimestamp( &$s, $rc ) {
342 $s .= $this->message
['semicolon-separator'] .
343 $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
346 /** Insert links to user page, user talk page and eventually a blocking link
348 * @param $rc RecentChange
350 public function insertUserRelatedLinks( &$s, &$rc ) {
351 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
352 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
354 $s .= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
355 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
359 /** insert a formatted action
361 * @param $rc RecentChange
363 public function insertLogEntry( $rc ) {
364 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
365 $formatter->setShowUserToolLinks( true );
366 $mark = $this->getLang()->getDirMark();
367 return $formatter->getActionText() . " $mark" . $formatter->getComment();
371 * Check whether to enable recent changes patrol features
374 public static function usePatrol() {
376 return $wgUser->useRCPatrol();
380 * Returns the string which indicates the number of watching users
382 protected function numberofWatchingusers( $count ) {
383 static $cache = array();
385 if( !isset( $cache[$count] ) ) {
386 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
387 array('parsemag', 'escape' ), $this->getLang()->formatNum( $count ) );
389 return $cache[$count];
396 * Determine if said field of a revision is hidden
397 * @param $rc RCCacheEntry
398 * @param $field Integer: one of DELETED_* bitfield constants
401 public static function isDeleted( $rc, $field ) {
402 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
406 * Determine if the current user is allowed to view a particular
407 * field of this revision, if it's marked as deleted.
408 * @param $rc RCCacheEntry
409 * @param $field Integer
412 public static function userCan( $rc, $field ) {
413 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
414 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
416 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
420 protected function maybeWatchedLink( $link, $watched = false ) {
422 return '<strong class="mw-watched">' . $link . '</strong>';
424 return '<span class="mw-rc-unwatched">' . $link . '</span>';
428 /** Inserts a rollback link
431 * @param $rc RecentChange
433 public function insertRollback( &$s, &$rc ) {
434 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
435 $page = $rc->getTitle();
436 /** Check for rollback and edit permissions, disallow special pages, and only
437 * show a link on the top-most revision */
438 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
440 $rev = new Revision( array(
441 'id' => $rc->mAttribs
['rc_this_oldid'],
442 'user' => $rc->mAttribs
['rc_user'],
443 'user_text' => $rc->mAttribs
['rc_user_text'],
444 'deleted' => $rc->mAttribs
['rc_deleted']
446 $rev->setTitle( $page );
447 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
454 * @param $rc RecentChange
458 public function insertTags( &$s, &$rc, &$classes ) {
459 if ( empty($rc->mAttribs
['ts_tags']) )
462 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
463 $classes = array_merge( $classes, $newClasses );
464 $s .= ' ' . $tagSummary;
467 public function insertExtra( &$s, &$rc, &$classes ) {
468 ## Empty, used for subclassers to add anything special.
474 * Generate a list of changes using the good old system (no javascript)
476 class OldChangesList
extends ChangesList
{
478 * Format a line using the old system (aka without any javascript).
480 * @param $rc RecentChange
482 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
483 global $wgRCShowChangedSize;
484 wfProfileIn( __METHOD__
);
485 # Should patrol-related stuff be shown?
486 $unpatrolled = $this->getUser()->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
488 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
489 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
493 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
495 if( $linenumber & 1 ) {
496 $classes[] = 'mw-line-odd';
499 $classes[] = 'mw-line-even';
503 // Moved pages (very very old, not supported anymore)
504 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
506 } elseif( $rc->mAttribs
['rc_log_type'] ) {
507 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
508 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
509 // Log entries (old format) or log targets, and special pages
510 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
511 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
512 if( $name == 'Log' ) {
513 $this->insertLog( $s, $rc->getTitle(), $subpage );
517 $this->insertDiffHist( $s, $rc, $unpatrolled );
518 # M, N, b and ! (minor, new, bot and unpatrolled)
519 $s .= $this->recentChangesFlags(
521 'newpage' => $rc->mAttribs
['rc_new'],
522 'minor' => $rc->mAttribs
['rc_minor'],
523 'unpatrolled' => $unpatrolled,
524 'bot' => $rc->mAttribs
['rc_bot']
528 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
531 $this->insertTimestamp( $s, $rc );
532 # Bytes added or removed
533 if( $wgRCShowChangedSize ) {
534 $cd = $rc->getCharacterDifference();
540 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
541 $s .= $this->insertLogEntry( $rc );
544 $this->insertUserRelatedLinks( $s, $rc );
545 # LTR/RTL direction mark
546 $s .= $this->getLang()->getDirMark();
550 $this->insertTags( $s, $rc, $classes );
552 $this->insertRollback( $s, $rc );
554 $this->insertExtra( $s, $rc, $classes );
556 # How many users watch this page
557 if( $rc->numberofWatchingusers
> 0 ) {
558 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
559 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
562 if( $this->watchlist
) {
563 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
566 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
568 wfProfileOut( __METHOD__
);
569 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
575 * Generate a list of changes using an Enhanced system (uses javascript).
577 class EnhancedChangesList
extends ChangesList
{
579 * Add the JavaScript file for enhanced changeslist
582 public function beginRecentChangesList() {
583 $this->rc_cache
= array();
584 $this->rcMoveIndex
= 0;
585 $this->rcCacheIndex
= 0;
586 $this->lastdate
= '';
587 $this->rclistOpen
= false;
588 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
592 * Format a line for enhanced recentchange (aka with javascript and block of lines).
594 * @param $baseRC RecentChange
595 * @param $watched bool
599 public function recentChangesLine( &$baseRC, $watched = false ) {
600 wfProfileIn( __METHOD__
);
602 # Create a specialised object
603 $rc = RCCacheEntry
::newFromParent( $baseRC );
605 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
607 # If it's a new day, add the headline and flush the cache
608 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
610 if( $date != $this->lastdate
) {
611 # Process current cache
612 $ret = $this->recentChangesBlock();
613 $this->rc_cache
= array();
614 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
615 $this->lastdate
= $date;
618 # Should patrol-related stuff be shown?
619 if( $this->getUser()->useRCPatrol() ) {
620 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
622 $rc->unpatrolled
= false;
625 $showdifflinks = true;
627 $type = $rc->mAttribs
['rc_type'];
628 $logType = $rc->mAttribs
['rc_log_type'];
630 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
631 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
632 $clink = wfMsg( $msg, Linker
::linkKnown( $rc->getTitle(), null,
633 array(), array( 'redirect' => 'no' ) ),
634 Linker
::linkKnown( $rc->getMovedToTitle() ) );
635 // New unpatrolled pages
636 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
637 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
638 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
640 } elseif( $type == RC_LOG
) {
642 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
643 $clink = '(' . Linker
::linkKnown( $logtitle,
644 LogPage
::logName( $logType ) ) . ')';
646 $clink = Linker
::link( $rc->getTitle() );
649 // Log entries (old format) and special pages
650 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
651 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
652 if ( $specialName == 'Log' ) {
654 $logname = LogPage
::logName( $logtype );
655 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
657 wfDebug( "Unexpected special page in recentchanges\n" );
662 $clink = Linker
::linkKnown( $rc->getTitle() );
665 # Don't show unusable diff links
666 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
667 $showdifflinks = false;
670 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
671 $rc->watched
= $watched;
673 $rc->timestamp
= $time;
674 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
676 # Make "cur" and "diff" links. Do not use link(), it is too slow if
677 # called too many times (50% of CPU time on RecentChanges!).
678 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
679 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
680 if( $rc->unpatrolled
) {
681 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
683 $rcIdQuery = array();
685 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
686 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
687 $lastOldid ) +
$rcIdQuery;
689 if( !$showdifflinks ) {
690 $curLink = $this->message
['cur'];
691 $diffLink = $this->message
['diff'];
692 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
693 if ( $type != RC_NEW
) {
694 $curLink = $this->message
['cur'];
696 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
697 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
699 $diffLink = $this->message
['diff'];
701 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
702 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
703 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
704 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
708 if( !$showdifflinks ||
!$lastOldid ) {
709 $lastLink = $this->message
['last'];
710 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
711 $lastLink = $this->message
['last'];
713 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
714 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
718 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
719 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
721 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
722 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
725 $rc->lastlink
= $lastLink;
726 $rc->curlink
= $curLink;
727 $rc->difflink
= $diffLink;
729 # Put accumulated information into the cache, for later display
730 # Page moves go on their own line
731 $title = $rc->getTitle();
732 $secureName = $title->getPrefixedDBkey();
733 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
734 # Use an @ character to prevent collision with page names
735 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
737 # Logs are grouped by type
738 if( $type == RC_LOG
){
739 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
741 if( !isset( $this->rc_cache
[$secureName] ) ) {
742 $this->rc_cache
[$secureName] = array();
745 array_push( $this->rc_cache
[$secureName], $rc );
748 wfProfileOut( __METHOD__
);
756 protected function recentChangesBlockGroup( $block ) {
757 global $wgRCShowChangedSize;
759 wfProfileIn( __METHOD__
);
761 # Add the namespace and title of the block as part of the class
762 if ( $block[0]->mAttribs
['rc_log_type'] ) {
764 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
766 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
768 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
769 Html
::openElement( 'tr' );
771 # Collate list of users
772 $userlinks = array();
774 $unpatrolled = false;
776 $curId = $currentRevision = 0;
777 # Some catalyst variables...
780 foreach( $block as $rcObj ) {
781 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
782 if( $rcObj->mAttribs
['rc_new'] ) {
785 // If all log actions to this page were hidden, then don't
786 // give the name of the affected page for this block!
787 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
790 $u = $rcObj->userlink
;
791 if( !isset( $userlinks[$u] ) ) {
794 if( $rcObj->unpatrolled
) {
797 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
800 # Get the latest entry with a page_id and oldid
801 # since logs may not have these.
802 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
803 $curId = $rcObj->mAttribs
['rc_cur_id'];
805 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
806 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
809 $bot = $rcObj->mAttribs
['rc_bot'];
813 # Sort the list and convert to text
814 krsort( $userlinks );
817 foreach( $userlinks as $userlink => $count) {
819 $text .= $this->getLang()->getDirMark();
821 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
823 array_push( $users, $text );
826 $users = ' <span class="changedby">[' .
827 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
830 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
831 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
833 $tl = "<span class='mw-collapsible-toggle'>"
834 . "<span class='mw-rc-openarrow'>"
835 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
836 . "</span><span class='mw-rc-closearrow'>"
837 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
839 $r .= "<td>$tl</td>";
842 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
845 'unpatrolled' => $unpatrolled,
850 $r .= ' '.$block[0]->timestamp
.' </td><td>';
854 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
855 } elseif( $allLogs ) {
856 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
858 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
861 $r .= $this->getLang()->getDirMark();
863 $queryParams['curid'] = $curId;
866 static $nchanges = array();
867 if ( !isset( $nchanges[$n] ) ) {
868 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
874 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
879 $params = $queryParams;
880 $params['diff'] = $currentRevision;
881 $params['oldid'] = $oldid;
884 $block[0]->getTitle(),
888 array( 'known', 'noclasses' )
895 // don't show history link for logs
896 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
897 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
899 $params = $queryParams;
900 $params['action'] = 'history';
902 $r .= $this->message
['pipe-separator'] .
904 $block[0]->getTitle(),
905 $this->message
['hist'],
912 # Character difference (does not apply if only log items)
913 if( $wgRCShowChangedSize && !$allLogs ) {
915 $first = count($block) - 1;
916 # Some events (like logs) have an "empty" size, so we need to skip those...
917 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
920 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
924 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
925 $block[$last]->mAttribs
['rc_new_len'] );
927 if( $chardiff == '' ) {
930 $r .= ' ' . $chardiff. ' . . ';
935 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
938 foreach( $block as $rcObj ) {
939 # Classes to apply -- TODO implement
941 $type = $rcObj->mAttribs
['rc_type'];
943 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
944 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
945 $r .= $this->recentChangesFlags( array(
946 'newpage' => $rcObj->mAttribs
['rc_new'],
947 'minor' => $rcObj->mAttribs
['rc_minor'],
948 'unpatrolled' => $rcObj->unpatrolled
,
949 'bot' => $rcObj->mAttribs
['rc_bot'],
951 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
953 $params = $queryParams;
955 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
956 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
960 if( $type == RC_LOG
) {
961 $link = $rcObj->timestamp
;
963 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
964 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
966 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
967 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
970 $link = Linker
::linkKnown(
976 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
977 $link = '<span class="history-deleted">'.$link.'</span> ';
979 $r .= $link . '</span>';
981 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
983 $r .= $rcObj->curlink
;
984 $r .= $this->message
['pipe-separator'];
985 $r .= $rcObj->lastlink
;
991 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
992 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
995 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
996 $r .= $this->insertLogEntry( $rcObj );
999 $r .= $rcObj->userlink
;
1000 $r .= $rcObj->usertalklink
;
1004 $this->insertRollback( $r, $rcObj );
1006 $this->insertTags( $r, $rcObj, $classes );
1008 $r .= "</td></tr>\n";
1012 $this->rcCacheIndex++
;
1014 wfProfileOut( __METHOD__
);
1020 * Generate HTML for an arrow or placeholder graphic
1021 * @param $dir String: one of '', 'd', 'l', 'r'
1022 * @param $alt String: text
1023 * @param $title String: text
1024 * @return String: HTML <img> tag
1026 protected function arrow( $dir, $alt='', $title='' ) {
1027 global $wgStylePath;
1028 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1029 $encAlt = htmlspecialchars( $alt );
1030 $encTitle = htmlspecialchars( $title );
1031 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1035 * Generate HTML for a right- or left-facing arrow,
1036 * depending on language direction.
1037 * @return String: HTML <img> tag
1039 protected function sideArrow() {
1041 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1042 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1046 * Generate HTML for a down-facing arrow
1047 * depending on language direction.
1048 * @return String: HTML <img> tag
1050 protected function downArrow() {
1051 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1055 * Generate HTML for a spacer image
1056 * @return String: HTML <img> tag
1058 protected function spacerArrow() {
1059 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1063 * Enhanced RC ungrouped line.
1065 * @param $rcObj RecentChange
1066 * @return String: a HTML formated line (generated using $r)
1068 protected function recentChangesBlockLine( $rcObj ) {
1069 global $wgRCShowChangedSize;
1071 wfProfileIn( __METHOD__
);
1072 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1074 $type = $rcObj->mAttribs
['rc_type'];
1075 $logType = $rcObj->mAttribs
['rc_log_type'];
1078 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1080 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1082 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1083 Html
::openElement( 'tr' );
1085 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1086 # Flag and Timestamp
1087 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1088 $r .= '    '; // 4 flags -> 4 spaces
1090 $r .= $this->recentChangesFlags( array(
1091 'newpage' => $type == RC_NEW
,
1092 'mino' => $rcObj->mAttribs
['rc_minor'],
1093 'unpatrolled' => $rcObj->unpatrolled
,
1094 'bot' => $rcObj->mAttribs
['rc_bot'],
1097 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1098 # Article or log link
1100 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1101 $logname = LogPage
::logName( $logType );
1102 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1104 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1106 # Diff and hist links
1107 if ( $type != RC_LOG
) {
1108 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1109 $query['action'] = 'history';
1110 $r .= Linker
::linkKnown(
1112 $this->message
['hist'],
1119 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1123 if ( $type == RC_LOG
) {
1124 $r .= $this->insertLogEntry( $rcObj );
1126 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1130 $classes = explode( ' ', $classes );
1131 $this->insertTags( $r, $rcObj, $classes );
1132 # Show how many people are watching this if enabled
1133 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1135 $r .= "</td></tr></table>\n";
1137 wfProfileOut( __METHOD__
);
1143 * If enhanced RC is in use, this function takes the previously cached
1144 * RC lines, arranges them, and outputs the HTML
1148 protected function recentChangesBlock() {
1149 if( count ( $this->rc_cache
) == 0 ) {
1153 wfProfileIn( __METHOD__
);
1156 foreach( $this->rc_cache
as $block ) {
1157 if( count( $block ) < 2 ) {
1158 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1160 $blockOut .= $this->recentChangesBlockGroup( $block );
1164 wfProfileOut( __METHOD__
);
1166 return '<div>'.$blockOut.'</div>';
1170 * Returns text for the end of RC
1171 * If enhanced RC is in use, returns pretty much all the text
1173 public function endRecentChangesList() {
1174 return $this->recentChangesBlock() . parent
::endRecentChangesList();