if ( !self::$cache->has( $dbKey, 'obj', 3600 ) ) {
self::$cache->set( $dbKey, 'obj', new self( $title ) );
}
+
return self::$cache->get( $dbKey, 'obj' );
}
if ( !isset( $this->db ) ) {
$this->db = wfGetDB( DB_SLAVE );
}
+
return $this->db;
}
$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 {
$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__,
}
wfProfileOut( __METHOD__ );
+
return $res;
}
// 1) try partition cache ...
if ( isset( $this->partitionCache[$table] ) ) {
$entry = reset( $this->partitionCache[$table] );
+
return min( $max, $entry['numRows'] );
}
// 1) try partition cache ...
if ( isset( $this->partitionCache[$table][$batchSize] ) ) {
wfDebug( __METHOD__ . ": got from partition cache\n" );
+
return $this->partitionCache[$table][$batchSize]['batches'];
}
if ( isset( $this->fullResultCache[$table] ) ) {
$cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
wfDebug( __METHOD__ . ": got from full result cache\n" );
+
return $cacheEntry['batches'];
}
if ( is_array( $memcValue ) ) {
$cacheEntry = $memcValue;
wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
+
return $cacheEntry['batches'];
}
$wgMemc->set( $memcKey, $cacheEntry['numRows'], self::CACHE_EXPIRY );
wfDebug( __METHOD__ . ": got from database\n" );
+
return $cacheEntry['batches'];
}
* 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() ) {
/**
* Hook to perform any expensive pre-serialize loading of dependency values.
*/
- function loadDependencyValues() { }
+ function loadDependencyValues() {
+ }
}
/**
*/
function __sleep() {
$this->loadDependencyValues();
+
return array( 'filename', 'timestamp' );
}
} else {
# Deleted
wfDebug( "Dependency triggered: {$this->filename} deleted.\n" );
+
return true;
}
} else {
if ( $lastmod > $this->timestamp ) {
# Modified or created
wfDebug( "Dependency triggered: {$this->filename} changed.\n" );
+
return true;
} else {
# Not modified
$this->linkBatch = new LinkBatch;
$this->linkBatch->setArray( $this->timestamps );
}
+
return $this->linkBatch;
}
if ( !isset( $GLOBALS[$this->name] ) ) {
return true;
}
+
return $GLOBALS[$this->name] != $this->value;
}
}
*/
final protected function baseCacheDirectory() {
global $wgFileCacheDirectory;
+
return $wgFileCacheDirectory;
}
if ( $this->mCached === null ) {
$this->mCached = file_exists( $this->cachePath() );
}
+
return $this->mCached;
}
*/
public function cacheTimestamp() {
$timestamp = filemtime( $this->cachePath() );
+
return ( $timestamp !== false )
? wfTimestamp( TS_MW, $timestamp )
: false;
public function fetchText() {
if ( $this->useGzip() ) {
$fh = gzopen( $this->cachePath(), 'rb' );
+
return stream_get_contents( $fh );
} else {
return file_get_contents( $this->cachePath() );
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;
}
*/
public function getMissesRecent() {
global $wgMemc;
+
return self::MISS_FACTOR * $wgMemc->get( $this->cacheMissKey() );
}
if ( $that === null ) {
$that = new self();
}
+
return $that;
}
- protected function __construct() {}
+ protected function __construct() {
+ }
/**
* Returns the default gender option in this wiki.
if ( $this->default === null ) {
$this->default = User::getDefaultOption( 'gender' );
}
+
return $this->default;
}
$this->misses++;
wfDebug( __METHOD__ . ": too many misses, returning default onwards\n" );
}
- return $this->getDefault();
+ return $this->getDefault();
} else {
$this->misses++;
$this->doQuery( $username, $caller );
if ( $indexSlash !== false ) {
$username = substr( $username, 0, $indexSlash );
}
+
// normalize underscore/spaces
return strtr( $username, '_', ' ' );
}
}
if ( $wgShowIPinHeader || $wgDebugToolbar ) {
wfDebug( "HTML file cache skipped. Either \$wgShowIPinHeader and/or \$wgDebugToolbar on\n" );
+
return false;
}
} elseif ( $query === 'maxage' || $query === 'smaxage' ) {
continue;
}
+
return false;
}
$user = $context->getUser();
// 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;
}
// @todo Ugly wfClientAcceptsGzip() function - use context!
if ( wfClientAcceptsGzip() ) {
header( 'Content-Encoding: gzip' );
+
return $compressed;
} else {
return $text;
*/
public function execute() {
$linkCache = LinkCache::singleton();
+
return $this->executeInto( $linkCache );
}
$this->doGenderQuery();
$ids = $this->addResultToCache( $cache, $res );
wfProfileOut( __METHOD__ );
+
return $ids;
}
$ids[$title->getPrefixedDBkey()] = 0;
}
}
+
return $ids;
}
}
$res = $dbr->select( $table, $fields, $conds, $caller );
wfProfileOut( __METHOD__ );
+
return $res;
}
$genderCache = GenderCache::singleton();
$genderCache->doLinkBatch( $this->data, $this->caller );
+
return true;
}
return self::$instance;
}
self::$instance = new LinkCache;
+
return self::$instance;
}
$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;
}
}
wfProfileOut( __METHOD__ );
+
return $id;
}
self::$magicWordKeys
) );
}
+
return isset( $this->mergeableKeys[$key] );
}
*/
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' );
if ( isset( $this->shallowFallbacks[$code] ) ) {
$this->loadItem( $this->shallowFallbacks[$code], $key );
+
return;
}
protected function loadSubitem( $code, $key, $subkey ) {
if ( !in_array( $key, self::$splitKeys ) ) {
$this->loadItem( $code, $key );
+
return;
}
// 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;
}
public function isExpired( $code ) {
if ( $this->forceRecache && !isset( $this->recachedLangs[$code] ) ) {
wfDebug( __METHOD__ . "($code): forced reload\n" );
+
return true;
}
// 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;
}
if ( !$dep instanceof CacheDependency || $dep->isExpired() ) {
wfDebug( __METHOD__ . "($code): cache for $code expired due to " .
get_class( $dep ) . "\n" );
+
return true;
}
}
# 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;
}
} else {
$this->initShallowFallback( $code, 'en' );
}
+
return;
}
'Please run maintenance/rebuildLocalisationCache.php.' );
}
$this->initShallowFallback( $code, 'en' );
+
return;
} else {
throw new MWException( 'Invalid or missing localisation cache.' );
throw new MWException( __METHOD__ . ": Invalid file type: $_fileType" );
}
wfProfileOut( __METHOD__ );
+
return $data;
}
$compiledRules = CLDRPluralRuleEvaluator::compile( $rules );
} catch ( CLDRPluralRuleError $e ) {
wfDebugLog( 'l10n', $e->getMessage() . "\n" );
+
return array();
}
+
return $compiledRules;
}
$fileName = Language::getMessagesFileName( $code );
if ( !file_exists( $fileName ) ) {
wfProfileOut( __METHOD__ );
+
return false;
}
$deps['plurals-mw'] = new FileDependency( "$IP/languages/data/plurals-mediawiki.xml" );
wfProfileOut( __METHOD__ );
+
return $data;
}
foreach ( $data as $key => $value ) {
$this->mergeItem( $key, $coreData[$key], $value );
}
-
}
# Fill in the fallback if it's not there already
public function get( $code, $key ) {
$k = wfMemcKey( 'l10n', $code, 'k', $key );
$r = $this->cache->get( $k );
+
return $r === false ? null : $r;
}
if ( $this->dbw->wasReadOnlyError() ) {
$this->readOnly = true;
$this->dbw->rollback( __METHOD__ );
+
return;
} else {
throw $e;
if ( $value === false ) {
return null;
}
+
return unserialize( $value );
}
}
if ( strval( $code ) === '' || strpos( $code, '/' ) !== false ) {
throw new MWException( __METHOD__ . ": Invalid language \"$code\"" );
}
+
return "{$this->directory}/l10n_cache-$code.cdb";
}
}
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 ) {
+ }
}
/**
public function getItem( $code, $key ) {
unset( $this->mruLangs[$code] );
$this->mruLangs[$code] = true;
+
return parent::getItem( $code, $key );
}
public function getSubitem( $code, $key, $subkey ) {
unset( $this->mruLangs[$code] );
$this->mruLangs[$code] = true;
+
return parent::getSubitem( $code, $key, $subkey );
}
$wgMsgCacheExpiry
);
}
+
return self::$instance;
}
$this->mParserOptions = new ParserOptions;
$this->mParserOptions->setEditSection( false );
}
+
return $this->mParserOptions;
}
$serialized .= fread( $file, 100000 );
}
fclose( $file );
+
return unserialize( $serialized );
} else {
fclose( $file );
+
return false; // Wrong hash
}
}
if ( !$file ) {
wfDebug( "Unable to open local cache file for writing\n" );
+
return;
}
wfDebug( __METHOD__ . ": disabled\n" );
$shownDisabled = true;
}
+
return true;
}
$info = implode( ', ', $where );
wfDebug( __METHOD__ . ": Loading $code... $info\n" );
wfProfileOut( __METHOD__ );
+
return $success;
}
$cache['VERSION'] = MSG_CACHE_VERSION;
$cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry );
wfProfileOut( __METHOD__ );
+
return $cache;
}
if ( $this->mDisable ) {
wfProfileOut( __METHOD__ );
+
return;
}
if ( wfTimestampNow() >= $cache['EXPIRY'] ) {
return true;
}
+
return false;
}
}
wfProfileOut( __METHOD__ );
+
return $success;
}
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
$this->mInParser = false;
$popts->setUserLang( $userlang );
}
+
return $message;
}
$this->mParser = clone $wgParser;
}
}
+
return $this->mParser;
}
$this->mInParser = false;
wfProfileOut( __METHOD__ );
+
return $res;
}
}
$message = implode( '/', $pieces );
+
return array( $message, $lang );
}
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 ) );
}
if ( isset( $this->cache[$key][$prop] ) ) {
return ( $maxAge <= 0 || ( time() - $this->cacheTimes[$key][$prop] ) <= $maxAge );
}
+
return false;
}
} elseif ( $query === 'debug' && $val === 'false' ) {
continue;
}
+
return false;
}
+
return true; // cacheable
}
$this->getMissesRecent() >= self::MISS_THRESHOLD // many misses
);
}
+
return $this->mCacheWorthy;
}
}
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
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?