Add a way for packagers to override some installation details
[mediawiki.git] / includes / ChangesList.php
blobd280c9a759432c3b8431dd842860a079f35f72bd
1 <?php
2 /**
3 * Classes to show lists of changes.
5 * These can be:
6 * - watchlist
7 * - related changes
8 * - recent changes
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @file
28 /**
29 * @todo document
31 class RCCacheEntry extends RecentChange {
32 var $secureName, $link;
33 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
34 var $userlink, $timestamp, $watched;
36 /**
37 * @param $rc RecentChange
38 * @return RCCacheEntry
40 static function newFromParent( $rc ) {
41 $rc2 = new RCCacheEntry;
42 $rc2->mAttribs = $rc->mAttribs;
43 $rc2->mExtra = $rc->mExtra;
44 return $rc2;
48 /**
49 * Base class for all changes lists
51 class ChangesList extends ContextSource {
53 /**
54 * @var Skin
56 public $skin;
58 protected $watchlist = false;
60 protected $message;
62 /**
63 * Changeslist contructor
65 * @param $obj Skin or IContextSource
67 public function __construct( $obj ) {
68 if ( $obj instanceof IContextSource ) {
69 $this->setContext( $obj );
70 $this->skin = $obj->getSkin();
71 } else {
72 $this->setContext( $obj->getContext() );
73 $this->skin = $obj;
75 $this->preCacheMessages();
78 /**
79 * Fetch an appropriate changes list class for the main context
80 * This first argument used to be an User object.
82 * @deprecated in 1.18; use newFromContext() instead
83 * @param $unused string|User Unused
84 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
86 public static function newFromUser( $unused ) {
87 wfDeprecated( __METHOD__, '1.18' );
88 return self::newFromContext( RequestContext::getMain() );
91 /**
92 * Fetch an appropriate changes list class for the specified context
93 * Some users might want to use an enhanced list format, for instance
95 * @param $context IContextSource to use
96 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
98 public static function newFromContext( IContextSource $context ) {
99 $user = $context->getUser();
100 $sk = $context->getSkin();
101 $list = null;
102 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
103 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
104 return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
105 } else {
106 return $list;
111 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
112 * @param $value Boolean
114 public function setWatchlistDivs( $value = true ) {
115 $this->watchlist = $value;
119 * As we use the same small set of messages in various methods and that
120 * they are called often, we call them once and save them in $this->message
122 private function preCacheMessages() {
123 if( !isset( $this->message ) ) {
124 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
125 'semicolon-separator pipe-separator' ) as $msg ) {
126 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
132 * Returns the appropriate flags for new page, minor change and patrolling
133 * @param $flags Array Associative array of 'flag' => Bool
134 * @param $nothing String to use for empty space
135 * @return String
137 protected function recentChangesFlags( $flags, $nothing = '&#160;' ) {
138 $f = '';
139 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
140 $f .= isset( $flags[$flag] ) && $flags[$flag]
141 ? self::flag( $flag )
142 : $nothing;
144 return $f;
148 * Provide the <abbr> element appropriate to a given abbreviated flag,
149 * namely the flag indicating a new page, a minor edit, a bot edit, or an
150 * unpatrolled edit. By default in English it will contain "N", "m", "b",
151 * "!" respectively, plus it will have an appropriate title and class.
153 * @param $flag String: 'newpage', 'unpatrolled', 'minor', or 'bot'
154 * @return String: Raw HTML
156 public static function flag( $flag ) {
157 static $messages = null;
158 if ( is_null( $messages ) ) {
159 $messages = array(
160 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
161 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
162 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
163 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
165 foreach( $messages as &$value ) {
166 $value[0] = wfMsgExt( $value[0], 'escapenoentities' );
167 $value[1] = wfMsgExt( $value[1], 'escapenoentities' );
171 # Inconsistent naming, bleh
172 $map = array(
173 'newpage' => 'newpage',
174 'minor' => 'minoredit',
175 'bot' => 'botedit',
176 'unpatrolled' => 'unpatrolled',
177 'minoredit' => 'minoredit',
178 'botedit' => 'botedit',
180 $flag = $map[$flag];
182 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
186 * Returns text for the start of the tabular part of RC
187 * @return String
189 public function beginRecentChangesList() {
190 $this->rc_cache = array();
191 $this->rcMoveIndex = 0;
192 $this->rcCacheIndex = 0;
193 $this->lastdate = '';
194 $this->rclistOpen = false;
195 return '';
199 * Show formatted char difference
200 * @param $old Integer: bytes
201 * @param $new Integer: bytes
202 * @return String
204 public static function showCharacterDifference( $old, $new ) {
205 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
206 $szdiff = $new - $old;
208 $code = $wgLang->getCode();
209 static $fastCharDiff = array();
210 if ( !isset($fastCharDiff[$code]) ) {
211 $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1';
214 $formattedSize = $wgLang->formatNum($szdiff);
216 if ( !$fastCharDiff[$code] ) {
217 $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize );
220 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
221 $tag = 'strong';
222 } else {
223 $tag = 'span';
226 if ( $szdiff === 0 ) {
227 $formattedSizeClass = 'mw-plusminus-null';
229 if ( $szdiff > 0 ) {
230 $formattedSize = '+' . $formattedSize;
231 $formattedSizeClass = 'mw-plusminus-pos';
233 if ( $szdiff < 0 ) {
234 $formattedSizeClass = 'mw-plusminus-neg';
237 $formattedTotalSize = wfMsgExt( 'rc-change-size-new', 'parsemag', $wgLang->formatNum( $new ) );
239 return Html::element( $tag,
240 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
241 wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark();
245 * Returns text for the end of RC
246 * @return String
248 public function endRecentChangesList() {
249 if( $this->rclistOpen ) {
250 return "</ul>\n";
251 } else {
252 return '';
256 public function insertDateHeader( &$s, $rc_timestamp ) {
257 # Make date header if necessary
258 $date = $this->getLanguage()->date( $rc_timestamp, true, true );
259 if( $date != $this->lastdate ) {
260 if( $this->lastdate != '' ) {
261 $s .= "</ul>\n";
263 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
264 $this->lastdate = $date;
265 $this->rclistOpen = true;
269 public function insertLog( &$s, $title, $logtype ) {
270 $page = new LogPage( $logtype );
271 $logname = $page->getName()->escaped();
272 $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
276 * @param $s
277 * @param $rc RecentChange
278 * @param $unpatrolled
280 public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
281 # Diff link
282 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
283 $diffLink = $this->message['diff'];
284 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
285 $diffLink = $this->message['diff'];
286 } else {
287 $query = array(
288 'curid' => $rc->mAttribs['rc_cur_id'],
289 'diff' => $rc->mAttribs['rc_this_oldid'],
290 'oldid' => $rc->mAttribs['rc_last_oldid']
293 if( $unpatrolled ) {
294 $query['rcid'] = $rc->mAttribs['rc_id'];
297 $diffLink = Linker::linkKnown(
298 $rc->getTitle(),
299 $this->message['diff'],
300 array( 'tabindex' => $rc->counter ),
301 $query
304 $diffhist = $diffLink . $this->message['pipe-separator'];
305 # History link
306 $diffhist .= Linker::linkKnown(
307 $rc->getTitle(),
308 $this->message['hist'],
309 array(),
310 array(
311 'curid' => $rc->mAttribs['rc_cur_id'],
312 'action' => 'history'
315 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' . . ';
319 * @param $s
320 * @param $rc RecentChange
321 * @param $unpatrolled
322 * @param $watched
324 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
325 # If it's a new article, there is no diff link, but if it hasn't been
326 # patrolled yet, we need to give users a way to do so
327 $params = array();
329 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) {
330 $params['rcid'] = $rc->mAttribs['rc_id'];
333 $articlelink = Linker::linkKnown(
334 $rc->getTitle(),
335 null,
336 array(),
337 $params
339 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
340 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
342 # Bolden pages watched by this user
343 if( $watched ) {
344 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
346 # RTL/LTR marker
347 $articlelink .= $this->getLanguage()->getDirMark();
349 wfRunHooks( 'ChangesListInsertArticleLink',
350 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
352 $s .= " $articlelink";
356 * @param $s
357 * @param $rc RecentChange
359 public function insertTimestamp( &$s, $rc ) {
360 $s .= $this->message['semicolon-separator'] .
361 $this->getLanguage()->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
365 * Insert links to user page, user talk page and eventually a blocking link
367 * @param &$s String HTML to update
368 * @param &$rc RecentChange
370 public function insertUserRelatedLinks( &$s, &$rc ) {
371 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
372 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
373 } else {
374 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
375 $rc->mAttribs['rc_user_text'] );
376 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
381 * Insert a formatted action
383 * @param $rc RecentChange
384 * @return string
386 public function insertLogEntry( $rc ) {
387 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
388 $formatter->setShowUserToolLinks( true );
389 $mark = $this->getLanguage()->getDirMark();
390 return $formatter->getActionText() . " $mark" . $formatter->getComment();
393 /**
394 * Insert a formatted comment
395 * @param $rc RecentChange
396 * @return string
398 public function insertComment( $rc ) {
399 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
400 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
401 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
402 } else {
403 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
409 * Check whether to enable recent changes patrol features
410 * @return Boolean
412 public static function usePatrol() {
413 global $wgUser;
414 return $wgUser->useRCPatrol();
418 * Returns the string which indicates the number of watching users
419 * @return string
421 protected function numberofWatchingusers( $count ) {
422 static $cache = array();
423 if( $count > 0 ) {
424 if( !isset( $cache[$count] ) ) {
425 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
426 array('parsemag', 'escape' ), $this->getLanguage()->formatNum( $count ) );
428 return $cache[$count];
429 } else {
430 return '';
435 * Determine if said field of a revision is hidden
436 * @param $rc RCCacheEntry
437 * @param $field Integer: one of DELETED_* bitfield constants
438 * @return Boolean
440 public static function isDeleted( $rc, $field ) {
441 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
445 * Determine if the current user is allowed to view a particular
446 * field of this revision, if it's marked as deleted.
447 * @param $rc RCCacheEntry
448 * @param $field Integer
449 * @param $user User object to check, or null to use $wgUser
450 * @return Boolean
452 public static function userCan( $rc, $field, User $user = null ) {
453 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
454 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
455 } else {
456 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
461 * @param $link string
462 * @param $watched bool
463 * @return string
465 protected function maybeWatchedLink( $link, $watched = false ) {
466 if( $watched ) {
467 return '<strong class="mw-watched">' . $link . '</strong>';
468 } else {
469 return '<span class="mw-rc-unwatched">' . $link . '</span>';
473 /** Inserts a rollback link
475 * @param $s string
476 * @param $rc RecentChange
478 public function insertRollback( &$s, &$rc ) {
479 if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
480 $page = $rc->getTitle();
481 /** Check for rollback and edit permissions, disallow special pages, and only
482 * show a link on the top-most revision */
483 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
485 $rev = new Revision( array(
486 'id' => $rc->mAttribs['rc_this_oldid'],
487 'user' => $rc->mAttribs['rc_user'],
488 'user_text' => $rc->mAttribs['rc_user_text'],
489 'deleted' => $rc->mAttribs['rc_deleted']
490 ) );
491 $rev->setTitle( $page );
492 $s .= ' '.Linker::generateRollback( $rev, $this->getContext() );
498 * @param $s string
499 * @param $rc RecentChange
500 * @param $classes
502 public function insertTags( &$s, &$rc, &$classes ) {
503 if ( empty($rc->mAttribs['ts_tags']) )
504 return;
506 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
507 $classes = array_merge( $classes, $newClasses );
508 $s .= ' ' . $tagSummary;
511 public function insertExtra( &$s, &$rc, &$classes ) {
512 ## Empty, used for subclassers to add anything special.
515 protected function showAsUnpatrolled( RecentChange $rc ) {
516 $unpatrolled = false;
517 if ( !$rc->mAttribs['rc_patrolled'] ) {
518 if ( $this->getUser()->useRCPatrol() ) {
519 $unpatrolled = true;
520 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_new'] ) {
521 $unpatrolled = true;
524 return $unpatrolled;
530 * Generate a list of changes using the good old system (no javascript)
532 class OldChangesList extends ChangesList {
534 * Format a line using the old system (aka without any javascript).
536 * @param $rc RecentChange
537 * @return string
539 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
540 global $wgRCShowChangedSize;
541 wfProfileIn( __METHOD__ );
543 # Should patrol-related stuff be shown?
544 $unpatrolled = $this->showAsUnpatrolled( $rc );
546 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
547 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
549 $s = '';
550 $classes = array();
551 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
552 if( $linenumber ) {
553 if( $linenumber & 1 ) {
554 $classes[] = 'mw-line-odd';
556 else {
557 $classes[] = 'mw-line-even';
561 // Moved pages (very very old, not supported anymore)
562 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
563 // Log entries
564 } elseif( $rc->mAttribs['rc_log_type'] ) {
565 $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
566 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
567 // Log entries (old format) or log targets, and special pages
568 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
569 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
570 if( $name == 'Log' ) {
571 $this->insertLog( $s, $rc->getTitle(), $subpage );
573 // Regular entries
574 } else {
575 $this->insertDiffHist( $s, $rc, $unpatrolled );
576 # M, N, b and ! (minor, new, bot and unpatrolled)
577 $s .= $this->recentChangesFlags(
578 array(
579 'newpage' => $rc->mAttribs['rc_new'],
580 'minor' => $rc->mAttribs['rc_minor'],
581 'unpatrolled' => $unpatrolled,
582 'bot' => $rc->mAttribs['rc_bot']
586 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
588 # Edit/log timestamp
589 $this->insertTimestamp( $s, $rc );
590 # Bytes added or removed
591 if( $wgRCShowChangedSize ) {
592 $cd = $rc->getCharacterDifference();
593 if( $cd != '' ) {
594 $s .= "$cd . . ";
598 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
599 $s .= $this->insertLogEntry( $rc );
600 } else {
601 # User tool links
602 $this->insertUserRelatedLinks( $s, $rc );
603 # LTR/RTL direction mark
604 $s .= $this->getLanguage()->getDirMark();
605 $s .= $this->insertComment( $rc );
608 # Tags
609 $this->insertTags( $s, $rc, $classes );
610 # Rollback
611 $this->insertRollback( $s, $rc );
612 # For subclasses
613 $this->insertExtra( $s, $rc, $classes );
615 # How many users watch this page
616 if( $rc->numberofWatchingusers > 0 ) {
617 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
618 array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $rc->numberofWatchingusers ) );
621 if( $this->watchlist ) {
622 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
625 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
627 wfProfileOut( __METHOD__ );
628 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
634 * Generate a list of changes using an Enhanced system (uses javascript).
636 class EnhancedChangesList extends ChangesList {
638 protected $rc_cache;
641 * Add the JavaScript file for enhanced changeslist
642 * @return String
644 public function beginRecentChangesList() {
645 $this->rc_cache = array();
646 $this->rcMoveIndex = 0;
647 $this->rcCacheIndex = 0;
648 $this->lastdate = '';
649 $this->rclistOpen = false;
650 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
651 return '';
654 * Format a line for enhanced recentchange (aka with javascript and block of lines).
656 * @param $baseRC RecentChange
657 * @param $watched bool
659 * @return string
661 public function recentChangesLine( &$baseRC, $watched = false ) {
662 wfProfileIn( __METHOD__ );
664 # Create a specialised object
665 $rc = RCCacheEntry::newFromParent( $baseRC );
667 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
669 # If it's a new day, add the headline and flush the cache
670 $date = $this->getLanguage()->date( $rc->mAttribs['rc_timestamp'], true );
671 $ret = '';
672 if( $date != $this->lastdate ) {
673 # Process current cache
674 $ret = $this->recentChangesBlock();
675 $this->rc_cache = array();
676 $ret .= Xml::element( 'h4', null, $date ) . "\n";
677 $this->lastdate = $date;
680 # Should patrol-related stuff be shown?
681 $rc->unpatrolled = $this->showAsUnpatrolled( $rc );
683 $showdifflinks = true;
684 # Make article link
685 $type = $rc->mAttribs['rc_type'];
686 $logType = $rc->mAttribs['rc_log_type'];
687 // Page moves, very old style, not supported anymore
688 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
689 // New unpatrolled pages
690 } elseif( $rc->unpatrolled && $type == RC_NEW ) {
691 $clink = Linker::linkKnown( $rc->getTitle(), null, array(),
692 array( 'rcid' => $rc->mAttribs['rc_id'] ) );
693 // Log entries
694 } elseif( $type == RC_LOG ) {
695 if( $logType ) {
696 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
697 $logpage = new LogPage( $logType );
698 $logname = $logpage->getName()->escaped();
699 $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
700 } else {
701 $clink = Linker::link( $rc->getTitle() );
703 $watched = false;
704 // Log entries (old format) and special pages
705 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
706 wfDebug( "Unexpected special page in recentchanges\n" );
707 $clink = '';
708 // Edits
709 } else {
710 $clink = Linker::linkKnown( $rc->getTitle() );
713 # Don't show unusable diff links
714 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
715 $showdifflinks = false;
718 $time = $this->getLanguage()->time( $rc->mAttribs['rc_timestamp'], true, true );
719 $rc->watched = $watched;
720 $rc->link = $clink;
721 $rc->timestamp = $time;
722 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
724 # Make "cur" and "diff" links. Do not use link(), it is too slow if
725 # called too many times (50% of CPU time on RecentChanges!).
726 $thisOldid = $rc->mAttribs['rc_this_oldid'];
727 $lastOldid = $rc->mAttribs['rc_last_oldid'];
728 if( $rc->unpatrolled ) {
729 $rcIdQuery = array( 'rcid' => $rc->mAttribs['rc_id'] );
730 } else {
731 $rcIdQuery = array();
733 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
734 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' =>
735 $lastOldid ) + $rcIdQuery;
737 if( !$showdifflinks ) {
738 $curLink = $this->message['cur'];
739 $diffLink = $this->message['diff'];
740 } elseif( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
741 if ( $type != RC_NEW ) {
742 $curLink = $this->message['cur'];
743 } else {
744 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
745 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
747 $diffLink = $this->message['diff'];
748 } else {
749 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
750 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
751 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
752 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
755 # Make "last" link
756 if( !$showdifflinks || !$lastOldid ) {
757 $lastLink = $this->message['last'];
758 } elseif( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
759 $lastLink = $this->message['last'];
760 } else {
761 $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'],
762 array(), $curIdEq + array('diff' => $thisOldid, 'oldid' => $lastOldid) + $rcIdQuery );
765 # Make user links
766 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
767 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
768 } else {
769 $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
770 $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
773 $rc->lastlink = $lastLink;
774 $rc->curlink = $curLink;
775 $rc->difflink = $diffLink;
777 # Put accumulated information into the cache, for later display
778 # Page moves go on their own line
779 $title = $rc->getTitle();
780 $secureName = $title->getPrefixedDBkey();
781 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
782 # Use an @ character to prevent collision with page names
783 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
784 } else {
785 # Logs are grouped by type
786 if( $type == RC_LOG ){
787 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
789 if( !isset( $this->rc_cache[$secureName] ) ) {
790 $this->rc_cache[$secureName] = array();
793 array_push( $this->rc_cache[$secureName], $rc );
796 wfProfileOut( __METHOD__ );
798 return $ret;
802 * Enhanced RC group
803 * @return string
805 protected function recentChangesBlockGroup( $block ) {
806 global $wgRCShowChangedSize;
808 wfProfileIn( __METHOD__ );
810 # Add the namespace and title of the block as part of the class
811 if ( $block[0]->mAttribs['rc_log_type'] ) {
812 # Log entry
813 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-'
814 . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
815 } else {
816 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns'
817 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
819 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
820 Html::openElement( 'tr' );
822 # Collate list of users
823 $userlinks = array();
824 # Other properties
825 $unpatrolled = false;
826 $isnew = false;
827 $curId = $currentRevision = 0;
828 # Some catalyst variables...
829 $namehidden = true;
830 $allLogs = true;
831 foreach( $block as $rcObj ) {
832 $oldid = $rcObj->mAttribs['rc_last_oldid'];
833 if( $rcObj->mAttribs['rc_new'] ) {
834 $isnew = true;
836 // If all log actions to this page were hidden, then don't
837 // give the name of the affected page for this block!
838 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
839 $namehidden = false;
841 $u = $rcObj->userlink;
842 if( !isset( $userlinks[$u] ) ) {
843 $userlinks[$u] = 0;
845 if( $rcObj->unpatrolled ) {
846 $unpatrolled = true;
848 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
849 $allLogs = false;
851 # Get the latest entry with a page_id and oldid
852 # since logs may not have these.
853 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
854 $curId = $rcObj->mAttribs['rc_cur_id'];
856 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
857 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
860 $bot = $rcObj->mAttribs['rc_bot'];
861 $userlinks[$u]++;
864 # Sort the list and convert to text
865 krsort( $userlinks );
866 asort( $userlinks );
867 $users = array();
868 foreach( $userlinks as $userlink => $count) {
869 $text = $userlink;
870 $text .= $this->getLanguage()->getDirMark();
871 if( $count > 1 ) {
872 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
874 array_push( $users, $text );
877 $users = ' <span class="changedby">'
878 . $this->getContext()->msg( 'brackets' )->rawParams(
879 implode( $this->message['semicolon-separator'], $users )
880 )->plain() . '</span>';
882 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow"></span>';
883 $r .= "<td>$tl</td>";
885 # Main line
886 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
887 'newpage' => $isnew,
888 'minor' => false,
889 'unpatrolled' => $unpatrolled,
890 'bot' => $bot ,
891 ) );
893 # Timestamp
894 $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td>';
896 # Article link
897 if( $namehidden ) {
898 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
899 } elseif( $allLogs ) {
900 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
901 } else {
902 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
905 $r .= $this->getLanguage()->getDirMark();
907 $queryParams['curid'] = $curId;
908 # Changes message
909 $n = count($block);
910 static $nchanges = array();
911 if ( !isset( $nchanges[$n] ) ) {
912 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) );
914 # Total change link
915 $r .= ' ';
916 $logtext = '';
917 if( !$allLogs ) {
918 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
919 $logtext .= $nchanges[$n];
920 } elseif( $isnew ) {
921 $logtext .= $nchanges[$n];
922 } else {
923 $params = $queryParams;
924 $params['diff'] = $currentRevision;
925 $params['oldid'] = $oldid;
927 $logtext .= Linker::link(
928 $block[0]->getTitle(),
929 $nchanges[$n],
930 array(),
931 $params,
932 array( 'known', 'noclasses' )
937 # History
938 if( $allLogs ) {
939 // don't show history link for logs
940 } elseif( $namehidden || !$block[0]->getTitle()->exists() ) {
941 $logtext .= $this->message['pipe-separator'] . $this->message['hist'];
942 } else {
943 $params = $queryParams;
944 $params['action'] = 'history';
946 $logtext .= $this->message['pipe-separator'] .
947 Linker::linkKnown(
948 $block[0]->getTitle(),
949 $this->message['hist'],
950 array(),
951 $params
955 if( $logtext !== '' ) {
956 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
959 $r .= ' . . ';
961 # Character difference (does not apply if only log items)
962 if( $wgRCShowChangedSize && !$allLogs ) {
963 $last = 0;
964 $first = count($block) - 1;
965 # Some events (like logs) have an "empty" size, so we need to skip those...
966 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
967 $last++;
969 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
970 $first--;
972 # Get net change
973 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
974 $block[$last]->mAttribs['rc_new_len'] );
976 if( $chardiff == '' ) {
977 $r .= ' ';
978 } else {
979 $r .= ' ' . $chardiff. ' . . ';
983 $r .= $users;
984 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
986 # Sub-entries
987 foreach( $block as $rcObj ) {
988 # Classes to apply -- TODO implement
989 $classes = array();
990 $type = $rcObj->mAttribs['rc_type'];
992 $r .= '<tr><td></td><td class="mw-enhanced-rc">';
993 $r .= $this->recentChangesFlags( array(
994 'newpage' => $rcObj->mAttribs['rc_new'],
995 'minor' => $rcObj->mAttribs['rc_minor'],
996 'unpatrolled' => $rcObj->unpatrolled,
997 'bot' => $rcObj->mAttribs['rc_bot'],
998 ) );
999 $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
1001 $params = $queryParams;
1003 if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
1004 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
1007 # Log timestamp
1008 if( $type == RC_LOG ) {
1009 $link = $rcObj->timestamp;
1010 # Revision link
1011 } elseif( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
1012 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
1013 } else {
1014 if ( $rcObj->unpatrolled && $type == RC_NEW) {
1015 $params['rcid'] = $rcObj->mAttribs['rc_id'];
1018 $link = Linker::linkKnown(
1019 $rcObj->getTitle(),
1020 $rcObj->timestamp,
1021 array(),
1022 $params
1024 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
1025 $link = '<span class="history-deleted">'.$link.'</span> ';
1027 $r .= $link . '</span>';
1029 if ( !$type == RC_LOG || $type == RC_NEW ) {
1030 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
1032 $r .= ' . . ';
1034 # Character diff
1035 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) {
1036 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1039 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
1040 $r .= $this->insertLogEntry( $rcObj );
1041 } else {
1042 # User links
1043 $r .= $rcObj->userlink;
1044 $r .= $rcObj->usertalklink;
1045 $r .= $this->insertComment( $rcObj );
1048 # Rollback
1049 $this->insertRollback( $r, $rcObj );
1050 # Tags
1051 $this->insertTags( $r, $rcObj, $classes );
1053 $r .= "</td></tr>\n";
1055 $r .= "</table>\n";
1057 $this->rcCacheIndex++;
1059 wfProfileOut( __METHOD__ );
1061 return $r;
1065 * Generate HTML for an arrow or placeholder graphic
1066 * @param $dir String: one of '', 'd', 'l', 'r'
1067 * @param $alt String: text
1068 * @param $title String: text
1069 * @return String: HTML <img> tag
1071 protected function arrow( $dir, $alt='', $title='' ) {
1072 global $wgStylePath;
1073 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1074 $encAlt = htmlspecialchars( $alt );
1075 $encTitle = htmlspecialchars( $title );
1076 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1080 * Generate HTML for a right- or left-facing arrow,
1081 * depending on language direction.
1082 * @return String: HTML <img> tag
1084 protected function sideArrow() {
1085 global $wgLang;
1086 $dir = $wgLang->isRTL() ? 'l' : 'r';
1087 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1091 * Generate HTML for a down-facing arrow
1092 * depending on language direction.
1093 * @return String: HTML <img> tag
1095 protected function downArrow() {
1096 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1100 * Generate HTML for a spacer image
1101 * @return String: HTML <img> tag
1103 protected function spacerArrow() {
1104 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1108 * Enhanced RC ungrouped line.
1110 * @param $rcObj RecentChange
1111 * @return String: a HTML formatted line (generated using $r)
1113 protected function recentChangesBlockLine( $rcObj ) {
1114 global $wgRCShowChangedSize;
1116 wfProfileIn( __METHOD__ );
1117 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
1119 $type = $rcObj->mAttribs['rc_type'];
1120 $logType = $rcObj->mAttribs['rc_log_type'];
1121 if( $logType ) {
1122 # Log entry
1123 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-'
1124 . $logType . '-' . $rcObj->mAttribs['rc_title'] );
1125 } else {
1126 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' .
1127 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
1129 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
1130 Html::openElement( 'tr' );
1132 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
1133 # Flag and Timestamp
1134 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
1135 $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
1136 } else {
1137 $r .= $this->recentChangesFlags( array(
1138 'newpage' => $type == RC_NEW,
1139 'minor' => $rcObj->mAttribs['rc_minor'],
1140 'unpatrolled' => $rcObj->unpatrolled,
1141 'bot' => $rcObj->mAttribs['rc_bot'],
1142 ) );
1144 $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td>';
1145 # Article or log link
1146 if( $logType ) {
1147 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
1148 $logname = LogPage::logName( $logType );
1149 $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, htmlspecialchars( $logname ) ) )->escaped();
1150 } else {
1151 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1153 # Diff and hist links
1154 if ( $type != RC_LOG ) {
1155 $query['action'] = 'history';
1156 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
1157 $rcObj->getTitle(),
1158 $this->message['hist'],
1159 array(),
1160 $query
1161 ) )->escaped();
1163 $r .= ' . . ';
1164 # Character diff
1165 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1166 $r .= "$cd . . ";
1169 if ( $type == RC_LOG ) {
1170 $r .= $this->insertLogEntry( $rcObj );
1171 } else {
1172 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1173 $r .= $this->insertComment( $rcObj );
1174 $r .= $this->insertRollback( $r, $rcObj );
1177 # Tags
1178 $classes = explode( ' ', $classes );
1179 $this->insertTags( $r, $rcObj, $classes );
1180 # Show how many people are watching this if enabled
1181 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
1183 $r .= "</td></tr></table>\n";
1185 wfProfileOut( __METHOD__ );
1187 return $r;
1191 * If enhanced RC is in use, this function takes the previously cached
1192 * RC lines, arranges them, and outputs the HTML
1194 * @return string
1196 protected function recentChangesBlock() {
1197 if( count ( $this->rc_cache ) == 0 ) {
1198 return '';
1201 wfProfileIn( __METHOD__ );
1203 $blockOut = '';
1204 foreach( $this->rc_cache as $block ) {
1205 if( count( $block ) < 2 ) {
1206 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1207 } else {
1208 $blockOut .= $this->recentChangesBlockGroup( $block );
1212 wfProfileOut( __METHOD__ );
1214 return '<div>'.$blockOut.'</div>';
1218 * Returns text for the end of RC
1219 * If enhanced RC is in use, returns pretty much all the text
1220 * @return string
1222 public function endRecentChangesList() {
1223 return $this->recentChangesBlock() . parent::endRecentChangesList();