MediaWiki  REL1_20
ChangesList.php
Go to the documentation of this file.
00001 <?php
00031 class RCCacheEntry extends RecentChange {
00032         var $secureName, $link;
00033         var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
00034         var $userlink, $timestamp, $watched;
00035 
00040         static function newFromParent( $rc ) {
00041                 $rc2 = new RCCacheEntry;
00042                 $rc2->mAttribs = $rc->mAttribs;
00043                 $rc2->mExtra = $rc->mExtra;
00044                 return $rc2;
00045         }
00046 }
00047 
00051 class ChangesList extends ContextSource {
00052 
00056         public $skin;
00057 
00058         protected $watchlist = false;
00059 
00060         protected $message;
00061 
00067         public function __construct( $obj ) {
00068                 if ( $obj instanceof IContextSource ) {
00069                         $this->setContext( $obj );
00070                         $this->skin = $obj->getSkin();
00071                 } else {
00072                         $this->setContext( $obj->getContext() );
00073                         $this->skin = $obj;
00074                 }
00075                 $this->preCacheMessages();
00076         }
00077 
00086         public static function newFromUser( $unused ) {
00087                 wfDeprecated( __METHOD__, '1.18' );
00088                 return self::newFromContext( RequestContext::getMain() );
00089         }
00090 
00098         public static function newFromContext( IContextSource $context ) {
00099                 $user = $context->getUser();
00100                 $sk = $context->getSkin();
00101                 $list = null;
00102                 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
00103                         $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
00104                         return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
00105                 } else {
00106                         return $list;
00107                 }
00108         }
00109 
00114         public function setWatchlistDivs( $value = true ) {
00115                 $this->watchlist = $value;
00116         }
00117 
00122         private function preCacheMessages() {
00123                 if( !isset( $this->message ) ) {
00124                         foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
00125                         'semicolon-separator pipe-separator' ) as $msg ) {
00126                                 $this->message[$msg] = $this->msg( $msg )->escaped();
00127                         }
00128                 }
00129         }
00130 
00137         protected function recentChangesFlags( $flags, $nothing = '&#160;' ) {
00138                 $f = '';
00139                 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){
00140                         $f .= isset( $flags[$flag] ) && $flags[$flag]
00141                                 ? self::flag( $flag )
00142                                 : $nothing;
00143                 }
00144                 return $f;
00145         }
00146 
00156         public static function flag( $flag ) {
00157                 static $messages = null;
00158                 if ( is_null( $messages ) ) {
00159                         $messages = array(
00160                                 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
00161                                 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ),
00162                                 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ),
00163                                 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ),
00164                         );
00165                         foreach( $messages as &$value ) {
00166                                 $value[0] = wfMessage( $value[0] )->escaped();
00167                                 $value[1] = wfMessage( $value[1] )->escaped();
00168                         }
00169                 }
00170 
00171                 # Inconsistent naming, bleh
00172                 $map = array(
00173                         'newpage' => 'newpage',
00174                         'minor' => 'minoredit',
00175                         'bot' => 'botedit',
00176                         'unpatrolled' => 'unpatrolled',
00177                         'minoredit' => 'minoredit',
00178                         'botedit' => 'botedit',
00179                 );
00180                 $flag = $map[$flag];
00181 
00182                 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
00183         }
00184 
00189         public function beginRecentChangesList() {
00190                 $this->rc_cache = array();
00191                 $this->rcMoveIndex = 0;
00192                 $this->rcCacheIndex = 0;
00193                 $this->lastdate = '';
00194                 $this->rclistOpen = false;
00195                 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
00196                 return '';
00197         }
00198 
00206         public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
00207                 global $wgRCChangedSizeThreshold, $wgMiserMode;
00208 
00209                 if ( !$context ) {
00210                         $context = RequestContext::getMain();
00211                 }
00212 
00213                 $new = (int)$new;
00214                 $old = (int)$old;
00215                 $szdiff = $new - $old;
00216 
00217                 $lang = $context->getLanguage();
00218                 $code = $lang->getCode();
00219                 static $fastCharDiff = array();
00220                 if ( !isset($fastCharDiff[$code]) ) {
00221                         $fastCharDiff[$code] = $wgMiserMode || $context->msg( 'rc-change-size' )->plain() === '$1';
00222                 }
00223 
00224                 $formattedSize = $lang->formatNum( $szdiff );
00225 
00226                 if ( !$fastCharDiff[$code] ) {
00227                         $formattedSize = $context->msg( 'rc-change-size', $formattedSize )->text();
00228                 }
00229 
00230                 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
00231                         $tag = 'strong';
00232                 } else {
00233                         $tag = 'span';
00234                 }
00235 
00236                 if ( $szdiff === 0 ) {
00237                         $formattedSizeClass = 'mw-plusminus-null';
00238                 }
00239                 if ( $szdiff > 0 ) {
00240                         $formattedSize = '+' . $formattedSize;
00241                         $formattedSizeClass = 'mw-plusminus-pos';
00242                 }
00243                 if ( $szdiff < 0 ) {
00244                         $formattedSizeClass = 'mw-plusminus-neg';
00245                 }
00246 
00247                 $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
00248 
00249                 return Html::element( $tag,
00250                         array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
00251                         $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
00252         }
00253 
00261         public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
00262                 $oldlen = $old->mAttribs['rc_old_len'];
00263 
00264                 if ( $new ) {
00265                         $newlen = $new->mAttribs['rc_new_len'];
00266                 } else {
00267                         $newlen = $old->mAttribs['rc_new_len'];
00268                 }
00269 
00270                 if( $oldlen === null || $newlen === null ) {
00271                         return '';
00272                 }
00273 
00274                 return self::showCharacterDifference( $oldlen, $newlen, $this->getContext() );
00275         }
00276 
00281         public function endRecentChangesList() {
00282                 if( $this->rclistOpen ) {
00283                         return "</ul>\n";
00284                 } else {
00285                         return '';
00286                 }
00287         }
00288 
00289         public function insertDateHeader( &$s, $rc_timestamp ) {
00290                 # Make date header if necessary
00291                 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() );
00292                 if( $date != $this->lastdate ) {
00293                         if( $this->lastdate != '' ) {
00294                                 $s .= "</ul>\n";
00295                         }
00296                         $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
00297                         $this->lastdate = $date;
00298                         $this->rclistOpen = true;
00299                 }
00300         }
00301 
00302         public function insertLog( &$s, $title, $logtype ) {
00303                 $page = new LogPage( $logtype );
00304                 $logname = $page->getName()->escaped();
00305                 $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped();
00306         }
00307 
00313         public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
00314                 # Diff link
00315                 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
00316                         $diffLink = $this->message['diff'];
00317                 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
00318                         $diffLink = $this->message['diff'];
00319                 } else {
00320                         $query = array(
00321                                 'curid' => $rc->mAttribs['rc_cur_id'],
00322                                 'diff'  => $rc->mAttribs['rc_this_oldid'],
00323                                 'oldid' => $rc->mAttribs['rc_last_oldid']
00324                         );
00325 
00326                         if( $unpatrolled ) {
00327                                 $query['rcid'] = $rc->mAttribs['rc_id'];
00328                         };
00329 
00330                         $diffLink = Linker::linkKnown(
00331                                 $rc->getTitle(),
00332                                 $this->message['diff'],
00333                                 array( 'tabindex' => $rc->counter ),
00334                                 $query
00335                         );
00336                 }
00337                 $diffhist = $diffLink . $this->message['pipe-separator'];
00338                 # History link
00339                 $diffhist .= Linker::linkKnown(
00340                         $rc->getTitle(),
00341                         $this->message['hist'],
00342                         array(),
00343                         array(
00344                                 'curid' => $rc->mAttribs['rc_cur_id'],
00345                                 'action' => 'history'
00346                         )
00347                 );
00348                 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' <span class="mw-changeslist-separator">. .</span> ';
00349         }
00350 
00357         public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
00358                 # If it's a new article, there is no diff link, but if it hasn't been
00359                 # patrolled yet, we need to give users a way to do so
00360                 $params = array();
00361 
00362                 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) {
00363                         $params['rcid'] = $rc->mAttribs['rc_id'];
00364                 }
00365 
00366                 $articlelink = Linker::linkKnown(
00367                         $rc->getTitle(),
00368                         null,
00369                         array( 'class' => 'mw-changeslist-title' ),
00370                         $params
00371                 );
00372                 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
00373                         $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
00374                 }
00375                 # To allow for boldening pages watched by this user
00376                 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>";
00377                 # RTL/LTR marker
00378                 $articlelink .= $this->getLanguage()->getDirMark();
00379 
00380                 wfRunHooks( 'ChangesListInsertArticleLink',
00381                         array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
00382 
00383                 $s .= " $articlelink";
00384         }
00385 
00390         public function insertTimestamp( &$s, $rc ) {
00391                 $s .= $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' .
00392                         $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> ';
00393         }
00394 
00401         public function insertUserRelatedLinks( &$s, &$rc ) {
00402                 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
00403                         $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
00404                 } else {
00405                         $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'],
00406                                 $rc->mAttribs['rc_user_text'] );
00407                         $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
00408                 }
00409         }
00410 
00417         public function insertLogEntry( $rc ) {
00418                 $formatter = LogFormatter::newFromRow( $rc->mAttribs );
00419                 $formatter->setContext( $this->getContext() );
00420                 $formatter->setShowUserToolLinks( true );
00421                 $mark = $this->getLanguage()->getDirMark();
00422                 return $formatter->getActionText() . " $mark" . $formatter->getComment();
00423         }
00424 
00430         public function insertComment( $rc ) {
00431                 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
00432                         if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
00433                                 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
00434                         } else {
00435                                 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
00436                         }
00437                 }
00438         }
00439 
00444         public static function usePatrol() {
00445                 global $wgUser;
00446                 return $wgUser->useRCPatrol();
00447         }
00448 
00453         protected function numberofWatchingusers( $count ) {
00454                 static $cache = array();
00455                 if( $count > 0 ) {
00456                         if( !isset( $cache[$count] ) ) {
00457                                 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped();
00458                         }
00459                         return $cache[$count];
00460                 } else {
00461                         return '';
00462                 }
00463         }
00464 
00471         public static function isDeleted( $rc, $field ) {
00472                 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
00473         }
00474 
00483         public static function userCan( $rc, $field, User $user = null ) {
00484                 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
00485                         return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
00486                 } else {
00487                         return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user );
00488                 }
00489         }
00490 
00496         protected function maybeWatchedLink( $link, $watched = false ) {
00497                 if( $watched ) {
00498                         return '<strong class="mw-watched">' . $link . '</strong>';
00499                 } else {
00500                         return '<span class="mw-rc-unwatched">' . $link . '</span>';
00501                 }
00502         }
00503 
00509         public function insertRollback( &$s, &$rc ) {
00510                 if( $rc->mAttribs['rc_type'] != RC_NEW && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
00511                         $page = $rc->getTitle();
00514                         if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
00515                         {
00516                                 $rev = new Revision( array(
00517                                         'id'        => $rc->mAttribs['rc_this_oldid'],
00518                                         'user'      => $rc->mAttribs['rc_user'],
00519                                         'user_text' => $rc->mAttribs['rc_user_text'],
00520                                         'deleted'   => $rc->mAttribs['rc_deleted']
00521                                 ) );
00522                                 $rev->setTitle( $page );
00523                                 $s .= ' '.Linker::generateRollback( $rev, $this->getContext() );
00524                         }
00525                 }
00526         }
00527 
00533         public function insertTags( &$s, &$rc, &$classes ) {
00534                 if ( empty($rc->mAttribs['ts_tags']) )
00535                         return;
00536 
00537                 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
00538                 $classes = array_merge( $classes, $newClasses );
00539                 $s .= ' ' . $tagSummary;
00540         }
00541 
00542         public function insertExtra( &$s, &$rc, &$classes ) {
00543                 ## Empty, used for subclassers to add anything special.
00544         }
00545 
00546         protected function showAsUnpatrolled( RecentChange $rc ) {
00547                 $unpatrolled = false;
00548                 if ( !$rc->mAttribs['rc_patrolled'] ) {
00549                         if ( $this->getUser()->useRCPatrol() ) {
00550                                 $unpatrolled = true;
00551                         } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_type'] == RC_NEW ) {
00552                                 $unpatrolled = true;
00553                         }
00554                 }
00555                 return $unpatrolled;
00556         }
00557 }
00558 
00559 
00563 class OldChangesList extends ChangesList {
00572         public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
00573                 global $wgRCShowChangedSize;
00574                 wfProfileIn( __METHOD__ );
00575 
00576                 # Should patrol-related stuff be shown?
00577                 $unpatrolled = $this->showAsUnpatrolled( $rc );
00578 
00579                 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
00580                 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
00581 
00582                 $s = '';
00583                 $classes = array();
00584                 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
00585                 if( $linenumber ) {
00586                         if( $linenumber & 1 ) {
00587                                 $classes[] = 'mw-line-odd';
00588                         }
00589                         else {
00590                                 $classes[] = 'mw-line-even';
00591                         }
00592                 }
00593 
00594                 // Indicate watched status on the line to allow for more
00595                 // comprehensive styling.
00596                 $classes[] = $watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
00597 
00598                 // Moved pages (very very old, not supported anymore)
00599                 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
00600                 // Log entries
00601                 } elseif( $rc->mAttribs['rc_log_type'] ) {
00602                         $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
00603                         $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
00604                 // Log entries (old format) or log targets, and special pages
00605                 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
00606                         list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] );
00607                         if( $name == 'Log' ) {
00608                                 $this->insertLog( $s, $rc->getTitle(), $subpage );
00609                         }
00610                 // Regular entries
00611                 } else {
00612                         $this->insertDiffHist( $s, $rc, $unpatrolled );
00613                         # M, N, b and ! (minor, new, bot and unpatrolled)
00614                         $s .= $this->recentChangesFlags(
00615                                 array(
00616                                         'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
00617                                         'minor' => $rc->mAttribs['rc_minor'],
00618                                         'unpatrolled' => $unpatrolled,
00619                                         'bot' => $rc->mAttribs['rc_bot']
00620                                 ),
00621                                 ''
00622                         );
00623                         $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
00624                 }
00625                 # Edit/log timestamp
00626                 $this->insertTimestamp( $s, $rc );
00627                 # Bytes added or removed
00628                 if ( $wgRCShowChangedSize ) {
00629                         $cd = $this->formatCharacterDifference( $rc );
00630                         if ( $cd !== '' ) {
00631                                 $s .= $cd . '  <span class="mw-changeslist-separator">. .</span> ';
00632                         }
00633                 }
00634 
00635                 if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
00636                         $s .= $this->insertLogEntry( $rc );
00637                 } else {
00638                         # User tool links
00639                         $this->insertUserRelatedLinks( $s, $rc );
00640                         # LTR/RTL direction mark
00641                         $s .= $this->getLanguage()->getDirMark();
00642                         $s .= $this->insertComment( $rc );
00643                 }
00644 
00645                 # Tags
00646                 $this->insertTags( $s, $rc, $classes );
00647                 # Rollback
00648                 $this->insertRollback( $s, $rc );
00649                 # For subclasses
00650                 $this->insertExtra( $s, $rc, $classes );
00651 
00652                 # How many users watch this page
00653                 if( $rc->numberofWatchingusers > 0 ) {
00654                         $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
00655                 }
00656 
00657                 if( $this->watchlist ) {
00658                         $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
00659                 }
00660 
00661                 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
00662 
00663                 wfProfileOut( __METHOD__ );
00664                 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
00665         }
00666 }
00667 
00668 
00672 class EnhancedChangesList extends ChangesList {
00673 
00674         protected $rc_cache;
00675 
00680         public function beginRecentChangesList() {
00681                 $this->rc_cache = array();
00682                 $this->rcMoveIndex = 0;
00683                 $this->rcCacheIndex = 0;
00684                 $this->lastdate = '';
00685                 $this->rclistOpen = false;
00686                 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
00687                 return '';
00688         }
00697         public function recentChangesLine( &$baseRC, $watched = false ) {
00698                 wfProfileIn( __METHOD__ );
00699 
00700                 # Create a specialised object
00701                 $rc = RCCacheEntry::newFromParent( $baseRC );
00702 
00703                 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
00704 
00705                 # If it's a new day, add the headline and flush the cache
00706                 $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() );
00707                 $ret = '';
00708                 if( $date != $this->lastdate ) {
00709                         # Process current cache
00710                         $ret = $this->recentChangesBlock();
00711                         $this->rc_cache = array();
00712                         $ret .= Xml::element( 'h4', null, $date ) . "\n";
00713                         $this->lastdate = $date;
00714                 }
00715 
00716                 # Should patrol-related stuff be shown?
00717                 $rc->unpatrolled = $this->showAsUnpatrolled( $rc );
00718 
00719                 $showdifflinks = true;
00720                 # Make article link
00721                 $type = $rc->mAttribs['rc_type'];
00722                 $logType = $rc->mAttribs['rc_log_type'];
00723                 // Page moves, very old style, not supported anymore
00724                 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
00725                 // New unpatrolled pages
00726                 } elseif( $rc->unpatrolled && $type == RC_NEW ) {
00727                         $clink = Linker::linkKnown( $rc->getTitle(), null, array(),
00728                                 array( 'rcid' => $rc->mAttribs['rc_id'] ) );
00729                 // Log entries
00730                 } elseif( $type == RC_LOG ) {
00731                         if( $logType ) {
00732                                 $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
00733                                 $logpage = new LogPage( $logType );
00734                                 $logname = $logpage->getName()->escaped();
00735                                 $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
00736                         } else {
00737                                 $clink = Linker::link( $rc->getTitle() );
00738                         }
00739                         $watched = false;
00740                 // Log entries (old format) and special pages
00741                 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
00742                         wfDebug( "Unexpected special page in recentchanges\n" );
00743                         $clink = '';
00744                 // Edits
00745                 } else {
00746                         $clink = Linker::linkKnown( $rc->getTitle() );
00747                 }
00748 
00749                 # Don't show unusable diff links
00750                 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
00751                         $showdifflinks = false;
00752                 }
00753 
00754                 $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() );
00755                 $rc->watched = $watched;
00756                 $rc->link = $clink;
00757                 $rc->timestamp = $time;
00758                 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
00759 
00760                 # Make "cur" and "diff" links.  Do not use link(), it is too slow if
00761                 # called too many times (50% of CPU time on RecentChanges!).
00762                 $thisOldid = $rc->mAttribs['rc_this_oldid'];
00763                 $lastOldid = $rc->mAttribs['rc_last_oldid'];
00764                 if( $rc->unpatrolled ) {
00765                         $rcIdQuery = array( 'rcid' => $rc->mAttribs['rc_id'] );
00766                 } else {
00767                         $rcIdQuery = array();
00768                 }
00769                 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
00770                 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' =>
00771                         $lastOldid ) + $rcIdQuery;
00772 
00773                 if( !$showdifflinks ) {
00774                         $curLink = $this->message['cur'];
00775                         $diffLink = $this->message['diff'];
00776                 } elseif( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
00777                         if ( $type != RC_NEW ) {
00778                                 $curLink = $this->message['cur'];
00779                         } else {
00780                                 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
00781                                 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
00782                         }
00783                         $diffLink = $this->message['diff'];
00784                 } else {
00785                         $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
00786                         $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
00787                         $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
00788                         $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
00789                 }
00790 
00791                 # Make "last" link
00792                 if( !$showdifflinks || !$lastOldid ) {
00793                         $lastLink = $this->message['last'];
00794                 } elseif( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
00795                         $lastLink = $this->message['last'];
00796                 } else {
00797                         $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'],
00798                                 array(), $curIdEq + array('diff' => $thisOldid, 'oldid' => $lastOldid) + $rcIdQuery );
00799                 }
00800 
00801                 # Make user links
00802                 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
00803                         $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
00804                 } else {
00805                         $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
00806                         $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
00807                 }
00808 
00809                 $rc->lastlink = $lastLink;
00810                 $rc->curlink  = $curLink;
00811                 $rc->difflink = $diffLink;
00812 
00813                 # Put accumulated information into the cache, for later display
00814                 # Page moves go on their own line
00815                 $title = $rc->getTitle();
00816                 $secureName = $title->getPrefixedDBkey();
00817                 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
00818                         # Use an @ character to prevent collision with page names
00819                         $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
00820                 } else {
00821                         # Logs are grouped by type
00822                         if( $type == RC_LOG ){
00823                                 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey();
00824                         }
00825                         if( !isset( $this->rc_cache[$secureName] ) ) {
00826                                 $this->rc_cache[$secureName] = array();
00827                         }
00828 
00829                         array_push( $this->rc_cache[$secureName], $rc );
00830                 }
00831 
00832                 wfProfileOut( __METHOD__ );
00833 
00834                 return $ret;
00835         }
00836 
00841         protected function recentChangesBlockGroup( $block ) {
00842                 global $wgRCShowChangedSize;
00843 
00844                 wfProfileIn( __METHOD__ );
00845 
00846                 # Add the namespace and title of the block as part of the class
00847                 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
00848                 if ( $block[0]->mAttribs['rc_log_type'] ) {
00849                         # Log entry
00850                         $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
00851                                         . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
00852                 } else {
00853                         $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
00854                                         . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
00855                 }
00856                 $classes[] = $block[0]->watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
00857                 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
00858                         Html::openElement( 'tr' );
00859 
00860                 # Collate list of users
00861                 $userlinks = array();
00862                 # Other properties
00863                 $unpatrolled = false;
00864                 $isnew = false;
00865                 $curId = $currentRevision = 0;
00866                 # Some catalyst variables...
00867                 $namehidden = true;
00868                 $allLogs = true;
00869                 foreach( $block as $rcObj ) {
00870                         $oldid = $rcObj->mAttribs['rc_last_oldid'];
00871                         if( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
00872                                 $isnew = true;
00873                         }
00874                         // If all log actions to this page were hidden, then don't
00875                         // give the name of the affected page for this block!
00876                         if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
00877                                 $namehidden = false;
00878                         }
00879                         $u = $rcObj->userlink;
00880                         if( !isset( $userlinks[$u] ) ) {
00881                                 $userlinks[$u] = 0;
00882                         }
00883                         if( $rcObj->unpatrolled ) {
00884                                 $unpatrolled = true;
00885                         }
00886                         if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
00887                                 $allLogs = false;
00888                         }
00889                         # Get the latest entry with a page_id and oldid
00890                         # since logs may not have these.
00891                         if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
00892                                 $curId = $rcObj->mAttribs['rc_cur_id'];
00893                         }
00894                         if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
00895                                 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
00896                         }
00897 
00898                         $bot = $rcObj->mAttribs['rc_bot'];
00899                         $userlinks[$u]++;
00900                 }
00901 
00902                 # Sort the list and convert to text
00903                 krsort( $userlinks );
00904                 asort( $userlinks );
00905                 $users = array();
00906                 foreach( $userlinks as $userlink => $count) {
00907                         $text = $userlink;
00908                         $text .= $this->getLanguage()->getDirMark();
00909                         if( $count > 1 ) {
00910                                 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
00911                         }
00912                         array_push( $users, $text );
00913                 }
00914 
00915                 $users = ' <span class="changedby">'
00916                         . $this->msg( 'brackets' )->rawParams(
00917                                 implode( $this->message['semicolon-separator'], $users )
00918                         )->escaped() . '</span>';
00919 
00920                 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow"></span>';
00921                 $r .= "<td>$tl</td>";
00922 
00923                 # Main line
00924                 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
00925                         'newpage' => $isnew,
00926                         'minor' => false,
00927                         'unpatrolled' => $unpatrolled,
00928                         'bot' => $bot ,
00929                 ) );
00930 
00931                 # Timestamp
00932                 $r .= '&#160;'.$block[0]->timestamp.'&#160;</td><td>';
00933 
00934                 # Article link
00935                 if( $namehidden ) {
00936                         $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
00937                 } elseif( $allLogs ) {
00938                         $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
00939                 } else {
00940                         $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
00941                 }
00942 
00943                 $r .= $this->getLanguage()->getDirMark();
00944 
00945                 $queryParams['curid'] = $curId;
00946                 # Changes message
00947                 $n = count($block);
00948                 static $nchanges = array();
00949                 if ( !isset( $nchanges[$n] ) ) {
00950                         $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped();
00951                 }
00952                 # Total change link
00953                 $r .= ' ';
00954                 $logtext = '';
00955                 if( !$allLogs ) {
00956                         if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
00957                                 $logtext .= $nchanges[$n];
00958                         } elseif( $isnew ) {
00959                                 $logtext .= $nchanges[$n];
00960                         } else {
00961                                 $params = $queryParams;
00962                                 $params['diff'] = $currentRevision;
00963                                 $params['oldid'] = $oldid;
00964 
00965                                 $logtext .= Linker::link(
00966                                         $block[0]->getTitle(),
00967                                         $nchanges[$n],
00968                                         array(),
00969                                         $params,
00970                                         array( 'known', 'noclasses' )
00971                                 );
00972                         }
00973                 }
00974 
00975                 # History
00976                 if( $allLogs ) {
00977                         // don't show history link for logs
00978                 } elseif( $namehidden || !$block[0]->getTitle()->exists() ) {
00979                         $logtext .= $this->message['pipe-separator'] . $this->message['hist'];
00980                 } else {
00981                         $params = $queryParams;
00982                         $params['action'] = 'history';
00983 
00984                         $logtext .= $this->message['pipe-separator'] .
00985                                 Linker::linkKnown(
00986                                         $block[0]->getTitle(),
00987                                         $this->message['hist'],
00988                                         array(),
00989                                         $params
00990                                 );
00991                 }
00992 
00993                 if( $logtext !== '' ) {
00994                         $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
00995                 }
00996 
00997                 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
00998 
00999                 # Character difference (does not apply if only log items)
01000                 if( $wgRCShowChangedSize && !$allLogs ) {
01001                         $last = 0;
01002                         $first = count($block) - 1;
01003                         # Some events (like logs) have an "empty" size, so we need to skip those...
01004                         while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) {
01005                                 $last++;
01006                         }
01007                         while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) {
01008                                 $first--;
01009                         }
01010                         # Get net change
01011                         $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
01012 
01013                         if( $chardiff == '' ) {
01014                                 $r .= ' ';
01015                         } else {
01016                                 $r .= ' ' . $chardiff. ' <span class="mw-changeslist-separator">. .</span> ';
01017                         }
01018                 }
01019 
01020                 $r .= $users;
01021                 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
01022 
01023                 # Sub-entries
01024                 foreach( $block as $rcObj ) {
01025                         # Classes to apply -- TODO implement
01026                         $classes = array();
01027                         $type = $rcObj->mAttribs['rc_type'];
01028 
01029                         $r .= '<tr><td></td><td class="mw-enhanced-rc">';
01030                         $r .= $this->recentChangesFlags( array(
01031                                 'newpage' => $type == RC_NEW,
01032                                 'minor' => $rcObj->mAttribs['rc_minor'],
01033                                 'unpatrolled' => $rcObj->unpatrolled,
01034                                 'bot' => $rcObj->mAttribs['rc_bot'],
01035                         ) );
01036                         $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
01037 
01038                         $params = $queryParams;
01039 
01040                         if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
01041                                 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
01042                         }
01043 
01044                         # Log timestamp
01045                         if( $type == RC_LOG ) {
01046                                 $link = $rcObj->timestamp;
01047                         # Revision link
01048                         } elseif( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
01049                                 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
01050                         } else {
01051                                 if ( $rcObj->unpatrolled && $type == RC_NEW) {
01052                                         $params['rcid'] = $rcObj->mAttribs['rc_id'];
01053                                 }
01054 
01055                                 $link = Linker::linkKnown(
01056                                                 $rcObj->getTitle(),
01057                                                 $rcObj->timestamp,
01058                                                 array(),
01059                                                 $params
01060                                         );
01061                                 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
01062                                         $link = '<span class="history-deleted">'.$link.'</span> ';
01063                         }
01064                         $r .= $link . '</span>';
01065 
01066                         if ( !$type == RC_LOG || $type == RC_NEW ) {
01067                                 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
01068                         }
01069                         $r .= ' <span class="mw-changeslist-separator">. .</span> ';
01070 
01071                         # Character diff
01072                         if ( $wgRCShowChangedSize ) {
01073                                 $cd = $this->formatCharacterDifference( $rcObj );
01074                                 if ( $cd !== '' ) {
01075                                         $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
01076                                 }
01077                         }
01078 
01079                         if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
01080                                 $r .= $this->insertLogEntry( $rcObj );
01081                         } else {
01082                                 # User links
01083                                 $r .= $rcObj->userlink;
01084                                 $r .= $rcObj->usertalklink;
01085                                 $r .= $this->insertComment( $rcObj );
01086                         }
01087 
01088                         # Rollback
01089                         $this->insertRollback( $r, $rcObj );
01090                         # Tags
01091                         $this->insertTags( $r, $rcObj, $classes );
01092 
01093                         $r .= "</td></tr>\n";
01094                 }
01095                 $r .= "</table>\n";
01096 
01097                 $this->rcCacheIndex++;
01098 
01099                 wfProfileOut( __METHOD__ );
01100 
01101                 return $r;
01102         }
01103 
01111         protected function arrow( $dir, $alt='', $title='' ) {
01112                 global $wgStylePath;
01113                 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
01114                 $encAlt = htmlspecialchars( $alt );
01115                 $encTitle = htmlspecialchars( $title );
01116                 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
01117         }
01118 
01124         protected function sideArrow() {
01125                 $dir = $this->getLanguage()->isRTL() ? 'l' : 'r';
01126                 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
01127         }
01128 
01134         protected function downArrow() {
01135                 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() );
01136         }
01137 
01142         protected function spacerArrow() {
01143                 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
01144         }
01145 
01152         protected function recentChangesBlockLine( $rcObj ) {
01153                 global $wgRCShowChangedSize;
01154 
01155                 wfProfileIn( __METHOD__ );
01156                 $query['curid'] = $rcObj->mAttribs['rc_cur_id'];
01157 
01158                 $type = $rcObj->mAttribs['rc_type'];
01159                 $logType = $rcObj->mAttribs['rc_log_type'];
01160                 $classes = array( 'mw-enhanced-rc' );
01161                 if( $logType ) {
01162                         # Log entry
01163                         $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
01164                                         . $logType . '-' . $rcObj->mAttribs['rc_title'] );
01165                 } else {
01166                         $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
01167                                         $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
01168                 }
01169                 $classes[] = $rcObj->watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
01170                 $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
01171                         Html::openElement( 'tr' );
01172 
01173                 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
01174                 # Flag and Timestamp
01175                 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
01176                         $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
01177                 } else {
01178                         $r .= $this->recentChangesFlags( array(
01179                                 'newpage' => $type == RC_NEW,
01180                                 'minor' => $rcObj->mAttribs['rc_minor'],
01181                                 'unpatrolled' => $rcObj->unpatrolled,
01182                                 'bot' => $rcObj->mAttribs['rc_bot'],
01183                         ) );
01184                 }
01185                 $r .= '&#160;'.$rcObj->timestamp.'&#160;</td><td>';
01186                 # Article or log link
01187                 if( $logType ) {
01188                         $logPage = new LogPage( $logType );
01189                         $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
01190                         $logName = $logPage->getName()->escaped();
01191                         $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
01192                 } else {
01193                         $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
01194                 }
01195                 # Diff and hist links
01196                 if ( $type != RC_LOG ) {
01197                         $query['action'] = 'history';
01198                         $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
01199                                 $rcObj->getTitle(),
01200                                 $this->message['hist'],
01201                                 array(),
01202                                 $query
01203                         ) )->escaped();
01204                 }
01205                 $r .= ' <span class="mw-changeslist-separator">. .</span> ';
01206                 # Character diff
01207                 if ( $wgRCShowChangedSize ) {
01208                         $cd = $this->formatCharacterDifference( $rcObj );
01209                         if ( $cd !== '' ) {
01210                                 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
01211                         }
01212                 }
01213 
01214                 if ( $type == RC_LOG ) {
01215                         $r .= $this->insertLogEntry( $rcObj );
01216                 } else {
01217                         $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
01218                         $r .= $this->insertComment( $rcObj );
01219                         $this->insertRollback( $r, $rcObj );
01220                 }
01221 
01222                 # Tags
01223                 $this->insertTags( $r, $rcObj, $classes );
01224                 # Show how many people are watching this if enabled
01225                 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
01226 
01227                 $r .= "</td></tr></table>\n";
01228 
01229                 wfProfileOut( __METHOD__ );
01230 
01231                 return $r;
01232         }
01233 
01240         protected function recentChangesBlock() {
01241                 if( count ( $this->rc_cache ) == 0 ) {
01242                         return '';
01243                 }
01244 
01245                 wfProfileIn( __METHOD__ );
01246 
01247                 $blockOut = '';
01248                 foreach( $this->rc_cache as $block ) {
01249                         if( count( $block ) < 2 ) {
01250                                 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
01251                         } else {
01252                                 $blockOut .= $this->recentChangesBlockGroup( $block );
01253                         }
01254                 }
01255 
01256                 wfProfileOut( __METHOD__ );
01257 
01258                 return '<div>'.$blockOut.'</div>';
01259         }
01260 
01266         public function endRecentChangesList() {
01267                 return $this->recentChangesBlock() . parent::endRecentChangesList();
01268         }
01269 
01270 }