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 IContextSource
50 public function __construct( $obj ) {
51 if ( $obj instanceof IContextSource
) {
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 IContextSource to use
78 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
80 public static function newFromContext( IContextSource
$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 $formattedSize = $wgLang->formatNum($szdiff);
198 if ( !$fastCharDiff[$code] ) {
199 $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize );
202 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
208 if ( $szdiff === 0 ) {
209 $formattedSizeClass = 'mw-plusminus-null';
212 $formattedSize = '+' . $formattedSize;
213 $formattedSizeClass = 'mw-plusminus-pos';
216 $formattedSizeClass = 'mw-plusminus-neg';
218 return Xml
::element($tag,
219 array('dir' => 'ltr', 'class' => $formattedSizeClass),
224 * Returns text for the end of RC
227 public function endRecentChangesList() {
228 if( $this->rclistOpen
) {
235 public function insertDateHeader( &$s, $rc_timestamp ) {
236 # Make date header if necessary
237 $date = $this->getLang()->date( $rc_timestamp, true, true );
238 if( $date != $this->lastdate
) {
239 if( $this->lastdate
!= '' ) {
242 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
243 $this->lastdate
= $date;
244 $this->rclistOpen
= true;
248 public function insertLog( &$s, $title, $logtype ) {
249 $page = new LogPage( $logtype );
250 $logname = $page->getName()->escaped();
251 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
256 * @param $rc RecentChange
257 * @param $unpatrolled
260 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
262 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
263 $diffLink = $this->message
['diff'];
264 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
265 $diffLink = $this->message
['diff'];
268 'curid' => $rc->mAttribs
['rc_cur_id'],
269 'diff' => $rc->mAttribs
['rc_this_oldid'],
270 'oldid' => $rc->mAttribs
['rc_last_oldid']
274 $query['rcid'] = $rc->mAttribs
['rc_id'];
277 $diffLink = Linker
::linkKnown(
279 $this->message
['diff'],
280 array( 'tabindex' => $rc->counter
),
284 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
286 $s .= Linker
::linkKnown(
288 $this->message
['hist'],
291 'curid' => $rc->mAttribs
['rc_cur_id'],
292 'action' => 'history'
300 * @param $rc RecentChange
301 * @param $unpatrolled
305 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
306 # If it's a new article, there is no diff link, but if it hasn't been
307 # patrolled yet, we need to give users a way to do so
310 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
311 $params['rcid'] = $rc->mAttribs
['rc_id'];
314 $articlelink = Linker
::linkKnown(
320 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
321 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
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 .= $this->getLang()->getDirMark() . 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 * Insert a formatted comment
372 * @param $rc RecentChange
374 public function insertComment( $rc ) {
375 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
376 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
377 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
379 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
385 * Check whether to enable recent changes patrol features
388 public static function usePatrol() {
390 return $wgUser->useRCPatrol();
394 * Returns the string which indicates the number of watching users
396 protected function numberofWatchingusers( $count ) {
397 static $cache = array();
399 if( !isset( $cache[$count] ) ) {
400 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
401 array('parsemag', 'escape' ), $this->getLang()->formatNum( $count ) );
403 return $cache[$count];
410 * Determine if said field of a revision is hidden
411 * @param $rc RCCacheEntry
412 * @param $field Integer: one of DELETED_* bitfield constants
415 public static function isDeleted( $rc, $field ) {
416 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
420 * Determine if the current user is allowed to view a particular
421 * field of this revision, if it's marked as deleted.
422 * @param $rc RCCacheEntry
423 * @param $field Integer
426 public static function userCan( $rc, $field ) {
427 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
428 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
430 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
434 protected function maybeWatchedLink( $link, $watched = false ) {
436 return '<strong class="mw-watched">' . $link . '</strong>';
438 return '<span class="mw-rc-unwatched">' . $link . '</span>';
442 /** Inserts a rollback link
445 * @param $rc RecentChange
447 public function insertRollback( &$s, &$rc ) {
448 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
449 $page = $rc->getTitle();
450 /** Check for rollback and edit permissions, disallow special pages, and only
451 * show a link on the top-most revision */
452 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
454 $rev = new Revision( array(
455 'id' => $rc->mAttribs
['rc_this_oldid'],
456 'user' => $rc->mAttribs
['rc_user'],
457 'user_text' => $rc->mAttribs
['rc_user_text'],
458 'deleted' => $rc->mAttribs
['rc_deleted']
460 $rev->setTitle( $page );
461 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
468 * @param $rc RecentChange
472 public function insertTags( &$s, &$rc, &$classes ) {
473 if ( empty($rc->mAttribs
['ts_tags']) )
476 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
477 $classes = array_merge( $classes, $newClasses );
478 $s .= ' ' . $tagSummary;
481 public function insertExtra( &$s, &$rc, &$classes ) {
482 ## Empty, used for subclassers to add anything special.
488 * Generate a list of changes using the good old system (no javascript)
490 class OldChangesList
extends ChangesList
{
492 * Format a line using the old system (aka without any javascript).
494 * @param $rc RecentChange
496 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
497 global $wgRCShowChangedSize;
498 wfProfileIn( __METHOD__
);
499 # Should patrol-related stuff be shown?
500 $unpatrolled = $this->getUser()->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
502 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
503 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
507 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
509 if( $linenumber & 1 ) {
510 $classes[] = 'mw-line-odd';
513 $classes[] = 'mw-line-even';
517 // Moved pages (very very old, not supported anymore)
518 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
520 } elseif( $rc->mAttribs
['rc_log_type'] ) {
521 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
522 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
523 // Log entries (old format) or log targets, and special pages
524 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
525 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
526 if( $name == 'Log' ) {
527 $this->insertLog( $s, $rc->getTitle(), $subpage );
531 $this->insertDiffHist( $s, $rc, $unpatrolled );
532 # M, N, b and ! (minor, new, bot and unpatrolled)
533 $s .= $this->recentChangesFlags(
535 'newpage' => $rc->mAttribs
['rc_new'],
536 'minor' => $rc->mAttribs
['rc_minor'],
537 'unpatrolled' => $unpatrolled,
538 'bot' => $rc->mAttribs
['rc_bot']
542 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
545 $this->insertTimestamp( $s, $rc );
546 # Bytes added or removed
547 if( $wgRCShowChangedSize ) {
548 $cd = $rc->getCharacterDifference();
554 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
555 $s .= $this->insertLogEntry( $rc );
558 $this->insertUserRelatedLinks( $s, $rc );
559 # LTR/RTL direction mark
560 $s .= $this->getLang()->getDirMark();
561 $s .= $this->insertComment( $rc );
565 $this->insertTags( $s, $rc, $classes );
567 $this->insertRollback( $s, $rc );
569 $this->insertExtra( $s, $rc, $classes );
571 # How many users watch this page
572 if( $rc->numberofWatchingusers
> 0 ) {
573 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
574 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
577 if( $this->watchlist
) {
578 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
581 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
583 wfProfileOut( __METHOD__
);
584 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
590 * Generate a list of changes using an Enhanced system (uses javascript).
592 class EnhancedChangesList
extends ChangesList
{
594 * Add the JavaScript file for enhanced changeslist
597 public function beginRecentChangesList() {
598 $this->rc_cache
= array();
599 $this->rcMoveIndex
= 0;
600 $this->rcCacheIndex
= 0;
601 $this->lastdate
= '';
602 $this->rclistOpen
= false;
603 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
607 * Format a line for enhanced recentchange (aka with javascript and block of lines).
609 * @param $baseRC RecentChange
610 * @param $watched bool
614 public function recentChangesLine( &$baseRC, $watched = false ) {
615 wfProfileIn( __METHOD__
);
617 # Create a specialised object
618 $rc = RCCacheEntry
::newFromParent( $baseRC );
620 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
622 # If it's a new day, add the headline and flush the cache
623 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
625 if( $date != $this->lastdate
) {
626 # Process current cache
627 $ret = $this->recentChangesBlock();
628 $this->rc_cache
= array();
629 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
630 $this->lastdate
= $date;
633 # Should patrol-related stuff be shown?
634 if( $this->getUser()->useRCPatrol() ) {
635 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
637 $rc->unpatrolled
= false;
640 $showdifflinks = true;
642 $type = $rc->mAttribs
['rc_type'];
643 $logType = $rc->mAttribs
['rc_log_type'];
644 // Page moves, very old style, not supported anymore
645 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
646 // New unpatrolled pages
647 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
648 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
649 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
651 } elseif( $type == RC_LOG
) {
653 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
654 $clink = '(' . Linker
::linkKnown( $logtitle,
655 LogPage
::logName( $logType ) ) . ')';
657 $clink = Linker
::link( $rc->getTitle() );
660 // Log entries (old format) and special pages
661 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
662 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
663 if ( $specialName == 'Log' ) {
665 $logname = LogPage
::logName( $logtype );
666 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
668 wfDebug( "Unexpected special page in recentchanges\n" );
673 $clink = Linker
::linkKnown( $rc->getTitle() );
676 # Don't show unusable diff links
677 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
678 $showdifflinks = false;
681 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
682 $rc->watched
= $watched;
684 $rc->timestamp
= $time;
685 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
687 # Make "cur" and "diff" links. Do not use link(), it is too slow if
688 # called too many times (50% of CPU time on RecentChanges!).
689 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
690 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
691 if( $rc->unpatrolled
) {
692 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
694 $rcIdQuery = array();
696 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
697 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
698 $lastOldid ) +
$rcIdQuery;
700 if( !$showdifflinks ) {
701 $curLink = $this->message
['cur'];
702 $diffLink = $this->message
['diff'];
703 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
704 if ( $type != RC_NEW
) {
705 $curLink = $this->message
['cur'];
707 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
708 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
710 $diffLink = $this->message
['diff'];
712 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
713 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
714 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
715 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
719 if( !$showdifflinks ||
!$lastOldid ) {
720 $lastLink = $this->message
['last'];
721 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
722 $lastLink = $this->message
['last'];
724 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
725 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
729 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
730 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
732 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
733 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
736 $rc->lastlink
= $lastLink;
737 $rc->curlink
= $curLink;
738 $rc->difflink
= $diffLink;
740 # Put accumulated information into the cache, for later display
741 # Page moves go on their own line
742 $title = $rc->getTitle();
743 $secureName = $title->getPrefixedDBkey();
744 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
745 # Use an @ character to prevent collision with page names
746 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
748 # Logs are grouped by type
749 if( $type == RC_LOG
){
750 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
752 if( !isset( $this->rc_cache
[$secureName] ) ) {
753 $this->rc_cache
[$secureName] = array();
756 array_push( $this->rc_cache
[$secureName], $rc );
759 wfProfileOut( __METHOD__
);
767 protected function recentChangesBlockGroup( $block ) {
768 global $wgRCShowChangedSize;
770 wfProfileIn( __METHOD__
);
772 # Add the namespace and title of the block as part of the class
773 if ( $block[0]->mAttribs
['rc_log_type'] ) {
775 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
777 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
779 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
780 Html
::openElement( 'tr' );
782 # Collate list of users
783 $userlinks = array();
785 $unpatrolled = false;
787 $curId = $currentRevision = 0;
788 # Some catalyst variables...
791 foreach( $block as $rcObj ) {
792 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
793 if( $rcObj->mAttribs
['rc_new'] ) {
796 // If all log actions to this page were hidden, then don't
797 // give the name of the affected page for this block!
798 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
801 $u = $rcObj->userlink
;
802 if( !isset( $userlinks[$u] ) ) {
805 if( $rcObj->unpatrolled
) {
808 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
811 # Get the latest entry with a page_id and oldid
812 # since logs may not have these.
813 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
814 $curId = $rcObj->mAttribs
['rc_cur_id'];
816 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
817 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
820 $bot = $rcObj->mAttribs
['rc_bot'];
824 # Sort the list and convert to text
825 krsort( $userlinks );
828 foreach( $userlinks as $userlink => $count) {
830 $text .= $this->getLang()->getDirMark();
832 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
834 array_push( $users, $text );
837 $users = ' <span class="changedby">[' .
838 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
841 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
842 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
844 $tl = "<span class='mw-collapsible-toggle'>"
845 . "<span class='mw-rc-openarrow'>"
846 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
847 . "</span><span class='mw-rc-closearrow'>"
848 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
850 $r .= "<td>$tl</td>";
853 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
856 'unpatrolled' => $unpatrolled,
861 $r .= ' '.$block[0]->timestamp
.' </td><td>';
865 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
866 } elseif( $allLogs ) {
867 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
869 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
872 $r .= $this->getLang()->getDirMark();
874 $queryParams['curid'] = $curId;
877 static $nchanges = array();
878 if ( !isset( $nchanges[$n] ) ) {
879 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
885 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
890 $params = $queryParams;
891 $params['diff'] = $currentRevision;
892 $params['oldid'] = $oldid;
895 $block[0]->getTitle(),
899 array( 'known', 'noclasses' )
906 // don't show history link for logs
907 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
908 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
910 $params = $queryParams;
911 $params['action'] = 'history';
913 $r .= $this->message
['pipe-separator'] .
915 $block[0]->getTitle(),
916 $this->message
['hist'],
923 # Character difference (does not apply if only log items)
924 if( $wgRCShowChangedSize && !$allLogs ) {
926 $first = count($block) - 1;
927 # Some events (like logs) have an "empty" size, so we need to skip those...
928 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
931 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
935 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
936 $block[$last]->mAttribs
['rc_new_len'] );
938 if( $chardiff == '' ) {
941 $r .= ' ' . $chardiff. ' . . ';
946 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
949 foreach( $block as $rcObj ) {
950 # Classes to apply -- TODO implement
952 $type = $rcObj->mAttribs
['rc_type'];
954 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
955 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
956 $r .= $this->recentChangesFlags( array(
957 'newpage' => $rcObj->mAttribs
['rc_new'],
958 'minor' => $rcObj->mAttribs
['rc_minor'],
959 'unpatrolled' => $rcObj->unpatrolled
,
960 'bot' => $rcObj->mAttribs
['rc_bot'],
962 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
964 $params = $queryParams;
966 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
967 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
971 if( $type == RC_LOG
) {
972 $link = $rcObj->timestamp
;
974 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
975 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
977 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
978 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
981 $link = Linker
::linkKnown(
987 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
988 $link = '<span class="history-deleted">'.$link.'</span> ';
990 $r .= $link . '</span>';
992 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
994 $r .= $rcObj->curlink
;
995 $r .= $this->message
['pipe-separator'];
996 $r .= $rcObj->lastlink
;
1002 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1003 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1006 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1007 $r .= $this->insertLogEntry( $rcObj );
1010 $r .= $rcObj->userlink
;
1011 $r .= $rcObj->usertalklink
;
1012 $r .= $this->insertComment( $rcObj );
1016 $this->insertRollback( $r, $rcObj );
1018 $this->insertTags( $r, $rcObj, $classes );
1020 $r .= "</td></tr>\n";
1024 $this->rcCacheIndex++
;
1026 wfProfileOut( __METHOD__
);
1032 * Generate HTML for an arrow or placeholder graphic
1033 * @param $dir String: one of '', 'd', 'l', 'r'
1034 * @param $alt String: text
1035 * @param $title String: text
1036 * @return String: HTML <img> tag
1038 protected function arrow( $dir, $alt='', $title='' ) {
1039 global $wgStylePath;
1040 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1041 $encAlt = htmlspecialchars( $alt );
1042 $encTitle = htmlspecialchars( $title );
1043 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1047 * Generate HTML for a right- or left-facing arrow,
1048 * depending on language direction.
1049 * @return String: HTML <img> tag
1051 protected function sideArrow() {
1053 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1054 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1058 * Generate HTML for a down-facing arrow
1059 * depending on language direction.
1060 * @return String: HTML <img> tag
1062 protected function downArrow() {
1063 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1067 * Generate HTML for a spacer image
1068 * @return String: HTML <img> tag
1070 protected function spacerArrow() {
1071 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1075 * Enhanced RC ungrouped line.
1077 * @param $rcObj RecentChange
1078 * @return String: a HTML formatted line (generated using $r)
1080 protected function recentChangesBlockLine( $rcObj ) {
1081 global $wgRCShowChangedSize;
1083 wfProfileIn( __METHOD__
);
1084 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1086 $type = $rcObj->mAttribs
['rc_type'];
1087 $logType = $rcObj->mAttribs
['rc_log_type'];
1090 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1092 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1094 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1095 Html
::openElement( 'tr' );
1097 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1098 # Flag and Timestamp
1099 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1100 $r .= '    '; // 4 flags -> 4 spaces
1102 $r .= $this->recentChangesFlags( array(
1103 'newpage' => $type == RC_NEW
,
1104 'mino' => $rcObj->mAttribs
['rc_minor'],
1105 'unpatrolled' => $rcObj->unpatrolled
,
1106 'bot' => $rcObj->mAttribs
['rc_bot'],
1109 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1110 # Article or log link
1112 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1113 $logname = LogPage
::logName( $logType );
1114 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1116 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1118 # Diff and hist links
1119 if ( $type != RC_LOG
) {
1120 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1121 $query['action'] = 'history';
1122 $r .= Linker
::linkKnown(
1124 $this->message
['hist'],
1131 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1135 if ( $type == RC_LOG
) {
1136 $r .= $this->insertLogEntry( $rcObj );
1138 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1139 $r .= $this->insertComment( $rcObj );
1140 $r .= $this->insertRollback( $r, $rcObj );
1144 $classes = explode( ' ', $classes );
1145 $this->insertTags( $r, $rcObj, $classes );
1146 # Show how many people are watching this if enabled
1147 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1149 $r .= "</td></tr></table>\n";
1151 wfProfileOut( __METHOD__
);
1157 * If enhanced RC is in use, this function takes the previously cached
1158 * RC lines, arranges them, and outputs the HTML
1162 protected function recentChangesBlock() {
1163 if( count ( $this->rc_cache
) == 0 ) {
1167 wfProfileIn( __METHOD__
);
1170 foreach( $this->rc_cache
as $block ) {
1171 if( count( $block ) < 2 ) {
1172 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1174 $blockOut .= $this->recentChangesBlockGroup( $block );
1178 wfProfileOut( __METHOD__
);
1180 return '<div>'.$blockOut.'</div>';
1184 * Returns text for the end of RC
1185 * If enhanced RC is in use, returns pretty much all the text
1187 public function endRecentChangesList() {
1188 return $this->recentChangesBlock() . parent
::endRecentChangesList();