* @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;
function __construct( $localInfo, $foreignInfo ) {
$this->localInfo = $localInfo;
$this->foreignInfo = $foreignInfo;
- $this->cache = new ProcessCacheLRU( self::MAX_CACHE_SIZE );
+ $this->cache = new MapCacheLRU( self::MAX_CACHE_SIZE );
}
/**
if ( isset( $options['bypassCache'] ) ) {
$options['latest'] = $options['bypassCache']; // b/c
}
+ $options += [ 'time' => false ];
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
+
$title = File::normalizeTitle( $title );
if ( !$title ) {
return false;
# Check the cache
$dbkey = $title->getDBkey();
+ $timeKey = is_string( $options['time'] ) ? $options['time'] : '';
if ( empty( $options['ignoreRedirect'] )
&& empty( $options['private'] )
&& empty( $options['latest'] )
) {
- $time = $options['time'] ?? '';
- if ( $this->cache->has( $dbkey, $time, 60 ) ) {
- return $this->cache->get( $dbkey, $time );
+ if ( $this->cache->hasField( $dbkey, $timeKey, 60 ) ) {
+ return $this->cache->getField( $dbkey, $timeKey );
}
$useCache = true;
} else {
- $time = false;
$useCache = false;
}
}
}
- $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->set( $dbkey, $time, $image );
+ $this->cache->setField( $dbkey, $timeKey, $image );
}
return $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 );
}