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' ) );
86 * Returns the appropriate flags for new page, minor change and patrolling
88 * @param $minor Boolean
89 * @param $patrolled Boolean
90 * @param $nothing String to use for empty space
94 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
95 $f = $new ? self
::flag( 'newpage' ) : $nothing;
96 $f .= $minor ? self
::flag( 'minor' ) : $nothing;
97 $f .= $bot ? self
::flag( 'bot' ) : $nothing;
98 $f .= $patrolled ? self
::flag( 'unpatrolled' ) : $nothing;
103 * Provide the <abbr> element appropriate to a given abbreviated flag,
104 * namely the flag indicating a new page, a minor edit, a bot edit, or an
105 * unpatrolled edit. By default in English it will contain "N", "m", "b",
106 * "!" respectively, plus it will have an appropriate title and class.
108 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
109 * @return String: Raw HTML
111 public static function flag( $key ) {
112 static $messages = null;
113 if ( is_null( $messages ) ) {
114 foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' .
115 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' .
116 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) {
117 $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' );
120 # Inconsistent naming, bleh
121 if ( $key == 'newpage' ||
$key == 'unpatrolled' ) {
124 $key2 = $key . 'edit';
126 return "<abbr class=\"$key\" title=\""
127 . $messages["recentchanges-label-$key"] . "\">"
128 . $messages["${key2}letter"]
133 * Returns text for the start of the tabular part of RC
136 public function beginRecentChangesList() {
137 $this->rc_cache
= array();
138 $this->rcMoveIndex
= 0;
139 $this->rcCacheIndex
= 0;
140 $this->lastdate
= '';
141 $this->rclistOpen
= false;
146 * Show formatted char difference
147 * @param $old Integer: bytes
148 * @param $new Integer: bytes
151 public static function showCharacterDifference( $old, $new ) {
152 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
153 $szdiff = $new - $old;
155 $code = $wgLang->getCode();
156 static $fastCharDiff = array();
157 if ( !isset($fastCharDiff[$code]) ) {
158 $fastCharDiff[$code] = $wgMiserMode ||
wfMsgNoTrans( 'rc-change-size' ) === '$1';
161 $formatedSize = $wgLang->formatNum($szdiff);
163 if ( !$fastCharDiff[$code] ) {
164 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
167 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
172 if( $szdiff === 0 ) {
173 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
174 } elseif( $szdiff > 0 ) {
175 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
177 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
182 * Returns text for the end of RC
185 public function endRecentChangesList() {
186 if( $this->rclistOpen
) {
193 public function insertMove( &$s, $rc ) {
195 $s .= '(' . $this->message
['diff'] . ') (';
197 $s .= $this->skin
->link(
198 $rc->getMovedToTitle(),
199 $this->message
['hist'],
201 array( 'action' => 'history' ),
202 array( 'known', 'noclasses' )
204 # "[[x]] moved to [[y]]"
205 $msg = ( $rc->mAttribs
['rc_type'] == RC_MOVE
) ?
'1movedto2' : '1movedto2_redir';
212 array( 'redirect' => 'no' ),
213 array( 'known', 'noclasses' )
216 $rc->getMovedToTitle(),
220 array( 'known', 'noclasses' )
225 public function insertDateHeader( &$s, $rc_timestamp ) {
227 # Make date header if necessary
228 $date = $wgLang->date( $rc_timestamp, true, true );
229 if( $date != $this->lastdate
) {
230 if( $this->lastdate
!= '' ) {
233 $s .= Xml
::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
234 $this->lastdate
= $date;
235 $this->rclistOpen
= true;
239 public function insertLog( &$s, $title, $logtype ) {
240 $logname = LogPage
::logName( $logtype );
241 $s .= '(' . $this->skin
->link(
246 array( 'known', 'noclasses' )
250 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
252 if( $rc->mAttribs
['rc_type'] == RC_NEW ||
$rc->mAttribs
['rc_type'] == RC_LOG
) {
253 $diffLink = $this->message
['diff'];
254 } else if( !self
::userCan($rc,Revision
::DELETED_TEXT
) ) {
255 $diffLink = $this->message
['diff'];
258 'curid' => $rc->mAttribs
['rc_cur_id'],
259 'diff' => $rc->mAttribs
['rc_this_oldid'],
260 'oldid' => $rc->mAttribs
['rc_last_oldid']
264 $query['rcid'] = $rc->mAttribs
['rc_id'];
267 $diffLink = $this->skin
->link(
269 $this->message
['diff'],
270 array( 'tabindex' => $rc->counter
),
272 array( 'known', 'noclasses' )
275 $s .= '(' . $diffLink . $this->message
['pipe-separator'];
277 $s .= $this->skin
->link(
279 $this->message
['hist'],
282 'curid' => $rc->mAttribs
['rc_cur_id'],
283 'action' => 'history'
285 array( 'known', 'noclasses' )
290 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
292 # If it's a new article, there is no diff link, but if it hasn't been
293 # patrolled yet, we need to give users a way to do so
296 if ( $unpatrolled && $rc->mAttribs
['rc_type'] == RC_NEW
) {
297 $params['rcid'] = $rc->mAttribs
['rc_id'];
300 if( $this->isDeleted($rc,Revision
::DELETED_TEXT
) ) {
301 $articlelink = $this->skin
->link(
306 array( 'known', 'noclasses' )
308 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
310 $articlelink = ' '. $this->skin
->link(
315 array( 'known', 'noclasses' )
318 # Bolden pages watched by this user
320 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
323 $articlelink .= $wgContLang->getDirMark();
325 wfRunHooks( 'ChangesListInsertArticleLink',
326 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
328 $s .= " $articlelink";
331 public function insertTimestamp( &$s, $rc ) {
333 $s .= $this->message
['semicolon-separator'] .
334 $wgLang->time( $rc->mAttribs
['rc_timestamp'], true, true ) . ' . . ';
337 /** Insert links to user page, user talk page and eventually a blocking link */
338 public function insertUserRelatedLinks( &$s, &$rc ) {
339 if( $this->isDeleted( $rc, Revision
::DELETED_USER
) ) {
340 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
342 $s .= $this->skin
->userLink( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
343 $s .= $this->skin
->userToolLinks( $rc->mAttribs
['rc_user'], $rc->mAttribs
['rc_user_text'] );
347 /** insert a formatted action */
348 public function insertAction( &$s, &$rc ) {
349 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
350 if( $this->isDeleted( $rc, LogPage
::DELETED_ACTION
) ) {
351 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
353 $s .= ' '.LogPage
::actionText( $rc->mAttribs
['rc_log_type'], $rc->mAttribs
['rc_log_action'],
354 $rc->getTitle(), $this->skin
, LogPage
::extractParams( $rc->mAttribs
['rc_params'] ), true, true );
359 /** insert a formatted comment */
360 public function insertComment( &$s, &$rc ) {
361 if( $rc->mAttribs
['rc_type'] != RC_MOVE
&& $rc->mAttribs
['rc_type'] != RC_MOVE_OVER_REDIRECT
) {
362 if( $this->isDeleted( $rc, Revision
::DELETED_COMMENT
) ) {
363 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
365 $s .= $this->skin
->commentBlock( $rc->mAttribs
['rc_comment'], $rc->getTitle() );
371 * Check whether to enable recent changes patrol features
374 public static function usePatrol() {
376 return $wgUser->useRCPatrol();
380 * Returns the string which indicates the number of watching users
382 protected function numberofWatchingusers( $count ) {
384 static $cache = array();
386 if( !isset( $cache[$count] ) ) {
387 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
388 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
390 return $cache[$count];
397 * Determine if said field of a revision is hidden
398 * @param $rc RCCacheEntry
399 * @param $field Integer: one of DELETED_* bitfield constants
402 public static function isDeleted( $rc, $field ) {
403 return ( $rc->mAttribs
['rc_deleted'] & $field ) == $field;
407 * Determine if the current user is allowed to view a particular
408 * field of this revision, if it's marked as deleted.
409 * @param $rc RCCacheEntry
410 * @param $field Integer
413 public static function userCan( $rc, $field ) {
414 if( $rc->mAttribs
['rc_type'] == RC_LOG
) {
415 return LogEventsList
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
417 return Revision
::userCanBitfield( $rc->mAttribs
['rc_deleted'], $field );
421 protected function maybeWatchedLink( $link, $watched = false ) {
423 return '<strong class="mw-watched">' . $link . '</strong>';
425 return '<span class="mw-rc-unwatched">' . $link . '</span>';
429 /** Inserts a rollback link */
430 public function insertRollback( &$s, &$rc ) {
432 if( !$rc->mAttribs
['rc_new'] && $rc->mAttribs
['rc_this_oldid'] && $rc->mAttribs
['rc_cur_id'] ) {
433 $page = $rc->getTitle();
434 /** Check for rollback and edit permissions, disallow special pages, and only
435 * show a link on the top-most revision */
436 if ($wgUser->isAllowed('rollback') && $rc->mAttribs
['page_latest'] == $rc->mAttribs
['rc_this_oldid'] )
438 $rev = new Revision( array(
439 'id' => $rc->mAttribs
['rc_this_oldid'],
440 'user' => $rc->mAttribs
['rc_user'],
441 'user_text' => $rc->mAttribs
['rc_user_text'],
442 'deleted' => $rc->mAttribs
['rc_deleted']
444 $rev->setTitle( $page );
445 $s .= ' '.$this->skin
->generateRollback( $rev );
450 public function insertTags( &$s, &$rc, &$classes ) {
451 if ( empty($rc->mAttribs
['ts_tags']) )
454 list($tagSummary, $newClasses) = ChangeTags
::formatSummaryRow( $rc->mAttribs
['ts_tags'], 'changeslist' );
455 $classes = array_merge( $classes, $newClasses );
456 $s .= ' ' . $tagSummary;
459 public function insertExtra( &$s, &$rc, &$classes ) {
460 ## Empty, used for subclassers to add anything special.
466 * Generate a list of changes using the good old system (no javascript)
468 class OldChangesList
extends ChangesList
{
470 * Format a line using the old system (aka without any javascript).
472 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
473 global $wgLang, $wgRCShowChangedSize, $wgUser;
474 wfProfileIn( __METHOD__
);
475 # Should patrol-related stuff be shown?
476 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs
['rc_patrolled'];
478 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
479 $this->insertDateHeader( $dateheader, $rc->mAttribs
['rc_timestamp'] );
483 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
485 if( $linenumber & 1 ) {
486 $classes[] = 'mw-line-odd';
489 $classes[] = 'mw-line-even';
494 if( $rc->mAttribs
['rc_type'] == RC_MOVE ||
$rc->mAttribs
['rc_type'] == RC_MOVE_OVER_REDIRECT
) {
495 $this->insertMove( $s, $rc );
497 } elseif( $rc->mAttribs
['rc_log_type'] ) {
498 $logtitle = Title
::newFromText( 'Log/'.$rc->mAttribs
['rc_log_type'], NS_SPECIAL
);
499 $this->insertLog( $s, $logtitle, $rc->mAttribs
['rc_log_type'] );
500 // Log entries (old format) or log targets, and special pages
501 } elseif( $rc->mAttribs
['rc_namespace'] == NS_SPECIAL
) {
502 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $rc->mAttribs
['rc_title'] );
503 if( $name == 'Log' ) {
504 $this->insertLog( $s, $rc->getTitle(), $subpage );
508 $this->insertDiffHist( $s, $rc, $unpatrolled );
509 # M, N, b and ! (minor, new, bot and unpatrolled)
510 $s .= $this->recentChangesFlags( $rc->mAttribs
['rc_new'], $rc->mAttribs
['rc_minor'],
511 $unpatrolled, '', $rc->mAttribs
['rc_bot'] );
512 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
515 $this->insertTimestamp( $s, $rc );
516 # Bytes added or removed
517 if( $wgRCShowChangedSize ) {
518 $cd = $rc->getCharacterDifference();
524 $this->insertUserRelatedLinks( $s, $rc );
525 # Log action text (if any)
526 $this->insertAction( $s, $rc );
527 # Edit or log comment
528 $this->insertComment( $s, $rc );
530 $this->insertTags( $s, $rc, $classes );
532 $this->insertRollback( $s, $rc );
534 $this->insertExtra( $s, $rc, $classes );
536 # How many users watch this page
537 if( $rc->numberofWatchingusers
> 0 ) {
538 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
539 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers
) );
542 if( $this->watchlist
) {
543 $classes[] = Sanitizer
::escapeClass( 'watchlist-'.$rc->mAttribs
['rc_namespace'].'-'.$rc->mAttribs
['rc_title'] );
546 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
548 wfProfileOut( __METHOD__
);
549 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
555 * Generate a list of changes using an Enhanced system (uses javascript).
557 class EnhancedChangesList
extends ChangesList
{
559 * Add the JavaScript file for enhanced changeslist
562 public function beginRecentChangesList() {
564 $this->rc_cache
= array();
565 $this->rcMoveIndex
= 0;
566 $this->rcCacheIndex
= 0;
567 $this->lastdate
= '';
568 $this->rclistOpen
= false;
569 $wgOut->addModules( 'mediawiki.legacy.enhancedchanges' );
573 * Format a line for enhanced recentchange (aka with javascript and block of lines).
575 public function recentChangesLine( &$baseRC, $watched = false ) {
576 global $wgLang, $wgUser;
578 wfProfileIn( __METHOD__
);
580 # Create a specialised object
581 $rc = RCCacheEntry
::newFromParent( $baseRC );
583 # Extract fields from DB into the function scope (rc_xxxx variables)
584 // FIXME: Would be good to replace this extract() call with something
585 // that explicitly initializes variables.
586 extract( $rc->mAttribs
);
587 $curIdEq = array( 'curid' => $rc_cur_id );
589 # If it's a new day, add the headline and flush the cache
590 $date = $wgLang->date( $rc_timestamp, true );
592 if( $date != $this->lastdate
) {
593 # Process current cache
594 $ret = $this->recentChangesBlock();
595 $this->rc_cache
= array();
596 $ret .= Xml
::element( 'h4', null, $date ) . "\n";
597 $this->lastdate
= $date;
600 # Should patrol-related stuff be shown?
601 if( $wgUser->useRCPatrol() ) {
602 $rc->unpatrolled
= !$rc_patrolled;
604 $rc->unpatrolled
= false;
607 $showdifflinks = true;
610 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
611 $msg = ( $rc_type == RC_MOVE
) ?
"1movedto2" : "1movedto2_redir";
612 $clink = wfMsg( $msg, $this->skin
->linkKnown( $rc->getTitle(), null,
613 array(), array( 'redirect' => 'no' ) ),
614 $this->skin
->linkKnown( $rc->getMovedToTitle() ) );
615 // New unpatrolled pages
616 } else if( $rc->unpatrolled
&& $rc_type == RC_NEW
) {
617 $clink = $this->skin
->linkKnown( $rc->getTitle(), null, array(),
618 array( 'rcid' => $rc_id ) );
620 } else if( $rc_type == RC_LOG
) {
622 $logtitle = SpecialPage
::getTitleFor( 'Log', $rc_log_type );
623 $clink = '(' . $this->skin
->linkKnown( $logtitle,
624 LogPage
::logName($rc_log_type) ) . ')';
626 $clink = $this->skin
->link( $rc->getTitle() );
629 // Log entries (old format) and special pages
630 } elseif( $rc_namespace == NS_SPECIAL
) {
631 list( $specialName, $logtype ) = SpecialPage
::resolveAliasWithSubpage( $rc_title );
632 if ( $specialName == 'Log' ) {
634 $logname = LogPage
::logName( $logtype );
635 $clink = '(' . $this->skin
->linkKnown( $rc->getTitle(), $logname ) . ')';
637 wfDebug( "Unexpected special page in recentchanges\n" );
642 $clink = $this->skin
->linkKnown( $rc->getTitle() );
645 # Don't show unusable diff links
646 if ( !ChangesList
::userCan($rc,Revision
::DELETED_TEXT
) ) {
647 $showdifflinks = false;
650 $time = $wgLang->time( $rc_timestamp, true, true );
651 $rc->watched
= $watched;
653 $rc->timestamp
= $time;
654 $rc->numberofWatchingusers
= $baseRC->numberofWatchingusers
;
656 # Make "cur" and "diff" links. Do not use link(), it is too slow if
657 # called too many times (50% of CPU time on RecentChanges!).
658 if( $rc->unpatrolled
) {
659 $rcIdQuery = array( 'rcid' => $rc_id );
661 $rcIdQuery = array();
663 $querycur = $curIdEq +
array( 'diff' => '0', 'oldid' => $rc_this_oldid );
664 $querydiff = $curIdEq +
array( 'diff' => $rc_this_oldid, 'oldid' =>
665 $rc_last_oldid ) +
$rcIdQuery;
667 if( !$showdifflinks ) {
668 $curLink = $this->message
['cur'];
669 $diffLink = $this->message
['diff'];
670 } else if( in_array( $rc_type, array(RC_NEW
,RC_LOG
,RC_MOVE
,RC_MOVE_OVER_REDIRECT
) ) ) {
671 if ( $rc_type != RC_NEW
) {
672 $curLink = $this->message
['cur'];
674 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
675 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
677 $diffLink = $this->message
['diff'];
679 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
680 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
681 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
682 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
686 if( !$showdifflinks ||
!$rc_last_oldid ) {
687 $lastLink = $this->message
['last'];
688 } else if( $rc_type == RC_LOG ||
$rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
689 $lastLink = $this->message
['last'];
691 $lastLink = $this->skin
->linkKnown( $rc->getTitle(), $this->message
['last'],
692 array(), $curIdEq +
array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) +
$rcIdQuery );
696 if( $this->isDeleted($rc,Revision
::DELETED_USER
) ) {
697 $rc->userlink
= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
699 $rc->userlink
= $this->skin
->userLink( $rc_user, $rc_user_text );
700 $rc->usertalklink
= $this->skin
->userToolLinks( $rc_user, $rc_user_text );
703 $rc->lastlink
= $lastLink;
704 $rc->curlink
= $curLink;
705 $rc->difflink
= $diffLink;
707 # Put accumulated information into the cache, for later display
708 # Page moves go on their own line
709 $title = $rc->getTitle();
710 $secureName = $title->getPrefixedDBkey();
711 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
712 # Use an @ character to prevent collision with page names
713 $this->rc_cache
['@@' . ($this->rcMoveIndex++
)] = array($rc);
715 # Logs are grouped by type
716 if( $rc_type == RC_LOG
){
717 $secureName = SpecialPage
::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
719 if( !isset( $this->rc_cache
[$secureName] ) ) {
720 $this->rc_cache
[$secureName] = array();
723 array_push( $this->rc_cache
[$secureName], $rc );
726 wfProfileOut( __METHOD__
);
734 protected function recentChangesBlockGroup( $block ) {
735 global $wgLang, $wgContLang, $wgRCShowChangedSize;
737 wfProfileIn( __METHOD__
);
739 # Add the namespace and title of the block as part of the class
740 if ( $block[0]->mAttribs
['rc_log_type'] ) {
742 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs
['rc_log_type'] . '-' . $block[0]->mAttribs
['rc_title'] );
744 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs
['rc_namespace'] . '-' . $block[0]->mAttribs
['rc_title'] );
746 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
747 Html
::openElement( 'tr' );
749 # Collate list of users
750 $userlinks = array();
752 $unpatrolled = false;
754 $curId = $currentRevision = 0;
755 # Some catalyst variables...
758 foreach( $block as $rcObj ) {
759 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
760 if( $rcObj->mAttribs
['rc_new'] ) {
763 // If all log actions to this page were hidden, then don't
764 // give the name of the affected page for this block!
765 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
768 $u = $rcObj->userlink
;
769 if( !isset( $userlinks[$u] ) ) {
772 if( $rcObj->unpatrolled
) {
775 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
778 # Get the latest entry with a page_id and oldid
779 # since logs may not have these.
780 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
781 $curId = $rcObj->mAttribs
['rc_cur_id'];
783 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
784 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
787 $bot = $rcObj->mAttribs
['rc_bot'];
791 # Sort the list and convert to text
792 krsort( $userlinks );
795 foreach( $userlinks as $userlink => $count) {
797 $text .= $wgContLang->getDirMark();
799 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
801 array_push( $users, $text );
804 $users = ' <span class="changedby">[' .
805 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
807 # ID for JS visibility toggle
808 $jsid = $this->rcCacheIndex
;
809 # onclick handler to toggle hidden/expanded
810 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
812 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
813 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
815 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
816 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
817 $r .= '<td class="mw-enhanced-rc">'.$tl.' ';
820 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
823 $r .= ' '.$block[0]->timestamp
.' </td><td style="padding:0px;">';
827 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
828 } else if( $allLogs ) {
829 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
831 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
834 $r .= $wgContLang->getDirMark();
836 $queryParams['curid'] = $curId;
839 static $nchanges = array();
840 if ( !isset( $nchanges[$n] ) ) {
841 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
847 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
849 } else if( $isnew ) {
852 $params = $queryParams;
853 $params['diff'] = $currentRevision;
854 $params['oldid'] = $oldid;
856 $r .= $this->skin
->link(
857 $block[0]->getTitle(),
861 array( 'known', 'noclasses' )
868 // don't show history link for logs
869 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
870 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
872 $params = $queryParams;
873 $params['action'] = 'history';
875 $r .= $this->message
['pipe-separator'] .
877 $block[0]->getTitle(),
878 $this->message
['hist'],
881 array( 'known', 'noclasses' )
886 # Character difference (does not apply if only log items)
887 if( $wgRCShowChangedSize && !$allLogs ) {
889 $first = count($block) - 1;
890 # Some events (like logs) have an "empty" size, so we need to skip those...
891 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
894 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
898 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
899 $block[$last]->mAttribs
['rc_new_len'] );
901 if( $chardiff == '' ) {
904 $r .= ' ' . $chardiff. ' . . ';
909 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
911 $r .= "</td></tr></table>\n";
914 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
915 $r .= '<table class="mw-enhanced-rc">';
916 foreach( $block as $rcObj ) {
917 # Extract fields from DB into the function scope (rc_xxxx variables)
918 // FIXME: Would be good to replace this extract() call with something
919 // that explicitly initializes variables.
920 # Classes to apply -- TODO implement
922 extract( $rcObj->mAttribs
);
924 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
925 $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
926 $r .= $this->spacerIndent() . $this->spacerIndent();
927 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
928 $r .= ' </td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
930 $params = $queryParams;
932 if( $rc_this_oldid != 0 ) {
933 $params['oldid'] = $rc_this_oldid;
937 if( $rc_type == RC_LOG
) {
938 $link = $rcObj->timestamp
;
940 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
941 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
943 if ( $rcObj->unpatrolled
&& $rc_type == RC_NEW
) {
944 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
947 $link = $this->skin
->link(
952 array( 'known', 'noclasses' )
954 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
955 $link = '<span class="history-deleted">'.$link.'</span> ';
957 $r .= $link . '</span>';
959 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
961 $r .= $rcObj->curlink
;
962 $r .= $this->message
['pipe-separator'];
963 $r .= $rcObj->lastlink
;
969 if( $wgRCShowChangedSize ) {
970 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
973 $r .= $rcObj->userlink
;
974 $r .= $rcObj->usertalklink
;
976 $this->insertAction( $r, $rcObj );
978 $this->insertComment( $r, $rcObj );
980 $this->insertRollback( $r, $rcObj );
982 $this->insertTags( $r, $rcObj, $classes );
984 $r .= "</td></tr>\n";
986 $r .= "</table></div>\n";
988 $this->rcCacheIndex++
;
990 wfProfileOut( __METHOD__
);
996 * Generate HTML for an arrow or placeholder graphic
997 * @param $dir String: one of '', 'd', 'l', 'r'
998 * @param $alt String: text
999 * @param $title String: text
1000 * @return String: HTML <img> tag
1002 protected function arrow( $dir, $alt='', $title='' ) {
1003 global $wgStylePath;
1004 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1005 $encAlt = htmlspecialchars( $alt );
1006 $encTitle = htmlspecialchars( $title );
1007 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1011 * Generate HTML for a right- or left-facing arrow,
1012 * depending on language direction.
1013 * @return String: HTML <img> tag
1015 protected function sideArrow() {
1017 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1018 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1022 * Generate HTML for a down-facing arrow
1023 * depending on language direction.
1024 * @return String: HTML <img> tag
1026 protected function downArrow() {
1027 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1031 * Generate HTML for a spacer image
1032 * @return String: HTML <img> tag
1034 protected function spacerArrow() {
1035 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1039 * Add a set of spaces
1040 * @return String: HTML <td> tag
1042 protected function spacerIndent() {
1043 return '     ';
1047 * Enhanced RC ungrouped line.
1048 * @return String: a HTML formated line (generated using $r)
1050 protected function recentChangesBlockLine( $rcObj ) {
1051 global $wgRCShowChangedSize;
1053 wfProfileIn( __METHOD__
);
1055 # Extract fields from DB into the function scope (rc_xxxx variables)
1056 // FIXME: Would be good to replace this extract() call with something
1057 // that explicitly initializes variables.
1059 extract( $rcObj->mAttribs
);
1060 $query['curid'] = $rc_cur_id;
1062 if( $rc_log_type ) {
1064 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-log-' . $rc_log_type . '-' . $rcObj->mAttribs
['rc_title'] );
1066 $classes = 'mw-enhanced-rc ' . Sanitizer
::escapeClass( 'mw-changeslist-ns' . $rcObj->mAttribs
['rc_namespace'] . '-' . $rcObj->mAttribs
['rc_title'] );
1068 $r = Html
::openElement( 'table', array( 'class' => $classes ) ) .
1069 Html
::openElement( 'tr' );
1071 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . ' ';
1072 # Flag and Timestamp
1073 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
1074 $r .= '    '; // 4 flags -> 4 spaces
1076 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
1078 $r .= ' '.$rcObj->timestamp
.' </td><td style="padding:0px;">';
1079 # Article or log link
1080 if( $rc_log_type ) {
1081 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
1082 $logname = LogPage
::logName( $rc_log_type );
1083 $r .= '(' . $this->skin
->link(
1088 array( 'known', 'noclasses' )
1091 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1093 # Diff and hist links
1094 if ( $rc_type != RC_LOG
) {
1095 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1096 $query['action'] = 'history';
1097 $r .= $this->skin
->link(
1099 $this->message
['hist'],
1102 array( 'known', 'noclasses' )
1107 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1111 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1112 # Log action (if any)
1113 if( $rc_log_type ) {
1114 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1115 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1117 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1118 $this->skin
, LogPage
::extractParams($rc_params), true, true );
1121 $this->insertComment( $r, $rcObj );
1122 $this->insertRollback( $r, $rcObj );
1124 $this->insertTags( $r, $rcObj, $classes );
1125 # Show how many people are watching this if enabled
1126 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1128 $r .= "</td></tr></table>\n";
1130 wfProfileOut( __METHOD__
);
1136 * If enhanced RC is in use, this function takes the previously cached
1137 * RC lines, arranges them, and outputs the HTML
1139 protected function recentChangesBlock() {
1140 if( count ( $this->rc_cache
) == 0 ) {
1144 wfProfileIn( __METHOD__
);
1147 foreach( $this->rc_cache
as $block ) {
1148 if( count( $block ) < 2 ) {
1149 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1151 $blockOut .= $this->recentChangesBlockGroup( $block );
1155 wfProfileOut( __METHOD__
);
1157 return '<div>'.$blockOut.'</div>';
1161 * Returns text for the end of RC
1162 * If enhanced RC is in use, returns pretty much all the text
1164 public function endRecentChangesList() {
1165 return $this->recentChangesBlock() . parent
::endRecentChangesList();