dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
externalstore: unbreak writes to non-default storage clusters due to isReadOnly()
[lhc/web/wiklou.git]
/
includes
/
filerepo
/
RepoGroup.php
diff --git
a/includes/filerepo/RepoGroup.php
b/includes/filerepo/RepoGroup.php
index
90c8707
..
e474ad3
100644
(file)
--- a/
includes/filerepo/RepoGroup.php
+++ b/
includes/filerepo/RepoGroup.php
@@
-21,6
+21,8
@@
* @ingroup FileRepo
*/
* @ingroup FileRepo
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Prioritized list of file repositories
*
/**
* Prioritized list of file repositories
*
@@
-33,6
+35,9
@@
class RepoGroup {
/** @var FileRepo[] */
protected $foreignRepos;
/** @var FileRepo[] */
protected $foreignRepos;
+ /** @var WANObjectCache */
+ protected $wanCache;
+
/** @var bool */
protected $reposInitialised = false;
/** @var bool */
protected $reposInitialised = false;
@@
-42,68
+47,63
@@
class RepoGroup {
/** @var array */
protected $foreignInfo;
/** @var array */
protected $foreignInfo;
- /** @var
Process
CacheLRU */
+ /** @var
Map
CacheLRU */
protected $cache;
protected $cache;
- /** @var RepoGroup */
- protected static $instance;
-
/** Maximum number of cache items */
const MAX_CACHE_SIZE = 500;
/**
/** Maximum number of cache items */
const MAX_CACHE_SIZE = 500;
/**
- * Get a RepoGroup instance. At present only one instance of RepoGroup is
- * needed in a MediaWiki invocation, this may change in the future.
+ * @deprecated since 1.34, use MediaWikiServices::getRepoGroup
* @return RepoGroup
*/
static function singleton() {
* @return RepoGroup
*/
static function singleton() {
- if ( self::$instance ) {
- return self::$instance;
- }
- global $wgLocalFileRepo, $wgForeignFileRepos;
- self::$instance = new RepoGroup( $wgLocalFileRepo, $wgForeignFileRepos );
-
- return self::$instance;
+ return MediaWikiServices::getInstance()->getRepoGroup();
}
/**
}
/**
- *
Destroy the singleton instance, so that a new one will be created next
- *
time singleton() is called
.
+ *
@deprecated since 1.34, use MediaWikiTestCase::overrideMwServices() or similar. This will
+ *
cause bugs if you don't reset all other services that depend on this one at the same time
.
*/
static function destroySingleton() {
*/
static function destroySingleton() {
-
self::$instance = null
;
+
MediaWikiServices::getInstance()->resetServiceForTesting( 'RepoGroup' )
;
}
/**
}
/**
- * Set the singleton instance to a given object
- * Used by extensions which hook into the Repo chain.
- * It's not enough to just create a superclass ... you have
- * to get people to call into it even though all they know is RepoGroup::singleton()
- *
+ * @deprecated since 1.34, use MediaWikiTestCase::setService, this can mess up state of other
+ * tests
* @param RepoGroup $instance
*/
static function setSingleton( $instance ) {
* @param RepoGroup $instance
*/
static function setSingleton( $instance ) {
- self::$instance = $instance;
+ $services = MediaWikiServices::getInstance();
+ $services->disableService( 'RepoGroup' );
+ $services->redefineService( 'RepoGroup',
+ function () use ( $instance ) {
+ return $instance;
+ }
+ );
}
/**
}
/**
- * Construct a group of file repositories.
+ * Construct a group of file repositories. Do not call this -- use
+ * MediaWikiServices::getRepoGroup.
*
* @param array $localInfo Associative array for local repo's info
* @param array $foreignInfo Array of repository info arrays.
* Each info array is an associative array with the 'class' member
* giving the class name. The entire array is passed to the repository
* constructor as the first parameter.
*
* @param array $localInfo Associative array for local repo's info
* @param array $foreignInfo Array of repository info arrays.
* Each info array is an associative array with the 'class' member
* giving the class name. The entire array is passed to the repository
* constructor as the first parameter.
+ * @param WANObjectCache $wanCache
*/
*/
- function __construct( $localInfo, $foreignInfo ) {
+ function __construct( $localInfo, $foreignInfo
, $wanCache
) {
$this->localInfo = $localInfo;
$this->foreignInfo = $foreignInfo;
$this->cache = new MapCacheLRU( self::MAX_CACHE_SIZE );
$this->localInfo = $localInfo;
$this->foreignInfo = $foreignInfo;
$this->cache = new MapCacheLRU( self::MAX_CACHE_SIZE );
+ $this->wanCache = $wanCache;
}
/**
* Search repositories for an image.
}
/**
* Search repositories for an image.
- * You can also use wfFindFile() to do this.
*
* @param Title|string $title Title object or string
* @param array $options Associative array of options:
*
* @param Title|string $title Title object or string
* @param array $options Associative array of options:
@@
-125,10
+125,12
@@
class RepoGroup {
if ( isset( $options['bypassCache'] ) ) {
$options['latest'] = $options['bypassCache']; // b/c
}
if ( isset( $options['bypassCache'] ) ) {
$options['latest'] = $options['bypassCache']; // b/c
}
+ $options += [ 'time' => false ];
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
if ( !$this->reposInitialised ) {
$this->initialiseRepos();
}
+
$title = File::normalizeTitle( $title );
if ( !$title ) {
return false;
$title = File::normalizeTitle( $title );
if ( !$title ) {
return false;
@@
-136,17
+138,16
@@
class RepoGroup {
# Check the cache
$dbkey = $title->getDBkey();
# Check the cache
$dbkey = $title->getDBkey();
+ $timeKey = is_string( $options['time'] ) ? $options['time'] : '';
if ( empty( $options['ignoreRedirect'] )
&& empty( $options['private'] )
&& empty( $options['latest'] )
) {
if ( empty( $options['ignoreRedirect'] )
&& empty( $options['private'] )
&& empty( $options['latest'] )
) {
- $time = $options['time'] ?? '';
- if ( $this->cache->hasField( $dbkey, $time, 60 ) ) {
- return $this->cache->getField( $dbkey, $time );
+ if ( $this->cache->hasField( $dbkey, $timeKey, 60 ) ) {
+ return $this->cache->getField( $dbkey, $timeKey );
}
$useCache = true;
} else {
}
$useCache = true;
} else {
- $time = false;
$useCache = false;
}
$useCache = false;
}
@@
-163,10
+164,10
@@
class RepoGroup {
}
}
}
}
- $image = $image
?
: false; // type sanity
+ $image = $image
instanceof File ? $image
: false; // type sanity
# Cache file existence or non-existence
if ( $useCache && ( !$image || $image->isCacheable() ) ) {
# Cache file existence or non-existence
if ( $useCache && ( !$image || $image->isCacheable() ) ) {
- $this->cache->setField( $dbkey, $time, $image );
+ $this->cache->setField( $dbkey, $time
Key
, $image );
}
return $image;
}
return $image;
@@
-316,7
+317,7
@@
class RepoGroup {
/**
* Get the repo instance with a given key.
* @param string|int $index
/**
* Get the repo instance with a given key.
* @param string|int $index
- * @return bool|
Local
Repo
+ * @return bool|
File
Repo
*/
function getRepo( $index ) {
if ( !$this->reposInitialised ) {
*/
function getRepo( $index ) {
if ( !$this->reposInitialised ) {
@@
-353,7
+354,10
@@
class RepoGroup {
* @return LocalRepo
*/
function getLocalRepo() {
* @return LocalRepo
*/
function getLocalRepo() {
- return $this->getRepo( 'local' );
+ /** @var LocalRepo $repo */
+ $repo = $this->getRepo( 'local' );
+
+ return $repo;
}
/**
}
/**
@@
-412,6
+416,8
@@
class RepoGroup {
protected function newRepo( $info ) {
$class = $info['class'];
protected function newRepo( $info ) {
$class = $info['class'];
+ $info['wanCache'] = $this->wanCache;
+
return new $class( $info );
}
return new $class( $info );
}