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( $key ) {
110 static $messages = null;
111 if ( is_null( $messages ) ) {
113 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
114 'minor' => array( 'minoreditletter', 'recentchanges-label-minor' ),
115 'bot' => 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' );
123 return "<abbr class='$key' title='" . $messages[$key][1] . "'>" . $messages[$key][0] . '</abbr>';
127 * Returns text for the start of the tabular part of RC
130 public function beginRecentChangesList() {
131 $this->rc_cache
= array();
132 $this->rcMoveIndex
= 0;
133 $this->rcCacheIndex
= 0;
134 $this->lastdate
= '';
135 $this->rclistOpen
= false;
140 * Show formatted char difference
141 * @param $old Integer: bytes
142 * @param $new Integer: bytes
145 public static function showCharacterDifference( $old, $new ) {
146 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
147 $szdiff = $new - $old;
149 $code = $wgLang->getCode();
150 static $fastCharDiff = array();
151 if ( !isset($fastCharDiff[$code]) ) {
152 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
155 $formatedSize = $wgLang->formatNum($szdiff);
157 if ( !$fastCharDiff[$code] ) {
158 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
161 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
166 if( $szdiff === 0 ) {
167 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
168 } elseif( $szdiff > 0 ) {
169 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
171 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
176 * Returns text for the end of RC
179 public function endRecentChangesList() {
180 if( $this->rclistOpen
) {
187 public function insertMove( &$s, $rc ) {
189 $s .= '(' . $this->message
['diff'] . ') (';
191 $s .= $this->skin
->link(
192 $rc->getMovedToTitle(),
193 $this->message
['hist'],
195 array( 'action' => 'history' ),
196 array( 'known', 'noclasses' )
198 # "[[x]] moved to [[y]]"
199 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
206 array( 'redirect' => 'no' ),
207 array( 'known', 'noclasses' )
210 $rc->getMovedToTitle(),
214 array( 'known', 'noclasses' )
219 public function insertDateHeader( &$s, $rc_timestamp ) {
221 # Make date header if necessary
222 $date = $wgLang->date( $rc_timestamp, true, true );
223 if( $date != $this->lastdate
) {
224 if( $this->lastdate
!= '' ) {
227 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
228 $this->lastdate
= $date;
229 $this->rclistOpen
= true;
233 public function insertLog( &$s, $title, $logtype ) {
234 $logname = LogPage
::logName( $logtype );
235 $s .= '(' . $this->skin
->link(
240 array( 'known', 'noclasses' )
244 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
246 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
247 $diffLink = $this->message
['diff'];
248 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
249 $diffLink = $this->message
['diff'];
252 'curid' => $rc->mAttribs
['rc_cur_id'],
253 'diff' => $rc->mAttribs
['rc_this_oldid'],
254 'oldid' => $rc->mAttribs
['rc_last_oldid']
258 $query['rcid'] = $rc->mAttribs
['rc_id'];
261 $diffLink = $this->skin
->link(
263 $this->message
['diff'],
264 array( 'tabindex' => $rc->counter
),
266 array( 'known', 'noclasses' )
269 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
271 $s .= $this->skin
->link(
273 $this->message
['hist'],
276 'curid' => $rc->mAttribs
['rc_cur_id'],
277 'action' => 'history'
279 array( 'known', 'noclasses' )
284 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
286 # If it's a new article, there is no diff link, but if it hasn't been
287 # patrolled yet, we need to give users a way to do so
290 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
291 $params['rcid'] = $rc->mAttribs
['rc_id'];
294 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
295 $articlelink = $this->skin
->link(
300 array( 'known', 'noclasses' )
302 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
304 $articlelink = ' '. $this->skin
->link(
309 array( 'known', 'noclasses' )
312 # Bolden pages watched by this user
314 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
317 $articlelink .= $wgContLang->getDirMark();
319 wfRunHooks( 'ChangesListInsertArticleLink',
320 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
322 $s .= " $articlelink";
325 public function insertTimestamp( &$s, $rc ) {
327 $s .= $this->message
['semicolon-separator'] .
328 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
331 /** Insert links to user page, user talk page and eventually a blocking link */
332 public function insertUserRelatedLinks( &$s, &$rc ) {
333 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
334 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
336 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
337 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
341 /** insert a formatted action */
342 public function insertAction( &$s, &$rc ) {
343 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
344 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
345 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
347 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
348 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
353 /** insert a formatted comment */
354 public function insertComment( &$s, &$rc ) {
355 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
356 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
357 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
359 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
365 * Check whether to enable recent changes patrol features
368 public static function usePatrol() {
370 return $wgUser->useRCPatrol();
374 * Returns the string which indicates the number of watching users
376 protected function numberofWatchingusers( $count ) {
378 static $cache = array();
380 if( !isset( $cache[$count] ) ) {
381 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
382 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
384 return $cache[$count];
391 * Determine if said field of a revision is hidden
392 * @param $rc RCCacheEntry
393 * @param $field Integer: one of DELETED_* bitfield constants
396 public static function isDeleted( $rc, $field ) {
397 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
401 * Determine if the current user is allowed to view a particular
402 * field of this revision, if it's marked as deleted.
403 * @param $rc RCCacheEntry
404 * @param $field Integer
407 public static function userCan( $rc, $field ) {
408 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
409 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
411 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
415 protected function maybeWatchedLink( $link, $watched = false ) {
417 return '<strong class="mw-watched">' . $link . '</strong>';
419 return '<span class="mw-rc-unwatched">' . $link . '</span>';
423 /** Inserts a rollback link */
424 public function insertRollback( &$s, &$rc ) {
426 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
427 $page = $rc->getTitle();
428 /** Check for rollback and edit permissions, disallow special pages, and only
429 * show a link on the top-most revision */
430 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
432 $rev = new Revision( array(
433 'id' => $rc->mAttribs
['rc_this_oldid'],
434 'user' => $rc->mAttribs
['rc_user'],
435 'user_text' => $rc->mAttribs
['rc_user_text'],
436 'deleted' => $rc->mAttribs
['rc_deleted']
438 $rev->setTitle( $page );
439 $s .= ' '.$this->skin
->generateRollback( $rev );
444 public function insertTags( &$s, &$rc, &$classes ) {
445 if ( empty($rc->mAttribs
['ts_tags']) )
448 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
449 $classes = array_merge( $classes, $newClasses );
450 $s .= ' ' . $tagSummary;
453 public function insertExtra( &$s, &$rc, &$classes ) {
454 ## Empty, used for subclassers to add anything special.
460 * Generate a list of changes using the good old system (no javascript)
462 class OldChangesList
extends ChangesList
{
464 * Format a line using the old system (aka without any javascript).
466 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
467 global $wgLang, $wgRCShowChangedSize, $wgUser;
468 wfProfileIn( __METHOD__
);
469 # Should patrol-related stuff be shown?
470 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
472 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
473 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
477 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
479 if( $linenumber & 1 ) {
480 $classes[] = 'mw-line-odd';
483 $classes[] = 'mw-line-even';
488 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
489 $this->insertMove( $s, $rc );
491 } elseif( $rc->mAttribs
['rc_log_type'] ) {
492 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
493 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
494 // Log entries (old format) or log targets, and special pages
495 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
496 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
497 if( $name == 'Log' ) {
498 $this->insertLog( $s, $rc->getTitle(), $subpage );
502 $this->insertDiffHist( $s, $rc, $unpatrolled );
503 # M, N, b and ! (minor, new, bot and unpatrolled)
504 $s .= $this->recentChangesFlags(
506 'new' => $rc->mAttribs
['rc_new'],
507 'minor' => $rc->mAttribs
['rc_minor'],
508 'unpatrolled' => $unpatrolled,
509 'bot' => $rc->mAttribs
['rc_bot']
513 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
516 $this->insertTimestamp( $s, $rc );
517 # Bytes added or removed
518 if( $wgRCShowChangedSize ) {
519 $cd = $rc->getCharacterDifference();
525 $this->insertUserRelatedLinks( $s, $rc );
526 # Log action text (if any)
527 $this->insertAction( $s, $rc );
528 # Edit or log comment
529 $this->insertComment( $s, $rc );
531 $this->insertTags( $s, $rc, $classes );
533 $this->insertRollback( $s, $rc );
535 $this->insertExtra( $s, $rc, $classes );
537 # How many users watch this page
538 if( $rc->numberofWatchingusers
> 0 ) {
539 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
540 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
543 if( $this->watchlist
) {
544 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
547 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
549 wfProfileOut( __METHOD__
);
550 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
556 * Generate a list of changes using an Enhanced system (uses javascript).
558 class EnhancedChangesList
extends ChangesList
{
560 * Add the JavaScript file for enhanced changeslist
563 public function beginRecentChangesList() {
565 $this->rc_cache
= array();
566 $this->rcMoveIndex
= 0;
567 $this->rcCacheIndex
= 0;
568 $this->lastdate
= '';
569 $this->rclistOpen
= false;
570 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
574 * Format a line for enhanced recentchange (aka with javascript and block of lines).
576 public function recentChangesLine( &$baseRC, $watched = false ) {
577 global $wgLang, $wgUser;
579 wfProfileIn( __METHOD__
);
581 # Create a specialised object
582 $rc = RCCacheEntry
::newFromParent( $baseRC );
584 # Extract fields from DB into the function scope (rc_xxxx variables)
585 // FIXME: Would be good to replace this extract() call with something
586 // that explicitly initializes variables.
587 extract( $rc->mAttribs
);
588 $curIdEq = array( 'curid' => $rc_cur_id );
590 # If it's a new day, add the headline and flush the cache
591 $date = $wgLang->date( $rc_timestamp, true );
593 if( $date != $this->lastdate
) {
594 # Process current cache
595 $ret = $this->recentChangesBlock();
596 $this->rc_cache
= array();
597 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
598 $this->lastdate
= $date;
601 # Should patrol-related stuff be shown?
602 if( $wgUser->useRCPatrol() ) {
603 $rc->unpatrolled
= !$rc_patrolled;
605 $rc->unpatrolled
= false;
608 $showdifflinks = true;
611 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
612 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
613 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
614 array(), array( 'redirect' => 'no' ) ),
615 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
616 // New unpatrolled pages
617 } else if( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
618 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
619 array( 'rcid' => $rc_id ) );
621 } else if( $rc_type == RC_LOG
) {
623 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc_log_type );
624 $clink = '(' . $this->skin
->linkKnown( $logtitle,
625 LogPage
::logName($rc_log_type) ) . ')';
627 $clink = $this->skin
->link( $rc->getTitle() );
630 // Log entries (old format) and special pages
631 } elseif( $rc_namespace == NS_SPECIAL
) {
632 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
633 if ( $specialName == 'Log' ) {
635 $logname = LogPage
::logName( $logtype );
636 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
638 wfDebug( "Unexpected special page in recentchanges\n" );
643 $clink = $this->skin
->linkKnown( $rc->getTitle() );
646 # Don't show unusable diff links
647 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
648 $showdifflinks = false;
651 $time = $wgLang->time( $rc_timestamp, true, true );
652 $rc->watched
= $watched;
654 $rc->timestamp
= $time;
655 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
657 # Make "cur" and "diff" links. Do not use link(), it is too slow if
658 # called too many times (50% of CPU time on RecentChanges!).
659 if( $rc->unpatrolled
) {
660 $rcIdQuery = array( 'rcid' => $rc_id );
662 $rcIdQuery = array();
664 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $rc_this_oldid );
665 $querydiff = $curIdEq +
array( 'diff' => $rc_this_oldid, 'oldid' =>
666 $rc_last_oldid ) +
$rcIdQuery;
668 if( !$showdifflinks ) {
669 $curLink = $this->message
['cur'];
670 $diffLink = $this->message
['diff'];
671 } else if( in_array( $rc_type, array(RC_NEW
,RC_LOG
,RC_MOVE
,RC_MOVE_OVER_REDIRECT
) ) ) {
672 if ( $rc_type != RC_NEW
) {
673 $curLink = $this->message
['cur'];
675 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
676 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
678 $diffLink = $this->message
['diff'];
680 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
681 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
682 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
683 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
687 if( !$showdifflinks ||
!$rc_last_oldid ) {
688 $lastLink = $this->message
['last'];
689 } else if( $rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
690 $lastLink = $this->message
['last'];
692 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
693 array(), $curIdEq +
array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) +
$rcIdQuery );
697 if( $this->isDeleted($rc,Revision
::DELETED_USER
) ) {
698 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
700 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
701 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
704 $rc->lastlink
= $lastLink;
705 $rc->curlink
= $curLink;
706 $rc->difflink
= $diffLink;
708 # Put accumulated information into the cache, for later display
709 # Page moves go on their own line
710 $title = $rc->getTitle();
711 $secureName = $title->getPrefixedDBkey();
712 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
713 # Use an @ character to prevent collision with page names
714 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
716 # Logs are grouped by type
717 if( $rc_type == RC_LOG
){
718 $secureName = SpecialPage
::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
720 if( !isset( $this->rc_cache
[$secureName] ) ) {
721 $this->rc_cache
[$secureName] = array();
724 array_push( $this->rc_cache
[$secureName], $rc );
727 wfProfileOut( __METHOD__
);
735 protected function recentChangesBlockGroup( $block ) {
736 global $wgLang, $wgContLang, $wgRCShowChangedSize;
738 wfProfileIn( __METHOD__
);
740 # Add the namespace and title of the block as part of the class
741 if ( $block[0]->mAttribs
['rc_log_type'] ) {
743 $classes = 'collapsible collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
745 $classes = 'collapsible collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
747 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
748 Html
::openElement( 'tr' );
750 # Collate list of users
751 $userlinks = array();
753 $unpatrolled = false;
755 $curId = $currentRevision = 0;
756 # Some catalyst variables...
759 foreach( $block as $rcObj ) {
760 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
761 if( $rcObj->mAttribs
['rc_new'] ) {
764 // If all log actions to this page were hidden, then don't
765 // give the name of the affected page for this block!
766 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
769 $u = $rcObj->userlink
;
770 if( !isset( $userlinks[$u] ) ) {
773 if( $rcObj->unpatrolled
) {
776 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
779 # Get the latest entry with a page_id and oldid
780 # since logs may not have these.
781 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
782 $curId = $rcObj->mAttribs
['rc_cur_id'];
784 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
785 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
788 $bot = $rcObj->mAttribs
['rc_bot'];
792 # Sort the list and convert to text
793 krsort( $userlinks );
796 foreach( $userlinks as $userlink => $count) {
798 $text .= $wgContLang->getDirMark();
800 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
802 array_push( $users, $text );
805 $users = ' <span class="changedby">[' .
806 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
809 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
810 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
812 $tl = "<span class='collapsible-expander'>"
813 . "<span class='mw-rc-openarrow'>"
814 . "<a href='#' title='$expandTitle'>{$this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) )}</a>"
815 . "</span><span class='mw-rc-closearrow'>"
816 . "<a href='#' title='$closeTitle'>{$this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) )}</a>"
818 $r .= "<td>$tl</td>";
821 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
824 'unpatrolled' => $unpatrolled,
829 $r .= ' '.$block[0]->timestamp
.' </td><td>';
833 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
834 } else if( $allLogs ) {
835 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
837 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
840 $r .= $wgContLang->getDirMark();
842 $queryParams['curid'] = $curId;
845 static $nchanges = array();
846 if ( !isset( $nchanges[$n] ) ) {
847 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
853 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
855 } else if( $isnew ) {
858 $params = $queryParams;
859 $params['diff'] = $currentRevision;
860 $params['oldid'] = $oldid;
862 $r .= $this->skin
->link(
863 $block[0]->getTitle(),
867 array( 'known', 'noclasses' )
874 // don't show history link for logs
875 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
876 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
878 $params = $queryParams;
879 $params['action'] = 'history';
881 $r .= $this->message
['pipe-separator'] .
883 $block[0]->getTitle(),
884 $this->message
['hist'],
887 array( 'known', 'noclasses' )
892 # Character difference (does not apply if only log items)
893 if( $wgRCShowChangedSize && !$allLogs ) {
895 $first = count($block) - 1;
896 # Some events (like logs) have an "empty" size, so we need to skip those...
897 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
900 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
904 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
905 $block[$last]->mAttribs
['rc_new_len'] );
907 if( $chardiff == '' ) {
910 $r .= ' ' . $chardiff. ' . . ';
915 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
918 foreach( $block as $rcObj ) {
919 # Extract fields from DB into the function scope (rc_xxxx variables)
920 // FIXME: Would be good to replace this extract() call with something
921 // that explicitly initializes variables.
922 # Classes to apply -- TODO implement
924 extract( $rcObj->mAttribs
);
926 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
927 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
928 $r .= $this->recentChangesFlags( array(
930 'minor' => $rc_minor,
931 'unpatrolled' => $rcObj->unpatrolled
,
934 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
936 $params = $queryParams;
938 if( $rc_this_oldid != 0 ) {
939 $params['oldid'] = $rc_this_oldid;
943 if( $rc_type == RC_LOG
) {
944 $link = $rcObj->timestamp
;
946 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
947 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
949 if ( $rcObj->unpatrolled
&& $rc_type == RC_NEW
) {
950 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
953 $link = $this->skin
->link(
958 array( 'known', 'noclasses' )
960 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
961 $link = '<span class="history-deleted">'.$link.'</span> ';
963 $r .= $link . '</span>';
965 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
967 $r .= $rcObj->curlink
;
968 $r .= $this->message
['pipe-separator'];
969 $r .= $rcObj->lastlink
;
975 if( $wgRCShowChangedSize ) {
976 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
979 $r .= $rcObj->userlink
;
980 $r .= $rcObj->usertalklink
;
982 $this->insertAction( $r, $rcObj );
984 $this->insertComment( $r, $rcObj );
986 $this->insertRollback( $r, $rcObj );
988 $this->insertTags( $r, $rcObj, $classes );
990 $r .= "</td></tr>\n";
994 $this->rcCacheIndex++
;
996 wfProfileOut( __METHOD__
);
1002 * Generate HTML for an arrow or placeholder graphic
1003 * @param $dir String: one of '', 'd', 'l', 'r'
1004 * @param $alt String: text
1005 * @param $title String: text
1006 * @return String: HTML <img> tag
1008 protected function arrow( $dir, $alt='', $title='' ) {
1009 global $wgStylePath;
1010 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1011 $encAlt = htmlspecialchars( $alt );
1012 $encTitle = htmlspecialchars( $title );
1013 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1017 * Enhanced RC ungrouped line.
1018 * @return String: a HTML formated line (generated using $r)
1020 protected function recentChangesBlockLine( $rcObj ) {
1021 global $wgRCShowChangedSize;
1023 wfProfileIn( __METHOD__
);
1025 # Extract fields from DB into the function scope (rc_xxxx variables)
1026 // FIXME: Would be good to replace this extract() call with something
1027 // that explicitly initializes variables.
1029 extract( $rcObj->mAttribs
);
1030 $query['curid'] = $rc_cur_id;
1032 if( $rc_log_type ) {
1034 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $rc_log_type . '-' . $rcObj->mAttribs
['rc_title'] );
1036 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1038 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1039 Html
::openElement( 'tr' );
1041 $r .= '<td class="mw-enhanced-rc">' . $this->arrow( '', codepointToUtf8( 0xa0 ) );
1042 # Flag and Timestamp
1043 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
1044 $r .= '    '; // 4 flags -> 4 spaces
1046 $r .= $this->recentChangesFlags( array(
1047 'new' => $rc_type == RC_NEW
,
1048 'minor' => $rc_minor,
1049 'unpatrolled' => $rcObj->unpatrolled
,
1053 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1054 # Article or log link
1055 if( $rc_log_type ) {
1056 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
1057 $logname = LogPage
::logName( $rc_log_type );
1058 $r .= '(' . $this->skin
->link(
1063 array( 'known', 'noclasses' )
1066 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1068 # Diff and hist links
1069 if ( $rc_type != RC_LOG
) {
1070 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1071 $query['action'] = 'history';
1072 $r .= $this->skin
->link(
1074 $this->message
['hist'],
1077 array( 'known', 'noclasses' )
1082 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1086 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1087 # Log action (if any)
1088 if( $rc_log_type ) {
1089 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1090 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1092 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1093 $this->skin
, LogPage
::extractParams($rc_params), true, true );
1096 $this->insertComment( $r, $rcObj );
1097 $this->insertRollback( $r, $rcObj );
1099 $this->insertTags( $r, $rcObj, $classes );
1100 # Show how many people are watching this if enabled
1101 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1103 $r .= "</td></tr></table>\n";
1105 wfProfileOut( __METHOD__
);
1111 * If enhanced RC is in use, this function takes the previously cached
1112 * RC lines, arranges them, and outputs the HTML
1114 protected function recentChangesBlock() {
1115 if( count ( $this->rc_cache
) == 0 ) {
1119 wfProfileIn( __METHOD__
);
1122 foreach( $this->rc_cache
as $block ) {
1123 if( count( $block ) < 2 ) {
1124 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1126 $blockOut .= $this->recentChangesBlockGroup( $block );
1130 wfProfileOut( __METHOD__
);
1132 return '<div>'.$blockOut.'</div>';
1136 * Returns text for the end of RC
1137 * If enhanced RC is in use, returns pretty much all the text
1139 public function endRecentChangesList() {
1140 return $this->recentChangesBlock() . parent
::endRecentChangesList();