From: Aaron Schulz Date: Mon, 6 Feb 2012 05:25:26 +0000 (+0000) Subject: In FileBackend: X-Git-Tag: 1.31.0-rc.0~24924 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=e0c78101e5dec086110bb6b76b9ad9092a2c6690;p=lhc%2Fweb%2Fwiklou.git In FileBackend: * Added simple getReadOnly()/getReadOnlyReason() functions. * Allow directly passing a LockManager object into __construct(), useful for testing. * Fixed bug in FSFileBackend were creating empty files would result in a failing status. * Added more file stat unit tests. --- diff --git a/includes/filerepo/backend/FSFileBackend.php b/includes/filerepo/backend/FSFileBackend.php index 3eabd29cfe..4556eaa03c 100644 --- a/includes/filerepo/backend/FSFileBackend.php +++ b/includes/filerepo/backend/FSFileBackend.php @@ -316,9 +316,9 @@ class FSFileBackend extends FileBackendStore { } wfSuppressWarnings(); - $ok = file_put_contents( $dest, $params['content'] ); + $bytes = file_put_contents( $dest, $params['content'] ); wfRestoreWarnings(); - if ( !$ok ) { + if ( $bytes === false ) { $status->fatal( 'backend-fail-create', $params['dst'] ); return $status; } @@ -357,9 +357,9 @@ class FSFileBackend extends FileBackendStore { // Seed new directories with a blank index.html, to prevent crawling... if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) { wfSuppressWarnings(); - $ok = file_put_contents( "{$dir}/index.html", '' ); + $bytes = file_put_contents( "{$dir}/index.html", '' ); wfRestoreWarnings(); - if ( !$ok ) { + if ( !$bytes ) { $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' ); return $status; } @@ -368,9 +368,9 @@ class FSFileBackend extends FileBackendStore { if ( !empty( $params['noAccess'] ) ) { if ( !file_exists( "{$contRoot}/.htaccess" ) ) { wfSuppressWarnings(); - $ok = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" ); + $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" ); wfRestoreWarnings(); - if ( !$ok ) { + if ( !$bytes ) { $storeDir = "mwstore://{$this->name}/{$shortCont}"; $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" ); return $status; diff --git a/includes/filerepo/backend/FileBackend.php b/includes/filerepo/backend/FileBackend.php index 27e3b844d1..b4b9ea244b 100644 --- a/includes/filerepo/backend/FileBackend.php +++ b/includes/filerepo/backend/FileBackend.php @@ -56,7 +56,9 @@ abstract class FileBackend { $this->wikiId = isset( $config['wikiId'] ) ? $config['wikiId'] : wfWikiID(); // e.g. "my_wiki-en_" - $this->lockManager = LockManagerGroup::singleton()->get( $config['lockManager'] ); + $this->lockManager = ( $config['lockManager'] instanceof LockManager ) + ? $config['lockManager'] + : LockManagerGroup::singleton()->get( $config['lockManager'] ); $this->readOnly = isset( $config['readOnly'] ) ? (string)$config['readOnly'] : ''; @@ -73,6 +75,24 @@ abstract class FileBackend { return $this->name; } + /** + * Check if this backend is read-only + * + * @return bool + */ + final public function isReadOnly() { + return ( $this->readOnly != '' ); + } + + /** + * Get an explanatory message if this backend is read-only + * + * @return string|false Returns falls if the backend is not read-only + */ + final public function getReadOnlyReason() { + return ( $this->readOnly != '' ) ? $this->readOnly : false; + } + /** * This is the main entry point into the backend for write operations. * Callers supply an ordered list of operations to perform as a transaction. @@ -160,7 +180,7 @@ abstract class FileBackend { * @return Status */ final public function doOperations( array $ops, array $opts = array() ) { - if ( $this->readOnly != '' ) { + if ( $this->isReadOnly() ) { return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); } if ( empty( $opts['force'] ) ) { // sanity @@ -291,7 +311,7 @@ abstract class FileBackend { * @return Status */ final public function prepare( array $params ) { - if ( $this->readOnly != '' ) { + if ( $this->isReadOnly() ) { return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); } return $this->doPrepare( $params ); @@ -318,7 +338,7 @@ abstract class FileBackend { * @return Status */ final public function secure( array $params ) { - if ( $this->readOnly != '' ) { + if ( $this->isReadOnly() ) { return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); } $status = $this->doPrepare( $params ); // dir must exist to restrict it @@ -345,7 +365,7 @@ abstract class FileBackend { * @return Status */ final public function clean( array $params ) { - if ( $this->readOnly != '' ) { + if ( $this->isReadOnly() ) { return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); } return $this->doClean( $params );