Merge "filebackend: cleaned up the FileBackend constructor"
[lhc/web/wiklou.git] / includes / filebackend / FileBackend.php
index a6eda18..bb21f1b 100644 (file)
@@ -114,35 +114,40 @@ abstract class FileBackend {
         *                   This name should not be changed after use (e.g. with journaling).
         *                   Note that the name is *not* used in actual container names.
         *   - wikiId      : Prefix to container names that is unique to this backend.
-        *                   If not provided, this defaults to the current wiki ID.
         *                   It should only consist of alphanumberic, '-', and '_' characters.
         *                   This ID is what avoids collisions if multiple logical backends
         *                   use the same storage system, so this should be set carefully.
-        *   - lockManager : Registered name of a file lock manager to use.
-        *   - fileJournal : File journal configuration; see FileJournal::factory().
-        *                   Journals simply log changes to files stored in the backend.
+        *   - lockManager : LockManager object to use for any file locking.
+        *                   If not provided, then no file locking will be enforced.
+        *   - fileJournal : FileJournal object to use for logging changes to files.
+        *                   If not provided, then change journaling will be disabled.
         *   - readOnly    : Write operations are disallowed if this is a non-empty string.
         *                   It should be an explanation for the backend being read-only.
         *   - parallelize : When to do file operations in parallel (when possible).
         *                   Allowed values are "implicit", "explicit" and "off".
         *   - concurrency : How many file operations can be done in parallel.
-        * @throws MWException
+        * @throws FileBackendException
         */
        public function __construct( array $config ) {
                $this->name = $config['name'];
                if ( !preg_match( '!^[a-zA-Z0-9-_]{1,255}$!', $this->name ) ) {
-                       throw new MWException( "Backend name `{$this->name}` is invalid." );
+                       throw new FileBackendException( "Backend name `{$this->name}` is invalid." );
                }
-               $this->wikiId = isset( $config['wikiId'] )
-                       ? $config['wikiId']
-                       : wfWikiID(); // e.g. "my_wiki-en_"
-               $this->lockManager = ( $config['lockManager'] instanceof LockManager )
+               if ( !isset( $config['wikiId'] ) ) {
+                       $config['wikiId'] = wfWikiID();
+                       wfDeprecated( __METHOD__ . ' called without "wikiID".', '1.23' );
+               }
+               if ( isset( $config['lockManager'] ) && !is_object( $config['lockManager'] ) ) {
+                       $config['lockManager'] =
+                               LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] );
+                       wfDeprecated( __METHOD__ . ' called with non-object "lockManager".', '1.23' );
+               }
+               $this->wikiId = $config['wikiId']; // e.g. "my_wiki-en_"
+               $this->lockManager = isset( $config['lockManager'] )
                        ? $config['lockManager']
-                       : LockManagerGroup::singleton( $this->wikiId )->get( $config['lockManager'] );
+                       : new NullLockManager( array() );
                $this->fileJournal = isset( $config['fileJournal'] )
-                       ? ( ( $config['fileJournal'] instanceof FileJournal )
-                               ? $config['fileJournal']
-                               : FileJournal::factory( $config['fileJournal'], $this->name ) )
+                       ? $config['fileJournal']
                        : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $this->name );
                $this->readOnly = isset( $config['readOnly'] )
                        ? (string)$config['readOnly']
@@ -1360,7 +1365,7 @@ abstract class FileBackend {
         *
         * @param string $type One of (attachment, inline)
         * @param string $filename Suggested file name (should not contain slashes)
-        * @throws MWException
+        * @throws FileBackendError
         * @return string
         * @since 1.20
         */
@@ -1369,7 +1374,7 @@ abstract class FileBackend {
 
                $type = strtolower( $type );
                if ( !in_array( $type, array( 'inline', 'attachment' ) ) ) {
-                       throw new MWException( "Invalid Content-Disposition type '$type'." );
+                       throw new FileBackendError( "Invalid Content-Disposition type '$type'." );
                }
                $parts[] = $type;
 
@@ -1416,8 +1421,19 @@ abstract class FileBackend {
 }
 
 /**
+ * Generic file backend exception for checked and unexpected (e.g. config) exceptions
+ *
+ * @ingroup FileBackend
+ * @since 1.23
+ */
+class FileBackendException extends MWException {
+}
+
+/**
+ * File backend exception for checked exceptions (e.g. I/O errors)
+ *
  * @ingroup FileBackend
  * @since 1.22
  */
-class FileBackendError extends MWException {
+class FileBackendError extends FileBackendException {
 }