MediaWiki  1.23.2
FileBackendGroup.php
Go to the documentation of this file.
1 <?php
33  protected static $instance = null;
34 
36  protected $backends = array();
37 
38  protected function __construct() {
39  }
40 
44  public static function singleton() {
45  if ( self::$instance == null ) {
46  self::$instance = new self();
47  self::$instance->initFromGlobals();
48  }
49 
50  return self::$instance;
51  }
52 
56  public static function destroySingleton() {
57  self::$instance = null;
58  }
59 
63  protected function initFromGlobals() {
64  global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends;
65 
66  // Register explicitly defined backends
67  $this->register( $wgFileBackends );
68 
69  $autoBackends = array();
70  // Automatically create b/c backends for file repos...
71  $repos = array_merge( $wgForeignFileRepos, array( $wgLocalFileRepo ) );
72  foreach ( $repos as $info ) {
73  $backendName = $info['backend'];
74  if ( is_object( $backendName ) || isset( $this->backends[$backendName] ) ) {
75  continue; // already defined (or set to the object for some reason)
76  }
77  $repoName = $info['name'];
78  // Local vars that used to be FSRepo members...
79  $directory = $info['directory'];
80  $deletedDir = isset( $info['deletedDir'] )
81  ? $info['deletedDir']
82  : false; // deletion disabled
83  $thumbDir = isset( $info['thumbDir'] )
84  ? $info['thumbDir']
85  : "{$directory}/thumb";
86  $transcodedDir = isset( $info['transcodedDir'] )
87  ? $info['transcodedDir']
88  : "{$directory}/transcoded";
89  $fileMode = isset( $info['fileMode'] )
90  ? $info['fileMode']
91  : 0644;
92  // Get the FS backend configuration
93  $autoBackends[] = array(
94  'name' => $backendName,
95  'class' => 'FSFileBackend',
96  'lockManager' => 'fsLockManager',
97  'containerPaths' => array(
98  "{$repoName}-public" => "{$directory}",
99  "{$repoName}-thumb" => $thumbDir,
100  "{$repoName}-transcoded" => $transcodedDir,
101  "{$repoName}-deleted" => $deletedDir,
102  "{$repoName}-temp" => "{$directory}/temp"
103  ),
104  'fileMode' => $fileMode,
105  );
106  }
107 
108  // Register implicitly defined backends
109  $this->register( $autoBackends );
110  }
111 
118  protected function register( array $configs ) {
119  foreach ( $configs as $config ) {
120  if ( !isset( $config['name'] ) ) {
121  throw new FileBackendException( "Cannot register a backend with no name." );
122  }
123  $name = $config['name'];
124  if ( isset( $this->backends[$name] ) ) {
125  throw new FileBackendException( "Backend with name `{$name}` already registered." );
126  } elseif ( !isset( $config['class'] ) ) {
127  throw new FileBackendException( "Backend with name `{$name}` has no class." );
128  }
129  $class = $config['class'];
130 
131  unset( $config['class'] ); // backend won't need this
132  $this->backends[$name] = array(
133  'class' => $class,
134  'config' => $config,
135  'instance' => null
136  );
137  }
138  }
139 
147  public function get( $name ) {
148  if ( !isset( $this->backends[$name] ) ) {
149  throw new FileBackendException( "No backend defined with the name `$name`." );
150  }
151  // Lazy-load the actual backend instance
152  if ( !isset( $this->backends[$name]['instance'] ) ) {
153  $class = $this->backends[$name]['class'];
154  $config = $this->backends[$name]['config'];
155  $config['wikiId'] = isset( $config['wikiId'] )
156  ? $config['wikiId']
157  : wfWikiID(); // e.g. "my_wiki-en_"
158  $config['lockManager'] =
159  LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] );
160  $config['fileJournal'] = isset( $config['fileJournal'] )
161  ? FileJournal::factory( $config['fileJournal'], $name )
162  : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $name );
163  $this->backends[$name]['instance'] = new $class( $config );
164  }
165 
166  return $this->backends[$name]['instance'];
167  }
168 
176  public function config( $name ) {
177  if ( !isset( $this->backends[$name] ) ) {
178  throw new FileBackendException( "No backend defined with the name `$name`." );
179  }
180  $class = $this->backends[$name]['class'];
181 
182  return array( 'class' => $class ) + $this->backends[$name]['config'];
183  }
184 
191  public function backendFromPath( $storagePath ) {
192  list( $backend, , ) = FileBackend::splitStoragePath( $storagePath );
193  if ( $backend !== null && isset( $this->backends[$backend] ) ) {
194  return $this->get( $backend );
195  }
196 
197  return null;
198  }
199 }
FileBackend\splitStoragePath
static splitStoragePath( $storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
Definition: FileBackend.php:1342
FileBackendGroup
Class to handle file backend registration.
Definition: FileBackendGroup.php:31
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LockManagerGroup\singleton
static singleton( $domain=false)
Definition: LockManagerGroup.php:50
FileBackendGroup\config
config( $name)
Get the config array for a backend object with a given name.
Definition: FileBackendGroup.php:175
FileBackendException
Generic file backend exception for checked and unexpected (e.g.
Definition: FileBackend.php:1483
FileBackendGroup\singleton
static singleton()
Definition: FileBackendGroup.php:43
FileBackendGroup\destroySingleton
static destroySingleton()
Destroy the singleton instance.
Definition: FileBackendGroup.php:55
FileJournal
Class for handling file operation journaling.
Definition: FileJournal.php:38
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
list
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
Definition: deferred.txt:11
FileBackendGroup\$instance
static $instance
Definition: FileBackendGroup.php:33
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3604
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
FileBackendGroup\initFromGlobals
initFromGlobals()
Register file backends from the global variables.
Definition: FileBackendGroup.php:62
FileBackendGroup\$backends
array $backends
(name => ('class' => string, 'config' => array, 'instance' => object)) *
Definition: FileBackendGroup.php:35
as
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
Definition: distributors.txt:9
FileBackendGroup\backendFromPath
backendFromPath( $storagePath)
Get an appropriate backend object from a storage path.
Definition: FileBackendGroup.php:190
FileBackendGroup\__construct
__construct()
Definition: FileBackendGroup.php:37
FileJournal\factory
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
Definition: FileJournal.php:61