MediaWiki
REL1_19
|
00001 <?php 00014 class RCCacheEntry extends RecentChange { 00015 var $secureName, $link; 00016 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink; 00017 var $userlink, $timestamp, $watched; 00018 00023 static function newFromParent( $rc ) { 00024 $rc2 = new RCCacheEntry; 00025 $rc2->mAttribs = $rc->mAttribs; 00026 $rc2->mExtra = $rc->mExtra; 00027 return $rc2; 00028 } 00029 } 00030 00034 class ChangesList extends ContextSource { 00035 00039 public $skin; 00040 00041 protected $watchlist = false; 00042 00043 protected $message; 00044 00050 public function __construct( $obj ) { 00051 if ( $obj instanceof IContextSource ) { 00052 $this->setContext( $obj ); 00053 $this->skin = $obj->getSkin(); 00054 } else { 00055 $this->setContext( $obj->getContext() ); 00056 $this->skin = $obj; 00057 } 00058 $this->preCacheMessages(); 00059 } 00060 00069 public static function newFromUser( $unused ) { 00070 wfDeprecated( __METHOD__, '1.18' ); 00071 return self::newFromContext( RequestContext::getMain() ); 00072 } 00073 00081 public static function newFromContext( IContextSource $context ) { 00082 $user = $context->getUser(); 00083 $sk = $context->getSkin(); 00084 $list = null; 00085 if( wfRunHooks( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) { 00086 $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) ); 00087 return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context ); 00088 } else { 00089 return $list; 00090 } 00091 } 00092 00097 public function setWatchlistDivs( $value = true ) { 00098 $this->watchlist = $value; 00099 } 00100 00105 private function preCacheMessages() { 00106 if( !isset( $this->message ) ) { 00107 foreach ( explode( ' ', 'cur diff hist last blocklink history ' . 00108 'semicolon-separator pipe-separator' ) as $msg ) { 00109 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) ); 00110 } 00111 } 00112 } 00113 00120 protected function recentChangesFlags( $flags, $nothing = ' ' ) { 00121 $f = ''; 00122 foreach( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as $flag ){ 00123 $f .= isset( $flags[$flag] ) && $flags[$flag] 00124 ? self::flag( $flag ) 00125 : $nothing; 00126 } 00127 return $f; 00128 } 00129 00139 public static function flag( $flag ) { 00140 static $messages = null; 00141 if ( is_null( $messages ) ) { 00142 $messages = array( 00143 'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ), 00144 'minoredit' => array( 'minoreditletter', 'recentchanges-label-minor' ), 00145 'botedit' => array( 'boteditletter', 'recentchanges-label-bot' ), 00146 'unpatrolled' => array( 'unpatrolledletter', 'recentchanges-label-unpatrolled' ), 00147 ); 00148 foreach( $messages as &$value ) { 00149 $value[0] = wfMsgExt( $value[0], 'escapenoentities' ); 00150 $value[1] = wfMsgExt( $value[1], 'escapenoentities' ); 00151 } 00152 } 00153 00154 # Inconsistent naming, bleh 00155 $map = array( 00156 'newpage' => 'newpage', 00157 'minor' => 'minoredit', 00158 'bot' => 'botedit', 00159 'unpatrolled' => 'unpatrolled', 00160 'minoredit' => 'minoredit', 00161 'botedit' => 'botedit', 00162 ); 00163 $flag = $map[$flag]; 00164 00165 return "<abbr class='$flag' title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>'; 00166 } 00167 00172 public function beginRecentChangesList() { 00173 $this->rc_cache = array(); 00174 $this->rcMoveIndex = 0; 00175 $this->rcCacheIndex = 0; 00176 $this->lastdate = ''; 00177 $this->rclistOpen = false; 00178 return ''; 00179 } 00180 00187 public static function showCharacterDifference( $old, $new ) { 00188 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode; 00189 $szdiff = $new - $old; 00190 00191 $code = $wgLang->getCode(); 00192 static $fastCharDiff = array(); 00193 if ( !isset($fastCharDiff[$code]) ) { 00194 $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1'; 00195 } 00196 00197 $formattedSize = $wgLang->formatNum($szdiff); 00198 00199 if ( !$fastCharDiff[$code] ) { 00200 $formattedSize = wfMsgExt( 'rc-change-size', array( 'parsemag' ), $formattedSize ); 00201 } 00202 00203 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) { 00204 $tag = 'strong'; 00205 } else { 00206 $tag = 'span'; 00207 } 00208 00209 if ( $szdiff === 0 ) { 00210 $formattedSizeClass = 'mw-plusminus-null'; 00211 } 00212 if ( $szdiff > 0 ) { 00213 $formattedSize = '+' . $formattedSize; 00214 $formattedSizeClass = 'mw-plusminus-pos'; 00215 } 00216 if ( $szdiff < 0 ) { 00217 $formattedSizeClass = 'mw-plusminus-neg'; 00218 } 00219 00220 $formattedTotalSize = wfMsgExt( 'rc-change-size-new', 'parsemag', $wgLang->formatNum( $new ) ); 00221 00222 return Html::element( $tag, 00223 array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ), 00224 wfMessage( 'parentheses', $formattedSize )->plain() ) . $wgLang->getDirMark(); 00225 } 00226 00231 public function endRecentChangesList() { 00232 if( $this->rclistOpen ) { 00233 return "</ul>\n"; 00234 } else { 00235 return ''; 00236 } 00237 } 00238 00239 public function insertDateHeader( &$s, $rc_timestamp ) { 00240 # Make date header if necessary 00241 $date = $this->getLanguage()->date( $rc_timestamp, true, true ); 00242 if( $date != $this->lastdate ) { 00243 if( $this->lastdate != '' ) { 00244 $s .= "</ul>\n"; 00245 } 00246 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">"; 00247 $this->lastdate = $date; 00248 $this->rclistOpen = true; 00249 } 00250 } 00251 00252 public function insertLog( &$s, $title, $logtype ) { 00253 $page = new LogPage( $logtype ); 00254 $logname = $page->getName()->escaped(); 00255 $s .= '(' . Linker::linkKnown( $title, $logname ) . ')'; 00256 } 00257 00263 public function insertDiffHist( &$s, &$rc, $unpatrolled ) { 00264 # Diff link 00265 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { 00266 $diffLink = $this->message['diff']; 00267 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) { 00268 $diffLink = $this->message['diff']; 00269 } else { 00270 $query = array( 00271 'curid' => $rc->mAttribs['rc_cur_id'], 00272 'diff' => $rc->mAttribs['rc_this_oldid'], 00273 'oldid' => $rc->mAttribs['rc_last_oldid'] 00274 ); 00275 00276 if( $unpatrolled ) { 00277 $query['rcid'] = $rc->mAttribs['rc_id']; 00278 }; 00279 00280 $diffLink = Linker::linkKnown( 00281 $rc->getTitle(), 00282 $this->message['diff'], 00283 array( 'tabindex' => $rc->counter ), 00284 $query 00285 ); 00286 } 00287 $s .= '(' . $diffLink . $this->message['pipe-separator']; 00288 # History link 00289 $s .= Linker::linkKnown( 00290 $rc->getTitle(), 00291 $this->message['hist'], 00292 array(), 00293 array( 00294 'curid' => $rc->mAttribs['rc_cur_id'], 00295 'action' => 'history' 00296 ) 00297 ); 00298 $s .= ') . . '; 00299 } 00300 00307 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) { 00308 # If it's a new article, there is no diff link, but if it hasn't been 00309 # patrolled yet, we need to give users a way to do so 00310 $params = array(); 00311 00312 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) { 00313 $params['rcid'] = $rc->mAttribs['rc_id']; 00314 } 00315 00316 $articlelink = Linker::linkKnown( 00317 $rc->getTitle(), 00318 null, 00319 array(), 00320 $params 00321 ); 00322 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) { 00323 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>'; 00324 } 00325 # Bolden pages watched by this user 00326 if( $watched ) { 00327 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>"; 00328 } 00329 # RTL/LTR marker 00330 $articlelink .= $this->getLanguage()->getDirMark(); 00331 00332 wfRunHooks( 'ChangesListInsertArticleLink', 00333 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) ); 00334 00335 $s .= " $articlelink"; 00336 } 00337 00342 public function insertTimestamp( &$s, $rc ) { 00343 $s .= $this->message['semicolon-separator'] . 00344 $this->getLanguage()->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . '; 00345 } 00346 00353 public function insertUserRelatedLinks( &$s, &$rc ) { 00354 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) { 00355 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>'; 00356 } else { 00357 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'], 00358 $rc->mAttribs['rc_user_text'] ); 00359 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); 00360 } 00361 } 00362 00368 public function insertLogEntry( $rc ) { 00369 $formatter = LogFormatter::newFromRow( $rc->mAttribs ); 00370 $formatter->setShowUserToolLinks( true ); 00371 $mark = $this->getLanguage()->getDirMark(); 00372 return $formatter->getActionText() . " $mark" . $formatter->getComment(); 00373 } 00374 00379 public function insertComment( $rc ) { 00380 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) { 00381 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) { 00382 return ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>'; 00383 } else { 00384 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() ); 00385 } 00386 } 00387 } 00388 00393 public static function usePatrol() { 00394 global $wgUser; 00395 return $wgUser->useRCPatrol(); 00396 } 00397 00401 protected function numberofWatchingusers( $count ) { 00402 static $cache = array(); 00403 if( $count > 0 ) { 00404 if( !isset( $cache[$count] ) ) { 00405 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview', 00406 array('parsemag', 'escape' ), $this->getLanguage()->formatNum( $count ) ); 00407 } 00408 return $cache[$count]; 00409 } else { 00410 return ''; 00411 } 00412 } 00413 00420 public static function isDeleted( $rc, $field ) { 00421 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field; 00422 } 00423 00432 public static function userCan( $rc, $field, User $user = null ) { 00433 if( $rc->mAttribs['rc_type'] == RC_LOG ) { 00434 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user ); 00435 } else { 00436 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user ); 00437 } 00438 } 00439 00445 protected function maybeWatchedLink( $link, $watched = false ) { 00446 if( $watched ) { 00447 return '<strong class="mw-watched">' . $link . '</strong>'; 00448 } else { 00449 return '<span class="mw-rc-unwatched">' . $link . '</span>'; 00450 } 00451 } 00452 00458 public function insertRollback( &$s, &$rc ) { 00459 if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) { 00460 $page = $rc->getTitle(); 00463 if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] ) 00464 { 00465 $rev = new Revision( array( 00466 'id' => $rc->mAttribs['rc_this_oldid'], 00467 'user' => $rc->mAttribs['rc_user'], 00468 'user_text' => $rc->mAttribs['rc_user_text'], 00469 'deleted' => $rc->mAttribs['rc_deleted'] 00470 ) ); 00471 $rev->setTitle( $page ); 00472 $s .= ' '.Linker::generateRollback( $rev, $this->getContext() ); 00473 } 00474 } 00475 } 00476 00482 public function insertTags( &$s, &$rc, &$classes ) { 00483 if ( empty($rc->mAttribs['ts_tags']) ) 00484 return; 00485 00486 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' ); 00487 $classes = array_merge( $classes, $newClasses ); 00488 $s .= ' ' . $tagSummary; 00489 } 00490 00491 public function insertExtra( &$s, &$rc, &$classes ) { 00492 ## Empty, used for subclassers to add anything special. 00493 } 00494 00495 protected function showAsUnpatrolled( RecentChange $rc ) { 00496 $unpatrolled = false; 00497 if ( !$rc->mAttribs['rc_patrolled'] ) { 00498 if ( $this->getUser()->useRCPatrol() ) { 00499 $unpatrolled = true; 00500 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_new'] ) { 00501 $unpatrolled = true; 00502 } 00503 } 00504 return $unpatrolled; 00505 } 00506 } 00507 00508 00512 class OldChangesList extends ChangesList { 00518 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { 00519 global $wgRCShowChangedSize; 00520 wfProfileIn( __METHOD__ ); 00521 00522 # Should patrol-related stuff be shown? 00523 $unpatrolled = $this->showAsUnpatrolled( $rc ); 00524 00525 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience. 00526 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] ); 00527 00528 $s = ''; 00529 $classes = array(); 00530 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468) 00531 if( $linenumber ) { 00532 if( $linenumber & 1 ) { 00533 $classes[] = 'mw-line-odd'; 00534 } 00535 else { 00536 $classes[] = 'mw-line-even'; 00537 } 00538 } 00539 00540 // Moved pages (very very old, not supported anymore) 00541 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) { 00542 // Log entries 00543 } elseif( $rc->mAttribs['rc_log_type'] ) { 00544 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL ); 00545 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] ); 00546 // Log entries (old format) or log targets, and special pages 00547 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { 00548 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] ); 00549 if( $name == 'Log' ) { 00550 $this->insertLog( $s, $rc->getTitle(), $subpage ); 00551 } 00552 // Regular entries 00553 } else { 00554 $this->insertDiffHist( $s, $rc, $unpatrolled ); 00555 # M, N, b and ! (minor, new, bot and unpatrolled) 00556 $s .= $this->recentChangesFlags( 00557 array( 00558 'newpage' => $rc->mAttribs['rc_new'], 00559 'minor' => $rc->mAttribs['rc_minor'], 00560 'unpatrolled' => $unpatrolled, 00561 'bot' => $rc->mAttribs['rc_bot'] 00562 ), 00563 '' 00564 ); 00565 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched ); 00566 } 00567 # Edit/log timestamp 00568 $this->insertTimestamp( $s, $rc ); 00569 # Bytes added or removed 00570 if( $wgRCShowChangedSize ) { 00571 $cd = $rc->getCharacterDifference(); 00572 if( $cd != '' ) { 00573 $s .= "$cd . . "; 00574 } 00575 } 00576 00577 if ( $rc->mAttribs['rc_type'] == RC_LOG ) { 00578 $s .= $this->insertLogEntry( $rc ); 00579 } else { 00580 # User tool links 00581 $this->insertUserRelatedLinks( $s, $rc ); 00582 # LTR/RTL direction mark 00583 $s .= $this->getLanguage()->getDirMark(); 00584 $s .= $this->insertComment( $rc ); 00585 } 00586 00587 # Tags 00588 $this->insertTags( $s, $rc, $classes ); 00589 # Rollback 00590 $this->insertRollback( $s, $rc ); 00591 # For subclasses 00592 $this->insertExtra( $s, $rc, $classes ); 00593 00594 # How many users watch this page 00595 if( $rc->numberofWatchingusers > 0 ) { 00596 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview', 00597 array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $rc->numberofWatchingusers ) ); 00598 } 00599 00600 if( $this->watchlist ) { 00601 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] ); 00602 } 00603 00604 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) ); 00605 00606 wfProfileOut( __METHOD__ ); 00607 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n"; 00608 } 00609 } 00610 00611 00615 class EnhancedChangesList extends ChangesList { 00616 00617 protected $rc_cache; 00618 00623 public function beginRecentChangesList() { 00624 $this->rc_cache = array(); 00625 $this->rcMoveIndex = 0; 00626 $this->rcCacheIndex = 0; 00627 $this->lastdate = ''; 00628 $this->rclistOpen = false; 00629 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' ); 00630 return ''; 00631 } 00640 public function recentChangesLine( &$baseRC, $watched = false ) { 00641 wfProfileIn( __METHOD__ ); 00642 00643 # Create a specialised object 00644 $rc = RCCacheEntry::newFromParent( $baseRC ); 00645 00646 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] ); 00647 00648 # If it's a new day, add the headline and flush the cache 00649 $date = $this->getLanguage()->date( $rc->mAttribs['rc_timestamp'], true ); 00650 $ret = ''; 00651 if( $date != $this->lastdate ) { 00652 # Process current cache 00653 $ret = $this->recentChangesBlock(); 00654 $this->rc_cache = array(); 00655 $ret .= Xml::element( 'h4', null, $date ) . "\n"; 00656 $this->lastdate = $date; 00657 } 00658 00659 # Should patrol-related stuff be shown? 00660 $rc->unpatrolled = $this->showAsUnpatrolled( $rc ); 00661 00662 $showdifflinks = true; 00663 # Make article link 00664 $type = $rc->mAttribs['rc_type']; 00665 $logType = $rc->mAttribs['rc_log_type']; 00666 // Page moves, very old style, not supported anymore 00667 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 00668 // New unpatrolled pages 00669 } elseif( $rc->unpatrolled && $type == RC_NEW ) { 00670 $clink = Linker::linkKnown( $rc->getTitle(), null, array(), 00671 array( 'rcid' => $rc->mAttribs['rc_id'] ) ); 00672 // Log entries 00673 } elseif( $type == RC_LOG ) { 00674 if( $logType ) { 00675 $logtitle = SpecialPage::getTitleFor( 'Log', $logType ); 00676 $logpage = new LogPage( $logType ); 00677 $logname = $logpage->getName()->escaped(); 00678 $clink = '(' . Linker::linkKnown( $logtitle, $logname ) . ')'; 00679 } else { 00680 $clink = Linker::link( $rc->getTitle() ); 00681 } 00682 $watched = false; 00683 // Log entries (old format) and special pages 00684 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { 00685 wfDebug( "Unexpected special page in recentchanges\n" ); 00686 $clink = ''; 00687 // Edits 00688 } else { 00689 $clink = Linker::linkKnown( $rc->getTitle() ); 00690 } 00691 00692 # Don't show unusable diff links 00693 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) { 00694 $showdifflinks = false; 00695 } 00696 00697 $time = $this->getLanguage()->time( $rc->mAttribs['rc_timestamp'], true, true ); 00698 $rc->watched = $watched; 00699 $rc->link = $clink; 00700 $rc->timestamp = $time; 00701 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers; 00702 00703 # Make "cur" and "diff" links. Do not use link(), it is too slow if 00704 # called too many times (50% of CPU time on RecentChanges!). 00705 $thisOldid = $rc->mAttribs['rc_this_oldid']; 00706 $lastOldid = $rc->mAttribs['rc_last_oldid']; 00707 if( $rc->unpatrolled ) { 00708 $rcIdQuery = array( 'rcid' => $rc->mAttribs['rc_id'] ); 00709 } else { 00710 $rcIdQuery = array(); 00711 } 00712 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid ); 00713 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' => 00714 $lastOldid ) + $rcIdQuery; 00715 00716 if( !$showdifflinks ) { 00717 $curLink = $this->message['cur']; 00718 $diffLink = $this->message['diff']; 00719 } elseif( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) { 00720 if ( $type != RC_NEW ) { 00721 $curLink = $this->message['cur']; 00722 } else { 00723 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) ); 00724 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>"; 00725 } 00726 $diffLink = $this->message['diff']; 00727 } else { 00728 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) ); 00729 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) ); 00730 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>"; 00731 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>"; 00732 } 00733 00734 # Make "last" link 00735 if( !$showdifflinks || !$lastOldid ) { 00736 $lastLink = $this->message['last']; 00737 } elseif( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) { 00738 $lastLink = $this->message['last']; 00739 } else { 00740 $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'], 00741 array(), $curIdEq + array('diff' => $thisOldid, 'oldid' => $lastOldid) + $rcIdQuery ); 00742 } 00743 00744 # Make user links 00745 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) { 00746 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>'; 00747 } else { 00748 $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); 00749 $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); 00750 } 00751 00752 $rc->lastlink = $lastLink; 00753 $rc->curlink = $curLink; 00754 $rc->difflink = $diffLink; 00755 00756 # Put accumulated information into the cache, for later display 00757 # Page moves go on their own line 00758 $title = $rc->getTitle(); 00759 $secureName = $title->getPrefixedDBkey(); 00760 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 00761 # Use an @ character to prevent collision with page names 00762 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc); 00763 } else { 00764 # Logs are grouped by type 00765 if( $type == RC_LOG ){ 00766 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey(); 00767 } 00768 if( !isset( $this->rc_cache[$secureName] ) ) { 00769 $this->rc_cache[$secureName] = array(); 00770 } 00771 00772 array_push( $this->rc_cache[$secureName], $rc ); 00773 } 00774 00775 wfProfileOut( __METHOD__ ); 00776 00777 return $ret; 00778 } 00779 00783 protected function recentChangesBlockGroup( $block ) { 00784 global $wgRCShowChangedSize; 00785 00786 wfProfileIn( __METHOD__ ); 00787 00788 # Add the namespace and title of the block as part of the class 00789 if ( $block[0]->mAttribs['rc_log_type'] ) { 00790 # Log entry 00791 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-log-' 00792 . $block[0]->mAttribs['rc_log_type'] ); 00793 } else { 00794 $classes = 'mw-collapsible mw-collapsed mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' 00795 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] ); 00796 } 00797 $r = Html::openElement( 'table', array( 'class' => $classes ) ) . 00798 Html::openElement( 'tr' ); 00799 00800 # Collate list of users 00801 $userlinks = array(); 00802 # Other properties 00803 $unpatrolled = false; 00804 $isnew = false; 00805 $curId = $currentRevision = 0; 00806 # Some catalyst variables... 00807 $namehidden = true; 00808 $allLogs = true; 00809 foreach( $block as $rcObj ) { 00810 $oldid = $rcObj->mAttribs['rc_last_oldid']; 00811 if( $rcObj->mAttribs['rc_new'] ) { 00812 $isnew = true; 00813 } 00814 // If all log actions to this page were hidden, then don't 00815 // give the name of the affected page for this block! 00816 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) { 00817 $namehidden = false; 00818 } 00819 $u = $rcObj->userlink; 00820 if( !isset( $userlinks[$u] ) ) { 00821 $userlinks[$u] = 0; 00822 } 00823 if( $rcObj->unpatrolled ) { 00824 $unpatrolled = true; 00825 } 00826 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) { 00827 $allLogs = false; 00828 } 00829 # Get the latest entry with a page_id and oldid 00830 # since logs may not have these. 00831 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) { 00832 $curId = $rcObj->mAttribs['rc_cur_id']; 00833 } 00834 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) { 00835 $currentRevision = $rcObj->mAttribs['rc_this_oldid']; 00836 } 00837 00838 $bot = $rcObj->mAttribs['rc_bot']; 00839 $userlinks[$u]++; 00840 } 00841 00842 # Sort the list and convert to text 00843 krsort( $userlinks ); 00844 asort( $userlinks ); 00845 $users = array(); 00846 foreach( $userlinks as $userlink => $count) { 00847 $text = $userlink; 00848 $text .= $this->getLanguage()->getDirMark(); 00849 if( $count > 1 ) { 00850 $text .= ' (' . $this->getLanguage()->formatNum( $count ) . '×)'; 00851 } 00852 array_push( $users, $text ); 00853 } 00854 00855 $users = ' <span class="changedby">[' . 00856 implode( $this->message['semicolon-separator'], $users ) . ']</span>'; 00857 00858 # Title for <a> tags 00859 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) ); 00860 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) ); 00861 00862 $tl = "<span class='mw-collapsible-toggle'>" 00863 . "<span class='mw-rc-openarrow'>" 00864 . "<a href='#' title='$expandTitle'>{$this->sideArrow()}</a>" 00865 . "</span><span class='mw-rc-closearrow'>" 00866 . "<a href='#' title='$closeTitle'>{$this->downArrow()}</a>" 00867 . "</span></span>"; 00868 $r .= "<td>$tl</td>"; 00869 00870 # Main line 00871 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array( 00872 'newpage' => $isnew, 00873 'minor' => false, 00874 'unpatrolled' => $unpatrolled, 00875 'bot' => $bot , 00876 ) ); 00877 00878 # Timestamp 00879 $r .= ' '.$block[0]->timestamp.' </td><td>'; 00880 00881 # Article link 00882 if( $namehidden ) { 00883 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>'; 00884 } elseif( $allLogs ) { 00885 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); 00886 } else { 00887 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched ); 00888 } 00889 00890 $r .= $this->getLanguage()->getDirMark(); 00891 00892 $queryParams['curid'] = $curId; 00893 # Changes message 00894 $n = count($block); 00895 static $nchanges = array(); 00896 if ( !isset( $nchanges[$n] ) ) { 00897 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $n ) ); 00898 } 00899 # Total change link 00900 $r .= ' '; 00901 if( !$allLogs ) { 00902 $r .= '('; 00903 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { 00904 $r .= $nchanges[$n]; 00905 } elseif( $isnew ) { 00906 $r .= $nchanges[$n]; 00907 } else { 00908 $params = $queryParams; 00909 $params['diff'] = $currentRevision; 00910 $params['oldid'] = $oldid; 00911 00912 $r .= Linker::link( 00913 $block[0]->getTitle(), 00914 $nchanges[$n], 00915 array(), 00916 $params, 00917 array( 'known', 'noclasses' ) 00918 ); 00919 } 00920 } 00921 00922 # History 00923 if( $allLogs ) { 00924 // don't show history link for logs 00925 } elseif( $namehidden || !$block[0]->getTitle()->exists() ) { 00926 $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')'; 00927 } else { 00928 $params = $queryParams; 00929 $params['action'] = 'history'; 00930 00931 $r .= $this->message['pipe-separator'] . 00932 Linker::linkKnown( 00933 $block[0]->getTitle(), 00934 $this->message['hist'], 00935 array(), 00936 $params 00937 ) . ')'; 00938 } 00939 $r .= ' . . '; 00940 00941 # Character difference (does not apply if only log items) 00942 if( $wgRCShowChangedSize && !$allLogs ) { 00943 $last = 0; 00944 $first = count($block) - 1; 00945 # Some events (like logs) have an "empty" size, so we need to skip those... 00946 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) { 00947 $last++; 00948 } 00949 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) { 00950 $first--; 00951 } 00952 # Get net change 00953 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'], 00954 $block[$last]->mAttribs['rc_new_len'] ); 00955 00956 if( $chardiff == '' ) { 00957 $r .= ' '; 00958 } else { 00959 $r .= ' ' . $chardiff. ' . . '; 00960 } 00961 } 00962 00963 $r .= $users; 00964 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers); 00965 00966 # Sub-entries 00967 foreach( $block as $rcObj ) { 00968 # Classes to apply -- TODO implement 00969 $classes = array(); 00970 $type = $rcObj->mAttribs['rc_type']; 00971 00972 #$r .= '<tr><td valign="top">'.$this->spacerArrow(); 00973 $r .= '<tr><td></td><td class="mw-enhanced-rc">'; 00974 $r .= $this->recentChangesFlags( array( 00975 'newpage' => $rcObj->mAttribs['rc_new'], 00976 'minor' => $rcObj->mAttribs['rc_minor'], 00977 'unpatrolled' => $rcObj->unpatrolled, 00978 'bot' => $rcObj->mAttribs['rc_bot'], 00979 ) ); 00980 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">'; 00981 00982 $params = $queryParams; 00983 00984 if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) { 00985 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid']; 00986 } 00987 00988 # Log timestamp 00989 if( $type == RC_LOG ) { 00990 $link = $rcObj->timestamp; 00991 # Revision link 00992 } elseif( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { 00993 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> '; 00994 } else { 00995 if ( $rcObj->unpatrolled && $type == RC_NEW) { 00996 $params['rcid'] = $rcObj->mAttribs['rc_id']; 00997 } 00998 00999 $link = Linker::linkKnown( 01000 $rcObj->getTitle(), 01001 $rcObj->timestamp, 01002 array(), 01003 $params 01004 ); 01005 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) 01006 $link = '<span class="history-deleted">'.$link.'</span> '; 01007 } 01008 $r .= $link . '</span>'; 01009 01010 if ( !$type == RC_LOG || $type == RC_NEW ) { 01011 $r .= ' ('; 01012 $r .= $rcObj->curlink; 01013 $r .= $this->message['pipe-separator']; 01014 $r .= $rcObj->lastlink; 01015 $r .= ')'; 01016 } 01017 $r .= ' . . '; 01018 01019 # Character diff 01020 if( $wgRCShowChangedSize && $rcObj->getCharacterDifference() ) { 01021 $r .= $rcObj->getCharacterDifference() . ' . . ' ; 01022 } 01023 01024 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) { 01025 $r .= $this->insertLogEntry( $rcObj ); 01026 } else { 01027 # User links 01028 $r .= $rcObj->userlink; 01029 $r .= $rcObj->usertalklink; 01030 $r .= $this->insertComment( $rcObj ); 01031 } 01032 01033 # Rollback 01034 $this->insertRollback( $r, $rcObj ); 01035 # Tags 01036 $this->insertTags( $r, $rcObj, $classes ); 01037 01038 $r .= "</td></tr>\n"; 01039 } 01040 $r .= "</table>\n"; 01041 01042 $this->rcCacheIndex++; 01043 01044 wfProfileOut( __METHOD__ ); 01045 01046 return $r; 01047 } 01048 01056 protected function arrow( $dir, $alt='', $title='' ) { 01057 global $wgStylePath; 01058 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' ); 01059 $encAlt = htmlspecialchars( $alt ); 01060 $encTitle = htmlspecialchars( $title ); 01061 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />"; 01062 } 01063 01069 protected function sideArrow() { 01070 global $wgLang; 01071 $dir = $wgLang->isRTL() ? 'l' : 'r'; 01072 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) ); 01073 } 01074 01080 protected function downArrow() { 01081 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) ); 01082 } 01083 01088 protected function spacerArrow() { 01089 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space 01090 } 01091 01098 protected function recentChangesBlockLine( $rcObj ) { 01099 global $wgRCShowChangedSize; 01100 01101 wfProfileIn( __METHOD__ ); 01102 $query['curid'] = $rcObj->mAttribs['rc_cur_id']; 01103 01104 $type = $rcObj->mAttribs['rc_type']; 01105 $logType = $rcObj->mAttribs['rc_log_type']; 01106 if( $logType ) { 01107 # Log entry 01108 $classes = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType ); 01109 } else { 01110 $classes = 'mw-enhanced-rc ' . Sanitizer::escapeClass( 'mw-changeslist-ns' . 01111 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] ); 01112 } 01113 $r = Html::openElement( 'table', array( 'class' => $classes ) ) . 01114 Html::openElement( 'tr' ); 01115 01116 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow(); 01117 # Flag and Timestamp 01118 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 01119 $r .= '    '; // 4 flags -> 4 spaces 01120 } else { 01121 $r .= $this->recentChangesFlags( array( 01122 'newpage' => $type == RC_NEW, 01123 'minor' => $rcObj->mAttribs['rc_minor'], 01124 'unpatrolled' => $rcObj->unpatrolled, 01125 'bot' => $rcObj->mAttribs['rc_bot'], 01126 ) ); 01127 } 01128 $r .= ' '.$rcObj->timestamp.' </td><td>'; 01129 # Article or log link 01130 if( $logType ) { 01131 $logtitle = SpecialPage::getTitleFor( 'Log', $logType ); 01132 $logname = LogPage::logName( $logType ); 01133 $r .= '(' . Linker::linkKnown( $logtitle, htmlspecialchars( $logname ) ) . ')'; 01134 } else { 01135 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched ); 01136 } 01137 # Diff and hist links 01138 if ( $type != RC_LOG ) { 01139 $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator']; 01140 $query['action'] = 'history'; 01141 $r .= Linker::linkKnown( 01142 $rcObj->getTitle(), 01143 $this->message['hist'], 01144 array(), 01145 $query 01146 ) . ')'; 01147 } 01148 $r .= ' . . '; 01149 # Character diff 01150 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) { 01151 $r .= "$cd . . "; 01152 } 01153 01154 if ( $type == RC_LOG ) { 01155 $r .= $this->insertLogEntry( $rcObj ); 01156 } else { 01157 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink; 01158 $r .= $this->insertComment( $rcObj ); 01159 $r .= $this->insertRollback( $r, $rcObj ); 01160 } 01161 01162 # Tags 01163 $classes = explode( ' ', $classes ); 01164 $this->insertTags( $r, $rcObj, $classes ); 01165 # Show how many people are watching this if enabled 01166 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers); 01167 01168 $r .= "</td></tr></table>\n"; 01169 01170 wfProfileOut( __METHOD__ ); 01171 01172 return $r; 01173 } 01174 01181 protected function recentChangesBlock() { 01182 if( count ( $this->rc_cache ) == 0 ) { 01183 return ''; 01184 } 01185 01186 wfProfileIn( __METHOD__ ); 01187 01188 $blockOut = ''; 01189 foreach( $this->rc_cache as $block ) { 01190 if( count( $block ) < 2 ) { 01191 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) ); 01192 } else { 01193 $blockOut .= $this->recentChangesBlockGroup( $block ); 01194 } 01195 } 01196 01197 wfProfileOut( __METHOD__ ); 01198 01199 return '<div>'.$blockOut.'</div>'; 01200 } 01201 01207 public function endRecentChangesList() { 01208 return $this->recentChangesBlock() . parent::endRecentChangesList(); 01209 } 01210 01211 }