Added @since to new function.
[lhc/web/wiklou.git] / includes / filebackend / FileBackend.php
index 4b707fc..e59a13b 100644 (file)
@@ -39,8 +39,7 @@
  * All "storage paths" are of the format "mwstore://<backend>/<container>/<path>".
  * The "<path>" portion is a relative path that uses UNIX file system (FS)
  * notation, though any particular backend may not actually be using a local
- * filesystem.
- * Therefore, the relative paths are only virtual.
+ * filesystem. Therefore, the relative paths are only virtual.
  *
  * Backend contents are stored under wiki-specific container names by default.
  * For legacy reasons, this has no effect for the FS backend class, and per-wiki
@@ -171,7 +170,8 @@ abstract class FileBackend {
         *         'dst'                 => <storage path>,
         *         'content'             => <string of new file contents>,
         *         'overwrite'           => <boolean>,
-        *         'overwriteSame'       => <boolean>
+        *         'overwriteSame'       => <boolean>,
+        *         'disposition'         => <Content-Disposition header value>
         *     );
         * @endcode
         *
@@ -182,7 +182,8 @@ abstract class FileBackend {
         *         'src'                 => <file system path>,
         *         'dst'                 => <storage path>,
         *         'overwrite'           => <boolean>,
-        *         'overwriteSame'       => <boolean>
+        *         'overwriteSame'       => <boolean>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         *
@@ -193,7 +194,8 @@ abstract class FileBackend {
         *         'src'                 => <storage path>,
         *         'dst'                 => <storage path>,
         *         'overwrite'           => <boolean>,
-        *         'overwriteSame'       => <boolean>
+        *         'overwriteSame'       => <boolean>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         *
@@ -204,7 +206,8 @@ abstract class FileBackend {
         *         'src'                 => <storage path>,
         *         'dst'                 => <storage path>,
         *         'overwrite'           => <boolean>,
-        *         'overwriteSame'       => <boolean>
+        *         'overwriteSame'       => <boolean>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         *
@@ -231,6 +234,10 @@ abstract class FileBackend {
         *   - overwriteSame       : An error will not be given if a file already
         *                           exists at the destination that has the same
         *                           contents as the new contents to be written there.
+        *   - disposition         : When supplied, the backend will add a Content-Disposition
+        *                           header when GETs/HEADs of the destination file are made.
+        *                           Backends that don't support file metadata will ignore this.
+        *                           See http://tools.ietf.org/html/rfc6266 (since 1.20).
         *
         * $opts is an associative of boolean flags, including:
         *   - force               : Operation precondition errors no longer trigger an abort.
@@ -242,6 +249,9 @@ abstract class FileBackend {
         *   - allowStale          : Don't require the latest available data.
         *                           This can increase performance for non-critical writes.
         *                           This has no effect unless the 'force' flag is set.
+        *   - preserveCache       : Don't clear the process cache before checking files.
+        *                           This should only be used if all entries in the process
+        *                           cache were added after the files were already locked.
         *   - nonJournaled        : Don't log this operation batch in the file journal.
         *                           This limits the ability of recovery scripts.
         *   - parallelize         : Try to do operations in parallel when possible.
@@ -397,7 +407,8 @@ abstract class FileBackend {
         *     array(
         *         'op'                  => 'create',
         *         'dst'                 => <storage path>,
-        *         'content'             => <string of new file contents>
+        *         'content'             => <string of new file contents>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         * b) Copy a file system file into storage
@@ -405,7 +416,8 @@ abstract class FileBackend {
         *     array(
         *         'op'                  => 'store',
         *         'src'                 => <file system path>,
-        *         'dst'                 => <storage path>
+        *         'dst'                 => <storage path>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         * c) Copy a file within storage
@@ -413,7 +425,8 @@ abstract class FileBackend {
         *     array(
         *         'op'                  => 'copy',
         *         'src'                 => <storage path>,
-        *         'dst'                 => <storage path>
+        *         'dst'                 => <storage path>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         * d) Move a file within storage
@@ -421,7 +434,8 @@ abstract class FileBackend {
         *     array(
         *         'op'                  => 'move',
         *         'src'                 => <storage path>,
-        *         'dst'                 => <storage path>
+        *         'dst'                 => <storage path>,
+        *         'disposition'         => <Content-Disposition header value>
         *     )
         * @endcode
         * e) Delete a file within storage
@@ -442,6 +456,10 @@ abstract class FileBackend {
         * @par Boolean flags for operations (operation-specific):
         *   - ignoreMissingSource : The operation will simply succeed and do
         *                           nothing if the source file does not exist.
+        *   - disposition         : When supplied, the backend will add a Content-Disposition
+        *                           header when GETs/HEADs of the destination file are made.
+        *                           Backends that don't support file metadata will ignore this.
+        *                           See http://tools.ietf.org/html/rfc6266 (since 1.20).
         *
         * $opts is an associative of boolean flags, including:
         *   - bypassReadOnly      : Allow writes in read-only mode (since 1.20)
@@ -899,7 +917,16 @@ abstract class FileBackend {
        }
 
        /**
-        * Invalidate any in-process file existence and property cache.
+        * Preload persistent file stat and property cache into in-process cache.
+        * This should be used when stat calls will be made on a known list of a many files.
+        *
+        * @param $paths Array Storage paths
+        * @return void
+        */
+       public function preloadCache( array $paths ) {}
+
+       /**
+        * Invalidate any in-process file stat and property cache.
         * If $paths is given, then only the cache for those files will be cleared.
         *
         * @param $paths Array Storage paths (optional)
@@ -1077,6 +1104,20 @@ abstract class FileBackend {
                return ( self::normalizeContainerPath( $path ) !== null );
        }
 
+       /**
+        * Build a Content-Disposition header value per RFC 6266
+        *
+        * @param $type string One of (attachment, inline)
+        * @param $filename string Suggested file name (should not contain slashes)
+        * @return string
+        * @since 1.20
+        */
+       final public static function makeContentDisposition( $type, $filename ) {
+               $type = strtolower( $type );
+               $type = in_array( $type, array( 'inline', 'attachment' ) ) ? $type : 'inline';
+               return "$type; filename*=UTF-8''" . rawurlencode( basename( $filename ) );
+       }
+
        /**
         * Validate and normalize a relative storage path.
         * Null is returned if the path involves directory traversal.