"<p id="userloginlink"><p>Don't have an account" is illegal xhtml
[mediawiki.git] / includes / ChangesList.php
blobfe75bf0b37bd3b3f13eec04ae0f285a63f1272d8
1 <?php
3 /**
4 * @todo document
5 */
6 class RCCacheEntry extends RecentChange {
7 var $secureName, $link;
8 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
9 var $userlink, $timestamp, $watched;
11 static function newFromParent( $rc ) {
12 $rc2 = new RCCacheEntry;
13 $rc2->mAttribs = $rc->mAttribs;
14 $rc2->mExtra = $rc->mExtra;
15 return $rc2;
19 /**
20 * Class to show various lists of changes:
21 * - what links here
22 * - related changes
23 * - recent changes
25 class ChangesList {
26 # Called by history lists and recent changes
27 public $skin;
28 protected $watchlist = false;
30 /**
31 * Changeslist contructor
32 * @param $skin Skin
34 public function __construct( $skin ) {
35 $this->skin = $skin;
36 $this->preCacheMessages();
39 /**
40 * Fetch an appropriate changes list class for the specified user
41 * Some users might want to use an enhanced list format, for instance
43 * @param $user User to fetch the list class for
44 * @return ChangesList derivative
46 public static function newFromUser( &$user ) {
47 global $wgRequest;
49 $sk = $user->getSkin();
50 $list = null;
51 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
52 $new = $wgRequest->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
53 return $new ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
54 } else {
55 return $list;
59 /**
60 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
61 * @param $value Boolean
63 public function setWatchlistDivs( $value = true ) {
64 $this->watchlist = $value;
67 /**
68 * As we use the same small set of messages in various methods and that
69 * they are called often, we call them once and save them in $this->message
71 private function preCacheMessages() {
72 if( !isset( $this->message ) ) {
73 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
74 'semicolon-separator pipe-separator' ) as $msg ) {
75 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
81 /**
82 * Returns the appropriate flags for new page, minor change and patrolling
83 * @param $new Boolean
84 * @param $minor Boolean
85 * @param $patrolled Boolean
86 * @param $nothing String to use for empty space
87 * @param $bot Boolean
88 * @return String
90 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&#160;', $bot = false ) {
91 $f = $new ? self::flag( 'newpage' ) : $nothing;
92 $f .= $minor ? self::flag( 'minor' ) : $nothing;
93 $f .= $bot ? self::flag( 'bot' ) : $nothing;
94 $f .= $patrolled ? self::flag( 'unpatrolled' ) : $nothing;
95 return $f;
98 /**
99 * Provide the <abbr> element appropriate to a given abbreviated flag,
100 * namely the flag indicating a new page, a minor edit, a bot edit, or an
101 * unpatrolled edit. By default in English it will contain "N", "m", "b",
102 * "!" respectively, plus it will have an appropriate title and class.
104 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
105 * @return String: Raw HTML
107 public static function flag( $key ) {
108 static $messages = null;
109 if ( is_null( $messages ) ) {
110 foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' .
111 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' .
112 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) {
113 $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' );
116 # Inconsistent naming, bleh
117 if ( $key == 'newpage' || $key == 'unpatrolled' ) {
118 $key2 = $key;
119 } else {
120 $key2 = $key . 'edit';
122 return "<abbr class=\"$key\" title=\""
123 . $messages["recentchanges-label-$key"] . "\">"
124 . $messages["${key2}letter"]
125 . '</abbr>';
129 * Some explanatory wrapper text for the given flag, to be used in a legend
130 * explaining what the flags mean. For instance, "N - new page". See
131 * also flag().
133 * @param $key String: 'newpage', 'unpatrolled', 'minor', or 'bot'
134 * @return String: Raw HTML
136 private static function flagLine( $key ) {
137 return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities',
138 'replaceafter' ), self::flag( $key ) );
142 * A handy legend to tell users what the little "m", "b", and so on mean.
144 * @return String: Raw HTML
146 public static function flagLegend() {
147 global $wgGroupPermissions, $wgLang;
149 $flags = array( self::flagLine( 'newpage' ),
150 self::flagLine( 'minor' ) );
152 # Don't show info on bot edits unless there's a bot group of some kind
153 foreach ( $wgGroupPermissions as $rights ) {
154 if ( isset( $rights['bot'] ) && $rights['bot'] ) {
155 $flags[] = self::flagLine( 'bot' );
156 break;
160 if ( self::usePatrol() ) {
161 $flags[] = self::flagLine( 'unpatrolled' );
164 return '<div class="mw-rc-label-legend">' .
165 wfMsgExt( 'recentchanges-label-legend', 'parseinline',
166 $wgLang->commaList( $flags ) ) . '</div>';
170 * Returns text for the start of the tabular part of RC
171 * @return String
173 public function beginRecentChangesList() {
174 $this->rc_cache = array();
175 $this->rcMoveIndex = 0;
176 $this->rcCacheIndex = 0;
177 $this->lastdate = '';
178 $this->rclistOpen = false;
179 return '';
183 * Show formatted char difference
184 * @param $old Integer: bytes
185 * @param $new Integer: bytes
186 * @returns String
188 public static function showCharacterDifference( $old, $new ) {
189 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
190 $szdiff = $new - $old;
192 $code = $wgLang->getCode();
193 static $fastCharDiff = array();
194 if ( !isset($fastCharDiff[$code]) ) {
195 $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1';
198 $formatedSize = $wgLang->formatNum($szdiff);
200 if ( !$fastCharDiff[$code] ) {
201 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
204 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
205 $tag = 'strong';
206 } else {
207 $tag = 'span';
209 if( $szdiff === 0 ) {
210 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
211 } elseif( $szdiff > 0 ) {
212 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
213 } else {
214 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
219 * Returns text for the end of RC
220 * @return String
222 public function endRecentChangesList() {
223 if( $this->rclistOpen ) {
224 return "</ul>\n";
225 } else {
226 return '';
230 public function insertMove( &$s, $rc ) {
231 # Diff
232 $s .= '(' . $this->message['diff'] . ') (';
233 # Hist
234 $s .= $this->skin->link(
235 $rc->getMovedToTitle(),
236 $this->message['hist'],
237 array(),
238 array( 'action' => 'history' ),
239 array( 'known', 'noclasses' )
240 ) . ') . . ';
241 # "[[x]] moved to [[y]]"
242 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
243 $s .= wfMsg(
244 $msg,
245 $this->skin->link(
246 $rc->getTitle(),
247 null,
248 array(),
249 array( 'redirect' => 'no' ),
250 array( 'known', 'noclasses' )
252 $this->skin->link(
253 $rc->getMovedToTitle(),
254 null,
255 array(),
256 array(),
257 array( 'known', 'noclasses' )
262 public function insertDateHeader( &$s, $rc_timestamp ) {
263 global $wgLang;
264 # Make date header if necessary
265 $date = $wgLang->date( $rc_timestamp, true, true );
266 if( $date != $this->lastdate ) {
267 if( $this->lastdate != '' ) {
268 $s .= "</ul>\n";
270 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
271 $this->lastdate = $date;
272 $this->rclistOpen = true;
276 public function insertLog( &$s, $title, $logtype ) {
277 $logname = LogPage::logName( $logtype );
278 $s .= '(' . $this->skin->link(
279 $title,
280 $logname,
281 array(),
282 array(),
283 array( 'known', 'noclasses' )
284 ) . ')';
287 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
288 # Diff link
289 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
290 $diffLink = $this->message['diff'];
291 } else if( !self::userCan($rc,Revision::DELETED_TEXT) ) {
292 $diffLink = $this->message['diff'];
293 } else {
294 $query = array(
295 'curid' => $rc->mAttribs['rc_cur_id'],
296 'diff' => $rc->mAttribs['rc_this_oldid'],
297 'oldid' => $rc->mAttribs['rc_last_oldid']
300 if( $unpatrolled ) {
301 $query['rcid'] = $rc->mAttribs['rc_id'];
304 $diffLink = $this->skin->link(
305 $rc->getTitle(),
306 $this->message['diff'],
307 array( 'tabindex' => $rc->counter ),
308 $query,
309 array( 'known', 'noclasses' )
312 $s .= '(' . $diffLink . $this->message['pipe-separator'];
313 # History link
314 $s .= $this->skin->link(
315 $rc->getTitle(),
316 $this->message['hist'],
317 array(),
318 array(
319 'curid' => $rc->mAttribs['rc_cur_id'],
320 'action' => 'history'
322 array( 'known', 'noclasses' )
324 $s .= ') . . ';
327 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
328 global $wgContLang;
329 # If it's a new article, there is no diff link, but if it hasn't been
330 # patrolled yet, we need to give users a way to do so
331 $params = array();
333 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) {
334 $params['rcid'] = $rc->mAttribs['rc_id'];
337 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
338 $articlelink = $this->skin->link(
339 $rc->getTitle(),
340 null,
341 array(),
342 $params,
343 array( 'known', 'noclasses' )
345 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
346 } else {
347 $articlelink = ' '. $this->skin->link(
348 $rc->getTitle(),
349 null,
350 array(),
351 $params,
352 array( 'known', 'noclasses' )
355 # Bolden pages watched by this user
356 if( $watched ) {
357 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
359 # RTL/LTR marker
360 $articlelink .= $wgContLang->getDirMark();
362 wfRunHooks( 'ChangesListInsertArticleLink',
363 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
365 $s .= " $articlelink";
368 public function insertTimestamp( &$s, $rc ) {
369 global $wgLang;
370 $s .= $this->message['semicolon-separator'] .
371 $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
374 /** Insert links to user page, user talk page and eventually a blocking link */
375 public function insertUserRelatedLinks( &$s, &$rc ) {
376 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
377 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
378 } else {
379 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
380 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
384 /** insert a formatted action */
385 public function insertAction( &$s, &$rc ) {
386 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
387 if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) {
388 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
389 } else {
390 $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
391 $rc->getTitle(), $this->skin, LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true );
396 /** insert a formatted comment */
397 public function insertComment( &$s, &$rc ) {
398 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
399 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
400 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
401 } else {
402 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
408 * Check whether to enable recent changes patrol features
409 * @return Boolean
411 public static function usePatrol() {
412 global $wgUser;
413 return $wgUser->useRCPatrol();
417 * Returns the string which indicates the number of watching users
419 protected function numberofWatchingusers( $count ) {
420 global $wgLang;
421 static $cache = array();
422 if( $count > 0 ) {
423 if( !isset( $cache[$count] ) ) {
424 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
425 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
427 return $cache[$count];
428 } else {
429 return '';
434 * Determine if said field of a revision is hidden
435 * @param $rc RCCacheEntry
436 * @param $field Integer: one of DELETED_* bitfield constants
437 * @return Boolean
439 public static function isDeleted( $rc, $field ) {
440 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
444 * Determine if the current user is allowed to view a particular
445 * field of this revision, if it's marked as deleted.
446 * @param $rc RCCacheEntry
447 * @param $field Integer
448 * @return Boolean
450 public static function userCan( $rc, $field ) {
451 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
452 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field );
453 } else {
454 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field );
458 protected function maybeWatchedLink( $link, $watched = false ) {
459 if( $watched ) {
460 return '<strong class="mw-watched">' . $link . '</strong>';
461 } else {
462 return '<span class="mw-rc-unwatched">' . $link . '</span>';
466 /** Inserts a rollback link */
467 public function insertRollback( &$s, &$rc ) {
468 global $wgUser;
469 if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
470 $page = $rc->getTitle();
471 /** Check for rollback and edit permissions, disallow special pages, and only
472 * show a link on the top-most revision */
473 if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
475 $rev = new Revision( array(
476 'id' => $rc->mAttribs['rc_this_oldid'],
477 'user' => $rc->mAttribs['rc_user'],
478 'user_text' => $rc->mAttribs['rc_user_text'],
479 'deleted' => $rc->mAttribs['rc_deleted']
480 ) );
481 $rev->setTitle( $page );
482 $s .= ' '.$this->skin->generateRollback( $rev );
487 public function insertTags( &$s, &$rc, &$classes ) {
488 if ( empty($rc->mAttribs['ts_tags']) )
489 return;
491 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
492 $classes = array_merge( $classes, $newClasses );
493 $s .= ' ' . $tagSummary;
496 public function insertExtra( &$s, &$rc, &$classes ) {
497 ## Empty, used for subclassers to add anything special.
503 * Generate a list of changes using the good old system (no javascript)
505 class OldChangesList extends ChangesList {
507 * Format a line using the old system (aka without any javascript).
509 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
510 global $wgLang, $wgRCShowChangedSize, $wgUser;
511 wfProfileIn( __METHOD__ );
512 # Should patrol-related stuff be shown?
513 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
515 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
516 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
518 $s = '';
519 $classes = array();
520 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
521 if( $linenumber ) {
522 if( $linenumber & 1 ) {
523 $classes[] = 'mw-line-odd';
525 else {
526 $classes[] = 'mw-line-even';
530 // Moved pages
531 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
532 $this->insertMove( $s, $rc );
533 // Log entries
534 } elseif( $rc->mAttribs['rc_log_type'] ) {
535 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
536 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
537 // Log entries (old format) or log targets, and special pages
538 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
539 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] );
540 if( $name == 'Log' ) {
541 $this->insertLog( $s, $rc->getTitle(), $subpage );
543 // Regular entries
544 } else {
545 $this->insertDiffHist( $s, $rc, $unpatrolled );
546 # M, N, b and ! (minor, new, bot and unpatrolled)
547 $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'],
548 $unpatrolled, '', $rc->mAttribs['rc_bot'] );
549 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
551 # Edit/log timestamp
552 $this->insertTimestamp( $s, $rc );
553 # Bytes added or removed
554 if( $wgRCShowChangedSize ) {
555 $cd = $rc->getCharacterDifference();
556 if( $cd != '' ) {
557 $s .= "$cd . . ";
560 # User tool links
561 $this->insertUserRelatedLinks( $s, $rc );
562 # Log action text (if any)
563 $this->insertAction( $s, $rc );
564 # Edit or log comment
565 $this->insertComment( $s, $rc );
566 # Tags
567 $this->insertTags( $s, $rc, $classes );
568 # Rollback
569 $this->insertRollback( $s, $rc );
570 # For subclasses
571 $this->insertExtra( $s, $rc, $classes );
573 # How many users watch this page
574 if( $rc->numberofWatchingusers > 0 ) {
575 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
576 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
579 if( $this->watchlist ) {
580 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
583 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
585 wfProfileOut( __METHOD__ );
586 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
592 * Generate a list of changes using an Enhanced system (uses javascript).
594 class EnhancedChangesList extends ChangesList {
596 * Add the JavaScript file for enhanced changeslist
597 * @return String
599 public function beginRecentChangesList() {
600 global $wgStylePath, $wgStyleVersion;
601 $this->rc_cache = array();
602 $this->rcMoveIndex = 0;
603 $this->rcCacheIndex = 0;
604 $this->lastdate = '';
605 $this->rclistOpen = false;
606 $script = Html::linkedScript( $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" );
607 return $script;
610 * Format a line for enhanced recentchange (aka with javascript and block of lines).
612 public function recentChangesLine( &$baseRC, $watched = false ) {
613 global $wgLang, $wgUser;
615 wfProfileIn( __METHOD__ );
617 # Create a specialised object
618 $rc = RCCacheEntry::newFromParent( $baseRC );
620 # Extract fields from DB into the function scope (rc_xxxx variables)
621 // FIXME: Would be good to replace this extract() call with something
622 // that explicitly initializes variables.
623 extract( $rc->mAttribs );
624 $curIdEq = array( 'curid' => $rc_cur_id );
626 # If it's a new day, add the headline and flush the cache
627 $date = $wgLang->date( $rc_timestamp, true );
628 $ret = '';
629 if( $date != $this->lastdate ) {
630 # Process current cache
631 $ret = $this->recentChangesBlock();
632 $this->rc_cache = array();
633 $ret .= Xml::element( 'h4', null, $date );
634 $this->lastdate = $date;
637 # Should patrol-related stuff be shown?
638 if( $wgUser->useRCPatrol() ) {
639 $rc->unpatrolled = !$rc_patrolled;
640 } else {
641 $rc->unpatrolled = false;
644 $showdifflinks = true;
645 # Make article link
646 // Page moves
647 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
648 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
649 $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null,
650 array(), array( 'redirect' => 'no' ) ),
651 $this->skin->linkKnown( $rc->getMovedToTitle() ) );
652 // New unpatrolled pages
653 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
654 $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(),
655 array( 'rcid' => $rc_id ) );
656 // Log entries
657 } else if( $rc_type == RC_LOG ) {
658 if( $rc_log_type ) {
659 $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
660 $clink = '(' . $this->skin->linkKnown( $logtitle,
661 LogPage::logName($rc_log_type) ) . ')';
662 } else {
663 $clink = $this->skin->link( $rc->getTitle() );
665 $watched = false;
666 // Log entries (old format) and special pages
667 } elseif( $rc_namespace == NS_SPECIAL ) {
668 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
669 if ( $specialName == 'Log' ) {
670 # Log updates, etc
671 $logname = LogPage::logName( $logtype );
672 $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')';
673 } else {
674 wfDebug( "Unexpected special page in recentchanges\n" );
675 $clink = '';
677 // Edits
678 } else {
679 $clink = $this->skin->linkKnown( $rc->getTitle() );
682 # Don't show unusable diff links
683 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
684 $showdifflinks = false;
687 $time = $wgLang->time( $rc_timestamp, true, true );
688 $rc->watched = $watched;
689 $rc->link = $clink;
690 $rc->timestamp = $time;
691 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
693 # Make "cur" and "diff" links. Do not use link(), it is too slow if
694 # called too many times (50% of CPU time on RecentChanges!).
695 if( $rc->unpatrolled ) {
696 $rcIdQuery = array( 'rcid' => $rc_id );
697 } else {
698 $rcIdQuery = array();
700 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $rc_this_oldid );
701 $querydiff = $curIdEq + array( 'diff' => $rc_this_oldid, 'oldid' =>
702 $rc_last_oldid ) + $rcIdQuery;
704 if( !$showdifflinks ) {
705 $curLink = $this->message['cur'];
706 $diffLink = $this->message['diff'];
707 } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) {
708 if ( $rc_type != RC_NEW ) {
709 $curLink = $this->message['cur'];
710 } else {
711 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
712 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
714 $diffLink = $this->message['diff'];
715 } else {
716 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
717 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
718 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
719 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
722 # Make "last" link
723 if( !$showdifflinks || !$rc_last_oldid ) {
724 $lastLink = $this->message['last'];
725 } else if( $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
726 $lastLink = $this->message['last'];
727 } else {
728 $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'],
729 array(), $curIdEq + array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) + $rcIdQuery );
732 # Make user links
733 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
734 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
735 } else {
736 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
737 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
740 $rc->lastlink = $lastLink;
741 $rc->curlink = $curLink;
742 $rc->difflink = $diffLink;
744 # Put accumulated information into the cache, for later display
745 # Page moves go on their own line
746 $title = $rc->getTitle();
747 $secureName = $title->getPrefixedDBkey();
748 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
749 # Use an @ character to prevent collision with page names
750 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
751 } else {
752 # Logs are grouped by type
753 if( $rc_type == RC_LOG ){
754 $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
756 if( !isset( $this->rc_cache[$secureName] ) ) {
757 $this->rc_cache[$secureName] = array();
760 array_push( $this->rc_cache[$secureName], $rc );
763 wfProfileOut( __METHOD__ );
765 return $ret;
769 * Enhanced RC group
771 protected function recentChangesBlockGroup( $block ) {
772 global $wgLang, $wgContLang, $wgRCShowChangedSize;
774 wfProfileIn( __METHOD__ );
776 $r = '<table class="mw-enhanced-rc"><tr>';
778 # Collate list of users
779 $userlinks = array();
780 # Other properties
781 $unpatrolled = false;
782 $isnew = false;
783 $curId = $currentRevision = 0;
784 # Some catalyst variables...
785 $namehidden = true;
786 $allLogs = true;
787 foreach( $block as $rcObj ) {
788 $oldid = $rcObj->mAttribs['rc_last_oldid'];
789 if( $rcObj->mAttribs['rc_new'] ) {
790 $isnew = true;
792 // If all log actions to this page were hidden, then don't
793 // give the name of the affected page for this block!
794 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
795 $namehidden = false;
797 $u = $rcObj->userlink;
798 if( !isset( $userlinks[$u] ) ) {
799 $userlinks[$u] = 0;
801 if( $rcObj->unpatrolled ) {
802 $unpatrolled = true;
804 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
805 $allLogs = false;
807 # Get the latest entry with a page_id and oldid
808 # since logs may not have these.
809 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
810 $curId = $rcObj->mAttribs['rc_cur_id'];
812 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
813 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
816 $bot = $rcObj->mAttribs['rc_bot'];
817 $userlinks[$u]++;
820 # Sort the list and convert to text
821 krsort( $userlinks );
822 asort( $userlinks );
823 $users = array();
824 foreach( $userlinks as $userlink => $count) {
825 $text = $userlink;
826 $text .= $wgContLang->getDirMark();
827 if( $count > 1 ) {
828 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
830 array_push( $users, $text );
833 $users = ' <span class="changedby">[' .
834 implode( $this->message['semicolon-separator'], $users ) . ']</span>';
836 # ID for JS visibility toggle
837 $jsid = $this->rcCacheIndex;
838 # onclick handler to toggle hidden/expanded
839 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
840 # Title for <a> tags
841 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
842 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
844 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
845 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
846 $r .= '<td class="mw-enhanced-rc">'.$tl.'&#160;';
848 # Main line
849 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&#160;', $bot );
851 # Timestamp
852 $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td style="padding:0px;">';
854 # Article link
855 if( $namehidden ) {
856 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
857 } else if( $allLogs ) {
858 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
859 } else {
860 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
863 $r .= $wgContLang->getDirMark();
865 $queryParams['curid'] = $curId;
866 # Changes message
867 $n = count($block);
868 static $nchanges = array();
869 if ( !isset( $nchanges[$n] ) ) {
870 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
872 # Total change link
873 $r .= ' ';
874 if( !$allLogs ) {
875 $r .= '(';
876 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) {
877 $r .= $nchanges[$n];
878 } else if( $isnew ) {
879 $r .= $nchanges[$n];
880 } else {
881 $params = $queryParams;
882 $params['diff'] = $currentRevision;
883 $params['oldid'] = $oldid;
885 $r .= $this->skin->link(
886 $block[0]->getTitle(),
887 $nchanges[$n],
888 array(),
889 $params,
890 array( 'known', 'noclasses' )
895 # History
896 if( $allLogs ) {
897 // don't show history link for logs
898 } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
899 $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')';
900 } else {
901 $params = $queryParams;
902 $params['action'] = 'history';
904 $r .= $this->message['pipe-separator'] .
905 $this->skin->link(
906 $block[0]->getTitle(),
907 $this->message['hist'],
908 array(),
909 $params,
910 array( 'known', 'noclasses' )
911 ) . ')';
913 $r .= ' . . ';
915 # Character difference (does not apply if only log items)
916 if( $wgRCShowChangedSize && !$allLogs ) {
917 $last = 0;
918 $first = count($block) - 1;
919 # Some events (like logs) have an "empty" size, so we need to skip those...
920 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
921 $last++;
923 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
924 $first--;
926 # Get net change
927 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
928 $block[$last]->mAttribs['rc_new_len'] );
930 if( $chardiff == '' ) {
931 $r .= ' ';
932 } else {
933 $r .= ' ' . $chardiff. ' . . ';
937 $r .= $users;
938 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
940 $r .= "</td></tr></table>\n";
942 # Sub-entries
943 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
944 $r .= '<table class="mw-enhanced-rc">';
945 foreach( $block as $rcObj ) {
946 # Extract fields from DB into the function scope (rc_xxxx variables)
947 // FIXME: Would be good to replace this extract() call with something
948 // that explicitly initializes variables.
949 # Classes to apply -- TODO implement
950 $classes = array();
951 extract( $rcObj->mAttribs );
953 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
954 $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
955 $r .= $this->spacerIndent() . $this->spacerIndent();
956 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&#160;', $rc_bot );
957 $r .= '&#160;</td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
959 $params = $queryParams;
961 if( $rc_this_oldid != 0 ) {
962 $params['oldid'] = $rc_this_oldid;
965 # Log timestamp
966 if( $rc_type == RC_LOG ) {
967 $link = $rcObj->timestamp;
968 # Revision link
969 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
970 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
971 } else {
972 if ( $rcObj->unpatrolled && $rc_type == RC_NEW) {
973 $params['rcid'] = $rcObj->mAttribs['rc_id'];
976 $link = $this->skin->link(
977 $rcObj->getTitle(),
978 $rcObj->timestamp,
979 array(),
980 $params,
981 array( 'known', 'noclasses' )
983 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
984 $link = '<span class="history-deleted">'.$link.'</span> ';
986 $r .= $link . '</span>';
988 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
989 $r .= ' (';
990 $r .= $rcObj->curlink;
991 $r .= $this->message['pipe-separator'];
992 $r .= $rcObj->lastlink;
993 $r .= ')';
995 $r .= ' . . ';
997 # Character diff
998 if( $wgRCShowChangedSize ) {
999 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
1001 # User links
1002 $r .= $rcObj->userlink;
1003 $r .= $rcObj->usertalklink;
1004 // log action
1005 $this->insertAction( $r, $rcObj );
1006 // log comment
1007 $this->insertComment( $r, $rcObj );
1008 # Rollback
1009 $this->insertRollback( $r, $rcObj );
1010 # Tags
1011 $this->insertTags( $r, $rcObj, $classes );
1013 $r .= "</td></tr>\n";
1015 $r .= "</table></div>\n";
1017 $this->rcCacheIndex++;
1019 wfProfileOut( __METHOD__ );
1021 return $r;
1025 * Generate HTML for an arrow or placeholder graphic
1026 * @param $dir String: one of '', 'd', 'l', 'r'
1027 * @param $alt String: text
1028 * @param $title String: text
1029 * @return String: HTML <img> tag
1031 protected function arrow( $dir, $alt='', $title='' ) {
1032 global $wgStylePath;
1033 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1034 $encAlt = htmlspecialchars( $alt );
1035 $encTitle = htmlspecialchars( $title );
1036 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1040 * Generate HTML for a right- or left-facing arrow,
1041 * depending on language direction.
1042 * @return String: HTML <img> tag
1044 protected function sideArrow() {
1045 global $wgContLang;
1046 $dir = $wgContLang->isRTL() ? 'l' : 'r';
1047 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1051 * Generate HTML for a down-facing arrow
1052 * depending on language direction.
1053 * @return String: HTML <img> tag
1055 protected function downArrow() {
1056 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1060 * Generate HTML for a spacer image
1061 * @return String: HTML <img> tag
1063 protected function spacerArrow() {
1064 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1068 * Add a set of spaces
1069 * @return String: HTML <td> tag
1071 protected function spacerIndent() {
1072 return '&#160;&#160;&#160;&#160;&#160;';
1076 * Enhanced RC ungrouped line.
1077 * @return String: a HTML formated line (generated using $r)
1079 protected function recentChangesBlockLine( $rcObj ) {
1080 global $wgRCShowChangedSize;
1082 wfProfileIn( __METHOD__ );
1084 # Extract fields from DB into the function scope (rc_xxxx variables)
1085 // FIXME: Would be good to replace this extract() call with something
1086 // that explicitly initializes variables.
1087 $classes = array(); // TODO implement
1088 extract( $rcObj->mAttribs );
1089 $query['curid'] = $rc_cur_id;
1091 $r = '<table class="mw-enhanced-rc"><tr>';
1092 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . '&#160;';
1093 # Flag and Timestamp
1094 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1095 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1096 } else {
1097 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&#160;', $rc_bot );
1099 $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td style="padding:0px;">';
1100 # Article or log link
1101 if( $rc_log_type ) {
1102 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
1103 $logname = LogPage::logName( $rc_log_type );
1104 $r .= '(' . $this->skin->link(
1105 $logtitle,
1106 $logname,
1107 array(),
1108 array(),
1109 array( 'known', 'noclasses' )
1110 ) . ')';
1111 } else {
1112 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1114 # Diff and hist links
1115 if ( $rc_type != RC_LOG ) {
1116 $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator'];
1117 $query['action'] = 'history';
1118 $r .= $this->skin->link(
1119 $rcObj->getTitle(),
1120 $this->message['hist'],
1121 array(),
1122 $query,
1123 array( 'known', 'noclasses' )
1124 ) . ')';
1126 $r .= ' . . ';
1127 # Character diff
1128 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1129 $r .= "$cd . . ";
1131 # User/talk
1132 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1133 # Log action (if any)
1134 if( $rc_log_type ) {
1135 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
1136 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1137 } else {
1138 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1139 $this->skin, LogPage::extractParams($rc_params), true, true );
1142 $this->insertComment( $r, $rcObj );
1143 $this->insertRollback( $r, $rcObj );
1144 # Tags
1145 $this->insertTags( $r, $rcObj, $classes );
1146 # Show how many people are watching this if enabled
1147 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
1149 $r .= "</td></tr></table>\n";
1151 wfProfileOut( __METHOD__ );
1153 return $r;
1157 * If enhanced RC is in use, this function takes the previously cached
1158 * RC lines, arranges them, and outputs the HTML
1160 protected function recentChangesBlock() {
1161 if( count ( $this->rc_cache ) == 0 ) {
1162 return '';
1165 wfProfileIn( __METHOD__ );
1167 $blockOut = '';
1168 foreach( $this->rc_cache as $block ) {
1169 if( count( $block ) < 2 ) {
1170 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1171 } else {
1172 $blockOut .= $this->recentChangesBlockGroup( $block );
1176 wfProfileOut( __METHOD__ );
1178 return '<div>'.$blockOut.'</div>';
1182 * Returns text for the end of RC
1183 * If enhanced RC is in use, returns pretty much all the text
1185 public function endRecentChangesList() {
1186 return $this->recentChangesBlock() . parent::endRecentChangesList();