[FileBackend] A few code cleanups and some error message improvements.
authorAaron <aschulz@wikimedia.org>
Thu, 17 May 2012 18:28:05 +0000 (11:28 -0700)
committerAaron <aschulz@wikimedia.org>
Thu, 17 May 2012 18:34:15 +0000 (11:34 -0700)
Change-Id: I75f066104b98638ca956042c4e877c0f6327509c

includes/filerepo/backend/FileBackend.php
includes/filerepo/backend/FileBackendStore.php
includes/filerepo/backend/FileOp.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index bb3f9ee..94e509e 100644 (file)
@@ -286,8 +286,7 @@ abstract class FileBackend {
         * @return Status
         */
        final public function create( array $params, array $opts = array() ) {
-               $params['op'] = 'create';
-               return $this->doOperation( $params, $opts );
+               return $this->doOperation( array( 'op' => 'create' ) + $params, $opts );
        }
 
        /**
@@ -301,8 +300,7 @@ abstract class FileBackend {
         * @return Status
         */
        final public function store( array $params, array $opts = array() ) {
-               $params['op'] = 'store';
-               return $this->doOperation( $params, $opts );
+               return $this->doOperation( array( 'op' => 'store' ) + $params, $opts );
        }
 
        /**
@@ -316,8 +314,7 @@ abstract class FileBackend {
         * @return Status
         */
        final public function copy( array $params, array $opts = array() ) {
-               $params['op'] = 'copy';
-               return $this->doOperation( $params, $opts );
+               return $this->doOperation( array( 'op' => 'copy' ) + $params, $opts );
        }
 
        /**
@@ -331,8 +328,7 @@ abstract class FileBackend {
         * @return Status
         */
        final public function move( array $params, array $opts = array() ) {
-               $params['op'] = 'move';
-               return $this->doOperation( $params, $opts );
+               return $this->doOperation( array( 'op' => 'move' ) + $params, $opts );
        }
 
        /**
@@ -346,8 +342,7 @@ abstract class FileBackend {
         * @return Status
         */
        final public function delete( array $params, array $opts = array() ) {
-               $params['op'] = 'delete';
-               return $this->doOperation( $params, $opts );
+               return $this->doOperation( array( 'op' => 'delete' ) + $params, $opts );
        }
 
        /**
index 1b788db..5537e93 100644 (file)
@@ -137,7 +137,8 @@ abstract class FileBackendStore extends FileBackend {
                wfProfileIn( __METHOD__ );
                wfProfileIn( __METHOD__ . '-' . $this->name );
                if ( filesize( $params['src'] ) > $this->maxFileSizeInternal() ) {
-                       $status = Status::newFatal( 'backend-fail-store', $params['dst'] );
+                       $status = Status::newFatal( 'backend-fail-maxsize',
+                               $params['dst'], $this->maxFileSizeInternal() );
                } else {
                        $status = $this->doStoreInternal( $params );
                        $this->clearCache( array( $params['dst'] ) );
index d134edd..b2b46ed 100644 (file)
@@ -450,10 +450,13 @@ class StoreFileOp extends FileOp {
                        return $status;
                // Check if the source file is too big
                } elseif ( filesize( $this->params['src'] ) > $this->backend->maxFileSizeInternal() ) {
+                       $status->fatal( 'backend-fail-maxsize',
+                               $this->params['dst'], $this->backend->maxFileSizeInternal() );
                        $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
                        return $status;
                }
@@ -507,10 +510,13 @@ class CreateFileOp extends FileOp {
                $status = Status::newGood();
                // Check if the source data is too big
                if ( strlen( $this->getParam( 'content' ) ) > $this->backend->maxFileSizeInternal() ) {
+                       $status->fatal( 'backend-fail-maxsize',
+                               $this->params['dst'], $this->backend->maxFileSizeInternal() );
                        $status->fatal( 'backend-fail-create', $this->params['dst'] );
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-create', $this->params['dst'] );
                        return $status;
                }
@@ -562,6 +568,7 @@ class CopyFileOp extends FileOp {
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-copy', $this->params['src'], $this->params['dst'] );
                        return $status;
                }
@@ -616,6 +623,7 @@ class MoveFileOp extends FileOp {
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-move', $this->params['src'], $this->params['dst'] );
                        return $status;
                }
index c13c9da..e3a1dee 100644 (file)
@@ -2283,8 +2283,9 @@ If the problem persists, contact an [[Special:ListUsers/sysop|administrator]].',
 'backend-fail-writetemp'     => 'Could not write to temporary file.',
 'backend-fail-closetemp'     => 'Could not close temporary file.',
 'backend-fail-read'          => 'Could not read file $1.',
-'backend-fail-create'        => 'Could not create file $1.',
-'backend-fail-maxsize'       => 'Could not create file $1 because it is larger than {{PLURAL:$2|one byte|$2 bytes}}.',
+'backend-fail-create'        => 'Could not write file $1.',
+'backend-fail-maxsize'       => 'Could not write file $1 because it is larger than {{PLURAL:$2|one byte|$2 bytes}}.',
+'backend-fail-usable'        => 'Could not write file $1 due to insufficient permissions or missing directories/containers.',
 'backend-fail-readonly'      => 'The storage backend "$1" is currently read-only. The reason given is: "\'\'$2\'\'"',
 'backend-fail-synced'        => 'The file "$1" is in an inconsistent state within the internal storage backends',
 'backend-fail-connect'       => 'Could not connect to storage backend "$1".',
index eb85c53..9ccf5f3 100644 (file)
@@ -1966,6 +1966,8 @@ Extensions making use of it:
 Parameters:
 * $1 is the number of operations attempted at once in this case.
 * $2 is the maximum number of operations that can be attempted at once.',
+'backend-fail-usable' => 'Parameters:
+* $1 is a file path',
 
 # File journal errors
 'filejournal-fail-dbconnect' => 'Parameters:
index c55b83d..6bf74b5 100644 (file)
@@ -1388,7 +1388,8 @@ $wgMessageStructure = array(
                'backend-fail-connect',
                'backend-fail-internal',
                'backend-fail-contenttype',
-               'backend-fail-batchsize'
+               'backend-fail-batchsize',
+               'backend-fail-usable'
        ),
 
        'filejournal-errors' => array(