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
41 protected $watchlist = false;
46 * Changeslist contructor
49 public function __construct( $skin ) {
51 $this->preCacheMessages();
55 * Fetch an appropriate changes list class for the specified user
56 * Some users might want to use an enhanced list format, for instance
58 * @param $user User to fetch the list class for
59 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
61 public static function newFromUser( $user ) {
64 $sk = $user->getSkin();
66 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
67 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
68 return $new ?
new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
75 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
76 * @param $value Boolean
78 public function setWatchlistDivs( $value = true ) {
79 $this->watchlist
= $value;
83 * As we use the same small set of messages in various methods and that
84 * they are called often, we call them once and save them in $this->message
86 private function preCacheMessages() {
87 if( !isset( $this->message
) ) {
88 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
89 'semicolon-separator pipe-separator' ) as $msg ) {
90 $this->message
[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
96 * Returns the appropriate flags for new page, minor change and patrolling
97 * @param $flags Array Associative array of 'flag' => Bool
98 * @param $nothing String to use for empty space
101 protected function recentChangesFlags( $flags, $nothing = ' ' ) {
103 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
104 $f .= isset( $flags[$flag] ) && $flags[$flag]
105 ? self
::flag( $flag )
112 * Provide the <abbr> element appropriate to a given abbreviated flag,
113 * namely the flag indicating a new page, a minor edit, a bot edit, or an
114 * unpatrolled edit. By default in English it will contain "N", "m", "b",
115 * "!" respectively, plus it will have an appropriate title and class.
117 * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot'
118 * @return String: Raw HTML
120 public static function flag( $flag ) {
121 static $messages = null;
122 if ( is_null( $messages ) ) {
124 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
125 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
126 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
127 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
129 foreach( $messages as &$value ) {
130 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
131 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
135 # Inconsistent naming, bleh
137 'newpage' => 'newpage',
138 'minor' => 'minoredit',
140 'unpatrolled' => 'unpatrolled',
141 'minoredit' => 'minoredit',
142 'botedit' => 'botedit',
146 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
150 * Returns text for the start of the tabular part of RC
153 public function beginRecentChangesList() {
154 $this->rc_cache
= array();
155 $this->rcMoveIndex
= 0;
156 $this->rcCacheIndex
= 0;
157 $this->lastdate
= '';
158 $this->rclistOpen
= false;
163 * Show formatted char difference
164 * @param $old Integer: bytes
165 * @param $new Integer: bytes
168 public static function showCharacterDifference( $old, $new ) {
169 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
170 $szdiff = $new - $old;
172 $code = $wgLang->getCode();
173 static $fastCharDiff = array();
174 if ( !isset($fastCharDiff[$code]) ) {
175 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
178 $formatedSize = $wgLang->formatNum($szdiff);
180 if ( !$fastCharDiff[$code] ) {
181 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
184 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
189 if( $szdiff === 0 ) {
190 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
191 } elseif( $szdiff > 0 ) {
192 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
194 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
199 * Returns text for the end of RC
202 public function endRecentChangesList() {
203 if( $this->rclistOpen
) {
212 * @param $rc RecentChange
215 public function insertMove( &$s, $rc ) {
217 $s .= '(' . $this->message
['diff'] . ') (';
219 $s .= $this->skin
->link(
220 $rc->getMovedToTitle(),
221 $this->message
['hist'],
223 array( 'action' => 'history' ),
224 array( 'known', 'noclasses' )
226 # "[[x]] moved to [[y]]"
227 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
234 array( 'redirect' => 'no' ),
235 array( 'known', 'noclasses' )
238 $rc->getMovedToTitle(),
242 array( 'known', 'noclasses' )
247 public function insertDateHeader( &$s, $rc_timestamp ) {
249 # Make date header if necessary
250 $date = $wgLang->date( $rc_timestamp, true, true );
251 if( $date != $this->lastdate
) {
252 if( $this->lastdate
!= '' ) {
255 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
256 $this->lastdate
= $date;
257 $this->rclistOpen
= true;
261 public function insertLog( &$s, $title, $logtype ) {
262 $logname = LogPage
::logName( $logtype );
263 $s .= '(' . $this->skin
->link(
268 array( 'known', 'noclasses' )
274 * @param $rc RecentChange
275 * @param $unpatrolled
278 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
280 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
281 $diffLink = $this->message
['diff'];
282 } elseif( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
283 $diffLink = $this->message
['diff'];
286 'curid' => $rc->mAttribs
['rc_cur_id'],
287 'diff' => $rc->mAttribs
['rc_this_oldid'],
288 'oldid' => $rc->mAttribs
['rc_last_oldid']
292 $query['rcid'] = $rc->mAttribs
['rc_id'];
295 $diffLink = $this->skin
->link(
297 $this->message
['diff'],
298 array( 'tabindex' => $rc->counter
),
300 array( 'known', 'noclasses' )
303 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
305 $s .= $this->skin
->link(
307 $this->message
['hist'],
310 'curid' => $rc->mAttribs
['rc_cur_id'],
311 'action' => 'history'
313 array( 'known', 'noclasses' )
320 * @param $rc RecentChange
321 * @param $unpatrolled
325 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
327 # If it's a new article, there is no diff link, but if it hasn't been
328 # patrolled yet, we need to give users a way to do so
331 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
332 $params['rcid'] = $rc->mAttribs
['rc_id'];
335 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
336 $articlelink = $this->skin
->link(
341 array( 'known', 'noclasses' )
343 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
345 $articlelink = ' '. $this->skin
->link(
350 array( 'known', 'noclasses' )
353 # Bolden pages watched by this user
355 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
358 $articlelink .= $wgLang->getDirMark();
360 wfRunHooks( 'ChangesListInsertArticleLink',
361 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
363 $s .= " $articlelink";
368 * @param $rc RecentChange
371 public function insertTimestamp( &$s, $rc ) {
373 $s .= $this->message
['semicolon-separator'] .
374 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
377 /** Insert links to user page, user talk page and eventually a blocking link
379 * @param $rc RecentChange
381 public function insertUserRelatedLinks( &$s, &$rc ) {
382 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
383 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
385 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
386 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
390 /** insert a formatted action
392 * @param $rc RecentChange
394 public function insertAction( &$s, &$rc ) {
395 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
396 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
397 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
399 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
400 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
405 /** insert a formatted comment
407 * @param $rc RecentChange
409 public function insertComment( &$s, &$rc ) {
410 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
411 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
412 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
414 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
420 * Check whether to enable recent changes patrol features
423 public static function usePatrol() {
425 return $wgUser->useRCPatrol();
429 * Returns the string which indicates the number of watching users
431 protected function numberofWatchingusers( $count ) {
433 static $cache = array();
435 if( !isset( $cache[$count] ) ) {
436 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
437 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
439 return $cache[$count];
446 * Determine if said field of a revision is hidden
447 * @param $rc RCCacheEntry
448 * @param $field Integer: one of DELETED_* bitfield constants
451 public static function isDeleted( $rc, $field ) {
452 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
456 * Determine if the current user is allowed to view a particular
457 * field of this revision, if it's marked as deleted.
458 * @param $rc RCCacheEntry
459 * @param $field Integer
462 public static function userCan( $rc, $field ) {
463 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
464 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
466 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
470 protected function maybeWatchedLink( $link, $watched = false ) {
472 return '<strong class="mw-watched">' . $link . '</strong>';
474 return '<span class="mw-rc-unwatched">' . $link . '</span>';
478 /** Inserts a rollback link
481 * @param $rc RecentChange
483 public function insertRollback( &$s, &$rc ) {
485 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
486 $page = $rc->getTitle();
487 /** Check for rollback and edit permissions, disallow special pages, and only
488 * show a link on the top-most revision */
489 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
491 $rev = new Revision( array(
492 'id' => $rc->mAttribs
['rc_this_oldid'],
493 'user' => $rc->mAttribs
['rc_user'],
494 'user_text' => $rc->mAttribs
['rc_user_text'],
495 'deleted' => $rc->mAttribs
['rc_deleted']
497 $rev->setTitle( $page );
498 $s .= ' '.$this->skin
->generateRollback( $rev );
505 * @param $rc RecentChange
509 public function insertTags( &$s, &$rc, &$classes ) {
510 if ( empty($rc->mAttribs
['ts_tags']) )
513 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
514 $classes = array_merge( $classes, $newClasses );
515 $s .= ' ' . $tagSummary;
518 public function insertExtra( &$s, &$rc, &$classes ) {
519 ## Empty, used for subclassers to add anything special.
525 * Generate a list of changes using the good old system (no javascript)
527 class OldChangesList
extends ChangesList
{
529 * Format a line using the old system (aka without any javascript).
531 * @param $rc RecentChange
533 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
534 global $wgLang, $wgRCShowChangedSize, $wgUser;
535 wfProfileIn( __METHOD__
);
536 # Should patrol-related stuff be shown?
537 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
539 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
540 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
544 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
546 if( $linenumber & 1 ) {
547 $classes[] = 'mw-line-odd';
550 $classes[] = 'mw-line-even';
555 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
556 $this->insertMove( $s, $rc );
558 } elseif( $rc->mAttribs
['rc_log_type'] ) {
559 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
560 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
561 // Log entries (old format) or log targets, and special pages
562 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
563 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
564 if( $name == 'Log' ) {
565 $this->insertLog( $s, $rc->getTitle(), $subpage );
569 $this->insertDiffHist( $s, $rc, $unpatrolled );
570 # M, N, b and ! (minor, new, bot and unpatrolled)
571 $s .= $this->recentChangesFlags(
573 'newpage' => $rc->mAttribs
['rc_new'],
574 'minor' => $rc->mAttribs
['rc_minor'],
575 'unpatrolled' => $unpatrolled,
576 'bot' => $rc->mAttribs
['rc_bot']
580 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
583 $this->insertTimestamp( $s, $rc );
584 # Bytes added or removed
585 if( $wgRCShowChangedSize ) {
586 $cd = $rc->getCharacterDifference();
592 $this->insertUserRelatedLinks( $s, $rc );
593 # LTR/RTL direction mark
594 $s .= $wgLang->getDirMark();
595 # Log action text (if any)
596 $this->insertAction( $s, $rc );
597 # Edit or log comment
598 $this->insertComment( $s, $rc );
600 $this->insertTags( $s, $rc, $classes );
602 $this->insertRollback( $s, $rc );
604 $this->insertExtra( $s, $rc, $classes );
606 # How many users watch this page
607 if( $rc->numberofWatchingusers
> 0 ) {
608 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
609 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
612 if( $this->watchlist
) {
613 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
616 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
618 wfProfileOut( __METHOD__
);
619 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
625 * Generate a list of changes using an Enhanced system (uses javascript).
627 class EnhancedChangesList
extends ChangesList
{
629 * Add the JavaScript file for enhanced changeslist
632 public function beginRecentChangesList() {
634 $this->rc_cache
= array();
635 $this->rcMoveIndex
= 0;
636 $this->rcCacheIndex
= 0;
637 $this->lastdate
= '';
638 $this->rclistOpen
= false;
639 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
643 * Format a line for enhanced recentchange (aka with javascript and block of lines).
645 * @param $baseRC RecentChange
646 * @param $watched bool
650 public function recentChangesLine( &$baseRC, $watched = false ) {
651 global $wgLang, $wgUser;
653 wfProfileIn( __METHOD__
);
655 # Create a specialised object
656 $rc = RCCacheEntry
::newFromParent( $baseRC );
658 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
660 # If it's a new day, add the headline and flush the cache
661 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
663 if( $date != $this->lastdate
) {
664 # Process current cache
665 $ret = $this->recentChangesBlock();
666 $this->rc_cache
= array();
667 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
668 $this->lastdate
= $date;
671 # Should patrol-related stuff be shown?
672 if( $wgUser->useRCPatrol() ) {
673 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
675 $rc->unpatrolled
= false;
678 $showdifflinks = true;
680 $type = $rc->mAttribs
['rc_type'];
681 $logType = $rc->mAttribs
['rc_log_type'];
683 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
684 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
685 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
686 array(), array( 'redirect' => 'no' ) ),
687 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
688 // New unpatrolled pages
689 } elseif( $rc->unpatrolled
&& $type == RC_NEW
) {
690 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
691 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
693 } elseif( $type == RC_LOG
) {
695 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
696 $clink = '(' . $this->skin
->linkKnown( $logtitle,
697 LogPage
::logName( $logType ) ) . ')';
699 $clink = $this->skin
->link( $rc->getTitle() );
702 // Log entries (old format) and special pages
703 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
704 list( $specialName, $logtype ) = SpecialPageFactory
::resolveAlias( $rc->mAttribs
['rc_title'] );
705 if ( $specialName == 'Log' ) {
707 $logname = LogPage
::logName( $logtype );
708 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
710 wfDebug( "Unexpected special page in recentchanges\n" );
715 $clink = $this->skin
->linkKnown( $rc->getTitle() );
718 # Don't show unusable diff links
719 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
720 $showdifflinks = false;
723 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
724 $rc->watched
= $watched;
726 $rc->timestamp
= $time;
727 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
729 # Make "cur" and "diff" links. Do not use link(), it is too slow if
730 # called too many times (50% of CPU time on RecentChanges!).
731 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
732 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
733 if( $rc->unpatrolled
) {
734 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
736 $rcIdQuery = array();
738 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
739 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
740 $lastOldid ) +
$rcIdQuery;
742 if( !$showdifflinks ) {
743 $curLink = $this->message
['cur'];
744 $diffLink = $this->message
['diff'];
745 } elseif( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
746 if ( $type != RC_NEW
) {
747 $curLink = $this->message
['cur'];
749 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
750 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
752 $diffLink = $this->message
['diff'];
754 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
755 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
756 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
757 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
761 if( !$showdifflinks ||
!$lastOldid ) {
762 $lastLink = $this->message
['last'];
763 } elseif( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
764 $lastLink = $this->message
['last'];
766 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
767 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
771 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
772 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
774 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
775 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
778 $rc->lastlink
= $lastLink;
779 $rc->curlink
= $curLink;
780 $rc->difflink
= $diffLink;
782 # Put accumulated information into the cache, for later display
783 # Page moves go on their own line
784 $title = $rc->getTitle();
785 $secureName = $title->getPrefixedDBkey();
786 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
787 # Use an @ character to prevent collision with page names
788 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
790 # Logs are grouped by type
791 if( $type == RC_LOG
){
792 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
794 if( !isset( $this->rc_cache
[$secureName] ) ) {
795 $this->rc_cache
[$secureName] = array();
798 array_push( $this->rc_cache
[$secureName], $rc );
801 wfProfileOut( __METHOD__
);
809 protected function recentChangesBlockGroup( $block ) {
810 global $wgLang, $wgRCShowChangedSize;
812 wfProfileIn( __METHOD__
);
814 # Add the namespace and title of the block as part of the class
815 if ( $block[0]->mAttribs
['rc_log_type'] ) {
817 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
819 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
821 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
822 Html
::openElement( 'tr' );
824 # Collate list of users
825 $userlinks = array();
827 $unpatrolled = false;
829 $curId = $currentRevision = 0;
830 # Some catalyst variables...
833 foreach( $block as $rcObj ) {
834 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
835 if( $rcObj->mAttribs
['rc_new'] ) {
838 // If all log actions to this page were hidden, then don't
839 // give the name of the affected page for this block!
840 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
843 $u = $rcObj->userlink
;
844 if( !isset( $userlinks[$u] ) ) {
847 if( $rcObj->unpatrolled
) {
850 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
853 # Get the latest entry with a page_id and oldid
854 # since logs may not have these.
855 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
856 $curId = $rcObj->mAttribs
['rc_cur_id'];
858 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
859 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
862 $bot = $rcObj->mAttribs
['rc_bot'];
866 # Sort the list and convert to text
867 krsort( $userlinks );
870 foreach( $userlinks as $userlink => $count) {
872 $text .= $wgLang->getDirMark();
874 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
876 array_push( $users, $text );
879 $users = ' <span class="changedby">[' .
880 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
883 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
884 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
886 $tl = "<span class='mw-collapsible-toggle'>"
887 . "<span class='mw-rc-openarrow'>"
888 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
889 . "</span><span class='mw-rc-closearrow'>"
890 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
892 $r .= "<td>$tl</td>";
895 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
898 'unpatrolled' => $unpatrolled,
903 $r .= ' '.$block[0]->timestamp
.' </td><td>';
907 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
908 } elseif( $allLogs ) {
909 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
911 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
914 $r .= $wgLang->getDirMark();
916 $queryParams['curid'] = $curId;
919 static $nchanges = array();
920 if ( !isset( $nchanges[$n] ) ) {
921 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
927 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
932 $params = $queryParams;
933 $params['diff'] = $currentRevision;
934 $params['oldid'] = $oldid;
936 $r .= $this->skin
->link(
937 $block[0]->getTitle(),
941 array( 'known', 'noclasses' )
948 // don't show history link for logs
949 } elseif( $namehidden ||
!$block[0]->getTitle()->exists() ) {
950 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
952 $params = $queryParams;
953 $params['action'] = 'history';
955 $r .= $this->message
['pipe-separator'] .
957 $block[0]->getTitle(),
958 $this->message
['hist'],
961 array( 'known', 'noclasses' )
966 # Character difference (does not apply if only log items)
967 if( $wgRCShowChangedSize && !$allLogs ) {
969 $first = count($block) - 1;
970 # Some events (like logs) have an "empty" size, so we need to skip those...
971 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
974 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
978 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
979 $block[$last]->mAttribs
['rc_new_len'] );
981 if( $chardiff == '' ) {
984 $r .= ' ' . $chardiff. ' . . ';
989 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
992 foreach( $block as $rcObj ) {
993 # Classes to apply -- TODO implement
995 $type = $rcObj->mAttribs
['rc_type'];
997 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
998 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
999 $r .= $this->recentChangesFlags( array(
1000 'newpage' => $rcObj->mAttribs
['rc_new'],
1001 'minor' => $rcObj->mAttribs
['rc_minor'],
1002 'unpatrolled' => $rcObj->unpatrolled
,
1003 'bot' => $rcObj->mAttribs
['rc_bot'],
1005 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1007 $params = $queryParams;
1009 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
1010 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
1014 if( $type == RC_LOG
) {
1015 $link = $rcObj->timestamp
;
1017 } elseif( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
1018 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
1020 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
1021 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
1024 $link = $this->skin
->link(
1029 array( 'known', 'noclasses' )
1031 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
1032 $link = '<span class="history-deleted">'.$link.'</span> ';
1034 $r .= $link . '</span>';
1036 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
1038 $r .= $rcObj->curlink
;
1039 $r .= $this->message
['pipe-separator'];
1040 $r .= $rcObj->lastlink
;
1046 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1047 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1051 $r .= $rcObj->userlink
;
1052 $r .= $rcObj->usertalklink
;
1054 $this->insertAction( $r, $rcObj );
1056 $this->insertComment( $r, $rcObj );
1058 $this->insertRollback( $r, $rcObj );
1060 $this->insertTags( $r, $rcObj, $classes );
1062 $r .= "</td></tr>\n";
1066 $this->rcCacheIndex++
;
1068 wfProfileOut( __METHOD__
);
1074 * Generate HTML for an arrow or placeholder graphic
1075 * @param $dir String: one of '', 'd', 'l', 'r'
1076 * @param $alt String: text
1077 * @param $title String: text
1078 * @return String: HTML <img> tag
1080 protected function arrow( $dir, $alt='', $title='' ) {
1081 global $wgStylePath;
1082 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1083 $encAlt = htmlspecialchars( $alt );
1084 $encTitle = htmlspecialchars( $title );
1085 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1089 * Generate HTML for a right- or left-facing arrow,
1090 * depending on language direction.
1091 * @return String: HTML <img> tag
1093 protected function sideArrow() {
1095 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1096 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1100 * Generate HTML for a down-facing arrow
1101 * depending on language direction.
1102 * @return String: HTML <img> tag
1104 protected function downArrow() {
1105 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1109 * Generate HTML for a spacer image
1110 * @return String: HTML <img> tag
1112 protected function spacerArrow() {
1113 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1117 * Enhanced RC ungrouped line.
1119 * @param $rcObj RecentChange
1120 * @return String: a HTML formated line (generated using $r)
1122 protected function recentChangesBlockLine( $rcObj ) {
1123 global $wgRCShowChangedSize;
1125 wfProfileIn( __METHOD__
);
1126 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1128 $type = $rcObj->mAttribs
['rc_type'];
1129 $logType = $rcObj->mAttribs
['rc_log_type'];
1132 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1134 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1136 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1137 Html
::openElement( 'tr' );
1139 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1140 # Flag and Timestamp
1141 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1142 $r .= '    '; // 4 flags -> 4 spaces
1144 $r .= $this->recentChangesFlags( array(
1145 'newpage' => $type == RC_NEW
,
1146 'mino' => $rcObj->mAttribs
['rc_minor'],
1147 'unpatrolled' => $rcObj->unpatrolled
,
1148 'bot' => $rcObj->mAttribs
['rc_bot'],
1151 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1152 # Article or log link
1154 $logtitle = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1155 $logname = LogPage
::logName( $logType );
1156 $r .= '(' . $this->skin
->link(
1161 array( 'known', 'noclasses' )
1164 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1166 # Diff and hist links
1167 if ( $type != RC_LOG
) {
1168 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1169 $query['action'] = 'history';
1170 $r .= $this->skin
->link(
1172 $this->message
['hist'],
1175 array( 'known', 'noclasses' )
1180 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1184 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1185 # Log action (if any)
1187 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1188 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1190 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1191 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1194 $this->insertComment( $r, $rcObj );
1195 $this->insertRollback( $r, $rcObj );
1197 $classes = explode( ' ', $classes );
1198 $this->insertTags( $r, $rcObj, $classes );
1199 # Show how many people are watching this if enabled
1200 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1202 $r .= "</td></tr></table>\n";
1204 wfProfileOut( __METHOD__
);
1210 * If enhanced RC is in use, this function takes the previously cached
1211 * RC lines, arranges them, and outputs the HTML
1215 protected function recentChangesBlock() {
1216 if( count ( $this->rc_cache
) == 0 ) {
1220 wfProfileIn( __METHOD__
);
1223 foreach( $this->rc_cache
as $block ) {
1224 if( count( $block ) < 2 ) {
1225 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1227 $blockOut .= $this->recentChangesBlockGroup( $block );
1231 wfProfileOut( __METHOD__
);
1233 return '<div>'.$blockOut.'</div>';
1237 * Returns text for the end of RC
1238 * If enhanced RC is in use, returns pretty much all the text
1240 public function endRecentChangesList() {
1241 return $this->recentChangesBlock() . parent
::endRecentChangesList();