Also fixed some intellij IDEA warnings.
Change-Id: I667ed7ef9b49c1da1c8c7c9914daadb7c74b3c79
/** @var string Secret key to pass as an X-Swift-Secret header to the proxied thumb service */
protected $thumbProxySecret;
+ /** @var WANObjectCache */
+ protected $wanCache;
+
/**
* @param array|null $info
* @throws MWException
}
$this->supportsSha1URLs = !empty( $info['supportsSha1URLs'] );
+
+ $this->wanCache = $info['wanCache'] ?? WANObjectCache::newEmpty();
}
/**
* @throws MWException
*/
protected function resolveToStoragePath( $path ) {
- if ( $this->isVirtualUrl( $path ) ) {
+ if ( self::isVirtualUrl( $path ) ) {
return $this->resolveVirtualUrl( $path );
}
/**
* Get a key on the primary cache for this repository.
* Returns false if the repository's cache is not accessible at this site.
- * The parameters are the parts of the key, as for wfMemcKey().
+ * The parameters are the parts of the key.
*
* STUB
* @return bool
/**
* Get a key for this repo in the local cache domain. These cache keys are
* not shared with remote instances of the repo.
- * The parameters are the parts of the key, as for wfMemcKey().
+ * The parameters are the parts of the key.
*
* @return string
*/
$args = func_get_args();
array_unshift( $args, 'filerepo', $this->getName() );
- return wfMemcKey( ...$args );
+ return $this->wanCache->makeKey( ...$args );
}
/**
*/
use MediaWiki\Logger\LoggerFactory;
-use MediaWiki\MediaWikiServices;
/**
* A foreign repository with a remote MediaWiki with an API thingy
* @return bool|string
*/
function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
- $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
// We can't check the local cache using FileRepo functions because
// we override fileExistsBatch(). We have to use the FileBackend directly.
$backend = $this->getBackend(); // convenience
$sizekey = "$width:$height:$params";
/* Get the array of urls that we already know */
- $knownThumbUrls = $cache->get( $key );
+ $knownThumbUrls = $this->wanCache->get( $key );
if ( !$knownThumbUrls ) {
/* No knownThumbUrls for this file */
$knownThumbUrls = [];
if ( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
/* Use our current and already downloaded thumbnail */
$knownThumbUrls[$sizekey] = $localUrl;
- $cache->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
+ $this->wanCache->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
return $localUrl;
}
$knownThumbUrls[$sizekey] = $localUrl;
$ttl = $mtime
- ? $cache->adaptiveTTL( $mtime, $this->apiThumbCacheExpiry )
+ ? $this->wanCache->adaptiveTTL( $mtime, $this->apiThumbCacheExpiry )
: $this->apiThumbCacheExpiry;
- $cache->set( $key, $knownThumbUrls, $ttl );
+ $this->wanCache->set( $key, $knownThumbUrls, $ttl );
wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" );
return $localUrl;
$url = $this->makeUrl( $query, 'api' );
}
- $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
- return $cache->getWithSetCallback(
+ return $this->wanCache->getWithSetCallback(
$this->getLocalCacheKey( static::class, $target, md5( $url ) ),
$cacheTTL,
- function ( $curValue, &$ttl ) use ( $url, $cache ) {
+ function ( $curValue, &$ttl ) use ( $url ) {
$html = self::httpGet( $url, 'default', [], $mtime );
if ( $html !== false ) {
- $ttl = $mtime ? $cache->adaptiveTTL( $mtime, $ttl ) : $ttl;
+ $ttl = $mtime ? $this->wanCache->adaptiveTTL( $mtime, $ttl ) : $ttl;
} else {
- $ttl = $cache->adaptiveTTL( $mtime, $ttl );
+ $ttl = $this->wanCache->adaptiveTTL( $mtime, $ttl );
$html = null; // caches negatives
}
return $html;
},
- [ 'pcTTL' => $cache::TTL_PROC_LONG ]
+ [ 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
);
}
*/
use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
}
$method = __METHOD__;
- $redirDbKey = MediaWikiServices::getInstance()->getMainWANObjectCache()->getWithSetCallback(
+ $redirDbKey = $this->wanCache->getWithSetCallback(
$memcKey,
$expiry,
function ( $oldValue, &$ttl, array &$setOpts ) use ( $method, $title ) {
);
};
- $applyMatchingFiles = function ( ResultWrapper $res, &$searchSet, &$finalFiles )
+ $applyMatchingFiles = function ( IResultWrapper $res, &$searchSet, &$finalFiles )
use ( $fileMatchesSearch, $flags )
{
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
/**
* Get a key on the primary cache for this repository.
* Returns false if the repository's cache is not accessible at this site.
- * The parameters are the parts of the key, as for wfMemcKey().
+ * The parameters are the parts of the key.
*
* @return string
*/
function getSharedCacheKey( /*...*/ ) {
$args = func_get_args();
- return wfMemcKey( ...$args );
+ return $this->wanCache->makeKey( ...$args );
}
/**
if ( $key ) {
$this->getMasterDB()->onTransactionPreCommitOrIdle(
function () use ( $key ) {
- MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
+ $this->wanCache->delete( $key );
},
__METHOD__
);
* @ingroup FileRepo
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Prioritized list of file repositories
*
return self::$instance;
}
global $wgLocalFileRepo, $wgForeignFileRepos;
+ /** @var array $wgLocalFileRepo */
self::$instance = new RepoGroup( $wgLocalFileRepo, $wgForeignFileRepos );
return self::$instance;
}
}
- $image = $image ?: false; // type sanity
+ $image = $image instanceof File ? $image : false; // type sanity
# Cache file existence or non-existence
if ( $useCache && ( !$image || $image->isCacheable() ) ) {
$this->cache->setField( $dbkey, $timeKey, $image );
/**
* Get the repo instance with a given key.
* @param string|int $index
- * @return bool|LocalRepo
+ * @return bool|FileRepo
*/
function getRepo( $index ) {
if ( !$this->reposInitialised ) {
* @return LocalRepo
*/
function getLocalRepo() {
- return $this->getRepo( 'local' );
+ /** @var LocalRepo $repo */
+ $repo = $this->getRepo( 'local' );
+
+ return $repo;
}
/**
protected function newRepo( $info ) {
$class = $info['class'];
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ $info['wanCache'] = $cache;
+
return new $class( $info );
}