From 8251479984cf2fd160fe226c6932d8c0ce815035 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 17 Nov 2013 21:36:27 +0100 Subject: [PATCH] Update formatting Change-Id: I9aa56cbe0989d6f302ee0f47c4a6154101f73e90 --- includes/cache/BacklinkCache.php | 14 +++++++--- includes/cache/CacheDependency.php | 12 ++++++--- includes/cache/FileCacheBase.php | 7 +++++ includes/cache/GenderCache.php | 8 ++++-- includes/cache/HTMLFileCache.php | 4 +++ includes/cache/LinkBatch.php | 5 ++++ includes/cache/LinkCache.php | 5 ++++ includes/cache/LocalisationCache.php | 39 +++++++++++++++++++++++----- includes/cache/MessageCache.php | 18 +++++++++++++ includes/cache/ProcessCacheLRU.php | 1 + includes/cache/ResourceFileCache.php | 3 +++ includes/cache/UserCache.php | 5 +++- 12 files changed, 106 insertions(+), 15 deletions(-) diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php index 4775b96a9c..dcd81918f5 100644 --- a/includes/cache/BacklinkCache.php +++ b/includes/cache/BacklinkCache.php @@ -108,6 +108,7 @@ class BacklinkCache { if ( !self::$cache->has( $dbKey, 'obj', 3600 ) ) { self::$cache->set( $dbKey, 'obj', new self( $title ) ); } + return self::$cache->get( $dbKey, 'obj' ); } @@ -149,6 +150,7 @@ class BacklinkCache { if ( !isset( $this->db ) ) { $this->db = wfGetDB( DB_SLAVE ); } + return $this->db; } @@ -179,8 +181,8 @@ class BacklinkCache { $fromField = $this->getPrefix( $table ) . '_from'; if ( !$startId && !$endId && is_infinite( $max ) - && isset( $this->fullResultCache[$table] ) ) - { + && isset( $this->fullResultCache[$table] ) + ) { wfDebug( __METHOD__ . ": got results from cache\n" ); $res = $this->fullResultCache[$table]; } else { @@ -204,7 +206,7 @@ class BacklinkCache { $res = $this->getDB()->select( $table, array( $this->getPrefix( $table ) . '_from AS page_id' ), - array_filter( $conds, function( $clause ) { // kind of janky + array_filter( $conds, function ( $clause ) { // kind of janky return !preg_match( '/(\b|=)page_id(\b|=)/', $clause ); } ), __METHOD__, @@ -230,6 +232,7 @@ class BacklinkCache { } wfProfileOut( __METHOD__ ); + return $res; } @@ -337,6 +340,7 @@ class BacklinkCache { // 1) try partition cache ... if ( isset( $this->partitionCache[$table] ) ) { $entry = reset( $this->partitionCache[$table] ); + return min( $max, $entry['numRows'] ); } @@ -385,6 +389,7 @@ class BacklinkCache { // 1) try partition cache ... if ( isset( $this->partitionCache[$table][$batchSize] ) ) { wfDebug( __METHOD__ . ": got from partition cache\n" ); + return $this->partitionCache[$table][$batchSize]['batches']; } @@ -395,6 +400,7 @@ class BacklinkCache { if ( isset( $this->fullResultCache[$table] ) ) { $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize ); wfDebug( __METHOD__ . ": got from full result cache\n" ); + return $cacheEntry['batches']; } @@ -410,6 +416,7 @@ class BacklinkCache { if ( is_array( $memcValue ) ) { $cacheEntry = $memcValue; wfDebug( __METHOD__ . ": got from memcached $memcKey\n" ); + return $cacheEntry['batches']; } @@ -444,6 +451,7 @@ class BacklinkCache { $wgMemc->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY ); wfDebug( __METHOD__ . ": got from database\n" ); + return $cacheEntry['batches']; } diff --git a/includes/cache/CacheDependency.php b/includes/cache/CacheDependency.php index 32bcdf7f4f..15b58b8cb8 100644 --- a/includes/cache/CacheDependency.php +++ b/includes/cache/CacheDependency.php @@ -110,8 +110,8 @@ class DependencyWrapper { * callback was defined. */ static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false, - $callbackParams = array(), $deps = array() ) - { + $callbackParams = array(), $deps = array() + ) { $obj = $cache->get( $key ); if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) { @@ -141,7 +141,8 @@ abstract class CacheDependency { /** * Hook to perform any expensive pre-serialize loading of dependency values. */ - function loadDependencyValues() { } + function loadDependencyValues() { + } } /** @@ -172,6 +173,7 @@ class FileDependency extends CacheDependency { */ function __sleep() { $this->loadDependencyValues(); + return array( 'filename', 'timestamp' ); } @@ -198,6 +200,7 @@ class FileDependency extends CacheDependency { } else { # Deleted wfDebug( "Dependency triggered: {$this->filename} deleted.\n" ); + return true; } } else { @@ -205,6 +208,7 @@ class FileDependency extends CacheDependency { if ( $lastmod > $this->timestamp ) { # Modified or created wfDebug( "Dependency triggered: {$this->filename} changed.\n" ); + return true; } else { # Not modified @@ -353,6 +357,7 @@ class TitleListDependency extends CacheDependency { $this->linkBatch = new LinkBatch; $this->linkBatch->setArray( $this->timestamps ); } + return $this->linkBatch; } @@ -407,6 +412,7 @@ class GlobalDependency extends CacheDependency { if ( !isset( $GLOBALS[$this->name] ) ) { return true; } + return $GLOBALS[$this->name] != $this->value; } } diff --git a/includes/cache/FileCacheBase.php b/includes/cache/FileCacheBase.php index d4bf5ee638..d5195c5a95 100644 --- a/includes/cache/FileCacheBase.php +++ b/includes/cache/FileCacheBase.php @@ -51,6 +51,7 @@ abstract class FileCacheBase { */ final protected function baseCacheDirectory() { global $wgFileCacheDirectory; + return $wgFileCacheDirectory; } @@ -91,6 +92,7 @@ abstract class FileCacheBase { if ( $this->mCached === null ) { $this->mCached = file_exists( $this->cachePath() ); } + return $this->mCached; } @@ -100,6 +102,7 @@ abstract class FileCacheBase { */ public function cacheTimestamp() { $timestamp = filemtime( $this->cachePath() ); + return ( $timestamp !== false ) ? wfTimestamp( TS_MW, $timestamp ) : false; @@ -140,6 +143,7 @@ abstract class FileCacheBase { public function fetchText() { if ( $this->useGzip() ) { $fh = gzopen( $this->cachePath(), 'rb' ); + return stream_get_contents( $fh ); } else { return file_get_contents( $this->cachePath() ); @@ -165,10 +169,12 @@ abstract class FileCacheBase { if ( !file_put_contents( $this->cachePath(), $text, LOCK_EX ) ) { wfDebug( __METHOD__ . "() failed saving " . $this->cachePath() . "\n" ); $this->mCached = null; + return false; } $this->mCached = true; + return $text; } @@ -262,6 +268,7 @@ abstract class FileCacheBase { */ public function getMissesRecent() { global $wgMemc; + return self::MISS_FACTOR * $wgMemc->get( $this->cacheMissKey() ); } diff --git a/includes/cache/GenderCache.php b/includes/cache/GenderCache.php index a933527a88..285675da17 100644 --- a/includes/cache/GenderCache.php +++ b/includes/cache/GenderCache.php @@ -41,10 +41,12 @@ class GenderCache { if ( $that === null ) { $that = new self(); } + return $that; } - protected function __construct() {} + protected function __construct() { + } /** * Returns the default gender option in this wiki. @@ -54,6 +56,7 @@ class GenderCache { if ( $this->default === null ) { $this->default = User::getDefaultOption( 'gender' ); } + return $this->default; } @@ -77,8 +80,8 @@ class GenderCache { $this->misses++; wfDebug( __METHOD__ . ": too many misses, returning default onwards\n" ); } - return $this->getDefault(); + return $this->getDefault(); } else { $this->misses++; $this->doQuery( $username, $caller ); @@ -184,6 +187,7 @@ class GenderCache { if ( $indexSlash !== false ) { $username = substr( $username, 0, $indexSlash ); } + // normalize underscore/spaces return strtr( $username, '_', ' ' ); } diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index ab379116e5..26299958fa 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -94,6 +94,7 @@ class HTMLFileCache extends FileCacheBase { } if ( $wgShowIPinHeader || $wgDebugToolbar ) { wfDebug( "HTML file cache skipped. Either \$wgShowIPinHeader and/or \$wgDebugToolbar on\n" ); + return false; } @@ -109,6 +110,7 @@ class HTMLFileCache extends FileCacheBase { } elseif ( $query === 'maxage' || $query === 'smaxage' ) { continue; } + return false; } $user = $context->getUser(); @@ -116,6 +118,7 @@ class HTMLFileCache extends FileCacheBase { // and extensions for auto-detecting user language. $ulang = $context->getLanguage()->getCode(); $clang = $wgContLang->getCode(); + // Check that there are no other sources of variation return !$user->getId() && !$user->getNewtalk() && $ulang == $clang; } @@ -185,6 +188,7 @@ class HTMLFileCache extends FileCacheBase { // @todo Ugly wfClientAcceptsGzip() function - use context! if ( wfClientAcceptsGzip() ) { header( 'Content-Encoding: gzip' ); + return $compressed; } else { return $text; diff --git a/includes/cache/LinkBatch.php b/includes/cache/LinkBatch.php index 48b60aa978..7bb41ac135 100644 --- a/includes/cache/LinkBatch.php +++ b/includes/cache/LinkBatch.php @@ -117,6 +117,7 @@ class LinkBatch { */ public function execute() { $linkCache = LinkCache::singleton(); + return $this->executeInto( $linkCache ); } @@ -133,6 +134,7 @@ class LinkBatch { $this->doGenderQuery(); $ids = $this->addResultToCache( $cache, $res ); wfProfileOut( __METHOD__ ); + return $ids; } @@ -170,6 +172,7 @@ class LinkBatch { $ids[$title->getPrefixedDBkey()] = 0; } } + return $ids; } @@ -197,6 +200,7 @@ class LinkBatch { } $res = $dbr->select( $table, $fields, $conds, $caller ); wfProfileOut( __METHOD__ ); + return $res; } @@ -217,6 +221,7 @@ class LinkBatch { $genderCache = GenderCache::singleton(); $genderCache->doLinkBatch( $this->data, $this->caller ); + return true; } diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 6ac7e7abe4..31d79f4ee1 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -51,6 +51,7 @@ class LinkCache { return self::$instance; } self::$instance = new LinkCache; + return self::$instance; } @@ -218,16 +219,19 @@ class LinkCache { $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; } @@ -262,6 +266,7 @@ class LinkCache { } wfProfileOut( __METHOD__ ); + return $id; } diff --git a/includes/cache/LocalisationCache.php b/includes/cache/LocalisationCache.php index c5a153a88b..0b52cc4e9a 100644 --- a/includes/cache/LocalisationCache.php +++ b/includes/cache/LocalisationCache.php @@ -241,6 +241,7 @@ class LocalisationCache { self::$magicWordKeys ) ); } + return isset( $this->mergeableKeys[$key] ); } @@ -276,7 +277,8 @@ class LocalisationCache { */ public function getSubitem( $code, $key, $subkey ) { if ( !isset( $this->loadedSubitems[$code][$key][$subkey] ) && - !isset( $this->loadedItems[$code][$key] ) ) { + !isset( $this->loadedItems[$code][$key] ) + ) { wfProfileIn( __METHOD__ . '-load' ); $this->loadSubitem( $code, $key, $subkey ); wfProfileOut( __METHOD__ . '-load' ); @@ -331,6 +333,7 @@ class LocalisationCache { if ( isset( $this->shallowFallbacks[$code] ) ) { $this->loadItem( $this->shallowFallbacks[$code], $key ); + return; } @@ -358,6 +361,7 @@ class LocalisationCache { protected function loadSubitem( $code, $key, $subkey ) { if ( !in_array( $key, self::$splitKeys ) ) { $this->loadItem( $code, $key ); + return; } @@ -367,12 +371,14 @@ class LocalisationCache { // Check to see if initLanguage() loaded it for us if ( isset( $this->loadedItems[$code][$key] ) || - isset( $this->loadedSubitems[$code][$key][$subkey] ) ) { + isset( $this->loadedSubitems[$code][$key][$subkey] ) + ) { return; } if ( isset( $this->shallowFallbacks[$code] ) ) { $this->loadSubitem( $this->shallowFallbacks[$code], $key, $subkey ); + return; } @@ -391,6 +397,7 @@ class LocalisationCache { public function isExpired( $code ) { if ( $this->forceRecache && !isset( $this->recachedLangs[$code] ) ) { wfDebug( __METHOD__ . "($code): forced reload\n" ); + return true; } @@ -400,6 +407,7 @@ class LocalisationCache { // Different keys may expire separately, at least in LCStore_Accel if ( $deps === null || $keys === null || $preload === null ) { wfDebug( __METHOD__ . "($code): cache missing, need to make one\n" ); + return true; } @@ -411,6 +419,7 @@ class LocalisationCache { if ( !$dep instanceof CacheDependency || $dep->isExpired() ) { wfDebug( __METHOD__ . "($code): cache for $code expired due to " . get_class( $dep ) . "\n" ); + return true; } } @@ -433,6 +442,7 @@ class LocalisationCache { # If the code is of the wrong form for a Messages*.php file, do a shallow fallback if ( !Language::isValidBuiltInCode( $code ) ) { $this->initShallowFallback( $code, 'en' ); + return; } @@ -445,6 +455,7 @@ class LocalisationCache { } else { $this->initShallowFallback( $code, 'en' ); } + return; } @@ -458,6 +469,7 @@ class LocalisationCache { 'Please run maintenance/rebuildLocalisationCache.php.' ); } $this->initShallowFallback( $code, 'en' ); + return; } else { throw new MWException( 'Invalid or missing localisation cache.' ); @@ -511,6 +523,7 @@ class LocalisationCache { throw new MWException( __METHOD__ . ": Invalid file type: $_fileType" ); } wfProfileOut( __METHOD__ ); + return $data; } @@ -527,8 +540,10 @@ class LocalisationCache { $compiledRules = CLDRPluralRuleEvaluator::compile( $rules ); } catch ( CLDRPluralRuleError $e ) { wfDebugLog( 'l10n', $e->getMessage() . "\n" ); + return array(); } + return $compiledRules; } @@ -616,6 +631,7 @@ class LocalisationCache { $fileName = Language::getMessagesFileName( $code ); if ( !file_exists( $fileName ) ) { wfProfileOut( __METHOD__ ); + return false; } @@ -633,6 +649,7 @@ class LocalisationCache { $deps['plurals-mw'] = new FileDependency( "$IP/languages/data/plurals-mediawiki.xml" ); wfProfileOut( __METHOD__ ); + return $data; } @@ -747,7 +764,6 @@ class LocalisationCache { foreach ( $data as $key => $value ) { $this->mergeItem( $key, $coreData[$key], $value ); } - } # Fill in the fallback if it's not there already @@ -1016,6 +1032,7 @@ class LCStore_Accel implements LCStore { public function get( $code, $key ) { $k = wfMemcKey( 'l10n', $code, 'k', $key ); $r = $this->cache->get( $k ); + return $r === false ? null : $r; } @@ -1096,6 +1113,7 @@ class LCStore_DB implements LCStore { if ( $this->dbw->wasReadOnlyError() ) { $this->readOnly = true; $this->dbw->rollback( __METHOD__ ); + return; } else { throw $e; @@ -1187,6 +1205,7 @@ class LCStore_CDB implements LCStore { if ( $value === false ) { return null; } + return unserialize( $value ); } } @@ -1227,6 +1246,7 @@ class LCStore_CDB implements LCStore { if ( strval( $code ) === '' || strpos( $code, '/' ) !== false ) { throw new MWException( __METHOD__ . ": Invalid language \"$code\"" ); } + return "{$this->directory}/l10n_cache-$code.cdb"; } } @@ -1239,9 +1259,14 @@ class LCStore_Null implements LCStore { return null; } - public function startWrite( $code ) {} - public function finishWrite() {} - public function set( $key, $value ) {} + public function startWrite( $code ) { + } + + public function finishWrite() { + } + + public function set( $key, $value ) { + } } /** @@ -1301,6 +1326,7 @@ class LocalisationCache_BulkLoad extends LocalisationCache { public function getItem( $code, $key ) { unset( $this->mruLangs[$code] ); $this->mruLangs[$code] = true; + return parent::getItem( $code, $key ); } @@ -1313,6 +1339,7 @@ class LocalisationCache_BulkLoad extends LocalisationCache { public function getSubitem( $code, $key, $subkey ) { unset( $this->mruLangs[$code] ); $this->mruLangs[$code] = true; + return parent::getSubitem( $code, $key, $subkey ); } diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index a92c87f481..eff3ea7b6b 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -110,6 +110,7 @@ class MessageCache { $wgMsgCacheExpiry ); } + return self::$instance; } @@ -147,6 +148,7 @@ class MessageCache { $this->mParserOptions = new ParserOptions; $this->mParserOptions->setEditSection( false ); } + return $this->mParserOptions; } @@ -179,9 +181,11 @@ class MessageCache { $serialized .= fread( $file, 100000 ); } fclose( $file ); + return unserialize( $serialized ); } else { fclose( $file ); + return false; // Wrong hash } } @@ -201,6 +205,7 @@ class MessageCache { if ( !$file ) { wfDebug( "Unable to open local cache file for writing\n" ); + return; } @@ -253,6 +258,7 @@ class MessageCache { wfDebug( __METHOD__ . ": disabled\n" ); $shownDisabled = true; } + return true; } @@ -415,6 +421,7 @@ class MessageCache { $info = implode( ', ', $where ); wfDebug( __METHOD__ . ": Loading $code... $info\n" ); wfProfileOut( __METHOD__ ); + return $success; } @@ -502,6 +509,7 @@ class MessageCache { $cache['VERSION'] = MSG_CACHE_VERSION; $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry ); wfProfileOut( __METHOD__ ); + return $cache; } @@ -517,6 +525,7 @@ class MessageCache { if ( $this->mDisable ) { wfProfileOut( __METHOD__ ); + return; } @@ -584,6 +593,7 @@ class MessageCache { if ( wfTimestampNow() >= $cache['EXPIRY'] ) { return true; } + return false; } @@ -617,6 +627,7 @@ class MessageCache { } wfProfileOut( __METHOD__ ); + return $success; } @@ -897,11 +908,13 @@ class MessageCache { if ( $entry ) { if ( substr( $entry, 0, 1 ) === ' ' ) { $this->mCache[$code][$title] = $entry; + // The message exists, so make sure a string // is returned. return (string)substr( $entry, 1 ); } elseif ( $entry === '!NONEXISTENT' ) { $this->mCache[$code][$title] = '!NONEXISTENT'; + return false; } else { # Corrupt/obsolete entry, delete it @@ -983,6 +996,7 @@ class MessageCache { $this->mInParser = false; $popts->setUserLang( $userlang ); } + return $message; } @@ -1003,6 +1017,7 @@ class MessageCache { $this->mParser = clone $wgParser; } } + return $this->mParser; } @@ -1043,6 +1058,7 @@ class MessageCache { $this->mInParser = false; wfProfileOut( __METHOD__ ); + return $res; } @@ -1085,6 +1101,7 @@ class MessageCache { } $message = implode( '/', $pieces ); + return array( $message, $lang ); } @@ -1109,6 +1126,7 @@ class MessageCache { unset( $cache['EXPIRY'] ); // Remove any !NONEXISTENT keys $cache = array_diff( $cache, array( '!NONEXISTENT' ) ); + // Keys may appear with a capital first letter. lcfirst them. return array_map( array( $wgContLang, 'lcfirst' ), array_keys( $cache ) ); } diff --git a/includes/cache/ProcessCacheLRU.php b/includes/cache/ProcessCacheLRU.php index 76c76f3701..786d74acec 100644 --- a/includes/cache/ProcessCacheLRU.php +++ b/includes/cache/ProcessCacheLRU.php @@ -79,6 +79,7 @@ class ProcessCacheLRU { if ( isset( $this->cache[$key][$prop] ) ) { return ( $maxAge <= 0 || ( time() - $this->cacheTimes[$key][$prop] ) <= $maxAge ); } + return false; } diff --git a/includes/cache/ResourceFileCache.php b/includes/cache/ResourceFileCache.php index 2ad7b853cf..3ace3960ba 100644 --- a/includes/cache/ResourceFileCache.php +++ b/includes/cache/ResourceFileCache.php @@ -80,8 +80,10 @@ class ResourceFileCache extends FileCacheBase { } elseif ( $query === 'debug' && $val === 'false' ) { continue; } + return false; } + return true; // cacheable } @@ -104,6 +106,7 @@ class ResourceFileCache extends FileCacheBase { $this->getMissesRecent() >= self::MISS_THRESHOLD // many misses ); } + return $this->mCacheWorthy; } } diff --git a/includes/cache/UserCache.php b/includes/cache/UserCache.php index 6085f586e9..2e4c1e99a7 100644 --- a/includes/cache/UserCache.php +++ b/includes/cache/UserCache.php @@ -36,10 +36,12 @@ class UserCache { if ( $instance === null ) { $instance = new self(); } + return $instance; } - protected function __construct() {} + protected function __construct() { + } /** * Get a property of a user based on their user ID @@ -53,6 +55,7 @@ class UserCache { wfDebug( __METHOD__ . ": querying DB for prop '$prop' for user ID '$userId'.\n" ); $this->doQuery( array( $userId ) ); // cache miss } + return isset( $this->cache[$userId][$prop] ) ? $this->cache[$userId][$prop] : false; // user does not exist? -- 2.20.1