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 );
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 $r = '<table class="mw-enhanced-rc"><tr>';
741 # Collate list of users
742 $userlinks = array();
744 $unpatrolled = false;
746 $curId = $currentRevision = 0;
747 # Some catalyst variables...
750 foreach( $block as $rcObj ) {
751 $oldid = $rcObj->mAttribs
['rc_last_oldid'];
752 if( $rcObj->mAttribs
['rc_new'] ) {
755 // If all log actions to this page were hidden, then don't
756 // give the name of the affected page for this block!
757 if( !$this->isDeleted( $rcObj, LogPage
::DELETED_ACTION
) ) {
760 $u = $rcObj->userlink
;
761 if( !isset( $userlinks[$u] ) ) {
764 if( $rcObj->unpatrolled
) {
767 if( $rcObj->mAttribs
['rc_type'] != RC_LOG
) {
770 # Get the latest entry with a page_id and oldid
771 # since logs may not have these.
772 if( !$curId && $rcObj->mAttribs
['rc_cur_id'] ) {
773 $curId = $rcObj->mAttribs
['rc_cur_id'];
775 if( !$currentRevision && $rcObj->mAttribs
['rc_this_oldid'] ) {
776 $currentRevision = $rcObj->mAttribs
['rc_this_oldid'];
779 $bot = $rcObj->mAttribs
['rc_bot'];
783 # Sort the list and convert to text
784 krsort( $userlinks );
787 foreach( $userlinks as $userlink => $count) {
789 $text .= $wgContLang->getDirMark();
791 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
793 array_push( $users, $text );
796 $users = ' <span class="changedby">[' .
797 implode( $this->message
['semicolon-separator'], $users ) . ']</span>';
799 # ID for JS visibility toggle
800 $jsid = $this->rcCacheIndex
;
801 # onclick handler to toggle hidden/expanded
802 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
804 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
805 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
807 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
808 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
809 $r .= '<td class="mw-enhanced-rc">'.$tl.' ';
812 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot );
815 $r .= ' '.$block[0]->timestamp
.' </td><td style="padding:0px;">';
819 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
820 } else if( $allLogs ) {
821 $r .= $this->maybeWatchedLink( $block[0]->link
, $block[0]->watched
);
823 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled
, $block[0]->watched
);
826 $r .= $wgContLang->getDirMark();
828 $queryParams['curid'] = $curId;
831 static $nchanges = array();
832 if ( !isset( $nchanges[$n] ) ) {
833 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
839 if( !ChangesList
::userCan( $rcObj, Revision
::DELETED_TEXT
) ) {
841 } else if( $isnew ) {
844 $params = $queryParams;
845 $params['diff'] = $currentRevision;
846 $params['oldid'] = $oldid;
848 $r .= $this->skin
->link(
849 $block[0]->getTitle(),
853 array( 'known', 'noclasses' )
860 // don't show history link for logs
861 } else if( $namehidden ||
!$block[0]->getTitle()->exists() ) {
862 $r .= $this->message
['pipe-separator'] . $this->message
['hist'] . ')';
864 $params = $queryParams;
865 $params['action'] = 'history';
867 $r .= $this->message
['pipe-separator'] .
869 $block[0]->getTitle(),
870 $this->message
['hist'],
873 array( 'known', 'noclasses' )
878 # Character difference (does not apply if only log items)
879 if( $wgRCShowChangedSize && !$allLogs ) {
881 $first = count($block) - 1;
882 # Some events (like logs) have an "empty" size, so we need to skip those...
883 while( $last < $first && $block[$last]->mAttribs
['rc_new_len'] === null ) {
886 while( $first > $last && $block[$first]->mAttribs
['rc_old_len'] === null ) {
890 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs
['rc_old_len'],
891 $block[$last]->mAttribs
['rc_new_len'] );
893 if( $chardiff == '' ) {
896 $r .= ' ' . $chardiff. ' . . ';
901 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers
);
903 $r .= "</td></tr></table>\n";
906 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
907 $r .= '<table class="mw-enhanced-rc">';
908 foreach( $block as $rcObj ) {
909 # Extract fields from DB into the function scope (rc_xxxx variables)
910 // FIXME: Would be good to replace this extract() call with something
911 // that explicitly initializes variables.
912 # Classes to apply -- TODO implement
914 extract( $rcObj->mAttribs
);
916 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
917 $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
918 $r .= $this->spacerIndent() . $this->spacerIndent();
919 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
920 $r .= ' </td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
922 $params = $queryParams;
924 if( $rc_this_oldid != 0 ) {
925 $params['oldid'] = $rc_this_oldid;
929 if( $rc_type == RC_LOG
) {
930 $link = $rcObj->timestamp
;
932 } else if( !ChangesList
::userCan($rcObj,Revision
::DELETED_TEXT
) ) {
933 $link = '<span class="history-deleted">'.$rcObj->timestamp
.'</span> ';
935 if ( $rcObj->unpatrolled
&& $rc_type == RC_NEW
) {
936 $params['rcid'] = $rcObj->mAttribs
['rc_id'];
939 $link = $this->skin
->link(
944 array( 'known', 'noclasses' )
946 if( $this->isDeleted($rcObj,Revision
::DELETED_TEXT
) )
947 $link = '<span class="history-deleted">'.$link.'</span> ';
949 $r .= $link . '</span>';
951 if ( !$rc_type == RC_LOG ||
$rc_type == RC_NEW
) {
953 $r .= $rcObj->curlink
;
954 $r .= $this->message
['pipe-separator'];
955 $r .= $rcObj->lastlink
;
961 if( $wgRCShowChangedSize ) {
962 $r .= ( $rcObj->getCharacterDifference() == '' ?
'' : $rcObj->getCharacterDifference() . ' . . ' ) ;
965 $r .= $rcObj->userlink
;
966 $r .= $rcObj->usertalklink
;
968 $this->insertAction( $r, $rcObj );
970 $this->insertComment( $r, $rcObj );
972 $this->insertRollback( $r, $rcObj );
974 $this->insertTags( $r, $rcObj, $classes );
976 $r .= "</td></tr>\n";
978 $r .= "</table></div>\n";
980 $this->rcCacheIndex++
;
982 wfProfileOut( __METHOD__
);
988 * Generate HTML for an arrow or placeholder graphic
989 * @param $dir String: one of '', 'd', 'l', 'r'
990 * @param $alt String: text
991 * @param $title String: text
992 * @return String: HTML <img> tag
994 protected function arrow( $dir, $alt='', $title='' ) {
996 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
997 $encAlt = htmlspecialchars( $alt );
998 $encTitle = htmlspecialchars( $title );
999 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1003 * Generate HTML for a right- or left-facing arrow,
1004 * depending on language direction.
1005 * @return String: HTML <img> tag
1007 protected function sideArrow() {
1009 $dir = $wgContLang->isRTL() ?
'l' : 'r';
1010 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1014 * Generate HTML for a down-facing arrow
1015 * depending on language direction.
1016 * @return String: HTML <img> tag
1018 protected function downArrow() {
1019 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1023 * Generate HTML for a spacer image
1024 * @return String: HTML <img> tag
1026 protected function spacerArrow() {
1027 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1031 * Add a set of spaces
1032 * @return String: HTML <td> tag
1034 protected function spacerIndent() {
1035 return '     ';
1039 * Enhanced RC ungrouped line.
1040 * @return String: a HTML formated line (generated using $r)
1042 protected function recentChangesBlockLine( $rcObj ) {
1043 global $wgRCShowChangedSize;
1045 wfProfileIn( __METHOD__
);
1047 # Extract fields from DB into the function scope (rc_xxxx variables)
1048 // FIXME: Would be good to replace this extract() call with something
1049 // that explicitly initializes variables.
1050 $classes = array(); // TODO implement
1051 extract( $rcObj->mAttribs
);
1052 $query['curid'] = $rc_cur_id;
1054 $r = '<table class="mw-enhanced-rc"><tr>';
1055 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . ' ';
1056 # Flag and Timestamp
1057 if( $rc_type == RC_MOVE ||
$rc_type == RC_MOVE_OVER_REDIRECT
) {
1058 $r .= '    '; // 4 flags -> 4 spaces
1060 $r .= $this->recentChangesFlags( $rc_type == RC_NEW
, $rc_minor, $rcObj->unpatrolled
, ' ', $rc_bot );
1062 $r .= ' '.$rcObj->timestamp
.' </td><td style="padding:0px;">';
1063 # Article or log link
1064 if( $rc_log_type ) {
1065 $logtitle = Title
::newFromText( "Log/$rc_log_type", NS_SPECIAL
);
1066 $logname = LogPage
::logName( $rc_log_type );
1067 $r .= '(' . $this->skin
->link(
1072 array( 'known', 'noclasses' )
1075 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled
, $rcObj->watched
);
1077 # Diff and hist links
1078 if ( $rc_type != RC_LOG
) {
1079 $r .= ' ('. $rcObj->difflink
. $this->message
['pipe-separator'];
1080 $query['action'] = 'history';
1081 $r .= $this->skin
->link(
1083 $this->message
['hist'],
1086 array( 'known', 'noclasses' )
1091 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1095 $r .= ' '.$rcObj->userlink
. $rcObj->usertalklink
;
1096 # Log action (if any)
1097 if( $rc_log_type ) {
1098 if( $this->isDeleted($rcObj,LogPage
::DELETED_ACTION
) ) {
1099 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1101 $r .= ' ' . LogPage
::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1102 $this->skin
, LogPage
::extractParams($rc_params), true, true );
1105 $this->insertComment( $r, $rcObj );
1106 $this->insertRollback( $r, $rcObj );
1108 $this->insertTags( $r, $rcObj, $classes );
1109 # Show how many people are watching this if enabled
1110 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers
);
1112 $r .= "</td></tr></table>\n";
1114 wfProfileOut( __METHOD__
);
1120 * If enhanced RC is in use, this function takes the previously cached
1121 * RC lines, arranges them, and outputs the HTML
1123 protected function recentChangesBlock() {
1124 if( count ( $this->rc_cache
) == 0 ) {
1128 wfProfileIn( __METHOD__
);
1131 foreach( $this->rc_cache
as $block ) {
1132 if( count( $block ) < 2 ) {
1133 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1135 $blockOut .= $this->recentChangesBlockGroup( $block );
1139 wfProfileOut( __METHOD__
);
1141 return '<div>'.$blockOut.'</div>';
1145 * Returns text for the end of RC
1146 * If enhanced RC is in use, returns pretty much all the text
1148 public function endRecentChangesList() {
1149 return $this->recentChangesBlock() . parent
::endRecentChangesList();