[FileBackend] A few code cleanups and some error message improvements.

Change-Id: I75f066104b98638ca956042c4e877c0f6327509c
This commit is contained in:
Aaron 2012-05-17 11:28:05 -07:00
parent 4024de4bd8
commit 159cc27fde
6 changed files with 22 additions and 14 deletions

View 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 );
}
/**

View 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'] ) );

View 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;
}

View 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".',

View 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:

View 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(