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';
219 return Html
::element( $tag,
220 array( 'dir' => 'ltr', 'class' => $formattedSizeClass ),
221 "($formattedSize)" );
225 * Returns text for the end of RC
228 public function endRecentChangesList() {
229 if( $this->rclistOpen
) {
236 public function insertDateHeader( &$s, $rc_timestamp ) {
237 # Make date header if necessary
238 $date = $this->getLang()->date( $rc_timestamp, true, true );
239 if( $date != $this->lastdate
) {
240 if( $this->lastdate
!= '' ) {
243 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
244 $this->lastdate
= $date;
245 $this->rclistOpen
= true;
249 public function insertLog( &$s, $title, $logtype ) {
250 $page = new LogPage( $logtype );
251 $logname = $page->getName()->escaped();
252 $s .= '(' . Linker
::linkKnown( $title, $logname ) . ')';
257 * @param $rc RecentChange
258 * @param $unpatrolled
261 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
263 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
264 $diffLink = $this->message
['diff'];
265 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
266 $diffLink = $this->message
['diff'];
269 'curid' => $rc->mAttribs
['rc_cur_id'],
270 'diff' => $rc->mAttribs
['rc_this_oldid'],
271 'oldid' => $rc->mAttribs
['rc_last_oldid']
275 $query['rcid'] = $rc->mAttribs
['rc_id'];
278 $diffLink = Linker
::linkKnown(
280 $this->message
['diff'],
281 array( 'tabindex' => $rc->counter
),
285 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
287 $s .= Linker
::linkKnown(
289 $this->message
['hist'],
292 'curid' => $rc->mAttribs
['rc_cur_id'],
293 'action' => 'history'
301 * @param $rc RecentChange
302 * @param $unpatrolled
306 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
307 # If it's a new article, there is no diff link, but if it hasn't been
308 # patrolled yet, we need to give users a way to do so
311 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
312 $params['rcid'] = $rc->mAttribs
['rc_id'];
315 $articlelink = Linker
::linkKnown(
321 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
322 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
324 # Bolden pages watched by this user
326 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
329 $articlelink .= $this->getLang()->getDirMark();
331 wfRunHooks( 'ChangesListInsertArticleLink',
332 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
334 $s .= " $articlelink";
339 * @param $rc RecentChange
342 public function insertTimestamp( &$s, $rc ) {
343 $s .= $this->message
['semicolon-separator'] .
344 $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
347 /** Insert links to user page, user talk page and eventually a blocking link
349 * @param $rc RecentChange
351 public function insertUserRelatedLinks( &$s, &$rc ) {
352 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
353 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
355 $s .= $this->getLang()->getDirMark() . Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
356 $s .= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
360 /** insert a formatted action
362 * @param $rc RecentChange
364 public function insertLogEntry( $rc ) {
365 $formatter = LogFormatter
::newFromRow( $rc->mAttribs
);
366 $formatter->setShowUserToolLinks( true );
367 $mark = $this->getLang()->getDirMark();
368 return $formatter->getActionText() . " $mark" . $formatter->getComment();
372 * Insert a formatted comment
373 * @param $rc RecentChange
375 public function insertComment( $rc ) {
376 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
377 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
378 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
380 return Linker
::commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
386 * Check whether to enable recent changes patrol features
389 public static function usePatrol() {
391 return $wgUser->useRCPatrol();
395 * Returns the string which indicates the number of watching users
397 protected function numberofWatchingusers( $count ) {
398 static $cache = array();
400 if( !isset( $cache[$count] ) ) {
401 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
402 array('parsemag', 'escape' ), $this->getLang()->formatNum( $count ) );
404 return $cache[$count];
411 * Determine if said field of a revision is hidden
412 * @param $rc RCCacheEntry
413 * @param $field Integer: one of DELETED_* bitfield constants
416 public static function isDeleted( $rc, $field ) {
417 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
421 * Determine if the current user is allowed to view a particular
422 * field of this revision, if it's marked as deleted.
423 * @param $rc RCCacheEntry
424 * @param $field Integer
427 public static function userCan( $rc, $field ) {
428 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
429 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
431 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
435 protected function maybeWatchedLink( $link, $watched = false ) {
437 return '<strong class="mw-watched">' . $link . '</strong>';
439 return '<span class="mw-rc-unwatched">' . $link . '</span>';
443 /** Inserts a rollback link
446 * @param $rc RecentChange
448 public function insertRollback( &$s, &$rc ) {
449 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
450 $page = $rc->getTitle();
451 /** Check for rollback and edit permissions, disallow special pages, and only
452 * show a link on the top-most revision */
453 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
455 $rev = new Revision( array(
456 'id' => $rc->mAttribs
['rc_this_oldid'],
457 'user' => $rc->mAttribs
['rc_user'],
458 'user_text' => $rc->mAttribs
['rc_user_text'],
459 'deleted' => $rc->mAttribs
['rc_deleted']
461 $rev->setTitle( $page );
462 $s .= ' '.Linker
::generateRollback( $rev, $this->getContext() );
469 * @param $rc RecentChange
473 public function insertTags( &$s, &$rc, &$classes ) {
474 if ( empty($rc->mAttribs
['ts_tags']) )
477 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
478 $classes = array_merge( $classes, $newClasses );
479 $s .= ' ' . $tagSummary;
482 public function insertExtra( &$s, &$rc, &$classes ) {
483 ## Empty, used for subclassers to add anything special.
489 * Generate a list of changes using the good old system (no javascript)
491 class OldChangesList
extends ChangesList
{
493 * Format a line using the old system (aka without any javascript).
495 * @param $rc RecentChange
497 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
498 global $wgRCShowChangedSize;
499 wfProfileIn( __METHOD__
);
500 # Should patrol-related stuff be shown?
501 $unpatrolled = $this->getUser()->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
503 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
504 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
508 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
510 if( $linenumber & 1 ) {
511 $classes[] = 'mw-line-odd';
514 $classes[] = 'mw-line-even';
518 // Moved pages (very very old, not supported anymore)
519 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
521 } elseif( $rc->mAttribs
['rc_log_type'] ) {
522 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc->mAttribs
['rc_log_type'] );
523 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
524 // Log entries (old format) or log targets, and special pages
525 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
526 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
527 if( $name == 'Log' ) {
528 $this->insertLog( $s, $rc->getTitle(), $subpage );
532 $this->insertDiffHist( $s, $rc, $unpatrolled );
533 # M, N, b and ! (minor, new, bot and unpatrolled)
534 $s .= $this->recentChangesFlags(
536 'newpage' => $rc->mAttribs
['rc_new'],
537 'minor' => $rc->mAttribs
['rc_minor'],
538 'unpatrolled' => $unpatrolled,
539 'bot' => $rc->mAttribs
['rc_bot']
543 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
546 $this->insertTimestamp( $s, $rc );
547 # Bytes added or removed
548 if( $wgRCShowChangedSize ) {
549 $cd = $rc->getCharacterDifference();
555 if ( $rc->mAttribs
['rc_type'] == RC_LOG
) {
556 $s .= $this->insertLogEntry( $rc );
559 $this->insertUserRelatedLinks( $s, $rc );
560 # LTR/RTL direction mark
561 $s .= $this->getLang()->getDirMark();
562 $s .= $this->insertComment( $rc );
566 $this->insertTags( $s, $rc, $classes );
568 $this->insertRollback( $s, $rc );
570 $this->insertExtra( $s, $rc, $classes );
572 # How many users watch this page
573 if( $rc->numberofWatchingusers
> 0 ) {
574 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
575 array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $rc->numberofWatchingusers
) );
578 if( $this->watchlist
) {
579 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
582 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
584 wfProfileOut( __METHOD__
);
585 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
591 * Generate a list of changes using an Enhanced system (uses javascript).
593 class EnhancedChangesList
extends ChangesList
{
595 * Add the JavaScript file for enhanced changeslist
598 public function beginRecentChangesList() {
599 $this->rc_cache
= array();
600 $this->rcMoveIndex
= 0;
601 $this->rcCacheIndex
= 0;
602 $this->lastdate
= '';
603 $this->rclistOpen
= false;
604 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
608 * Format a line for enhanced recentchange (aka with javascript and block of lines).
610 * @param $baseRC RecentChange
611 * @param $watched bool
615 public function recentChangesLine( &$baseRC, $watched = false ) {
616 wfProfileIn( __METHOD__
);
618 # Create a specialised object
619 $rc = RCCacheEntry
::newFromParent( $baseRC );
621 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
623 # If it's a new day, add the headline and flush the cache
624 $date = $this->getLang()->date( $rc->mAttribs
['rc_timestamp'], true );
626 if( $date != $this->lastdate
) {
627 # Process current cache
628 $ret = $this->recentChangesBlock();
629 $this->rc_cache
= array();
630 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
631 $this->lastdate
= $date;
634 # Should patrol-related stuff be shown?
635 if( $this->getUser()->useRCPatrol() ) {
636 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
638 $rc->unpatrolled
= false;
641 $showdifflinks = true;
643 $type = $rc->mAttribs
['rc_type'];
644 $logType = $rc->mAttribs
['rc_log_type'];
645 // Page moves, very old style, not supported anymore
646 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
647 // New unpatrolled pages
648 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
649 $clink = Linker
::linkKnown( $rc->getTitle(), null, array(),
650 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
652 } elseif( $type == RC_LOG
) {
654 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
655 $clink = '(' . Linker
::linkKnown( $logtitle,
656 LogPage
::logName( $logType ) ) . ')';
658 $clink = Linker
::link( $rc->getTitle() );
661 // Log entries (old format) and special pages
662 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
663 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
664 if ( $specialName == 'Log' ) {
666 $logname = LogPage
::logName( $logtype );
667 $clink = '(' . Linker
::linkKnown( $rc->getTitle(), $logname ) . ')';
669 wfDebug( "Unexpected special page in recentchanges\n" );
674 $clink = Linker
::linkKnown( $rc->getTitle() );
677 # Don't show unusable diff links
678 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
679 $showdifflinks = false;
682 $time = $this->getLang()->time( $rc->mAttribs
['rc_timestamp'], true, true );
683 $rc->watched
= $watched;
685 $rc->timestamp
= $time;
686 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
688 # Make "cur" and "diff" links. Do not use link(), it is too slow if
689 # called too many times (50% of CPU time on RecentChanges!).
690 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
691 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
692 if( $rc->unpatrolled
) {
693 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
695 $rcIdQuery = array();
697 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
698 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
699 $lastOldid ) +
$rcIdQuery;
701 if( !$showdifflinks ) {
702 $curLink = $this->message
['cur'];
703 $diffLink = $this->message
['diff'];
704 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
705 if ( $type != RC_NEW
) {
706 $curLink = $this->message
['cur'];
708 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
709 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
711 $diffLink = $this->message
['diff'];
713 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
714 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
715 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
716 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
720 if( !$showdifflinks ||
!$lastOldid ) {
721 $lastLink = $this->message
['last'];
722 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
723 $lastLink = $this->message
['last'];
725 $lastLink = Linker
::linkKnown( $rc->getTitle(), $this->message
['last'],
726 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
730 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
731 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
733 $rc->userlink
= Linker
::userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
734 $rc->usertalklink
= Linker
::userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
737 $rc->lastlink
= $lastLink;
738 $rc->curlink
= $curLink;
739 $rc->difflink
= $diffLink;
741 # Put accumulated information into the cache, for later display
742 # Page moves go on their own line
743 $title = $rc->getTitle();
744 $secureName = $title->getPrefixedDBkey();
745 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
746 # Use an @ character to prevent collision with page names
747 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
749 # Logs are grouped by type
750 if( $type == RC_LOG
){
751 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
753 if( !isset( $this->rc_cache
[$secureName] ) ) {
754 $this->rc_cache
[$secureName] = array();
757 array_push( $this->rc_cache
[$secureName], $rc );
760 wfProfileOut( __METHOD__
);
768 protected function recentChangesBlockGroup( $block ) {
769 global $wgRCShowChangedSize;
771 wfProfileIn( __METHOD__
);
773 # Add the namespace and title of the block as part of the class
774 if ( $block[0]->mAttribs
['rc_log_type'] ) {
776 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
778 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
780 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
781 Html
::openElement( 'tr' );
783 # Collate list of users
784 $userlinks = array();
786 $unpatrolled = false;
788 $curId = $currentRevision = 0;
789 # Some catalyst variables...
792 foreach( $block as $rcObj ) {
793 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
794 if( $rcObj->mAttribs
['rc_new'] ) {
797 // If all log actions to this page were hidden, then don't
798 // give the name of the affected page for this block!
799 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
802 $u = $rcObj->userlink
;
803 if( !isset( $userlinks[$u] ) ) {
806 if( $rcObj->unpatrolled
) {
809 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
812 # Get the latest entry with a page_id and oldid
813 # since logs may not have these.
814 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
815 $curId = $rcObj->mAttribs
['rc_cur_id'];
817 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
818 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
821 $bot = $rcObj->mAttribs
['rc_bot'];
825 # Sort the list and convert to text
826 krsort( $userlinks );
829 foreach( $userlinks as $userlink => $count) {
831 $text .= $this->getLang()->getDirMark();
833 $text .= ' (' . $this->getLang()->formatNum( $count ) . '×)';
835 array_push( $users, $text );
838 $users = ' <span class="changedby">[' .
839 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
842 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
843 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
845 $tl = "<span class='mw-collapsible-toggle'>"
846 . "<span class='mw-rc-openarrow'>"
847 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
848 . "</span><span class='mw-rc-closearrow'>"
849 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
851 $r .= "<td>$tl</td>";
854 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
857 'unpatrolled' => $unpatrolled,
862 $r .= ' '.$block[0]->timestamp
.' </td><td>';
866 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
867 } elseif( $allLogs ) {
868 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
870 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
873 $r .= $this->getLang()->getDirMark();
875 $queryParams['curid'] = $curId;
878 static $nchanges = array();
879 if ( !isset( $nchanges[$n] ) ) {
880 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) );
886 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
891 $params = $queryParams;
892 $params['diff'] = $currentRevision;
893 $params['oldid'] = $oldid;
896 $block[0]->getTitle(),
900 array( 'known', 'noclasses' )
907 // don't show history link for logs
908 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
909 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
911 $params = $queryParams;
912 $params['action'] = 'history';
914 $r .= $this->message
['pipe-separator'] .
916 $block[0]->getTitle(),
917 $this->message
['hist'],
924 # Character difference (does not apply if only log items)
925 if( $wgRCShowChangedSize && !$allLogs ) {
927 $first = count($block) - 1;
928 # Some events (like logs) have an "empty" size, so we need to skip those...
929 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
932 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
936 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
937 $block[$last]->mAttribs
['rc_new_len'] );
939 if( $chardiff == '' ) {
942 $r .= ' ' . $chardiff. ' . . ';
947 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
950 foreach( $block as $rcObj ) {
951 # Classes to apply -- TODO implement
953 $type = $rcObj->mAttribs
['rc_type'];
955 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
956 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
957 $r .= $this->recentChangesFlags( array(
958 'newpage' => $rcObj->mAttribs
['rc_new'],
959 'minor' => $rcObj->mAttribs
['rc_minor'],
960 'unpatrolled' => $rcObj->unpatrolled
,
961 'bot' => $rcObj->mAttribs
['rc_bot'],
963 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
965 $params = $queryParams;
967 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
968 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
972 if( $type == RC_LOG
) {
973 $link = $rcObj->timestamp
;
975 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
976 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
978 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
979 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
982 $link = Linker
::linkKnown(
988 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
989 $link = '<span class="history-deleted">'.$link.'</span> ';
991 $r .= $link . '</span>';
993 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
995 $r .= $rcObj->curlink
;
996 $r .= $this->message
['pipe-separator'];
997 $r .= $rcObj->lastlink
;
1003 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1004 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1007 if ( $rcObj->mAttribs
['rc_type'] == RC_LOG
) {
1008 $r .= $this->insertLogEntry( $rcObj );
1011 $r .= $rcObj->userlink
;
1012 $r .= $rcObj->usertalklink
;
1013 $r .= $this->insertComment( $rcObj );
1017 $this->insertRollback( $r, $rcObj );
1019 $this->insertTags( $r, $rcObj, $classes );
1021 $r .= "</td></tr>\n";
1025 $this->rcCacheIndex++
;
1027 wfProfileOut( __METHOD__
);
1033 * Generate HTML for an arrow or placeholder graphic
1034 * @param $dir String: one of '', 'd', 'l', 'r'
1035 * @param $alt String: text
1036 * @param $title String: text
1037 * @return String: HTML <img> tag
1039 protected function arrow( $dir, $alt='', $title='' ) {
1040 global $wgStylePath;
1041 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1042 $encAlt = htmlspecialchars( $alt );
1043 $encTitle = htmlspecialchars( $title );
1044 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1048 * Generate HTML for a right- or left-facing arrow,
1049 * depending on language direction.
1050 * @return String: HTML <img> tag
1052 protected function sideArrow() {
1054 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1055 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1059 * Generate HTML for a down-facing arrow
1060 * depending on language direction.
1061 * @return String: HTML <img> tag
1063 protected function downArrow() {
1064 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1068 * Generate HTML for a spacer image
1069 * @return String: HTML <img> tag
1071 protected function spacerArrow() {
1072 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1076 * Enhanced RC ungrouped line.
1078 * @param $rcObj RecentChange
1079 * @return String: a HTML formatted line (generated using $r)
1081 protected function recentChangesBlockLine( $rcObj ) {
1082 global $wgRCShowChangedSize;
1084 wfProfileIn( __METHOD__
);
1085 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1087 $type = $rcObj->mAttribs
['rc_type'];
1088 $logType = $rcObj->mAttribs
['rc_log_type'];
1091 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1093 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1095 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1096 Html
::openElement( 'tr' );
1098 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1099 # Flag and Timestamp
1100 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1101 $r .= '    '; // 4 flags -> 4 spaces
1103 $r .= $this->recentChangesFlags( array(
1104 'newpage' => $type == RC_NEW
,
1105 'mino' => $rcObj->mAttribs
['rc_minor'],
1106 'unpatrolled' => $rcObj->unpatrolled
,
1107 'bot' => $rcObj->mAttribs
['rc_bot'],
1110 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1111 # Article or log link
1113 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
1114 $logname = LogPage
::logName( $logType );
1115 $r .= '(' . Linker
::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')';
1117 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1119 # Diff and hist links
1120 if ( $type != RC_LOG
) {
1121 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1122 $query['action'] = 'history';
1123 $r .= Linker
::linkKnown(
1125 $this->message
['hist'],
1132 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1136 if ( $type == RC_LOG
) {
1137 $r .= $this->insertLogEntry( $rcObj );
1139 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1140 $r .= $this->insertComment( $rcObj );
1141 $r .= $this->insertRollback( $r, $rcObj );
1145 $classes = explode( ' ', $classes );
1146 $this->insertTags( $r, $rcObj, $classes );
1147 # Show how many people are watching this if enabled
1148 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1150 $r .= "</td></tr></table>\n";
1152 wfProfileOut( __METHOD__
);
1158 * If enhanced RC is in use, this function takes the previously cached
1159 * RC lines, arranges them, and outputs the HTML
1163 protected function recentChangesBlock() {
1164 if( count ( $this->rc_cache
) == 0 ) {
1168 wfProfileIn( __METHOD__
);
1171 foreach( $this->rc_cache
as $block ) {
1172 if( count( $block ) < 2 ) {
1173 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1175 $blockOut .= $this->recentChangesBlockGroup( $block );
1179 wfProfileOut( __METHOD__
);
1181 return '<div>'.$blockOut.'</div>';
1185 * Returns text for the end of RC
1186 * If enhanced RC is in use, returns pretty much all the text
1188 public function endRecentChangesList() {
1189 return $this->recentChangesBlock() . parent
::endRecentChangesList();