[FileBackend] Added back ability to delete file HTTP headers.
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Nov 2012 04:58:47 +0000 (20:58 -0800)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 21 Nov 2012 05:30:27 +0000 (05:30 +0000)
* This partially reverts b80bd6159bdf946c1d4fa1e143fea221937d848a.
* Clarified 'headers' parameter documentation a bit.
* Added the "describe" function wrappers that the other ops have.

Change-Id: I7142fd4d973f5f3407d244a4cae793934083bc26

includes/filebackend/FileBackend.php
includes/filebackend/FileBackendStore.php
tests/phpunit/includes/filebackend/FileBackendTest.php

index ef49fe5..6ea042c 100644 (file)
@@ -267,6 +267,9 @@ abstract class FileBackend {
         *   - headers             : If supplied, the backend will return these headers when
         *                           GETs/HEADs of the destination file are made. Header values
         *                           should be smaller than 256 bytes, often options or numbers.
+        *                           Existing headers will remain, but these will replace any
+        *                           conflicting previous headers, and headers will be removed
+        *                           if they are set to an empty string.
         *                           Backends that don't support metadata ignore this. (since 1.21)
         *
         * $opts is an associative of boolean flags, including:
@@ -407,6 +410,21 @@ abstract class FileBackend {
                return $this->doOperation( array( 'op' => 'delete' ) + $params, $opts );
        }
 
+       /**
+        * Performs a single describe operation.
+        * This sets $params['op'] to 'describe' and passes it to doOperation().
+        *
+        * @see FileBackend::doOperation()
+        *
+        * @param $params Array Operation parameters
+        * @param $opts Array Operation options
+        * @return Status
+        * @since 1.21
+        */
+       final public function describe( array $params, array $opts = array() ) {
+               return $this->doOperation( array( 'op' => 'describe' ) + $params, $opts );
+       }
+
        /**
         * Perform a set of independent file operations on some files.
         *
@@ -503,6 +521,9 @@ abstract class FileBackend {
         *   - headers             : If supplied, the backend will return these headers when
         *                           GETs/HEADs of the destination file are made. Header values
         *                           should be smaller than 256 bytes, often options or numbers.
+        *                           Existing headers will remain, but these will replace any
+        *                           conflicting previous headers, and headers will be removed
+        *                           if they are set to an empty string.
         *                           Backends that don't support metadata ignore this. (since 1.21)
         *
         * $opts is an associative of boolean flags, including:
@@ -619,6 +640,20 @@ abstract class FileBackend {
                return $this->doQuickOperation( array( 'op' => 'delete' ) + $params );
        }
 
+       /**
+        * Performs a single quick describe operation.
+        * This sets $params['op'] to 'describe' and passes it to doQuickOperation().
+        *
+        * @see FileBackend::doQuickOperation()
+        *
+        * @param $params Array Operation parameters
+        * @return Status
+        * @since 1.21
+        */
+       final public function quickDescribe( array $params ) {
+               return $this->doQuickOperation( array( 'op' => 'describe' ) + $params );
+       }
+
        /**
         * Concatenate a list of storage files into a single file system file.
         * The target path should refer to a file that is already locked or
index 9bbcc0a..475ac7d 100644 (file)
@@ -1269,8 +1269,7 @@ abstract class FileBackendStore extends FileBackend {
                                        trigger_error( "Header '$name: $value' is too long." );
                                        unset( $op['headers'][$name] );
                                } elseif ( !strlen( $value ) ) {
-                                       trigger_error( "Header value for '$name' is empty." );
-                                       unset( $op['headers'][$name] ); // ignore
+                                       $op['headers'][$name] = ''; // null/false => ""
                                }
                        }
                }
index 5369112..7beb4fe 100644 (file)
@@ -635,7 +635,7 @@ class FileBackendTest extends MediaWikiTestCase {
                $source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt';
 
                $op = array( 'op' => 'describe', 'src' => $source,
-                       'headers' => array( 'X-Content-Length' => '91.3' ),
+                       'headers' => array( 'X-Content-Length' => '91.3', 'Content-Old-Header' => '' ),
                        'disposition' => 'inline' );
                $cases[] = array(
                        $op, // operation