Merge "[FileBackend] Clear the stat cache in doQuickOperations() for sanity."
[lhc/web/wiklou.git] / includes / filebackend / FileBackendStore.php
index fe57379..2d7fa07 100644 (file)
@@ -93,6 +93,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - content       : the raw file contents
         *   - dst           : destination storage path
         *   - disposition   : Content-Disposition header value for the destination
+        *   - headers       : HTTP header name/value map
         *   - async         : Status will be returned immediately if supported.
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
@@ -130,6 +131,7 @@ abstract class FileBackendStore extends FileBackend {
         *   - src           : source path on disk
         *   - dst           : destination storage path
         *   - disposition   : Content-Disposition header value for the destination
+        *   - headers       : HTTP header name/value map
         *   - async         : Status will be returned immediately if supported.
         *                     If the status is OK, then its value field will be
         *                     set to a FileBackendStoreOpHandle object.
@@ -1066,6 +1068,9 @@ abstract class FileBackendStore extends FileBackend {
                wfProfileIn( __METHOD__ . '-' . $this->name );
                $status = Status::newGood();
 
+               // Fix up custom header name/value pairs...
+               $ops = array_map( array( $this, 'stripInvalidHeadersFromOp' ), $ops );
+
                // Build up a list of FileOps...
                $performOps = $this->getOperationsInternal( $ops );
 
@@ -1115,6 +1120,9 @@ abstract class FileBackendStore extends FileBackend {
                wfProfileIn( __METHOD__ . '-' . $this->name );
                $status = Status::newGood();
 
+               // Fix up custom header name/value pairs...
+               $ops = array_map( array( $this, 'stripInvalidHeadersFromOp' ), $ops );
+
                // Clear any file cache entries
                $this->clearCache();
 
@@ -1209,6 +1217,24 @@ abstract class FileBackendStore extends FileBackend {
                return array();
        }
 
+       /**
+        * Strip long HTTP headers from a file operation
+        *
+        * @param $op array Same format as doOperation()
+        * @return Array
+        */
+       protected function stripInvalidHeadersFromOp( array $op ) {
+               if ( isset( $op['headers'] ) ) {
+                       foreach ( $op['headers'] as $name => $value ) {
+                               if ( strlen( $name ) > 255 || strlen( $value ) > 255 ) {
+                                       trigger_error( "Header '$name: $value' is too long." );
+                                       unset( $op['headers'][$name] );
+                               }
+                       }
+               }
+               return $op;
+       }
+
        /**
         * @see FileBackend::preloadCache()
         */