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 = $info[
'deletedDir'] ??
false;
83 $thumbDir = $info[
'thumbDir'] ??
"{$directory}/thumb";
84 $transcodedDir = $info[
'transcodedDir'] ??
"{$directory}/transcoded";
87 'name' => $backendName,
88 'class' => FSFileBackend::class,
89 'lockManager' =>
'fsLockManager',
91 "{$repoName}-public" =>
"{$directory}",
92 "{$repoName}-thumb" => $thumbDir,
93 "{$repoName}-transcoded" => $transcodedDir,
94 "{$repoName}-deleted" => $deletedDir,
95 "{$repoName}-temp" =>
"{$directory}/temp"
97 'fileMode' => $info[
'fileMode'] ?? 0644,
113 protected function register(
array $configs, $readOnlyReason =
null ) {
114 foreach ( $configs
as $config ) {
115 if ( !isset( $config[
'name'] ) ) {
116 throw new InvalidArgumentException(
"Cannot register a backend with no name." );
118 $name = $config[
'name'];
119 if ( isset( $this->backends[
$name] ) ) {
120 throw new LogicException(
"Backend with name `{$name}` already registered." );
121 } elseif ( !isset( $config[
'class'] ) ) {
122 throw new InvalidArgumentException(
"Backend with name `{$name}` has no class." );
124 $class = $config[
'class'];
126 $config[
'readOnly'] = $config[
'readOnly'] ?? $readOnlyReason;
128 unset( $config[
'class'] );
129 $this->backends[
$name] = [
146 if ( !isset( $this->backends[
$name][
'instance'] ) ) {
147 $config = $this->
config( $name );
149 $class = $config[
'class'];
150 if ( $class === FileBackendMultiWrite::class ) {
151 foreach ( $config[
'backends']
as $index => $beConfig ) {
152 if ( isset( $beConfig[
'template'] ) ) {
155 $config[
'backends'][$index] += $this->
config( $beConfig[
'template'] );
160 $this->backends[
$name][
'instance'] =
new $class( $config );
163 return $this->backends[
$name][
'instance'];
174 if ( !isset( $this->backends[
$name] ) ) {
175 throw new InvalidArgumentException(
"No backend defined with the name `$name`." );
177 $class = $this->backends[
$name][
'class'];
179 $config = $this->backends[
$name][
'config'];
180 $config[
'class'] = $class;
181 if ( isset( $config[
'domainId'] ) ) {
182 $domain = $config[
'domainId'];
185 $domain = $config[
'wikiId'] ??
wfWikiID();
189 'domainId' => $domain,
190 'mimeCallback' => [ $this,
'guessMimeInternal' ],
191 'obResetFunc' =>
'wfResetOutputBuffers',
192 'streamMimeFunc' => [ StreamFile::class,
'contentTypeFromPath' ],
194 'statusWrapper' => [ Status::class,
'wrap' ],
195 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(),
196 'srvCache' => ObjectCache::getLocalServerInstance(
'hash' ),
197 'logger' => LoggerFactory::getInstance(
'FileOperation' ),
198 'profiler' =>
function (
$section ) {
199 return Profiler::instance()->scopedProfileIn(
$section );
202 $config[
'lockManager'] =
204 $config[
'fileJournal'] = isset( $config[
'fileJournal'] )
219 if ( $backend !==
null && isset( $this->backends[$backend] ) ) {
220 return $this->
get( $backend );
234 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
237 $type = $magic->guessTypesForExtension(
$ext );
239 if ( !
$type && $fsPath ) {
240 $type = $magic->guessMimeType( $fsPath,
false );
243 file_put_contents( $tmpFile->getPath(),
$content );
244 $type = $magic->guessMimeType( $tmpFile->getPath(),
false );
246 return $type ?:
'unknown/unknown';
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgFileBackends
File backend structure configuration.
$wgDirectoryMode
Default value for chmoding of new directories.
$wgLocalFileRepo
File repository structures.
$wgForeignFileRepos
Enable the use of files from one or more other wikis.
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Allows to change the fields on the form that will be generated $name
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!is_readable( $file)) $ext