MediaWiki
REL1_21
|
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 = ' ' ) { 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 00293 public function insertDateHeader( &$s, $rc_timestamp ) { 00294 # Make date header if necessary 00295 $date = $this->getLanguage()->userDate( $rc_timestamp, $this->getUser() ); 00296 if( $date != $this->lastdate ) { 00297 if( $this->lastdate != '' ) { 00298 $s .= "</ul>\n"; 00299 } 00300 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">"; 00301 $this->lastdate = $date; 00302 $this->rclistOpen = true; 00303 } 00304 } 00305 00311 public function insertLog( &$s, $title, $logtype ) { 00312 $page = new LogPage( $logtype ); 00313 $logname = $page->getName()->escaped(); 00314 $s .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $title, $logname ) )->escaped(); 00315 } 00316 00322 public function insertDiffHist( &$s, &$rc, $unpatrolled ) { 00323 # Diff link 00324 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) { 00325 $diffLink = $this->message['diff']; 00326 } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) { 00327 $diffLink = $this->message['diff']; 00328 } else { 00329 $query = array( 00330 'curid' => $rc->mAttribs['rc_cur_id'], 00331 'diff' => $rc->mAttribs['rc_this_oldid'], 00332 'oldid' => $rc->mAttribs['rc_last_oldid'] 00333 ); 00334 00335 if( $unpatrolled ) { 00336 $query['rcid'] = $rc->mAttribs['rc_id']; 00337 }; 00338 00339 $diffLink = Linker::linkKnown( 00340 $rc->getTitle(), 00341 $this->message['diff'], 00342 array( 'tabindex' => $rc->counter ), 00343 $query 00344 ); 00345 } 00346 $diffhist = $diffLink . $this->message['pipe-separator']; 00347 # History link 00348 $diffhist .= Linker::linkKnown( 00349 $rc->getTitle(), 00350 $this->message['hist'], 00351 array(), 00352 array( 00353 'curid' => $rc->mAttribs['rc_cur_id'], 00354 'action' => 'history' 00355 ) 00356 ); 00357 $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() . ' <span class="mw-changeslist-separator">. .</span> '; 00358 } 00359 00366 public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) { 00367 # If it's a new article, there is no diff link, but if it hasn't been 00368 # patrolled yet, we need to give users a way to do so 00369 $params = array(); 00370 00371 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) { 00372 $params['rcid'] = $rc->mAttribs['rc_id']; 00373 } 00374 00375 $articlelink = Linker::linkKnown( 00376 $rc->getTitle(), 00377 null, 00378 array( 'class' => 'mw-changeslist-title' ), 00379 $params 00380 ); 00381 if( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) { 00382 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>'; 00383 } 00384 # To allow for boldening pages watched by this user 00385 $articlelink = "<span class=\"mw-title\">{$articlelink}</span>"; 00386 # RTL/LTR marker 00387 $articlelink .= $this->getLanguage()->getDirMark(); 00388 00389 wfRunHooks( 'ChangesListInsertArticleLink', 00390 array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) ); 00391 00392 $s .= " $articlelink"; 00393 } 00394 00402 public function getTimestamp( $rc ) { 00403 return $this->message['semicolon-separator'] . '<span class="mw-changeslist-date">' . 00404 $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ) . '</span> <span class="mw-changeslist-separator">. .</span> '; 00405 } 00406 00413 public function insertTimestamp( &$s, $rc ) { 00414 $s .= $this->getTimestamp( $rc ); 00415 } 00416 00423 public function insertUserRelatedLinks( &$s, &$rc ) { 00424 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) { 00425 $s .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>'; 00426 } else { 00427 $s .= $this->getLanguage()->getDirMark() . Linker::userLink( $rc->mAttribs['rc_user'], 00428 $rc->mAttribs['rc_user_text'] ); 00429 $s .= Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); 00430 } 00431 } 00432 00439 public function insertLogEntry( $rc ) { 00440 $formatter = LogFormatter::newFromRow( $rc->mAttribs ); 00441 $formatter->setContext( $this->getContext() ); 00442 $formatter->setShowUserToolLinks( true ); 00443 $mark = $this->getLanguage()->getDirMark(); 00444 return $formatter->getActionText() . " $mark" . $formatter->getComment(); 00445 } 00446 00452 public function insertComment( $rc ) { 00453 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) { 00454 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) { 00455 return ' <span class="history-deleted">' . $this->msg( 'rev-deleted-comment' )->escaped() . '</span>'; 00456 } else { 00457 return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() ); 00458 } 00459 } 00460 return ''; 00461 } 00462 00467 public static function usePatrol() { 00468 global $wgUser; 00469 return $wgUser->useRCPatrol(); 00470 } 00471 00476 protected function numberofWatchingusers( $count ) { 00477 static $cache = array(); 00478 if( $count > 0 ) { 00479 if( !isset( $cache[$count] ) ) { 00480 $cache[$count] = $this->msg( 'number_of_watching_users_RCview' )->numParams( $count )->escaped(); 00481 } 00482 return $cache[$count]; 00483 } else { 00484 return ''; 00485 } 00486 } 00487 00494 public static function isDeleted( $rc, $field ) { 00495 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field; 00496 } 00497 00506 public static function userCan( $rc, $field, User $user = null ) { 00507 if( $rc->mAttribs['rc_type'] == RC_LOG ) { 00508 return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user ); 00509 } else { 00510 return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field, $user ); 00511 } 00512 } 00513 00519 protected function maybeWatchedLink( $link, $watched = false ) { 00520 if( $watched ) { 00521 return '<strong class="mw-watched">' . $link . '</strong>'; 00522 } else { 00523 return '<span class="mw-rc-unwatched">' . $link . '</span>'; 00524 } 00525 } 00526 00532 public function insertRollback( &$s, &$rc ) { 00533 if( $rc->mAttribs['rc_type'] != RC_NEW && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) { 00534 $page = $rc->getTitle(); 00537 if ( $this->getUser()->isAllowed( 'rollback' ) && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] ) 00538 { 00539 $rev = new Revision( array( 00540 'title' => $page, 00541 'id' => $rc->mAttribs['rc_this_oldid'], 00542 'user' => $rc->mAttribs['rc_user'], 00543 'user_text' => $rc->mAttribs['rc_user_text'], 00544 'deleted' => $rc->mAttribs['rc_deleted'] 00545 ) ); 00546 $s .= ' '.Linker::generateRollback( $rev, $this->getContext() ); 00547 } 00548 } 00549 } 00550 00556 public function insertTags( &$s, &$rc, &$classes ) { 00557 if ( empty( $rc->mAttribs['ts_tags'] ) ) 00558 return; 00559 00560 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' ); 00561 $classes = array_merge( $classes, $newClasses ); 00562 $s .= ' ' . $tagSummary; 00563 } 00564 00565 public function insertExtra( &$s, &$rc, &$classes ) { 00566 // Empty, used for subclasses to add anything special. 00567 } 00568 00569 protected function showAsUnpatrolled( RecentChange $rc ) { 00570 $unpatrolled = false; 00571 if ( !$rc->mAttribs['rc_patrolled'] ) { 00572 if ( $this->getUser()->useRCPatrol() ) { 00573 $unpatrolled = true; 00574 } elseif ( $this->getUser()->useNPPatrol() && $rc->mAttribs['rc_type'] == RC_NEW ) { 00575 $unpatrolled = true; 00576 } 00577 } 00578 return $unpatrolled; 00579 } 00580 } 00581 00585 class OldChangesList extends ChangesList { 00595 public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { 00596 global $wgRCShowChangedSize; 00597 wfProfileIn( __METHOD__ ); 00598 00599 # Should patrol-related stuff be shown? 00600 $unpatrolled = $this->showAsUnpatrolled( $rc ); 00601 00602 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience. 00603 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] ); 00604 00605 $s = ''; 00606 $classes = array(); 00607 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468) 00608 if( $linenumber ) { 00609 if( $linenumber & 1 ) { 00610 $classes[] = 'mw-line-odd'; 00611 } 00612 else { 00613 $classes[] = 'mw-line-even'; 00614 } 00615 } 00616 00617 // Indicate watched status on the line to allow for more 00618 // comprehensive styling. 00619 $classes[] = $watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched'; 00620 00621 // Moved pages (very very old, not supported anymore) 00622 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) { 00623 // Log entries 00624 } elseif( $rc->mAttribs['rc_log_type'] ) { 00625 $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] ); 00626 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] ); 00627 // Log entries (old format) or log targets, and special pages 00628 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { 00629 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $rc->mAttribs['rc_title'] ); 00630 if( $name == 'Log' ) { 00631 $this->insertLog( $s, $rc->getTitle(), $subpage ); 00632 } 00633 // Regular entries 00634 } else { 00635 $this->insertDiffHist( $s, $rc, $unpatrolled ); 00636 # M, N, b and ! (minor, new, bot and unpatrolled) 00637 $s .= $this->recentChangesFlags( 00638 array( 00639 'newpage' => $rc->mAttribs['rc_type'] == RC_NEW, 00640 'minor' => $rc->mAttribs['rc_minor'], 00641 'unpatrolled' => $unpatrolled, 00642 'bot' => $rc->mAttribs['rc_bot'] 00643 ), 00644 '' 00645 ); 00646 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched ); 00647 } 00648 # Edit/log timestamp 00649 $this->insertTimestamp( $s, $rc ); 00650 # Bytes added or removed 00651 if ( $wgRCShowChangedSize ) { 00652 $cd = $this->formatCharacterDifference( $rc ); 00653 if ( $cd !== '' ) { 00654 $s .= $cd . ' <span class="mw-changeslist-separator">. .</span> '; 00655 } 00656 } 00657 00658 if ( $rc->mAttribs['rc_type'] == RC_LOG ) { 00659 $s .= $this->insertLogEntry( $rc ); 00660 } else { 00661 # User tool links 00662 $this->insertUserRelatedLinks( $s, $rc ); 00663 # LTR/RTL direction mark 00664 $s .= $this->getLanguage()->getDirMark(); 00665 $s .= $this->insertComment( $rc ); 00666 } 00667 00668 # Tags 00669 $this->insertTags( $s, $rc, $classes ); 00670 # Rollback 00671 $this->insertRollback( $s, $rc ); 00672 # For subclasses 00673 $this->insertExtra( $s, $rc, $classes ); 00674 00675 # How many users watch this page 00676 if( $rc->numberofWatchingusers > 0 ) { 00677 $s .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers ); 00678 } 00679 00680 if( $this->watchlist ) { 00681 $classes[] = Sanitizer::escapeClass( 'watchlist-' . $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] ); 00682 } 00683 00684 if ( !wfRunHooks( 'OldChangesListRecentChangesLine', array( &$this, &$s, $rc, &$classes ) ) ) { 00685 wfProfileOut( __METHOD__ ); 00686 return false; 00687 } 00688 00689 wfProfileOut( __METHOD__ ); 00690 return "$dateheader<li class=\"" . implode( ' ', $classes ) . "\">" . $s . "</li>\n"; 00691 } 00692 } 00693 00697 class EnhancedChangesList extends ChangesList { 00698 00699 protected $rc_cache; 00700 00705 public function beginRecentChangesList() { 00706 $this->rc_cache = array(); 00707 $this->rcMoveIndex = 0; 00708 $this->rcCacheIndex = 0; 00709 $this->lastdate = ''; 00710 $this->rclistOpen = false; 00711 $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' ); 00712 return ''; 00713 } 00722 public function recentChangesLine( &$baseRC, $watched = false ) { 00723 wfProfileIn( __METHOD__ ); 00724 00725 # Create a specialised object 00726 $rc = RCCacheEntry::newFromParent( $baseRC ); 00727 00728 $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] ); 00729 00730 # If it's a new day, add the headline and flush the cache 00731 $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() ); 00732 $ret = ''; 00733 if( $date != $this->lastdate ) { 00734 # Process current cache 00735 $ret = $this->recentChangesBlock(); 00736 $this->rc_cache = array(); 00737 $ret .= Xml::element( 'h4', null, $date ) . "\n"; 00738 $this->lastdate = $date; 00739 } 00740 00741 # Should patrol-related stuff be shown? 00742 $rc->unpatrolled = $this->showAsUnpatrolled( $rc ); 00743 00744 $showdifflinks = true; 00745 # Make article link 00746 $type = $rc->mAttribs['rc_type']; 00747 $logType = $rc->mAttribs['rc_log_type']; 00748 // Page moves, very old style, not supported anymore 00749 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 00750 // New unpatrolled pages 00751 } elseif( $rc->unpatrolled && $type == RC_NEW ) { 00752 $clink = Linker::linkKnown( $rc->getTitle(), null, array(), 00753 array( 'rcid' => $rc->mAttribs['rc_id'] ) ); 00754 // Log entries 00755 } elseif( $type == RC_LOG ) { 00756 if( $logType ) { 00757 $logtitle = SpecialPage::getTitleFor( 'Log', $logType ); 00758 $logpage = new LogPage( $logType ); 00759 $logname = $logpage->getName()->escaped(); 00760 $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped(); 00761 } else { 00762 $clink = Linker::link( $rc->getTitle() ); 00763 } 00764 $watched = false; 00765 // Log entries (old format) and special pages 00766 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { 00767 wfDebug( "Unexpected special page in recentchanges\n" ); 00768 $clink = ''; 00769 // Edits 00770 } else { 00771 $clink = Linker::linkKnown( $rc->getTitle() ); 00772 } 00773 00774 # Don't show unusable diff links 00775 if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) { 00776 $showdifflinks = false; 00777 } 00778 00779 $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() ); 00780 $rc->watched = $watched; 00781 $rc->link = $clink; 00782 $rc->timestamp = $time; 00783 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers; 00784 00785 # Make "cur" and "diff" links. Do not use link(), it is too slow if 00786 # called too many times (50% of CPU time on RecentChanges!). 00787 $thisOldid = $rc->mAttribs['rc_this_oldid']; 00788 $lastOldid = $rc->mAttribs['rc_last_oldid']; 00789 if( $rc->unpatrolled ) { 00790 $rcIdQuery = array( 'rcid' => $rc->mAttribs['rc_id'] ); 00791 } else { 00792 $rcIdQuery = array(); 00793 } 00794 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid ); 00795 $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' => 00796 $lastOldid ) + $rcIdQuery; 00797 00798 if( !$showdifflinks ) { 00799 $curLink = $this->message['cur']; 00800 $diffLink = $this->message['diff']; 00801 } elseif( in_array( $type, array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) { 00802 if ( $type != RC_NEW ) { 00803 $curLink = $this->message['cur']; 00804 } else { 00805 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) ); 00806 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>"; 00807 } 00808 $diffLink = $this->message['diff']; 00809 } else { 00810 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) ); 00811 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) ); 00812 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>"; 00813 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>"; 00814 } 00815 00816 # Make "last" link 00817 if( !$showdifflinks || !$lastOldid ) { 00818 $lastLink = $this->message['last']; 00819 } elseif( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) { 00820 $lastLink = $this->message['last']; 00821 } else { 00822 $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'], 00823 array(), $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) + $rcIdQuery ); 00824 } 00825 00826 # Make user links 00827 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) { 00828 $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>'; 00829 } else { 00830 $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); 00831 $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] ); 00832 } 00833 00834 $rc->lastlink = $lastLink; 00835 $rc->curlink = $curLink; 00836 $rc->difflink = $diffLink; 00837 00838 # Put accumulated information into the cache, for later display 00839 # Page moves go on their own line 00840 $title = $rc->getTitle(); 00841 $secureName = $title->getPrefixedDBkey(); 00842 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 00843 # Use an @ character to prevent collision with page names 00844 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array( $rc ); 00845 } else { 00846 # Logs are grouped by type 00847 if( $type == RC_LOG ) { 00848 $secureName = SpecialPage::getTitleFor( 'Log', $logType )->getPrefixedDBkey(); 00849 } 00850 if( !isset( $this->rc_cache[$secureName] ) ) { 00851 $this->rc_cache[$secureName] = array(); 00852 } 00853 00854 array_push( $this->rc_cache[$secureName], $rc ); 00855 } 00856 00857 wfProfileOut( __METHOD__ ); 00858 00859 return $ret; 00860 } 00861 00866 protected function recentChangesBlockGroup( $block ) { 00867 global $wgRCShowChangedSize; 00868 00869 wfProfileIn( __METHOD__ ); 00870 00871 # Add the namespace and title of the block as part of the class 00872 $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' ); 00873 if ( $block[0]->mAttribs['rc_log_type'] ) { 00874 # Log entry 00875 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' 00876 . $block[0]->mAttribs['rc_log_type'] ); 00877 } else { 00878 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' 00879 . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] ); 00880 } 00881 $classes[] = $block[0]->watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched'; 00882 $r = Html::openElement( 'table', array( 'class' => $classes ) ) . 00883 Html::openElement( 'tr' ); 00884 00885 # Collate list of users 00886 $userlinks = array(); 00887 # Other properties 00888 $unpatrolled = false; 00889 $isnew = false; 00890 $allBots = true; 00891 $allMinors = true; 00892 $curId = $currentRevision = 0; 00893 # Some catalyst variables... 00894 $namehidden = true; 00895 $allLogs = true; 00896 foreach( $block as $rcObj ) { 00897 $oldid = $rcObj->mAttribs['rc_last_oldid']; 00898 if( $rcObj->mAttribs['rc_type'] == RC_NEW ) { 00899 $isnew = true; 00900 } 00901 // If all log actions to this page were hidden, then don't 00902 // give the name of the affected page for this block! 00903 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) { 00904 $namehidden = false; 00905 } 00906 $u = $rcObj->userlink; 00907 if( !isset( $userlinks[$u] ) ) { 00908 $userlinks[$u] = 0; 00909 } 00910 if( $rcObj->unpatrolled ) { 00911 $unpatrolled = true; 00912 } 00913 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) { 00914 $allLogs = false; 00915 } 00916 # Get the latest entry with a page_id and oldid 00917 # since logs may not have these. 00918 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) { 00919 $curId = $rcObj->mAttribs['rc_cur_id']; 00920 } 00921 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) { 00922 $currentRevision = $rcObj->mAttribs['rc_this_oldid']; 00923 } 00924 00925 if( !$rcObj->mAttribs['rc_bot'] ) { 00926 $allBots = false; 00927 } 00928 if( !$rcObj->mAttribs['rc_minor'] ) { 00929 $allMinors = false; 00930 } 00931 00932 $userlinks[$u]++; 00933 } 00934 00935 # Sort the list and convert to text 00936 krsort( $userlinks ); 00937 asort( $userlinks ); 00938 $users = array(); 00939 foreach( $userlinks as $userlink => $count) { 00940 $text = $userlink; 00941 $text .= $this->getLanguage()->getDirMark(); 00942 if( $count > 1 ) { 00943 $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped(); 00944 } 00945 array_push( $users, $text ); 00946 } 00947 00948 $users = ' <span class="changedby">' 00949 . $this->msg( 'brackets' )->rawParams( 00950 implode( $this->message['semicolon-separator'], $users ) 00951 )->escaped() . '</span>'; 00952 00953 $tl = '<span class="mw-collapsible-toggle mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>'; 00954 $r .= "<td>$tl</td>"; 00955 00956 # Main line 00957 $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array( 00958 'newpage' => $isnew, # show, when one have this flag 00959 'minor' => $allMinors, # show only, when all have this flag 00960 'unpatrolled' => $unpatrolled, # show, when one have this flag 00961 'bot' => $allBots, # show only, when all have this flag 00962 ) ); 00963 00964 # Timestamp 00965 $r .= ' ' . $block[0]->timestamp . ' </td><td>'; 00966 00967 # Article link 00968 if( $namehidden ) { 00969 $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>'; 00970 } elseif( $allLogs ) { 00971 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); 00972 } else { 00973 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched ); 00974 } 00975 00976 $r .= $this->getLanguage()->getDirMark(); 00977 00978 $queryParams['curid'] = $curId; 00979 # Changes message 00980 $n = count( $block ); 00981 static $nchanges = array(); 00982 if ( !isset( $nchanges[$n] ) ) { 00983 $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped(); 00984 } 00985 # Total change link 00986 $r .= ' '; 00987 $logtext = ''; 00988 if( !$allLogs ) { 00989 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { 00990 $logtext .= $nchanges[$n]; 00991 } elseif( $isnew ) { 00992 $logtext .= $nchanges[$n]; 00993 } else { 00994 $params = $queryParams; 00995 $params['diff'] = $currentRevision; 00996 $params['oldid'] = $oldid; 00997 00998 $logtext .= Linker::link( 00999 $block[0]->getTitle(), 01000 $nchanges[$n], 01001 array(), 01002 $params, 01003 array( 'known', 'noclasses' ) 01004 ); 01005 } 01006 } 01007 01008 # History 01009 if( $allLogs ) { 01010 // don't show history link for logs 01011 } elseif( $namehidden || !$block[0]->getTitle()->exists() ) { 01012 $logtext .= $this->message['pipe-separator'] . $this->message['hist']; 01013 } else { 01014 $params = $queryParams; 01015 $params['action'] = 'history'; 01016 01017 $logtext .= $this->message['pipe-separator'] . 01018 Linker::linkKnown( 01019 $block[0]->getTitle(), 01020 $this->message['hist'], 01021 array(), 01022 $params 01023 ); 01024 } 01025 01026 if( $logtext !== '' ) { 01027 $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped(); 01028 } 01029 01030 $r .= ' <span class="mw-changeslist-separator">. .</span> '; 01031 01032 # Character difference (does not apply if only log items) 01033 if( $wgRCShowChangedSize && !$allLogs ) { 01034 $last = 0; 01035 $first = count( $block ) - 1; 01036 # Some events (like logs) have an "empty" size, so we need to skip those... 01037 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === null ) { 01038 $last++; 01039 } 01040 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === null ) { 01041 $first--; 01042 } 01043 # Get net change 01044 $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] ); 01045 01046 if( $chardiff == '' ) { 01047 $r .= ' '; 01048 } else { 01049 $r .= ' ' . $chardiff. ' <span class="mw-changeslist-separator">. .</span> '; 01050 } 01051 } 01052 01053 $r .= $users; 01054 $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers ); 01055 01056 # Sub-entries 01057 foreach( $block as $rcObj ) { 01058 # Classes to apply -- TODO implement 01059 $classes = array(); 01060 $type = $rcObj->mAttribs['rc_type']; 01061 01062 $r .= '<tr><td></td><td class="mw-enhanced-rc">'; 01063 $r .= $this->recentChangesFlags( array( 01064 'newpage' => $type == RC_NEW, 01065 'minor' => $rcObj->mAttribs['rc_minor'], 01066 'unpatrolled' => $rcObj->unpatrolled, 01067 'bot' => $rcObj->mAttribs['rc_bot'], 01068 ) ); 01069 $r .= ' </td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">'; 01070 01071 $params = $queryParams; 01072 01073 if( $rcObj->mAttribs['rc_this_oldid'] != 0 ) { 01074 $params['oldid'] = $rcObj->mAttribs['rc_this_oldid']; 01075 } 01076 01077 # Log timestamp 01078 if( $type == RC_LOG ) { 01079 $link = $rcObj->timestamp; 01080 # Revision link 01081 } elseif( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { 01082 $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> '; 01083 } else { 01084 if ( $rcObj->unpatrolled && $type == RC_NEW) { 01085 $params['rcid'] = $rcObj->mAttribs['rc_id']; 01086 } 01087 01088 $link = Linker::linkKnown( 01089 $rcObj->getTitle(), 01090 $rcObj->timestamp, 01091 array(), 01092 $params 01093 ); 01094 if( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) { 01095 $link = '<span class="history-deleted">' . $link . '</span> '; 01096 } 01097 } 01098 $r .= $link . '</span>'; 01099 01100 if ( !$type == RC_LOG || $type == RC_NEW ) { 01101 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped(); 01102 } 01103 $r .= ' <span class="mw-changeslist-separator">. .</span> '; 01104 01105 # Character diff 01106 if ( $wgRCShowChangedSize ) { 01107 $cd = $this->formatCharacterDifference( $rcObj ); 01108 if ( $cd !== '' ) { 01109 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> '; 01110 } 01111 } 01112 01113 if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) { 01114 $r .= $this->insertLogEntry( $rcObj ); 01115 } else { 01116 # User links 01117 $r .= $rcObj->userlink; 01118 $r .= $rcObj->usertalklink; 01119 $r .= $this->insertComment( $rcObj ); 01120 } 01121 01122 # Rollback 01123 $this->insertRollback( $r, $rcObj ); 01124 # Tags 01125 $this->insertTags( $r, $rcObj, $classes ); 01126 01127 $r .= "</td></tr>\n"; 01128 } 01129 $r .= "</table>\n"; 01130 01131 $this->rcCacheIndex++; 01132 01133 wfProfileOut( __METHOD__ ); 01134 01135 return $r; 01136 } 01137 01145 protected function arrow( $dir, $alt = '', $title = '' ) { 01146 global $wgStylePath; 01147 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' ); 01148 $encAlt = htmlspecialchars( $alt ); 01149 $encTitle = htmlspecialchars( $title ); 01150 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />"; 01151 } 01152 01158 protected function sideArrow() { 01159 $dir = $this->getLanguage()->isRTL() ? 'l' : 'r'; 01160 return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() ); 01161 } 01162 01168 protected function downArrow() { 01169 return $this->arrow( 'd', '-', $this->msg( 'rc-enhanced-hide' )->text() ); 01170 } 01171 01176 protected function spacerArrow() { 01177 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space 01178 } 01179 01186 protected function recentChangesBlockLine( $rcObj ) { 01187 global $wgRCShowChangedSize; 01188 01189 wfProfileIn( __METHOD__ ); 01190 $query['curid'] = $rcObj->mAttribs['rc_cur_id']; 01191 01192 $type = $rcObj->mAttribs['rc_type']; 01193 $logType = $rcObj->mAttribs['rc_log_type']; 01194 $classes = array( 'mw-enhanced-rc' ); 01195 if( $logType ) { 01196 # Log entry 01197 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType ); 01198 } else { 01199 $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' . 01200 $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] ); 01201 } 01202 $classes[] = $rcObj->watched ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched'; 01203 $r = Html::openElement( 'table', array( 'class' => $classes ) ) . 01204 Html::openElement( 'tr' ); 01205 01206 $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>'; 01207 # Flag and Timestamp 01208 if( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 01209 $r .= '    '; // 4 flags -> 4 spaces 01210 } else { 01211 $r .= $this->recentChangesFlags( array( 01212 'newpage' => $type == RC_NEW, 01213 'minor' => $rcObj->mAttribs['rc_minor'], 01214 'unpatrolled' => $rcObj->unpatrolled, 01215 'bot' => $rcObj->mAttribs['rc_bot'], 01216 ) ); 01217 } 01218 $r .= ' ' . $rcObj->timestamp . ' </td><td>'; 01219 # Article or log link 01220 if( $logType ) { 01221 $logPage = new LogPage( $logType ); 01222 $logTitle = SpecialPage::getTitleFor( 'Log', $logType ); 01223 $logName = $logPage->getName()->escaped(); 01224 $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped(); 01225 } else { 01226 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched ); 01227 } 01228 # Diff and hist links 01229 if ( $type != RC_LOG ) { 01230 $query['action'] = 'history'; 01231 $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown( 01232 $rcObj->getTitle(), 01233 $this->message['hist'], 01234 array(), 01235 $query 01236 ) )->escaped(); 01237 } 01238 $r .= ' <span class="mw-changeslist-separator">. .</span> '; 01239 # Character diff 01240 if ( $wgRCShowChangedSize ) { 01241 $cd = $this->formatCharacterDifference( $rcObj ); 01242 if ( $cd !== '' ) { 01243 $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> '; 01244 } 01245 } 01246 01247 if ( $type == RC_LOG ) { 01248 $r .= $this->insertLogEntry( $rcObj ); 01249 } else { 01250 $r .= ' ' . $rcObj->userlink . $rcObj->usertalklink; 01251 $r .= $this->insertComment( $rcObj ); 01252 $this->insertRollback( $r, $rcObj ); 01253 } 01254 01255 # Tags 01256 $this->insertTags( $r, $rcObj, $classes ); 01257 # Show how many people are watching this if enabled 01258 $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers ); 01259 01260 $r .= "</td></tr></table>\n"; 01261 01262 wfProfileOut( __METHOD__ ); 01263 01264 return $r; 01265 } 01266 01273 protected function recentChangesBlock() { 01274 if( count ( $this->rc_cache ) == 0 ) { 01275 return ''; 01276 } 01277 01278 wfProfileIn( __METHOD__ ); 01279 01280 $blockOut = ''; 01281 foreach( $this->rc_cache as $block ) { 01282 if( count( $block ) < 2 ) { 01283 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) ); 01284 } else { 01285 $blockOut .= $this->recentChangesBlockGroup( $block ); 01286 } 01287 } 01288 01289 wfProfileOut( __METHOD__ ); 01290 01291 return '<div>' . $blockOut . '</div>'; 01292 } 01293 01299 public function endRecentChangesList() { 01300 return $this->recentChangesBlock() . parent::endRecentChangesList(); 01301 } 01302 01303 }