From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- includes/cache/BacklinkCache.php | 60 ++++- includes/cache/CacheDependency.php | 18 +- includes/cache/HTMLFileCache.php | 2 +- includes/cache/LinkBatch.php | 4 - includes/cache/LinkCache.php | 17 +- includes/cache/LocalisationCache.php | 71 +++--- includes/cache/MapCacheLRU.php | 123 ---------- includes/cache/MessageCache.php | 36 +-- includes/cache/ResourceFileCache.php | 9 +- includes/cache/UserCache.php | 2 - includes/cache/bloom/BloomCache.php | 323 --------------------------- includes/cache/bloom/BloomCacheRedis.php | 370 ------------------------------- includes/cache/bloom/BloomFilters.php | 79 ------- 13 files changed, 118 insertions(+), 996 deletions(-) delete mode 100644 includes/cache/MapCacheLRU.php delete mode 100644 includes/cache/bloom/BloomCache.php delete mode 100644 includes/cache/bloom/BloomCacheRedis.php delete mode 100644 includes/cache/bloom/BloomFilters.php (limited to 'includes/cache') diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php index ed62bba0..10b4fb00 100644 --- a/includes/cache/BacklinkCache.php +++ b/includes/cache/BacklinkCache.php @@ -38,8 +38,6 @@ * of memory. * * Introduced by r47317 - * - * @internal documentation reviewed on 18 Mar 2011 by hashar */ class BacklinkCache { /** @var ProcessCacheLRU */ @@ -176,7 +174,6 @@ class BacklinkCache { * @return ResultWrapper */ protected function queryLinks( $table, $startId, $endId, $max, $select = 'all' ) { - wfProfileIn( __METHOD__ ); $fromField = $this->getPrefix( $table ) . '_from'; @@ -231,8 +228,6 @@ class BacklinkCache { } } - wfProfileOut( __METHOD__ ); - return $res; } @@ -255,7 +250,7 @@ class BacklinkCache { return $prefixes[$table]; } else { $prefix = null; - wfRunHooks( 'BacklinkCacheGetPrefix', array( $table, &$prefix ) ); + Hooks::run( 'BacklinkCacheGetPrefix', array( $table, &$prefix ) ); if ( $prefix ) { return $prefix; } else { @@ -303,7 +298,7 @@ class BacklinkCache { break; default: $conds = null; - wfRunHooks( 'BacklinkCacheGetConditions', array( $table, $this->title, &$conds ) ); + Hooks::run( 'BacklinkCacheGetConditions', array( $table, $this->title, &$conds ) ); if ( !$conds ) { throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); } @@ -490,4 +485,55 @@ class BacklinkCache { return array( 'numRows' => $numRows, 'batches' => $batches ); } + + /** + * Get a Title iterator for cascade-protected template/file use backlinks + * + * @return TitleArray + * @since 1.25 + */ + public function getCascadeProtectedLinks() { + $dbr = $this->getDB(); + + // @todo: use UNION without breaking tests that use temp tables + $resSets = array(); + $resSets[] = $dbr->select( + array( 'templatelinks', 'page_restrictions', 'page' ), + array( 'page_namespace', 'page_title', 'page_id' ), + array( + 'tl_namespace' => $this->title->getNamespace(), + 'tl_title' => $this->title->getDBkey(), + 'tl_from = pr_page', + 'pr_cascade' => 1, + 'page_id = tl_from' + ), + __METHOD__, + array( 'DISTINCT' ) + ); + if ( $this->title->getNamespace() == NS_FILE ) { + $resSets[] = $dbr->select( + array( 'imagelinks', 'page_restrictions', 'page' ), + array( 'page_namespace', 'page_title', 'page_id' ), + array( + 'il_to' => $this->title->getDBkey(), + 'il_from = pr_page', + 'pr_cascade' => 1, + 'page_id = il_from' + ), + __METHOD__, + array( 'DISTINCT' ) + ); + } + + // Combine and de-duplicate the results + $mergedRes = array(); + foreach ( $resSets as $res ) { + foreach ( $res as $row ) { + $mergedRes[$row->page_id] = $row; + } + } + + return TitleArray::newFromResult( + new FakeResultWrapper( array_values( $mergedRes ) ) ); + } } diff --git a/includes/cache/CacheDependency.php b/includes/cache/CacheDependency.php index 9b48ecb7..517f3798 100644 --- a/includes/cache/CacheDependency.php +++ b/includes/cache/CacheDependency.php @@ -181,13 +181,11 @@ class FileDependency extends CacheDependency { function loadDependencyValues() { if ( is_null( $this->timestamp ) ) { - if ( !file_exists( $this->filename ) ) { - # Dependency on a non-existent file - # This is a valid concept! - $this->timestamp = false; - } else { - $this->timestamp = filemtime( $this->filename ); - } + wfSuppressWarnings(); + # Dependency on a non-existent file stores "false" + # This is a valid concept! + $this->timestamp = filemtime( $this->filename ); + wfRestoreWarnings(); } } @@ -195,7 +193,10 @@ class FileDependency extends CacheDependency { * @return bool */ function isExpired() { - if ( !file_exists( $this->filename ) ) { + wfSuppressWarnings(); + $lastmod = filemtime( $this->filename ); + wfRestoreWarnings(); + if ( $lastmod === false ) { if ( $this->timestamp === false ) { # Still nonexistent return false; @@ -206,7 +207,6 @@ class FileDependency extends CacheDependency { return true; } } else { - $lastmod = filemtime( $this->filename ); if ( $lastmod > $this->timestamp ) { # Modified or created wfDebug( "Dependency triggered: {$this->filename} changed.\n" ); diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index 58ca2dcd..c07032bf 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -131,7 +131,7 @@ class HTMLFileCache extends FileCacheBase { return false; } // Allow extensions to disable caching - return wfRunHooks( 'HTMLFileCache::useFileCache', array( $context ) ); + return Hooks::run( 'HTMLFileCache::useFileCache', array( $context ) ); } /** diff --git a/includes/cache/LinkBatch.php b/includes/cache/LinkBatch.php index 48c063f4..77e4d490 100644 --- a/includes/cache/LinkBatch.php +++ b/includes/cache/LinkBatch.php @@ -128,11 +128,9 @@ class LinkBatch { * @return array Remaining IDs */ protected function executeInto( &$cache ) { - wfProfileIn( __METHOD__ ); $res = $this->doQuery(); $this->doGenderQuery(); $ids = $this->addResultToCache( $cache, $res ); - wfProfileOut( __METHOD__ ); return $ids; } @@ -185,7 +183,6 @@ class LinkBatch { if ( $this->isEmpty() ) { return false; } - wfProfileIn( __METHOD__ ); // This is similar to LinkHolderArray::replaceInternal $dbr = wfGetDB( DB_SLAVE ); @@ -205,7 +202,6 @@ class LinkBatch { $caller .= " (for {$this->caller})"; } $res = $dbr->select( $table, $fields, $conds, $caller ); - wfProfileOut( __METHOD__ ); return $res; } diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 6925df90..eace1eea 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -216,25 +216,20 @@ class LinkCache { * @return int */ public function addLinkObj( $nt ) { - global $wgAntiLockFlags, $wgContentHandlerUseDB; - - wfProfileIn( __METHOD__ ); + global $wgContentHandlerUseDB; $key = $nt->getPrefixedDBkey(); if ( $this->isBadLink( $key ) || $nt->isExternal() ) { - wfProfileOut( __METHOD__ ); return 0; } $id = $this->getGoodLinkID( $key ); if ( $id != 0 ) { - wfProfileOut( __METHOD__ ); return $id; } if ( $key === '' ) { - wfProfileOut( __METHOD__ ); return 0; } @@ -242,14 +237,8 @@ class LinkCache { # Some fields heavily used for linking... if ( $this->mForUpdate ) { $db = wfGetDB( DB_MASTER ); - if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) { - $options = array( 'FOR UPDATE' ); - } else { - $options = array(); - } } else { $db = wfGetDB( DB_SLAVE ); - $options = array(); } $f = array( 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ); @@ -259,7 +248,7 @@ class LinkCache { $s = $db->selectRow( 'page', $f, array( 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey() ), - __METHOD__, $options ); + __METHOD__ ); # Set fields... if ( $s !== false ) { $this->addGoodLinkObjFromRow( $nt, $s ); @@ -269,8 +258,6 @@ class LinkCache { $id = 0; } - wfProfileOut( __METHOD__ ); - return $id; } diff --git a/includes/cache/LocalisationCache.php b/includes/cache/LocalisationCache.php index ae27fba3..dc5a2eb6 100644 --- a/includes/cache/LocalisationCache.php +++ b/includes/cache/LocalisationCache.php @@ -20,6 +20,10 @@ * @file */ +use Cdb\Exception as CdbException; +use Cdb\Reader as CdbReader; +use Cdb\Writer as CdbWriter; + /** * Class for caching the contents of localisation files, Messages*.php * and *.i18n.php. @@ -33,7 +37,7 @@ * as grammatical transformation, is done by the caller. */ class LocalisationCache { - const VERSION = 2; + const VERSION = 3; /** Configuration associative array */ private $conf; @@ -253,9 +257,7 @@ class LocalisationCache { */ public function getItem( $code, $key ) { if ( !isset( $this->loadedItems[$code][$key] ) ) { - wfProfileIn( __METHOD__ . '-load' ); $this->loadItem( $code, $key ); - wfProfileOut( __METHOD__ . '-load' ); } if ( $key === 'fallback' && isset( $this->shallowFallbacks[$code] ) ) { @@ -276,9 +278,7 @@ class LocalisationCache { if ( !isset( $this->loadedSubitems[$code][$key][$subkey] ) && !isset( $this->loadedItems[$code][$key] ) ) { - wfProfileIn( __METHOD__ . '-load' ); $this->loadSubitem( $code, $key, $subkey ); - wfProfileOut( __METHOD__ . '-load' ); } if ( isset( $this->data[$code][$key][$subkey] ) ) { @@ -505,7 +505,6 @@ class LocalisationCache { * @return array */ protected function readPHPFile( $_fileName, $_fileType ) { - wfProfileIn( __METHOD__ ); // Disable APC caching wfSuppressWarnings(); $_apcEnabled = ini_set( 'apc.cache_by_default', '0' ); @@ -522,10 +521,8 @@ class LocalisationCache { } elseif ( $_fileType == 'aliases' ) { $data = compact( 'aliases' ); } else { - wfProfileOut( __METHOD__ ); throw new MWException( __METHOD__ . ": Invalid file type: $_fileType" ); } - wfProfileOut( __METHOD__ ); return $data; } @@ -537,24 +534,20 @@ class LocalisationCache { * @return array Array with a 'messages' key, or empty array if the file doesn't exist */ public function readJSONFile( $fileName ) { - wfProfileIn( __METHOD__ ); if ( !is_readable( $fileName ) ) { - wfProfileOut( __METHOD__ ); return array(); } $json = file_get_contents( $fileName ); if ( $json === false ) { - wfProfileOut( __METHOD__ ); return array(); } $data = FormatJson::decode( $json, true ); if ( $data === null ) { - wfProfileOut( __METHOD__ ); throw new MWException( __METHOD__ . ": Invalid JSON file: $fileName" ); } @@ -566,8 +559,6 @@ class LocalisationCache { } } - wfProfileOut( __METHOD__ ); - // The JSON format only supports messages, none of the other variables, so wrap the data return array( 'messages' => $data ); } @@ -650,10 +641,16 @@ class LocalisationCache { * rules, and save the compiled rules in a process-local cache. * * @param string $fileName + * @throws MWException */ protected function loadPluralFile( $fileName ) { + // Use file_get_contents instead of DOMDocument::load (T58439) + $xml = file_get_contents( $fileName ); + if ( !$xml ) { + throw new MWException( "Unable to read plurals file $fileName" ); + } $doc = new DOMDocument; - $doc->load( $fileName ); + $doc->loadXML( $xml ); $rulesets = $doc->getElementsByTagName( "pluralRules" ); foreach ( $rulesets as $ruleset ) { $codes = $ruleset->getAttribute( 'locales' ); @@ -687,7 +684,6 @@ class LocalisationCache { */ protected function readSourceFilesAndRegisterDeps( $code, &$deps ) { global $IP; - wfProfileIn( __METHOD__ ); // This reads in the PHP i18n file with non-messages l10n data $fileName = Language::getMessagesFileName( $code ); @@ -708,8 +704,6 @@ class LocalisationCache { $deps['plurals'] = new FileDependency( "$IP/languages/data/plurals.xml" ); $deps['plurals-mw'] = new FileDependency( "$IP/languages/data/plurals-mediawiki.xml" ); - wfProfileOut( __METHOD__ ); - return $data; } @@ -789,6 +783,22 @@ class LocalisationCache { return $used; } + /** + * Gets the combined list of messages dirs from + * core and extensions + * + * @since 1.25 + * @return array + */ + public function getMessagesDirs() { + global $wgMessagesDirs, $IP; + return array( + 'core' => "$IP/languages/i18n", + 'api' => "$IP/includes/api/i18n", + 'oojs-ui' => "$IP/resources/lib/oojs-ui/i18n", + ) + $wgMessagesDirs; + } + /** * Load localisation data for a given language for both core and extensions * and save it to the persistent cache store and the process cache @@ -796,11 +806,9 @@ class LocalisationCache { * @throws MWException */ public function recache( $code ) { - global $wgExtensionMessagesFiles, $wgMessagesDirs; - wfProfileIn( __METHOD__ ); + global $wgExtensionMessagesFiles; if ( !$code ) { - wfProfileOut( __METHOD__ ); throw new MWException( "Invalid language code requested" ); } $this->recachedLangs[$code] = true; @@ -843,15 +851,14 @@ class LocalisationCache { } $codeSequence = array_merge( array( $code ), $coreData['fallbackSequence'] ); - - wfProfileIn( __METHOD__ . '-fallbacks' ); + $messageDirs = $this->getMessagesDirs(); # Load non-JSON localisation data for extensions $extensionData = array_combine( $codeSequence, array_fill( 0, count( $codeSequence ), $initialData ) ); foreach ( $wgExtensionMessagesFiles as $extension => $fileName ) { - if ( isset( $wgMessagesDirs[$extension] ) ) { + if ( isset( $messageDirs[$extension] ) ) { # This extension has JSON message data; skip the PHP shim continue; } @@ -879,7 +886,7 @@ class LocalisationCache { $csData = $initialData; # Load core messages and the extension localisations. - foreach ( $wgMessagesDirs as $dirs ) { + foreach ( $messageDirs as $dirs ) { foreach ( (array)$dirs as $dir ) { $fileName = "$dir/$csCode.json"; $data = $this->readJSONFile( $fileName ); @@ -924,7 +931,7 @@ class LocalisationCache { # Allow extensions an opportunity to adjust the data for this # fallback - wfRunHooks( 'LocalisationCacheRecacheFallback', array( $this, $csCode, &$csData ) ); + Hooks::run( 'LocalisationCacheRecacheFallback', array( $this, $csCode, &$csData ) ); # Merge the data for this fallback into the final array if ( $csCode === $code ) { @@ -942,10 +949,9 @@ class LocalisationCache { } } - wfProfileOut( __METHOD__ . '-fallbacks' ); - # Add cache dependencies for any referenced globals $deps['wgExtensionMessagesFiles'] = new GlobalDependency( 'wgExtensionMessagesFiles' ); + // $wgMessagesDirs is used in LocalisationCache::getMessagesDirs() $deps['wgMessagesDirs'] = new GlobalDependency( 'wgMessagesDirs' ); $deps['version'] = new ConstantDependency( 'LocalisationCache::VERSION' ); @@ -981,10 +987,9 @@ class LocalisationCache { } # Run hooks $purgeBlobs = true; - wfRunHooks( 'LocalisationCacheRecache', array( $this, $code, &$allData, &$purgeBlobs ) ); + Hooks::run( 'LocalisationCacheRecache', array( $this, $code, &$allData, &$purgeBlobs ) ); if ( is_null( $allData['namespaceNames'] ) ) { - wfProfileOut( __METHOD__ ); throw new MWException( __METHOD__ . ': Localisation data failed sanity check! ' . 'Check that your languages/messages/MessagesEn.php file is intact.' ); } @@ -999,7 +1004,6 @@ class LocalisationCache { } # Save to the persistent cache - wfProfileIn( __METHOD__ . '-write' ); $this->store->startWrite( $code ); foreach ( $allData as $key => $value ) { if ( in_array( $key, self::$splitKeys ) ) { @@ -1011,16 +1015,15 @@ class LocalisationCache { } } $this->store->finishWrite(); - wfProfileOut( __METHOD__ . '-write' ); # Clear out the MessageBlobStore # HACK: If using a null (i.e. disabled) storage backend, we # can't write to the MessageBlobStore either if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) { - MessageBlobStore::getInstance()->clear(); + $blobStore = new MessageBlobStore(); + $blobStore->clear(); } - wfProfileOut( __METHOD__ ); } /** diff --git a/includes/cache/MapCacheLRU.php b/includes/cache/MapCacheLRU.php deleted file mode 100644 index 95e3af76..00000000 --- a/includes/cache/MapCacheLRU.php +++ /dev/null @@ -1,123 +0,0 @@ - value) - - protected $maxCacheKeys; // integer; max entries - - /** - * @param int $maxKeys Maximum number of entries allowed (min 1). - * @throws MWException When $maxCacheKeys is not an int or =< 0. - */ - public function __construct( $maxKeys ) { - if ( !is_int( $maxKeys ) || $maxKeys < 1 ) { - throw new MWException( __METHOD__ . " must be given an integer and >= 1" ); - } - $this->maxCacheKeys = $maxKeys; - } - - /** - * Set a key/value pair. - * This will prune the cache if it gets too large based on LRU. - * If the item is already set, it will be pushed to the top of the cache. - * - * @param string $key - * @param mixed $value - * @return void - */ - public function set( $key, $value ) { - if ( array_key_exists( $key, $this->cache ) ) { - $this->ping( $key ); // push to top - } elseif ( count( $this->cache ) >= $this->maxCacheKeys ) { - reset( $this->cache ); - $evictKey = key( $this->cache ); - unset( $this->cache[$evictKey] ); - } - $this->cache[$key] = $value; - } - - /** - * Check if a key exists - * - * @param string $key - * @return bool - */ - public function has( $key ) { - return array_key_exists( $key, $this->cache ); - } - - /** - * Get the value for a key. - * This returns null if the key is not set. - * If the item is already set, it will be pushed to the top of the cache. - * - * @param string $key - * @return mixed - */ - public function get( $key ) { - if ( array_key_exists( $key, $this->cache ) ) { - $this->ping( $key ); // push to top - return $this->cache[$key]; - } else { - return null; - } - } - - /** - * Clear one or several cache entries, or all cache entries - * - * @param string|array $keys - * @return void - */ - public function clear( $keys = null ) { - if ( $keys === null ) { - $this->cache = array(); - } else { - foreach ( (array)$keys as $key ) { - unset( $this->cache[$key] ); - } - } - } - - /** - * Push an entry to the top of the cache - * - * @param string $key - */ - protected function ping( $key ) { - $item = $this->cache[$key]; - unset( $this->cache[$key] ); - $this->cache[$key] = $item; - } -} diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index 1ef7cc58..a55e25a3 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -72,7 +72,7 @@ class MessageCache { protected $mExpiry; /** - * Message cache has it's own parser which it uses to transform + * Message cache has its own parser which it uses to transform * messages. */ protected $mParserOptions, $mParser; @@ -266,7 +266,6 @@ class MessageCache { } # Loading code starts - wfProfileIn( __METHOD__ ); $success = false; # Keep track of success $staleCache = false; # a cache array with expired data, or false if none has been loaded $where = array(); # Debug info, delayed to avoid spamming debug log too much @@ -276,7 +275,6 @@ class MessageCache { # Hash of the contents is stored in memcache, to detect if local cache goes # out of date (e.g. due to replace() on some other server) if ( $wgUseLocalMessageCache ) { - wfProfileIn( __METHOD__ . '-fromlocal' ); $hash = $this->mMemc->get( wfMemcKey( 'messages', $code, 'hash' ) ); if ( $hash ) { @@ -292,7 +290,6 @@ class MessageCache { $this->mCache[$code] = $cache; } } - wfProfileOut( __METHOD__ . '-fromlocal' ); } if ( !$success ) { @@ -300,7 +297,6 @@ class MessageCache { # the lock can't be acquired, wait for the other thread to finish # and then try the global cache a second time. for ( $failedAttempts = 0; $failedAttempts < 2; $failedAttempts++ ) { - wfProfileIn( __METHOD__ . '-fromcache' ); $cache = $this->mMemc->get( $cacheKey ); if ( !$cache ) { $where[] = 'global cache is empty'; @@ -314,8 +310,6 @@ class MessageCache { $success = true; } - wfProfileOut( __METHOD__ . '-fromcache' ); - if ( $success ) { # Done, no need to retry break; @@ -422,8 +416,7 @@ class MessageCache { $this->mLoadedLanguages[$code] = true; } $info = implode( ', ', $where ); - wfDebug( __METHOD__ . ": Loading $code... $info\n" ); - wfProfileOut( __METHOD__ ); + wfDebugLog( 'MessageCache', __METHOD__ . ": Loading $code... $info\n" ); return $success; } @@ -437,7 +430,6 @@ class MessageCache { * @return array Loaded messages for storing in caches. */ function loadFromDB( $code ) { - wfProfileIn( __METHOD__ ); global $wgMaxMsgCacheEntrySize, $wgLanguageCode, $wgAdaptiveMessageCache; $dbr = wfGetDB( DB_SLAVE ); $cache = array(); @@ -511,7 +503,6 @@ class MessageCache { $cache['VERSION'] = MSG_CACHE_VERSION; $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry ); - wfProfileOut( __METHOD__ ); return $cache; } @@ -524,10 +515,8 @@ class MessageCache { */ public function replace( $title, $text ) { global $wgMaxMsgCacheEntrySize; - wfProfileIn( __METHOD__ ); if ( $this->mDisable ) { - wfProfileOut( __METHOD__ ); return; } @@ -573,11 +562,11 @@ class MessageCache { // Update the message in the message blob store global $wgContLang; - MessageBlobStore::getInstance()->updateMessage( $wgContLang->lcfirst( $msg ) ); + $blobStore = new MessageBlobStore(); + $blobStore->updateMessage( $wgContLang->lcfirst( $msg ) ); - wfRunHooks( 'MessageCacheReplace', array( $title, $text ) ); + Hooks::run( 'MessageCacheReplace', array( $title, $text ) ); - wfProfileOut( __METHOD__ ); } /** @@ -610,7 +599,6 @@ class MessageCache { * @return bool */ protected function saveToCaches( $cache, $dest, $code = false ) { - wfProfileIn( __METHOD__ ); global $wgUseLocalMessageCache; $cacheKey = wfMemcKey( 'messages', $code ); @@ -629,8 +617,6 @@ class MessageCache { $this->saveToLocal( $serialized, $hash, $code ); } - wfProfileOut( __METHOD__ ); - return $success; } @@ -708,8 +694,6 @@ class MessageCache { function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) { global $wgContLang; - $section = new ProfileSection( __METHOD__ ); - if ( is_int( $key ) ) { // Fix numerical strings that somehow become ints // on their way here @@ -736,7 +720,7 @@ class MessageCache { $lckey = $wgContLang->lcfirst( $lckey ); } - wfRunHooks( 'MessageCache::get', array( &$lckey ) ); + Hooks::run( 'MessageCache::get', array( &$lckey ) ); if ( ord( $lckey ) < 128 ) { $uckey = ucfirst( $lckey ); @@ -909,7 +893,7 @@ class MessageCache { } else { // XXX: This is not cached in process cache, should it? $message = false; - wfRunHooks( 'MessagesPreLoad', array( $title, &$message ) ); + Hooks::run( 'MessagesPreLoad', array( $title, &$message ) ); if ( $message !== false ) { return $message; } @@ -1056,24 +1040,22 @@ class MessageCache { $popts->setInterfaceMessage( $interface ); $popts->setTargetLanguage( $language ); - wfProfileIn( __METHOD__ ); if ( !$title || !$title instanceof Title ) { global $wgTitle; + wfDebugLog( 'GlobalTitleFail', __METHOD__ . ' called by ' . wfGetAllCallers( 5 ) . ' with no title set.' ); $title = $wgTitle; } // Sometimes $wgTitle isn't set either... if ( !$title ) { # It's not uncommon having a null $wgTitle in scripts. See r80898 # Create a ghost title in such case - $title = Title::newFromText( 'Dwimmerlaik' ); + $title = Title::makeTitle( NS_SPECIAL, 'Badtitle/title not set in ' . __METHOD__ ); } $this->mInParser = true; $res = $parser->parse( $text, $title, $popts, $linestart ); $this->mInParser = false; - wfProfileOut( __METHOD__ ); - return $res; } diff --git a/includes/cache/ResourceFileCache.php b/includes/cache/ResourceFileCache.php index 55da52c5..6d26a2d5 100644 --- a/includes/cache/ResourceFileCache.php +++ b/includes/cache/ResourceFileCache.php @@ -40,7 +40,9 @@ class ResourceFileCache extends FileCacheBase { public static function newFromContext( ResourceLoaderContext $context ) { $cache = new self(); - if ( $context->getOnly() === 'styles' ) { + if ( $context->getImage() ) { + $cache->mType = 'image'; + } elseif ( $context->getOnly() === 'styles' ) { $cache->mType = 'css'; } else { $cache->mType = 'js'; @@ -69,7 +71,8 @@ class ResourceFileCache extends FileCacheBase { // Get all query values $queryVals = $context->getRequest()->getValues(); foreach ( $queryVals as $query => $val ) { - if ( $query === 'modules' || $query === 'version' || $query === '*' ) { + if ( in_array( $query, array( 'modules', 'image', 'variant', 'version', '*' ) ) ) { + // Use file cache regardless of the value of this parameter continue; // note: &* added as IE fix } elseif ( $query === 'skin' && $val === $wgDefaultSkin ) { continue; @@ -79,6 +82,8 @@ class ResourceFileCache extends FileCacheBase { continue; } elseif ( $query === 'debug' && $val === 'false' ) { continue; + } elseif ( $query === 'format' && $val === 'rasterized' ) { + continue; } return false; diff --git a/includes/cache/UserCache.php b/includes/cache/UserCache.php index 7f36f5a6..8a42489c 100644 --- a/includes/cache/UserCache.php +++ b/includes/cache/UserCache.php @@ -80,7 +80,6 @@ class UserCache { * @param string $caller The calling method */ public function doQuery( array $userIds, $options = array(), $caller = '' ) { - wfProfileIn( __METHOD__ ); $usersToCheck = array(); $usersToQuery = array(); @@ -134,7 +133,6 @@ class UserCache { } $lb->execute(); - wfProfileOut( __METHOD__ ); } /** diff --git a/includes/cache/bloom/BloomCache.php b/includes/cache/bloom/BloomCache.php deleted file mode 100644 index 236db954..00000000 --- a/includes/cache/bloom/BloomCache.php +++ /dev/null @@ -1,323 +0,0 @@ - BloomCache) */ - protected static $instances = array(); - - /** - * @param string $id - * @return BloomCache - */ - final public static function get( $id ) { - global $wgBloomFilterStores; - - if ( !isset( self::$instances[$id] ) ) { - if ( isset( $wgBloomFilterStores[$id] ) ) { - $class = $wgBloomFilterStores[$id]['class']; - self::$instances[$id] = new $class( $wgBloomFilterStores[$id] ); - } else { - wfDebug( "No bloom filter store '$id'; using EmptyBloomCache." ); - return new EmptyBloomCache( array() ); - } - } - - return self::$instances[$id]; - } - - /** - * Create a new bloom cache instance from configuration. - * This should only be called from within BloomCache. - * - * @param array $config Parameters include: - * - cacheID : Prefix to all bloom filter names that is unique to this cache. - * It should only consist of alphanumberic, '-', and '_' characters. - * This ID is what avoids collisions if multiple logical caches - * use the same storage system, so this should be set carefully. - */ - public function __construct( array $config ) { - $this->cacheID = $config['cacheId']; - if ( !preg_match( '!^[a-zA-Z0-9-_]{1,32}$!', $this->cacheID ) ) { - throw new MWException( "Cache ID '{$this->cacheID}' is invalid." ); - } - } - - /** - * Check if a member is set in the bloom filter - * - * A member being set means that it *might* have been added. - * A member not being set means it *could not* have been added. - * - * This abstracts over isHit() to deal with filter updates and readiness. - * A class must exist with the name BloomFilter and a static public - * mergeAndCheck() method. The later takes the following arguments: - * (BloomCache $bcache, $domain, $virtualKey, array $status) - * The method should return a bool indicating whether to use the filter. - * - * The 'shared' bloom key must be used for any updates and will be used - * for the membership check if the method returns true. Since the key is shared, - * the method should never use delete(). The filter cannot be used in cases where - * membership in the filter needs to be taken away. In such cases, code *cannot* - * use this method - instead, it can directly use the other BloomCache methods - * to manage custom filters with their own keys (e.g. not 'shared'). - * - * @param string $domain - * @param string $type - * @param string $member - * @return bool True if set, false if not (also returns true on error) - */ - final public function check( $domain, $type, $member ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - if ( method_exists( "BloomFilter{$type}", 'mergeAndCheck' ) ) { - try { - $virtualKey = "$domain:$type"; - - $status = $this->getStatus( $virtualKey ); - if ( $status == false ) { - wfDebug( "Could not query virtual bloom filter '$virtualKey'." ); - return null; - } - - $useFilter = call_user_func_array( - array( "BloomFilter{$type}", 'mergeAndCheck' ), - array( $this, $domain, $virtualKey, $status ) - ); - - if ( $useFilter ) { - return ( $this->isHit( 'shared', "$virtualKey:$member" ) !== false ); - } - } catch ( MWException $e ) { - MWExceptionHandler::logException( $e ); - return true; - } - } - - return true; - } - - /** - * Inform the bloom filter of a new member in order to keep it up to date - * - * @param string $domain - * @param string $type - * @param string|array $members - * @return bool Success - */ - final public function insert( $domain, $type, $members ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - if ( method_exists( "BloomFilter{$type}", 'mergeAndCheck' ) ) { - try { - $virtualKey = "$domain:$type"; - $prefixedMembers = array(); - foreach ( (array)$members as $member ) { - $prefixedMembers[] = "$virtualKey:$member"; - } - - return $this->add( 'shared', $prefixedMembers ); - } catch ( MWException $e ) { - MWExceptionHandler::logException( $e ); - return false; - } - } - - return true; - } - - /** - * Create a new bloom filter at $key (if one does not exist yet) - * - * @param string $key - * @param integer $size Bit length [default: 1000000] - * @param float $precision [default: .001] - * @return bool Success - */ - final public function init( $key, $size = 1000000, $precision = .001 ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - return $this->doInit( "{$this->cacheID}:$key", $size, min( .1, $precision ) ); - } - - /** - * Add a member to the bloom filter at $key - * - * @param string $key - * @param string|array $members - * @return bool Success - */ - final public function add( $key, $members ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - return $this->doAdd( "{$this->cacheID}:$key", (array)$members ); - } - - /** - * Check if a member is set in the bloom filter. - * - * A member being set means that it *might* have been added. - * A member not being set means it *could not* have been added. - * - * If this returns true, then the caller usually should do the - * expensive check (whatever that may be). It can be avoided otherwise. - * - * @param string $key - * @param string $member - * @return bool|null True if set, false if not, null on error - */ - final public function isHit( $key, $member ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - return $this->doIsHit( "{$this->cacheID}:$key", $member ); - } - - /** - * Destroy a bloom filter at $key - * - * @param string $key - * @return bool Success - */ - final public function delete( $key ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - return $this->doDelete( "{$this->cacheID}:$key" ); - } - - /** - * Set the status map of the virtual bloom filter at $key - * - * @param string $virtualKey - * @param array $values Map including some of (lastID, asOfTime, epoch) - * @return bool Success - */ - final public function setStatus( $virtualKey, array $values ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - return $this->doSetStatus( "{$this->cacheID}:$virtualKey", $values ); - } - - /** - * Get the status map of the virtual bloom filter at $key - * - * The map includes: - * - lastID : the highest ID of the items merged in - * - asOfTime : UNIX timestamp that the filter is up-to-date as of - * - epoch : UNIX timestamp that filter started being populated - * Unset fields will have a null value. - * - * @param string $virtualKey - * @return array|bool False on failure - */ - final public function getStatus( $virtualKey ) { - $section = new ProfileSection( get_class( $this ) . '::' . __FUNCTION__ ); - - return $this->doGetStatus( "{$this->cacheID}:$virtualKey" ); - } - - /** - * Get an exclusive lock on a filter for updates - * - * @param string $virtualKey - * @return ScopedCallback|ScopedLock|null Returns null if acquisition failed - */ - public function getScopedLock( $virtualKey ) { - return null; - } - - /** - * @param string $key - * @param integer $size Bit length - * @param float $precision - * @return bool Success - */ - abstract protected function doInit( $key, $size, $precision ); - - /** - * @param string $key - * @param array $members - * @return bool Success - */ - abstract protected function doAdd( $key, array $members ); - - /** - * @param string $key - * @param string $member - * @return bool|null - */ - abstract protected function doIsHit( $key, $member ); - - /** - * @param string $key - * @return bool Success - */ - abstract protected function doDelete( $key ); - - /** - * @param string $virtualKey - * @param array $values - * @return bool Success - */ - abstract protected function doSetStatus( $virtualKey, array $values ); - - /** - * @param string $key - * @return array|bool - */ - abstract protected function doGetStatus( $key ); -} - -class EmptyBloomCache extends BloomCache { - public function __construct( array $config ) { - parent::__construct( array( 'cacheId' => 'none' ) ); - } - - protected function doInit( $key, $size, $precision ) { - return true; - } - - protected function doAdd( $key, array $members ) { - return true; - } - - protected function doIsHit( $key, $member ) { - return true; - } - - protected function doDelete( $key ) { - return true; - } - - protected function doSetStatus( $virtualKey, array $values ) { - return true; - } - - protected function doGetStatus( $virtualKey ) { - return array( 'lastID' => null, 'asOfTime' => null, 'epoch' => null ) ; - } -} diff --git a/includes/cache/bloom/BloomCacheRedis.php b/includes/cache/bloom/BloomCacheRedis.php deleted file mode 100644 index 212e5e8b..00000000 --- a/includes/cache/bloom/BloomCacheRedis.php +++ /dev/null @@ -1,370 +0,0 @@ -= 2.6 and should have volatile-lru or volatile-ttl - * if there is any eviction policy. It should not be allkeys-* in any case. Also, - * this can be used in a simple master/slave setup or with Redis Sentinel preferably. - * - * Some bits are based on https://github.com/ErikDubbelboer/redis-lua-scaling-bloom-filter - * but are simplified to use a single filter instead of up to 32 filters. - * - * @since 1.24 - */ -class BloomCacheRedis extends BloomCache { - /** @var RedisConnectionPool */ - protected $redisPool; - /** @var RedisLockManager */ - protected $lockMgr; - /** @var array */ - protected $servers; - /** @var integer Federate each filter into this many redis bitfield objects */ - protected $segments = 128; - - /** - * @params include: - * - redisServers : list of servers (address:) (the first is the master) - * - redisConf : additional redis configuration - * - * @param array $config - */ - public function __construct( array $config ) { - parent::__construct( $config ); - - $redisConf = $config['redisConfig']; - $redisConf['serializer'] = 'none'; // manage that in this class - $this->redisPool = RedisConnectionPool::singleton( $redisConf ); - $this->servers = $config['redisServers']; - $this->lockMgr = new RedisLockManager( array( - 'lockServers' => array( 'srv1' => $this->servers[0] ), - 'srvsByBucket' => array( 0 => array( 'srv1' ) ), - 'redisConfig' => $config['redisConfig'] - ) ); - } - - protected function doInit( $key, $size, $precision ) { - $conn = $this->getConnection( 'master' ); - if ( !$conn ) { - return false; - } - - // 80000000 items at p = .001 take up 500MB and fit into one value. - // Do not hit the 512MB redis value limit by reducing the demands. - $size = min( $size, 80000000 * $this->segments ); - $precision = max( round( $precision, 3 ), .001 ); - $epoch = microtime( true ); - - static $script = -<<script( 'load', $script ); - $conn->multi( Redis::MULTI ); - for ( $i = 0; $i < $this->segments; ++$i ) { - $res = $conn->luaEval( $script, - array( - "$key:$i:bloom-metadata", # KEYS[1] - "$key:$i:bloom-data", # KEYS[2] - ceil( $size / $this->segments ), # ARGV[1] - $precision, # ARGV[2] - $epoch # ARGV[3] - ), - 2 # number of first argument(s) that are keys - ); - } - $results = $conn->exec(); - $res = $results && !in_array( false, $results, true ); - } catch ( RedisException $e ) { - $this->handleException( $conn, $e ); - } - - return ( $res !== false ); - } - - protected function doAdd( $key, array $members ) { - $conn = $this->getConnection( 'master' ); - if ( !$conn ) { - return false; - } - - static $script = -<<script( 'load', $script ); - $conn->multi( Redis::PIPELINE ); - foreach ( $members as $member ) { - $i = $this->getSegment( $member ); - $conn->luaEval( $script, - array( - "$key:$i:bloom-metadata", # KEYS[1], - "$key:$i:bloom-data", # KEYS[2] - $member # ARGV[1] - ), - 2 # number of first argument(s) that are keys - ); - } - $results = $conn->exec(); - $res = $results && !in_array( false, $results, true ); - } catch ( RedisException $e ) { - $this->handleException( $conn, $e ); - } - - if ( $res === false ) { - wfDebug( "Could not add to the '$key' bloom filter; it may be missing." ); - } - - return ( $res !== false ); - } - - protected function doSetStatus( $virtualKey, array $values ) { - $conn = $this->getConnection( 'master' ); - if ( !$conn ) { - return null; - } - - $res = false; - try { - $res = $conn->hMSet( "$virtualKey:filter-metadata", $values ); - } catch ( RedisException $e ) { - $this->handleException( $conn, $e ); - } - - return ( $res !== false ); - } - - protected function doGetStatus( $virtualKey ) { - $conn = $this->getConnection( 'slave' ); - if ( !$conn ) { - return false; - } - - $res = false; - try { - $res = $conn->hGetAll( "$virtualKey:filter-metadata" ); - } catch ( RedisException $e ) { - $this->handleException( $conn, $e ); - } - - if ( is_array( $res ) ) { - $res['lastID'] = isset( $res['lastID'] ) ? $res['lastID'] : null; - $res['asOfTime'] = isset( $res['asOfTime'] ) ? $res['asOfTime'] : null; - $res['epoch'] = isset( $res['epoch'] ) ? $res['epoch'] : null; - } - - return $res; - } - - protected function doIsHit( $key, $member ) { - $conn = $this->getConnection( 'slave' ); - if ( !$conn ) { - return null; - } - - static $script = -<<getSegment( $member ); - $res = $conn->luaEval( $script, - array( - "$key:$i:bloom-metadata", # KEYS[1], - "$key:$i:bloom-data", # KEYS[2] - $member # ARGV[1] - ), - 2 # number of first argument(s) that are keys - ); - } catch ( RedisException $e ) { - $this->handleException( $conn, $e ); - } - - return is_int( $res ) ? (bool)$res : null; - } - - protected function doDelete( $key ) { - $conn = $this->getConnection( 'master' ); - if ( !$conn ) { - return false; - } - - $res = false; - try { - $keys = array(); - for ( $i = 0; $i < $this->segments; ++$i ) { - $keys[] = "$key:$i:bloom-metadata"; - $keys[] = "$key:$i:bloom-data"; - } - $res = $conn->delete( $keys ); - } catch ( RedisException $e ) { - $this->handleException( $conn, $e ); - } - - return ( $res !== false ); - } - - public function getScopedLock( $virtualKey ) { - $status = Status::newGood(); - return ScopedLock::factory( $this->lockMgr, - array( $virtualKey ), LockManager::LOCK_EX, $status ); - } - - /** - * @param string $member - * @return integer - */ - protected function getSegment( $member ) { - return hexdec( substr( md5( $member ), 0, 2 ) ) % $this->segments; - } - - /** - * $param string $to (master/slave) - * @return RedisConnRef|bool Returns false on failure - */ - protected function getConnection( $to ) { - if ( $to === 'master' ) { - $conn = $this->redisPool->getConnection( $this->servers[0] ); - } else { - static $lastServer = null; - - $conn = false; - if ( $lastServer ) { - $conn = $this->redisPool->getConnection( $lastServer ); - if ( $conn ) { - return $conn; // reuse connection - } - } - $servers = $this->servers; - $attempts = min( 3, count( $servers ) ); - for ( $i = 1; $i <= $attempts; ++$i ) { - $index = mt_rand( 0, count( $servers ) - 1 ); - $conn = $this->redisPool->getConnection( $servers[$index] ); - if ( $conn ) { - $lastServer = $servers[$index]; - return $conn; - } - unset( $servers[$index] ); // skip next time - } - } - - return $conn; - } - - /** - * @param RedisConnRef $conn - * @param Exception $e - */ - protected function handleException( RedisConnRef $conn, $e ) { - $this->redisPool->handleError( $conn, $e ); - } -} diff --git a/includes/cache/bloom/BloomFilters.php b/includes/cache/bloom/BloomFilters.php deleted file mode 100644 index 9b710d79..00000000 --- a/includes/cache/bloom/BloomFilters.php +++ /dev/null @@ -1,79 +0,0 @@ -getScopedLock( $virtualKey ) - : false; - - if ( $scopedLock ) { - $updates = self::merge( $bcache, $domain, $virtualKey, $status ); - if ( isset( $updates['asOfTime'] ) ) { - $age = ( microtime( true ) - $updates['asOfTime'] ); - } - } - - return ( $age < 30 ); - } - - public static function merge( - BloomCache $bcache, $domain, $virtualKey, array $status - ) { - $limit = 1000; - $dbr = wfGetDB( DB_SLAVE, array(), $domain ); - $res = $dbr->select( 'logging', - array( 'log_namespace', 'log_title', 'log_id', 'log_timestamp' ), - array( 'log_id > ' . $dbr->addQuotes( (int)$status['lastID'] ) ), - __METHOD__, - array( 'ORDER BY' => 'log_id', 'LIMIT' => $limit ) - ); - - $updates = array(); - if ( $res->numRows() > 0 ) { - $members = array(); - foreach ( $res as $row ) { - $members[] = "$virtualKey:{$row->log_namespace}:{$row->log_title}"; - } - $lastID = $row->log_id; - $lastTime = $row->log_timestamp; - if ( !$bcache->add( 'shared', $members ) ) { - return false; - } - $updates['lastID'] = $lastID; - $updates['asOfTime'] = wfTimestamp( TS_UNIX, $lastTime ); - } else { - $updates['asOfTime'] = microtime( true ); - } - - $updates['epoch'] = $status['epoch'] ?: microtime( true ); - - $bcache->setStatus( $virtualKey, $updates ); - - return $updates; - } -} -- cgit v1.2.3-54-g00ecf