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',
129 'unpatrolled' => 'unpatrolled',
133 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
137 * Returns text for the start of the tabular part of RC
140 public function beginRecentChangesList() {
141 $this->rc_cache
= array();
142 $this->rcMoveIndex
= 0;
143 $this->rcCacheIndex
= 0;
144 $this->lastdate
= '';
145 $this->rclistOpen
= false;
150 * Show formatted char difference
151 * @param $old Integer: bytes
152 * @param $new Integer: bytes
155 public static function showCharacterDifference( $old, $new ) {
156 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
157 $szdiff = $new - $old;
159 $code = $wgLang->getCode();
160 static $fastCharDiff = array();
161 if ( !isset($fastCharDiff[$code]) ) {
162 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
165 $formatedSize = $wgLang->formatNum($szdiff);
167 if ( !$fastCharDiff[$code] ) {
168 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
171 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
176 if( $szdiff === 0 ) {
177 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
178 } elseif( $szdiff > 0 ) {
179 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
181 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
186 * Returns text for the end of RC
189 public function endRecentChangesList() {
190 if( $this->rclistOpen
) {
197 public function insertMove( &$s, $rc ) {
199 $s .= '(' . $this->message
['diff'] . ') (';
201 $s .= $this->skin
->link(
202 $rc->getMovedToTitle(),
203 $this->message
['hist'],
205 array( 'action' => 'history' ),
206 array( 'known', 'noclasses' )
208 # "[[x]] moved to [[y]]"
209 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
216 array( 'redirect' => 'no' ),
217 array( 'known', 'noclasses' )
220 $rc->getMovedToTitle(),
224 array( 'known', 'noclasses' )
229 public function insertDateHeader( &$s, $rc_timestamp ) {
231 # Make date header if necessary
232 $date = $wgLang->date( $rc_timestamp, true, true );
233 if( $date != $this->lastdate
) {
234 if( $this->lastdate
!= '' ) {
237 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
238 $this->lastdate
= $date;
239 $this->rclistOpen
= true;
243 public function insertLog( &$s, $title, $logtype ) {
244 $logname = LogPage
::logName( $logtype );
245 $s .= '(' . $this->skin
->link(
250 array( 'known', 'noclasses' )
254 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
256 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
257 $diffLink = $this->message
['diff'];
258 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
259 $diffLink = $this->message
['diff'];
262 'curid' => $rc->mAttribs
['rc_cur_id'],
263 'diff' => $rc->mAttribs
['rc_this_oldid'],
264 'oldid' => $rc->mAttribs
['rc_last_oldid']
268 $query['rcid'] = $rc->mAttribs
['rc_id'];
271 $diffLink = $this->skin
->link(
273 $this->message
['diff'],
274 array( 'tabindex' => $rc->counter
),
276 array( 'known', 'noclasses' )
279 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
281 $s .= $this->skin
->link(
283 $this->message
['hist'],
286 'curid' => $rc->mAttribs
['rc_cur_id'],
287 'action' => 'history'
289 array( 'known', 'noclasses' )
294 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
296 # If it's a new article, there is no diff link, but if it hasn't been
297 # patrolled yet, we need to give users a way to do so
300 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
301 $params['rcid'] = $rc->mAttribs
['rc_id'];
304 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
305 $articlelink = $this->skin
->link(
310 array( 'known', 'noclasses' )
312 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
314 $articlelink = ' '. $this->skin
->link(
319 array( 'known', 'noclasses' )
322 # Bolden pages watched by this user
324 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
327 $articlelink .= $wgContLang->getDirMark();
329 wfRunHooks( 'ChangesListInsertArticleLink',
330 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
332 $s .= " $articlelink";
335 public function insertTimestamp( &$s, $rc ) {
337 $s .= $this->message
['semicolon-separator'] .
338 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
341 /** Insert links to user page, user talk page and eventually a blocking link */
342 public function insertUserRelatedLinks( &$s, &$rc ) {
343 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
344 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
346 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
347 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
351 /** insert a formatted action */
352 public function insertAction( &$s, &$rc ) {
353 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
354 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
355 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
357 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
358 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
363 /** insert a formatted comment */
364 public function insertComment( &$s, &$rc ) {
365 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
366 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
367 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
369 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
375 * Check whether to enable recent changes patrol features
378 public static function usePatrol() {
380 return $wgUser->useRCPatrol();
384 * Returns the string which indicates the number of watching users
386 protected function numberofWatchingusers( $count ) {
388 static $cache = array();
390 if( !isset( $cache[$count] ) ) {
391 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
392 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
394 return $cache[$count];
401 * Determine if said field of a revision is hidden
402 * @param $rc RCCacheEntry
403 * @param $field Integer: one of DELETED_* bitfield constants
406 public static function isDeleted( $rc, $field ) {
407 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
411 * Determine if the current user is allowed to view a particular
412 * field of this revision, if it's marked as deleted.
413 * @param $rc RCCacheEntry
414 * @param $field Integer
417 public static function userCan( $rc, $field ) {
418 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
419 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
421 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
425 protected function maybeWatchedLink( $link, $watched = false ) {
427 return '<strong class="mw-watched">' . $link . '</strong>';
429 return '<span class="mw-rc-unwatched">' . $link . '</span>';
433 /** Inserts a rollback link */
434 public function insertRollback( &$s, &$rc ) {
436 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
437 $page = $rc->getTitle();
438 /** Check for rollback and edit permissions, disallow special pages, and only
439 * show a link on the top-most revision */
440 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
442 $rev = new Revision( array(
443 'id' => $rc->mAttribs
['rc_this_oldid'],
444 'user' => $rc->mAttribs
['rc_user'],
445 'user_text' => $rc->mAttribs
['rc_user_text'],
446 'deleted' => $rc->mAttribs
['rc_deleted']
448 $rev->setTitle( $page );
449 $s .= ' '.$this->skin
->generateRollback( $rev );
454 public function insertTags( &$s, &$rc, &$classes ) {
455 if ( empty($rc->mAttribs
['ts_tags']) )
458 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
459 $classes = array_merge( $classes, $newClasses );
460 $s .= ' ' . $tagSummary;
463 public function insertExtra( &$s, &$rc, &$classes ) {
464 ## Empty, used for subclassers to add anything special.
470 * Generate a list of changes using the good old system (no javascript)
472 class OldChangesList
extends ChangesList
{
474 * Format a line using the old system (aka without any javascript).
476 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
477 global $wgLang, $wgRCShowChangedSize, $wgUser;
478 wfProfileIn( __METHOD__
);
479 # Should patrol-related stuff be shown?
480 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
482 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
483 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
487 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
489 if( $linenumber & 1 ) {
490 $classes[] = 'mw-line-odd';
493 $classes[] = 'mw-line-even';
498 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
499 $this->insertMove( $s, $rc );
501 } elseif( $rc->mAttribs
['rc_log_type'] ) {
502 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
503 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
504 // Log entries (old format) or log targets, and special pages
505 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
506 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
507 if( $name == 'Log' ) {
508 $this->insertLog( $s, $rc->getTitle(), $subpage );
512 $this->insertDiffHist( $s, $rc, $unpatrolled );
513 # M, N, b and ! (minor, new, bot and unpatrolled)
514 $s .= $this->recentChangesFlags(
516 'newpage' => $rc->mAttribs
['rc_new'],
517 'minoredit' => $rc->mAttribs
['rc_minor'],
518 'unpatrolled' => $unpatrolled,
519 'botedit' => $rc->mAttribs
['rc_bot']
523 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
526 $this->insertTimestamp( $s, $rc );
527 # Bytes added or removed
528 if( $wgRCShowChangedSize ) {
529 $cd = $rc->getCharacterDifference();
535 $this->insertUserRelatedLinks( $s, $rc );
536 # Log action text (if any)
537 $this->insertAction( $s, $rc );
538 # Edit or log comment
539 $this->insertComment( $s, $rc );
541 $this->insertTags( $s, $rc, $classes );
543 $this->insertRollback( $s, $rc );
545 $this->insertExtra( $s, $rc, $classes );
547 # How many users watch this page
548 if( $rc->numberofWatchingusers
> 0 ) {
549 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
550 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
553 if( $this->watchlist
) {
554 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
557 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
559 wfProfileOut( __METHOD__
);
560 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
566 * Generate a list of changes using an Enhanced system (uses javascript).
568 class EnhancedChangesList
extends ChangesList
{
570 * Add the JavaScript file for enhanced changeslist
573 public function beginRecentChangesList() {
575 $this->rc_cache
= array();
576 $this->rcMoveIndex
= 0;
577 $this->rcCacheIndex
= 0;
578 $this->lastdate
= '';
579 $this->rclistOpen
= false;
580 $wgOut->addModuleStyles( 'mediawiki.special.changeslist' );
584 * Format a line for enhanced recentchange (aka with javascript and block of lines).
586 public function recentChangesLine( &$baseRC, $watched = false ) {
587 global $wgLang, $wgUser;
589 wfProfileIn( __METHOD__
);
591 # Create a specialised object
592 $rc = RCCacheEntry
::newFromParent( $baseRC );
594 $curIdEq = array( 'curid' => $rc->mAttribs
['rc_cur_id'] );
596 # If it's a new day, add the headline and flush the cache
597 $date = $wgLang->date( $rc->mAttribs
['rc_timestamp'], true );
599 if( $date != $this->lastdate
) {
600 # Process current cache
601 $ret = $this->recentChangesBlock();
602 $this->rc_cache
= array();
603 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
604 $this->lastdate
= $date;
607 # Should patrol-related stuff be shown?
608 if( $wgUser->useRCPatrol() ) {
609 $rc->unpatrolled
= !$rc->mAttribs
['rc_patrolled'];
611 $rc->unpatrolled
= false;
614 $showdifflinks = true;
616 $type = $rc->mAttribs
['rc_type'];
617 $logType = $rc->mAttribs
['rc_log_type'];
619 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
620 $msg = ( $type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
621 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
622 array(), array( 'redirect' => 'no' ) ),
623 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
624 // New unpatrolled pages
625 } else if( $rc->unpatrolled
&& $type == RC_NEW
) {
626 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
627 array( 'rcid' => $rc->mAttribs
['rc_id'] ) );
629 } else if( $type == RC_LOG
) {
631 $logtitle = SpecialPage
::getTitleFor( 'Log', $logType );
632 $clink = '(' . $this->skin
->linkKnown( $logtitle,
633 LogPage
::logName( $logType ) ) . ')';
635 $clink = $this->skin
->link( $rc->getTitle() );
638 // Log entries (old format) and special pages
639 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
640 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
641 if ( $specialName == 'Log' ) {
643 $logname = LogPage
::logName( $logtype );
644 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
646 wfDebug( "Unexpected special page in recentchanges\n" );
651 $clink = $this->skin
->linkKnown( $rc->getTitle() );
654 # Don't show unusable diff links
655 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
656 $showdifflinks = false;
659 $time = $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true );
660 $rc->watched
= $watched;
662 $rc->timestamp
= $time;
663 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
665 # Make "cur" and "diff" links. Do not use link(), it is too slow if
666 # called too many times (50% of CPU time on RecentChanges!).
667 $thisOldid = $rc->mAttribs
['rc_this_oldid'];
668 $lastOldid = $rc->mAttribs
['rc_last_oldid'];
669 if( $rc->unpatrolled
) {
670 $rcIdQuery = array( 'rcid' => $rc->mAttribs
['rc_id'] );
672 $rcIdQuery = array();
674 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $thisOldid );
675 $querydiff = $curIdEq +
array( 'diff' => $thisOldid, 'oldid' =>
676 $lastOldid ) +
$rcIdQuery;
678 if( !$showdifflinks ) {
679 $curLink = $this->message
['cur'];
680 $diffLink = $this->message
['diff'];
681 } else if( in_array( $type, array( RC_NEW
, RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
682 if ( $type != RC_NEW
) {
683 $curLink = $this->message
['cur'];
685 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
686 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
688 $diffLink = $this->message
['diff'];
690 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
691 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
692 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
693 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
697 if( !$showdifflinks ||
!$lastOldid ) {
698 $lastLink = $this->message
['last'];
699 } else if( in_array( $type, array( RC_LOG
, RC_MOVE
, RC_MOVE_OVER_REDIRECT
) ) ) {
700 $lastLink = $this->message
['last'];
702 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
703 array(), $curIdEq +
array('diff' => $thisOldid, 'oldid' => $lastOldid) +
$rcIdQuery );
707 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
708 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
710 $rc->userlink
= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
711 $rc->usertalklink
= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
714 $rc->lastlink
= $lastLink;
715 $rc->curlink
= $curLink;
716 $rc->difflink
= $diffLink;
718 # Put accumulated information into the cache, for later display
719 # Page moves go on their own line
720 $title = $rc->getTitle();
721 $secureName = $title->getPrefixedDBkey();
722 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
723 # Use an @ character to prevent collision with page names
724 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
726 # Logs are grouped by type
727 if( $type == RC_LOG
){
728 $secureName = SpecialPage
::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
730 if( !isset( $this->rc_cache
[$secureName] ) ) {
731 $this->rc_cache
[$secureName] = array();
734 array_push( $this->rc_cache
[$secureName], $rc );
737 wfProfileOut( __METHOD__
);
745 protected function recentChangesBlockGroup( $block ) {
746 global $wgLang, $wgContLang, $wgRCShowChangedSize;
748 wfProfileIn( __METHOD__
);
750 # Add the namespace and title of the block as part of the class
751 if ( $block[0]->mAttribs
['rc_log_type'] ) {
753 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
755 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
757 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
758 Html
::openElement( 'tr' );
760 # Collate list of users
761 $userlinks = array();
763 $unpatrolled = false;
765 $curId = $currentRevision = 0;
766 # Some catalyst variables...
769 foreach( $block as $rcObj ) {
770 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
771 if( $rcObj->mAttribs
['rc_new'] ) {
774 // If all log actions to this page were hidden, then don't
775 // give the name of the affected page for this block!
776 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
779 $u = $rcObj->userlink
;
780 if( !isset( $userlinks[$u] ) ) {
783 if( $rcObj->unpatrolled
) {
786 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
789 # Get the latest entry with a page_id and oldid
790 # since logs may not have these.
791 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
792 $curId = $rcObj->mAttribs
['rc_cur_id'];
794 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
795 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
798 $bot = $rcObj->mAttribs
['rc_bot'];
802 # Sort the list and convert to text
803 krsort( $userlinks );
806 foreach( $userlinks as $userlink => $count) {
808 $text .= $wgContLang->getDirMark();
810 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
812 array_push( $users, $text );
815 $users = ' <span class="changedby">[' .
816 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
819 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
820 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
822 $tl = "<span class='mw-collapsible-toggle'>"
823 . "<span class='mw-rc-openarrow'>"
824 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>"
825 . "</span><span class='mw-rc-closearrow'>"
826 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>"
828 $r .= "<td>$tl</td>";
831 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
833 'minoredit' => false,
834 'unpatrolled' => $unpatrolled,
839 $r .= ' '.$block[0]->timestamp
.' </td><td>';
843 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
844 } else if( $allLogs ) {
845 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
847 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
850 $r .= $wgContLang->getDirMark();
852 $queryParams['curid'] = $curId;
855 static $nchanges = array();
856 if ( !isset( $nchanges[$n] ) ) {
857 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
863 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
865 } else if( $isnew ) {
868 $params = $queryParams;
869 $params['diff'] = $currentRevision;
870 $params['oldid'] = $oldid;
872 $r .= $this->skin
->link(
873 $block[0]->getTitle(),
877 array( 'known', 'noclasses' )
884 // don't show history link for logs
885 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
886 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
888 $params = $queryParams;
889 $params['action'] = 'history';
891 $r .= $this->message
['pipe-separator'] .
893 $block[0]->getTitle(),
894 $this->message
['hist'],
897 array( 'known', 'noclasses' )
902 # Character difference (does not apply if only log items)
903 if( $wgRCShowChangedSize && !$allLogs ) {
905 $first = count($block) - 1;
906 # Some events (like logs) have an "empty" size, so we need to skip those...
907 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
910 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
914 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
915 $block[$last]->mAttribs
['rc_new_len'] );
917 if( $chardiff == '' ) {
920 $r .= ' ' . $chardiff. ' . . ';
925 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
928 foreach( $block as $rcObj ) {
929 # Classes to apply -- TODO implement
931 $type = $rcObj->mAttribs
['rc_type'];
933 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
934 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
935 $r .= $this->recentChangesFlags( array(
936 'newpage' => $rcObj->mAttribs
['rc_new'],
937 'minoredit' => $rcObj->mAttribs
['rc_minor'],
938 'unpatrolled' => $rcObj->unpatrolled
,
939 'botedit' => $rcObj->mAttribs
['rc_bot'],
941 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
943 $params = $queryParams;
945 if( $rcObj->mAttribs
['rc_this_oldid'] != 0 ) {
946 $params['oldid'] = $rcObj->mAttribs
['rc_this_oldid'];
950 if( $type == RC_LOG
) {
951 $link = $rcObj->timestamp
;
953 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
954 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
956 if ( $rcObj->unpatrolled
&& $type == RC_NEW
) {
957 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
960 $link = $this->skin
->link(
965 array( 'known', 'noclasses' )
967 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
968 $link = '<span class="history-deleted">'.$link.'</span> ';
970 $r .= $link . '</span>';
972 if ( !$type == RC_LOG ||
$type == RC_NEW
) {
974 $r .= $rcObj->curlink
;
975 $r .= $this->message
['pipe-separator'];
976 $r .= $rcObj->lastlink
;
982 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
983 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
987 $r .= $rcObj->userlink
;
988 $r .= $rcObj->usertalklink
;
990 $this->insertAction( $r, $rcObj );
992 $this->insertComment( $r, $rcObj );
994 $this->insertRollback( $r, $rcObj );
996 $this->insertTags( $r, $rcObj, $classes );
998 $r .= "</td></tr>\n";
1002 $this->rcCacheIndex++
;
1004 wfProfileOut( __METHOD__
);
1010 * Generate HTML for an arrow or placeholder graphic
1011 * @param $dir String: one of '', 'd', 'l', 'r'
1012 * @param $alt String: text
1013 * @param $title String: text
1014 * @return String: HTML <img> tag
1016 protected function arrow( $dir, $alt='', $title='' ) {
1017 global $wgStylePath;
1018 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1019 $encAlt = htmlspecialchars( $alt );
1020 $encTitle = htmlspecialchars( $title );
1021 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1025 * Generate HTML for a right- or left-facing arrow,
1026 * depending on language direction.
1027 * @return String: HTML <img> tag
1029 protected function sideArrow() {
1031 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1032 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1036 * Generate HTML for a down-facing arrow
1037 * depending on language direction.
1038 * @return String: HTML <img> tag
1040 protected function downArrow() {
1041 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1045 * Generate HTML for a spacer image
1046 * @return String: HTML <img> tag
1048 protected function spacerArrow() {
1049 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1053 * Enhanced RC ungrouped line.
1054 * @return String: a HTML formated line (generated using $r)
1056 protected function recentChangesBlockLine( $rcObj ) {
1057 global $wgRCShowChangedSize;
1059 wfProfileIn( __METHOD__
);
1060 $query['curid'] = $rcObj->mAttribs
['rc_cur_id'];
1062 $type = $rcObj->mAttribs
['rc_type'];
1063 $logType = $rcObj->mAttribs
['rc_log_type'];
1066 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $logType . '-' . $rcObj->mAttribs
['rc_title'] );
1068 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1070 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1071 Html
::openElement( 'tr' );
1073 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow();
1074 # Flag and Timestamp
1075 if( $type == RC_MOVE ||
$type == RC_MOVE_OVER_REDIRECT
) {
1076 $r .= '    '; // 4 flags -> 4 spaces
1078 $r .= $this->recentChangesFlags( array(
1079 'newpage' => $type == RC_NEW
,
1080 'minoredit' => $rcObj->mAttribs
['rc_minor'],
1081 'unpatrolled' => $rcObj->unpatrolled
,
1082 'botedit' => $rcObj->mAttribs
['rc_bot'],
1085 $r .= ' '.$rcObj->timestamp
.' </td><td>';
1086 # Article or log link
1088 $logtitle = Title
::newFromText( "Log/$logType", NS_SPECIAL
);
1089 $logname = LogPage
::logName( $logType );
1090 $r .= '(' . $this->skin
->link(
1095 array( 'known', 'noclasses' )
1098 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1100 # Diff and hist links
1101 if ( $type != RC_LOG
) {
1102 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1103 $query['action'] = 'history';
1104 $r .= $this->skin
->link(
1106 $this->message
['hist'],
1109 array( 'known', 'noclasses' )
1114 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1118 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1119 # Log action (if any)
1121 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1122 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1124 $r .= ' ' . LogPage
::actionText( $logType, $rcObj->mAttribs
['rc_log_action'], $rcObj->getTitle(),
1125 $this->skin
, LogPage
::extractParams( $rcObj->mAttribs
['rc_params'] ), true, true );
1128 $this->insertComment( $r, $rcObj );
1129 $this->insertRollback( $r, $rcObj );
1131 $this->insertTags( $r, $rcObj, $classes );
1132 # Show how many people are watching this if enabled
1133 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1135 $r .= "</td></tr></table>\n";
1137 wfProfileOut( __METHOD__
);
1143 * If enhanced RC is in use, this function takes the previously cached
1144 * RC lines, arranges them, and outputs the HTML
1146 protected function recentChangesBlock() {
1147 if( count ( $this->rc_cache
) == 0 ) {
1151 wfProfileIn( __METHOD__
);
1154 foreach( $this->rc_cache
as $block ) {
1155 if( count( $block ) < 2 ) {
1156 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1158 $blockOut .= $this->recentChangesBlockGroup( $block );
1162 wfProfileOut( __METHOD__
);
1164 return '<div>'.$blockOut.'</div>';
1168 * Returns text for the end of RC
1169 * If enhanced RC is in use, returns pretty much all the text
1171 public function endRecentChangesList() {
1172 return $this->recentChangesBlock() . parent
::endRecentChangesList();