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;
19 static function newFromParent( $rc ) {
20 $rc2 = new RCCacheEntry
;
21 $rc2->mAttribs
= $rc->mAttribs
;
22 $rc2->mExtra
= $rc->mExtra
;
28 * Base class for all changes lists
32 protected $watchlist = false;
35 * Changeslist contructor
38 public function __construct( $skin ) {
40 $this->preCacheMessages();
44 * Fetch an appropriate changes list class for the specified user
45 * Some users might want to use an enhanced list format, for instance
47 * @param $user User to fetch the list class for
48 * @return ChangesList derivative
50 public static function newFromUser( &$user ) {
53 $sk = $user->getSkin();
55 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
56 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
57 return $new ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
64 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
65 * @param $value Boolean
67 public function setWatchlistDivs( $value = true ) {
68 $this->watchlist
= $value;
72 * As we use the same small set of messages in various methods and that
73 * they are called often, we call them once and save them in $this->message
75 private function preCacheMessages() {
76 if( !isset( $this->message
) ) {
77 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
78 'semicolon-separator pipe-separator' ) as $msg ) {
79 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
85 * Returns the appropriate flags for new page, minor change and patrolling
86 * @param $flags Associative array of 'flag' => Bool
87 * @param $nothing String to use for empty space
90 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
92 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
93 $f .= isset( $flags[$flag] ) && $flags[$flag]
101 * Provide the <abbr> element appropriate to a given abbreviated flag,
102 * namely the flag indicating a new page, a minor edit, a bot edit, or an
103 * unpatrolled edit. By default in English it will contain "N", "m", "b",
104 * "!" respectively, plus it will have an appropriate title and class.
106 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
107 * @return String: Raw HTML
109 public static function flag( $flag ) {
110 static $messages = null;
111 if ( is_null( $messages ) ) {
113 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
114 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
115 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
116 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
118 foreach( $messages as $key => &$value ) {
119 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
120 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
124 # Inconsistent naming, bleh
126 'newpage' => 'newpage',
127 'minor' => 'minoredit',
129 'unpatrolled' => 'unpatrolled',
130 'minoredit' => 'minoredit',
131 'botedit' => 'botedit',
135 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
139 * Returns text for the start of the tabular part of RC
142 public function beginRecentChangesList() {
143 $this->rc_cache
= array();
144 $this->rcMoveIndex
= 0;
145 $this->rcCacheIndex
= 0;
146 $this->lastdate
= '';
147 $this->rclistOpen
= false;
152 * Show formatted char difference
153 * @param $old Integer: bytes
154 * @param $new Integer: bytes
157 public static function showCharacterDifference( $old, $new ) {
158 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
159 $szdiff = $new - $old;
161 $code = $wgLang->getCode();
162 static $fastCharDiff = array();
163 if ( !isset($fastCharDiff[$code]) ) {
164 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
167 $formatedSize = $wgLang->formatNum($szdiff);
169 if ( !$fastCharDiff[$code] ) {
170 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
173 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
178 if( $szdiff === 0 ) {
179 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
180 } elseif( $szdiff > 0 ) {
181 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
183 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
188 * Returns text for the end of RC
191 public function endRecentChangesList() {
192 if( $this->rclistOpen
) {
199 public function insertMove( &$s, $rc ) {
201 $s .= '(' . $this->message
['diff'] . ') (';
203 $s .= $this->skin
->link(
204 $rc->getMovedToTitle(),
205 $this->message
['hist'],
207 array( 'action' => 'history' ),
208 array( 'known', 'noclasses' )
210 # "[[x]] moved to [[y]]"
211 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
218 array( 'redirect' => 'no' ),
219 array( 'known', 'noclasses' )
222 $rc->getMovedToTitle(),
226 array( 'known', 'noclasses' )
231 public function insertDateHeader( &$s, $rc_timestamp ) {
233 # Make date header if necessary
234 $date = $wgLang->date( $rc_timestamp, true, true );
235 if( $date != $this->lastdate
) {
236 if( $this->lastdate
!= '' ) {
239 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
240 $this->lastdate
= $date;
241 $this->rclistOpen
= true;
245 public function insertLog( &$s, $title, $logtype ) {
246 $logname = LogPage
::logName( $logtype );
247 $s .= '(' . $this->skin
->link(
252 array( 'known', 'noclasses' )
256 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
258 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
259 $diffLink = $this->message
['diff'];
260 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
261 $diffLink = $this->message
['diff'];
264 'curid' => $rc->mAttribs
['rc_cur_id'],
265 'diff' => $rc->mAttribs
['rc_this_oldid'],
266 'oldid' => $rc->mAttribs
['rc_last_oldid']
270 $query['rcid'] = $rc->mAttribs
['rc_id'];
273 $diffLink = $this->skin
->link(
275 $this->message
['diff'],
276 array( 'tabindex' => $rc->counter
),
278 array( 'known', 'noclasses' )
281 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
283 $s .= $this->skin
->link(
285 $this->message
['hist'],
288 'curid' => $rc->mAttribs
['rc_cur_id'],
289 'action' => 'history'
291 array( 'known', 'noclasses' )
296 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
298 # If it's a new article, there is no diff link, but if it hasn't been
299 # patrolled yet, we need to give users a way to do so
302 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
303 $params['rcid'] = $rc->mAttribs
['rc_id'];
306 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
307 $articlelink = $this->skin
->link(
312 array( 'known', 'noclasses' )
314 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
316 $articlelink = ' '. $this->skin
->link(
321 array( 'known', 'noclasses' )
324 # Bolden pages watched by this user
326 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
329 $articlelink .= $wgContLang->getDirMark();
331 wfRunHooks( 'ChangesListInsertArticleLink',
332 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
334 $s .= " $articlelink";
337 public function insertTimestamp( &$s, $rc ) {
339 $s .= $this->message
['semicolon-separator'] .
340 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
343 /** Insert links to user page, user talk page and eventually a blocking link */
344 public function insertUserRelatedLinks( &$s, &$rc ) {
345 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
346 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
348 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
349 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
353 /** insert a formatted action */
354 public function insertAction( &$s, &$rc ) {
355 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
356 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
357 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
359 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
360 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
365 /** insert a formatted comment */
366 public function insertComment( &$s, &$rc ) {
367 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
368 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
369 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
371 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
377 * Check whether to enable recent changes patrol features
380 public static function usePatrol() {
382 return $wgUser->useRCPatrol();
386 * Returns the string which indicates the number of watching users
388 protected function numberofWatchingusers( $count ) {
390 static $cache = array();
392 if( !isset( $cache[$count] ) ) {
393 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
394 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
396 return $cache[$count];
403 * Determine if said field of a revision is hidden
404 * @param $rc RCCacheEntry
405 * @param $field Integer: one of DELETED_* bitfield constants
408 public static function isDeleted( $rc, $field ) {
409 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
413 * Determine if the current user is allowed to view a particular
414 * field of this revision, if it's marked as deleted.
415 * @param $rc RCCacheEntry
416 * @param $field Integer
419 public static function userCan( $rc, $field ) {
420 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
421 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
423 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
427 protected function maybeWatchedLink( $link, $watched = false ) {
429 return '<strong class="mw-watched">' . $link . '</strong>';
431 return '<span class="mw-rc-unwatched">' . $link . '</span>';
435 /** Inserts a rollback link */
436 public function insertRollback( &$s, &$rc ) {
438 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
439 $page = $rc->getTitle();
440 /** Check for rollback and edit permissions, disallow special pages, and only
441 * show a link on the top-most revision */
442 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
444 $rev = new Revision( array(
445 'id' => $rc->mAttribs
['rc_this_oldid'],
446 'user' => $rc->mAttribs
['rc_user'],
447 'user_text' => $rc->mAttribs
['rc_user_text'],
448 'deleted' => $rc->mAttribs
['rc_deleted']
450 $rev->setTitle( $page );
451 $s .= ' '.$this->skin
->generateRollback( $rev );
456 public function insertTags( &$s, &$rc, &$classes ) {
457 if ( empty($rc->mAttribs
['ts_tags']) )
460 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
461 $classes = array_merge( $classes, $newClasses );
462 $s .= ' ' . $tagSummary;
465 public function insertExtra( &$s, &$rc, &$classes ) {
466 ## Empty, used for subclassers to add anything special.
472 * Generate a list of changes using the good old system (no javascript)
474 class OldChangesList
extends ChangesList
{
476 * Format a line using the old system (aka without any javascript).
478 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
479 global $wgLang, $wgRCShowChangedSize, $wgUser;
480 wfProfileIn( __METHOD__
);
481 # Should patrol-related stuff be shown?
482 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
484 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
485 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
489 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
491 if( $linenumber & 1 ) {
492 $classes[] = 'mw-line-odd';
495 $classes[] = 'mw-line-even';
500 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
501 $this->insertMove( $s, $rc );
503 } elseif( $rc->mAttribs
['rc_log_type'] ) {
504 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
505 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
506 // Log entries (old format) or log targets, and special pages
507 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
508 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
509 if( $name == 'Log' ) {
510 $this->insertLog( $s, $rc->getTitle(), $subpage );
514 $this->insertDiffHist( $s, $rc, $unpatrolled );
515 # M, N, b and ! (minor, new, bot and unpatrolled)
516 $s .= $this->recentChangesFlags(
518 'newpage' => $rc->mAttribs
['rc_new'],
519 'minor' => $rc->mAttribs
['rc_minor'],
520 'unpatrolled' => $unpatrolled,
521 'bot' => $rc->mAttribs
['rc_bot']
525 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
528 $this->insertTimestamp( $s, $rc );
529 # Bytes added or removed
530 if( $wgRCShowChangedSize ) {
531 $cd = $rc->getCharacterDifference();
537 $this->insertUserRelatedLinks( $s, $rc );
538 # Log action text (if any)
539 $this->insertAction( $s, $rc );
540 # Edit or log comment
541 $this->insertComment( $s, $rc );
543 $this->insertTags( $s, $rc, $classes );
545 $this->insertRollback( $s, $rc );
547 $this->insertExtra( $s, $rc, $classes );
549 # How many users watch this page
550 if( $rc->numberofWatchingusers
> 0 ) {
551 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
552 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
555 if( $this->watchlist
) {
556 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
559 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
561 wfProfileOut( __METHOD__
);
562 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
568 * Generate a list of changes using an Enhanced system (uses javascript).
570 class EnhancedChangesList
extends ChangesList
{
572 * Add the JavaScript file for enhanced changeslist
575 public function beginRecentChangesList() {
577 $this->rc_cache
= array();
578 $this->rcMoveIndex
= 0;
579 $this->rcCacheIndex
= 0;
580 $this->lastdate
= '';
581 $this->rclistOpen
= false;
582 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
586 * Format a line for enhanced recentchange (aka with javascript and block of lines).
588 public function recentChangesLine( &$baseRC, $watched = false ) {
589 global $wgLang, $wgUser;
591 wfProfileIn( __METHOD__
);
593 # Create a specialised object
594 $rc = RCCacheEntry
::newFromParent( $baseRC );
596 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
598 # If it's a new day, add the headline and flush the cache
599 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
601 if( $date != $this->lastdate
) {
602 # Process current cache
603 $ret = $this->recentChangesBlock();
604 $this->rc_cache
= array();
605 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
606 $this->lastdate
= $date;
609 # Should patrol-related stuff be shown?
610 if( $wgUser->useRCPatrol() ) {
611 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
613 $rc->unpatrolled
= false;
616 $showdifflinks = true;
618 $type = $rc->mAttribs
['rc_type'];
619 $logType = $rc->mAttribs
['rc_log_type'];
621 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
622 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
623 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
624 array(), array( 'redirect' => 'no' ) ),
625 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
626 // New unpatrolled pages
627 } else if( $rc->unpatrolled
&& $type == RC_NEW
) {
628 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
629 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
631 } else if( $type == RC_LOG
) {
633 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
634 $clink = '(' . $this->skin
->linkKnown( $logtitle,
635 LogPage
::logName( $logType ) ) . ')';
637 $clink = $this->skin
->link( $rc->getTitle() );
640 // Log entries (old format) and special pages
641 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
642 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
643 if ( $specialName == 'Log' ) {
645 $logname = LogPage
::logName( $logtype );
646 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
648 wfDebug( "Unexpected special page in recentchanges\n" );
653 $clink = $this->skin
->linkKnown( $rc->getTitle() );
656 # Don't show unusable diff links
657 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
658 $showdifflinks = false;
661 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
662 $rc->watched
= $watched;
664 $rc->timestamp
= $time;
665 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
667 # Make "cur" and "diff" links. Do not use link(), it is too slow if
668 # called too many times (50% of CPU time on RecentChanges!).
669 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
670 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
671 if( $rc->unpatrolled
) {
672 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
674 $rcIdQuery = array();
676 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
677 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
678 $lastOldid ) +
$rcIdQuery;
680 if( !$showdifflinks ) {
681 $curLink = $this->message
['cur'];
682 $diffLink = $this->message
['diff'];
683 } else if( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
684 if ( $type != RC_NEW
) {
685 $curLink = $this->message
['cur'];
687 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
688 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
690 $diffLink = $this->message
['diff'];
692 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
693 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
694 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
695 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
699 if( !$showdifflinks ||
!$lastOldid ) {
700 $lastLink = $this->message
['last'];
701 } else if( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
702 $lastLink = $this->message
['last'];
704 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
705 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
709 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
710 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
712 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
713 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
716 $rc->lastlink
= $lastLink;
717 $rc->curlink
= $curLink;
718 $rc->difflink
= $diffLink;
720 # Put accumulated information into the cache, for later display
721 # Page moves go on their own line
722 $title = $rc->getTitle();
723 $secureName = $title->getPrefixedDBkey();
724 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
725 # Use an @ character to prevent collision with page names
726 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
728 # Logs are grouped by type
729 if( $type == RC_LOG
){
730 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
732 if( !isset( $this->rc_cache
[$secureName] ) ) {
733 $this->rc_cache
[$secureName] = array();
736 array_push( $this->rc_cache
[$secureName], $rc );
739 wfProfileOut( __METHOD__
);
747 protected function recentChangesBlockGroup( $block ) {
748 global $wgLang, $wgContLang, $wgRCShowChangedSize;
750 wfProfileIn( __METHOD__
);
752 # Add the namespace and title of the block as part of the class
753 if ( $block[0]->mAttribs
['rc_log_type'] ) {
755 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
757 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
759 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
760 Html
::openElement( 'tr' );
762 # Collate list of users
763 $userlinks = array();
765 $unpatrolled = false;
767 $curId = $currentRevision = 0;
768 # Some catalyst variables...
771 foreach( $block as $rcObj ) {
772 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
773 if( $rcObj->mAttribs
['rc_new'] ) {
776 // If all log actions to this page were hidden, then don't
777 // give the name of the affected page for this block!
778 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
781 $u = $rcObj->userlink
;
782 if( !isset( $userlinks[$u] ) ) {
785 if( $rcObj->unpatrolled
) {
788 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
791 # Get the latest entry with a page_id and oldid
792 # since logs may not have these.
793 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
794 $curId = $rcObj->mAttribs
['rc_cur_id'];
796 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
797 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
800 $bot = $rcObj->mAttribs
['rc_bot'];
804 # Sort the list and convert to text
805 krsort( $userlinks );
808 foreach( $userlinks as $userlink => $count) {
810 $text .= $wgContLang->getDirMark();
812 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
814 array_push( $users, $text );
817 $users = ' <span class="changedby">[' .
818 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
821 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
822 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
824 $tl = "<span class='mw-collapsible-toggle'>"
825 . "<span class='mw-rc-openarrow'>"
826 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
827 . "</span><span class='mw-rc-closearrow'>"
828 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
830 $r .= "<td>$tl</td>";
833 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
836 'unpatrolled' => $unpatrolled,
841 $r .= ' '.$block[0]->timestamp
.' </td><td>';
845 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
846 } else if( $allLogs ) {
847 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
849 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
852 $r .= $wgContLang->getDirMark();
854 $queryParams['curid'] = $curId;
857 static $nchanges = array();
858 if ( !isset( $nchanges[$n] ) ) {
859 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
865 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
867 } else if( $isnew ) {
870 $params = $queryParams;
871 $params['diff'] = $currentRevision;
872 $params['oldid'] = $oldid;
874 $r .= $this->skin
->link(
875 $block[0]->getTitle(),
879 array( 'known', 'noclasses' )
886 // don't show history link for logs
887 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
888 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
890 $params = $queryParams;
891 $params['action'] = 'history';
893 $r .= $this->message
['pipe-separator'] .
895 $block[0]->getTitle(),
896 $this->message
['hist'],
899 array( 'known', 'noclasses' )
904 # Character difference (does not apply if only log items)
905 if( $wgRCShowChangedSize && !$allLogs ) {
907 $first = count($block) - 1;
908 # Some events (like logs) have an "empty" size, so we need to skip those...
909 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
912 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
916 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
917 $block[$last]->mAttribs
['rc_new_len'] );
919 if( $chardiff == '' ) {
922 $r .= ' ' . $chardiff. ' . . ';
927 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
930 foreach( $block as $rcObj ) {
931 # Classes to apply -- TODO implement
933 $type = $rcObj->mAttribs
['rc_type'];
935 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
936 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
937 $r .= $this->recentChangesFlags( array(
938 'newpage' => $rcObj->mAttribs
['rc_new'],
939 'minor' => $rcObj->mAttribs
['rc_minor'],
940 'unpatrolled' => $rcObj->unpatrolled
,
941 'bot' => $rcObj->mAttribs
['rc_bot'],
943 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
945 $params = $queryParams;
947 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
948 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
952 if( $type == RC_LOG
) {
953 $link = $rcObj->timestamp
;
955 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
956 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
958 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
959 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
962 $link = $this->skin
->link(
967 array( 'known', 'noclasses' )
969 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
970 $link = '<span class="history-deleted">'.$link.'</span> ';
972 $r .= $link . '</span>';
974 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
976 $r .= $rcObj->curlink
;
977 $r .= $this->message
['pipe-separator'];
978 $r .= $rcObj->lastlink
;
984 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
985 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
989 $r .= $rcObj->userlink
;
990 $r .= $rcObj->usertalklink
;
992 $this->insertAction( $r, $rcObj );
994 $this->insertComment( $r, $rcObj );
996 $this->insertRollback( $r, $rcObj );
998 $this->insertTags( $r, $rcObj, $classes );
1000 $r .= "</td></tr>\n";
1004 $this->rcCacheIndex++
;
1006 wfProfileOut( __METHOD__
);
1012 * Generate HTML for an arrow or placeholder graphic
1013 * @param $dir String: one of '', 'd', 'l', 'r'
1014 * @param $alt String: text
1015 * @param $title String: text
1016 * @return String: HTML <img> tag
1018 protected function arrow( $dir, $alt='', $title='' ) {
1019 global $wgStylePath;
1020 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1021 $encAlt = htmlspecialchars( $alt );
1022 $encTitle = htmlspecialchars( $title );
1023 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1027 * Generate HTML for a right- or left-facing arrow,
1028 * depending on language direction.
1029 * @return String: HTML <img> tag
1031 protected function sideArrow() {
1033 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1034 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1038 * Generate HTML for a down-facing arrow
1039 * depending on language direction.
1040 * @return String: HTML <img> tag
1042 protected function downArrow() {
1043 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1047 * Generate HTML for a spacer image
1048 * @return String: HTML <img> tag
1050 protected function spacerArrow() {
1051 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1055 * Enhanced RC ungrouped line.
1056 * @return String: a HTML formated line (generated using $r)
1058 protected function recentChangesBlockLine( $rcObj ) {
1059 global $wgRCShowChangedSize;
1061 wfProfileIn( __METHOD__
);
1062 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1064 $type = $rcObj->mAttribs
['rc_type'];
1065 $logType = $rcObj->mAttribs
['rc_log_type'];
1068 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1070 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1072 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1073 Html
::openElement( 'tr' );
1075 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1076 # Flag and Timestamp
1077 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1078 $r .= '    '; // 4 flags -> 4 spaces
1080 $r .= $this->recentChangesFlags( array(
1081 'newpage' => $type == RC_NEW
,
1082 'mino' => $rcObj->mAttribs
['rc_minor'],
1083 'unpatrolled' => $rcObj->unpatrolled
,
1084 'bot' => $rcObj->mAttribs
['rc_bot'],
1087 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1088 # Article or log link
1090 $logtitle = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1091 $logname = LogPage
::logName( $logType );
1092 $r .= '(' . $this->skin
->link(
1097 array( 'known', 'noclasses' )
1100 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1102 # Diff and hist links
1103 if ( $type != RC_LOG
) {
1104 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1105 $query['action'] = 'history';
1106 $r .= $this->skin
->link(
1108 $this->message
['hist'],
1111 array( 'known', 'noclasses' )
1116 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1120 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1121 # Log action (if any)
1123 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1124 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1126 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1127 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1130 $this->insertComment( $r, $rcObj );
1131 $this->insertRollback( $r, $rcObj );
1133 $this->insertTags( $r, $rcObj, $classes );
1134 # Show how many people are watching this if enabled
1135 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1137 $r .= "</td></tr></table>\n";
1139 wfProfileOut( __METHOD__
);
1145 * If enhanced RC is in use, this function takes the previously cached
1146 * 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();