23use \MediaWiki\Logger\LoggerFactory;
46 if ( self::$instance ==
null ) {
47 self::$instance =
new self();
48 self::$instance->initFromGlobals();
58 self::$instance =
null;
73 foreach ( $repos as $info ) {
74 $backendName = $info[
'backend'];
75 if ( is_object( $backendName ) || isset( $this->backends[$backendName] ) ) {
78 $repoName = $info[
'name'];
80 $directory = $info[
'directory'];
81 $deletedDir = isset( $info[
'deletedDir'] )
84 $thumbDir = isset( $info[
'thumbDir'] )
86 :
"{$directory}/thumb";
87 $transcodedDir = isset( $info[
'transcodedDir'] )
88 ? $info[
'transcodedDir']
89 :
"{$directory}/transcoded";
92 'name' => $backendName,
93 'class' =>
'FSFileBackend',
94 'lockManager' =>
'fsLockManager',
96 "{$repoName}-public" =>
"{$directory}",
97 "{$repoName}-thumb" => $thumbDir,
98 "{$repoName}-transcoded" => $transcodedDir,
99 "{$repoName}-deleted" => $deletedDir,
100 "{$repoName}-temp" =>
"{$directory}/temp"
102 'fileMode' => isset( $info[
'fileMode'] ) ? $info[
'fileMode'] : 0644,
118 protected function register( array $configs, $readOnlyReason = null ) {
119 foreach ( $configs as $config ) {
120 if ( !isset( $config[
'name'] ) ) {
121 throw new InvalidArgumentException(
"Cannot register a backend with no name." );
123 $name = $config[
'name'];
124 if ( isset( $this->backends[$name] ) ) {
125 throw new LogicException(
"Backend with name `{$name}` already registered." );
126 } elseif ( !isset( $config[
'class'] ) ) {
127 throw new InvalidArgumentException(
"Backend with name `{$name}` has no class." );
129 $class = $config[
'class'];
131 $config[
'readOnly'] = !empty( $config[
'readOnly'] )
132 ? $config[
'readOnly']
135 unset( $config[
'class'] );
136 $this->backends[
$name] = [
153 if ( !isset( $this->backends[$name][
'instance'] ) ) {
154 $config = $this->
config( $name );
156 $class = $config[
'class'];
157 if ( $class ===
'FileBackendMultiWrite' ) {
158 foreach ( $config[
'backends'] as $index => $beConfig ) {
159 if ( isset( $beConfig[
'template'] ) ) {
162 $config[
'backends'][$index] += $this->
config( $beConfig[
'template'] );
167 $this->backends[
$name][
'instance'] =
new $class( $config );
170 return $this->backends[
$name][
'instance'];
181 if ( !isset( $this->backends[$name] ) ) {
182 throw new InvalidArgumentException(
"No backend defined with the name `$name`." );
184 $class = $this->backends[
$name][
'class'];
186 $config = $this->backends[
$name][
'config'];
187 $config[
'class'] = $class;
190 'mimeCallback' => [ $this,
'guessMimeInternal' ],
191 'obResetFunc' =>
'wfResetOutputBuffers',
192 'streamMimeFunc' => [
'StreamFile',
'contentTypeFromPath' ],
194 'statusWrapper' => [
'Status',
'wrap' ],
195 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(),
196 'srvCache' => ObjectCache::getLocalServerInstance(
'hash' ),
197 'logger' => LoggerFactory::getInstance(
'FileOperation' ),
198 'profiler' => Profiler::instance()
200 $config[
'lockManager'] =
202 $config[
'fileJournal'] = isset( $config[
'fileJournal'] )
217 if ( $backend !==
null && isset( $this->backends[$backend] ) ) {
218 return $this->
get( $backend );
235 $type = $magic->guessTypesForExtension(
$ext );
237 if ( !
$type && $fsPath ) {
238 $type = $magic->guessMimeType( $fsPath,
false );
239 } elseif ( !
$type && strlen( $content ) ) {
241 file_put_contents( $tmpFile->getPath(), $content );
242 $type = $magic->guessMimeType( $tmpFile->getPath(),
false );
244 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 singleton()
Get an instance of this class.
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