Merge "CologneBlue rewrite: rewrite bottomLinks()"
[lhc/web/wiklou.git] / includes / filebackend / FileBackend.php
index 042cb67..e01bfc2 100644 (file)
@@ -128,6 +128,17 @@ abstract class FileBackend {
                return $this->name;
        }
 
+       /**
+        * Get the wiki identifier used for this backend (possibly empty).
+        * Note that this might *not* be in the same format as wfWikiID().
+        *
+        * @return string
+        * @since 1.20
+        */
+       final public function getWikiId() {
+               return $this->wikiId;
+       }
+
        /**
         * Check if this backend is read-only
         *
@@ -195,6 +206,7 @@ abstract class FileBackend {
         *         'dst'                 => <storage path>,
         *         'overwrite'           => <boolean>,
         *         'overwriteSame'       => <boolean>,
+        *         'ignoreMissingSource' => <boolean>, # since 1.21
         *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
@@ -207,6 +219,7 @@ abstract class FileBackend {
         *         'dst'                 => <storage path>,
         *         'overwrite'           => <boolean>,
         *         'overwriteSame'       => <boolean>,
+        *         'ignoreMissingSource' => <boolean>, # since 1.21
         *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
@@ -416,6 +429,7 @@ abstract class FileBackend {
         *         'op'                  => 'copy',
         *         'src'                 => <storage path>,
         *         'dst'                 => <storage path>,
+        *         'ignoreMissingSource' => <boolean>, # since 1.21
         *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
@@ -425,6 +439,7 @@ abstract class FileBackend {
         *         'op'                  => 'move',
         *         'src'                 => <storage path>,
         *         'dst'                 => <storage path>,
+        *         'ignoreMissingSource' => <boolean>, # since 1.21
         *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
@@ -573,8 +588,9 @@ abstract class FileBackend {
         *
         * @param $params Array Operation parameters
         * $params include:
-        *   - srcs : ordered source storage paths (e.g. chunk1, chunk2, ...)
-        *   - dst  : file system path to 0-byte temp file
+        *   - srcs        : ordered source storage paths (e.g. chunk1, chunk2, ...)
+        *   - dst         : file system path to 0-byte temp file
+        *   - parallelize : try to do operations in parallel when possible
         * @return Status
         */
        abstract public function concatenate( array $params );
@@ -720,7 +736,29 @@ abstract class FileBackend {
         *   - latest : use the latest available data
         * @return string|bool Returns false on failure
         */
-       abstract public function getFileContents( array $params );
+       final public function getFileContents( array $params ) {
+               $contents = $this->getFileContentsMulti(
+                       array( 'srcs' => array( $params['src'] ) ) + $params );
+
+               return $contents[$params['src']];
+       }
+
+       /**
+        * Like getFileContents() except it takes an array of storage paths
+        * and returns a map of storage paths to strings (or null on failure).
+        * The map keys (paths) are in the same order as the provided list of paths.
+        *
+        * @see FileBackend::getFileContents()
+        *
+        * @param $params Array
+        * $params include:
+        *   - srcs        : list of source storage paths
+        *   - latest      : use the latest available data
+        *   - parallelize : try to do operations in parallel when possible
+        * @return Array Map of (path name => string or false on failure)
+        * @since 1.20
+        */
+       abstract public function getFileContentsMulti( array $params );
 
        /**
         * Get the size (bytes) of a file at a storage path in the backend.
@@ -807,7 +845,29 @@ abstract class FileBackend {
         *   - latest : use the latest available data
         * @return FSFile|null Returns null on failure
         */
-       abstract public function getLocalReference( array $params );
+       final public function getLocalReference( array $params ) {
+               $fsFiles = $this->getLocalReferenceMulti(
+                       array( 'srcs' => array( $params['src'] ) ) + $params );
+
+               return $fsFiles[$params['src']];
+       }
+
+       /**
+        * Like getLocalReference() except it takes an array of storage paths
+        * and returns a map of storage paths to FSFile objects (or null on failure).
+        * The map keys (paths) are in the same order as the provided list of paths.
+        *
+        * @see FileBackend::getLocalReference()
+        *
+        * @param $params Array
+        * $params include:
+        *   - srcs        : list of source storage paths
+        *   - latest      : use the latest available data
+        *   - parallelize : try to do operations in parallel when possible
+        * @return Array Map of (path name => FSFile or null on failure)
+        * @since 1.20
+        */
+       abstract public function getLocalReferenceMulti( array $params );
 
        /**
         * Get a local copy on disk of the file at a storage path in the backend.
@@ -820,7 +880,29 @@ abstract class FileBackend {
         *   - latest : use the latest available data
         * @return TempFSFile|null Returns null on failure
         */
-       abstract public function getLocalCopy( array $params );
+       final public function getLocalCopy( array $params ) {
+               $tmpFiles = $this->getLocalCopyMulti(
+                       array( 'srcs' => array( $params['src'] ) ) + $params );
+
+               return $tmpFiles[$params['src']];
+       }
+
+       /**
+        * Like getLocalCopy() except it takes an array of storage paths and
+        * returns a map of storage paths to TempFSFile objects (or null on failure).
+        * The map keys (paths) are in the same order as the provided list of paths.
+        *
+        * @see FileBackend::getLocalCopy()
+        *
+        * @param $params Array
+        * $params include:
+        *   - srcs        : list of source storage paths
+        *   - latest      : use the latest available data
+        *   - parallelize : try to do operations in parallel when possible
+        * @return Array Map of (path name => TempFSFile or null on failure)
+        * @since 1.20
+        */
+       abstract public function getLocalCopyMulti( array $params );
 
        /**
         * Check if a directory exists at a given storage path.
@@ -995,6 +1077,17 @@ abstract class FileBackend {
                return "mwstore://{$this->name}";
        }
 
+       /**
+        * Get the storage path for the given container for this backend
+        *
+        * @param $container string Container name
+        * @return string Storage path
+        * @since 1.21
+        */
+       final public function getContainerStoragePath( $container ) {
+               return $this->getRootStoragePath() . "/{$container}";
+       }
+
        /**
         * Get the file journal object for this backend
         *
@@ -1099,6 +1192,7 @@ abstract class FileBackend {
         *
         * @param $type string One of (attachment, inline)
         * @param $filename string Suggested file name (should not contain slashes)
+        * @throws MWException
         * @return string
         * @since 1.20
         */