From 2e0e6a00133c17a4d403c8ae403365ab71db0d11 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 20 Nov 2012 20:58:47 -0800 Subject: [PATCH] [FileBackend] Added back ability to delete file HTTP headers. * 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 | 35 +++++++++++++++++++ includes/filebackend/FileBackendStore.php | 3 +- .../includes/filebackend/FileBackendTest.php | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/includes/filebackend/FileBackend.php b/includes/filebackend/FileBackend.php index ef49fe5442..6ea042c84b 100644 --- a/includes/filebackend/FileBackend.php +++ b/includes/filebackend/FileBackend.php @@ -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 diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index 9bbcc0a375..475ac7decb 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -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 => "" } } } diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index 5369112964..7beb4feeab 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -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 -- 2.20.1