47 if ( self::$instance ==
null ) {
48 self::$instance =
new self();
49 self::$instance->initFromGlobals();
59 self::$instance =
null;
74 foreach ( $repos as $info ) {
75 $backendName = $info[
'backend'];
76 if ( is_object( $backendName ) || isset( $this->backends[$backendName] ) ) {
79 $repoName = $info[
'name'];
81 $directory = $info[
'directory'];
82 $deletedDir = isset( $info[
'deletedDir'] )
85 $thumbDir = isset( $info[
'thumbDir'] )
87 :
"{$directory}/thumb";
88 $transcodedDir = isset( $info[
'transcodedDir'] )
89 ? $info[
'transcodedDir']
90 :
"{$directory}/transcoded";
93 'name' => $backendName,
94 'class' => FSFileBackend::class,
95 'lockManager' =>
'fsLockManager',
97 "{$repoName}-public" =>
"{$directory}",
98 "{$repoName}-thumb" => $thumbDir,
99 "{$repoName}-transcoded" => $transcodedDir,
100 "{$repoName}-deleted" => $deletedDir,
101 "{$repoName}-temp" =>
"{$directory}/temp"
103 'fileMode' => isset( $info[
'fileMode'] ) ? $info[
'fileMode'] : 0644,
119 protected function register( array $configs, $readOnlyReason = null ) {
120 foreach ( $configs as $config ) {
121 if ( !isset( $config[
'name'] ) ) {
122 throw new InvalidArgumentException(
"Cannot register a backend with no name." );
124 $name = $config[
'name'];
125 if ( isset( $this->backends[$name] ) ) {
126 throw new LogicException(
"Backend with name `{$name}` already registered." );
127 } elseif ( !isset( $config[
'class'] ) ) {
128 throw new InvalidArgumentException(
"Backend with name `{$name}` has no class." );
130 $class = $config[
'class'];
132 $config[
'readOnly'] = !empty( $config[
'readOnly'] )
133 ? $config[
'readOnly']
136 unset( $config[
'class'] );
137 $this->backends[
$name] = [
154 if ( !isset( $this->backends[$name][
'instance'] ) ) {
155 $config = $this->
config( $name );
157 $class = $config[
'class'];
158 if ( $class === FileBackendMultiWrite::class ) {
159 foreach ( $config[
'backends'] as $index => $beConfig ) {
160 if ( isset( $beConfig[
'template'] ) ) {
163 $config[
'backends'][$index] += $this->
config( $beConfig[
'template'] );
168 $this->backends[
$name][
'instance'] =
new $class( $config );
171 return $this->backends[
$name][
'instance'];
182 if ( !isset( $this->backends[$name] ) ) {
183 throw new InvalidArgumentException(
"No backend defined with the name `$name`." );
185 $class = $this->backends[
$name][
'class'];
187 $config = $this->backends[
$name][
'config'];
188 $config[
'class'] = $class;
191 'mimeCallback' => [ $this,
'guessMimeInternal' ],
192 'obResetFunc' =>
'wfResetOutputBuffers',
193 'streamMimeFunc' => [ StreamFile::class,
'contentTypeFromPath' ],
195 'statusWrapper' => [ Status::class,
'wrap' ],
196 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(),
197 'srvCache' => ObjectCache::getLocalServerInstance(
'hash' ),
198 'logger' => LoggerFactory::getInstance(
'FileOperation' ),
199 'profiler' => Profiler::instance()
201 $config[
'lockManager'] =
203 $config[
'fileJournal'] = isset( $config[
'fileJournal'] )
218 if ( $backend !==
null && isset( $this->backends[$backend] ) ) {
219 return $this->
get( $backend );
233 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
236 $type = $magic->guessTypesForExtension(
$ext );
238 if ( !
$type && $fsPath ) {
239 $type = $magic->guessMimeType( $fsPath,
false );
240 } elseif ( !
$type && strlen( $content ) ) {
242 file_put_contents( $tmpFile->getPath(), $content );
243 $type = $magic->guessMimeType( $tmpFile->getPath(),
false );
245 return $type ?:
'unknown/unknown';
$wgFileBackends
File backend structure configuration.
$wgDirectoryMode
Default value for chmoding of new directories.
$wgLocalFileRepo
File repository structures.
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
wfTempDir()
Tries to get the system directory for temporary files.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Class to handle file backend registration.
static destroySingleton()
Destroy the singleton instance.
config( $name)
Get the config array for a backend object with a given name.
guessMimeInternal( $storagePath, $content, $fsPath)
initFromGlobals()
Register file backends from the global variables.
static FileBackendGroup $instance
array $backends
(name => ('class' => string, 'config' => array, 'instance' => object))
backendFromPath( $storagePath)
Get an appropriate backend object from a storage path.
static splitStoragePath( $storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
static singleton( $domain=false)
static factory( $prefix, $extension='', $tmpDirectory=null)
Make a new temporary file on the file system.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Allows to change the fields on the form that will be generated $name
if(!is_readable( $file)) $ext