}
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;
}
// 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;
}
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;
$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']
: '';
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.
* @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
* @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 );
* @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
* @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 );