Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php |
— | — | @@ -316,9 +316,9 @@ |
317 | 317 | } |
318 | 318 | |
319 | 319 | wfSuppressWarnings(); |
320 | | - $ok = file_put_contents( $dest, $params['content'] ); |
| 320 | + $bytes = file_put_contents( $dest, $params['content'] ); |
321 | 321 | wfRestoreWarnings(); |
322 | | - if ( !$ok ) { |
| 322 | + if ( $bytes === false ) { |
323 | 323 | $status->fatal( 'backend-fail-create', $params['dst'] ); |
324 | 324 | return $status; |
325 | 325 | } |
— | — | @@ -357,9 +357,9 @@ |
358 | 358 | // Seed new directories with a blank index.html, to prevent crawling... |
359 | 359 | if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) { |
360 | 360 | wfSuppressWarnings(); |
361 | | - $ok = file_put_contents( "{$dir}/index.html", '' ); |
| 361 | + $bytes = file_put_contents( "{$dir}/index.html", '' ); |
362 | 362 | wfRestoreWarnings(); |
363 | | - if ( !$ok ) { |
| 363 | + if ( !$bytes ) { |
364 | 364 | $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' ); |
365 | 365 | return $status; |
366 | 366 | } |
— | — | @@ -368,9 +368,9 @@ |
369 | 369 | if ( !empty( $params['noAccess'] ) ) { |
370 | 370 | if ( !file_exists( "{$contRoot}/.htaccess" ) ) { |
371 | 371 | wfSuppressWarnings(); |
372 | | - $ok = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" ); |
| 372 | + $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" ); |
373 | 373 | wfRestoreWarnings(); |
374 | | - if ( !$ok ) { |
| 374 | + if ( !$bytes ) { |
375 | 375 | $storeDir = "mwstore://{$this->name}/{$shortCont}"; |
376 | 376 | $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" ); |
377 | 377 | return $status; |
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -56,7 +56,9 @@ |
57 | 57 | $this->wikiId = isset( $config['wikiId'] ) |
58 | 58 | ? $config['wikiId'] |
59 | 59 | : wfWikiID(); // e.g. "my_wiki-en_" |
60 | | - $this->lockManager = LockManagerGroup::singleton()->get( $config['lockManager'] ); |
| 60 | + $this->lockManager = ( $config['lockManager'] instanceof LockManager ) |
| 61 | + ? $config['lockManager'] |
| 62 | + : LockManagerGroup::singleton()->get( $config['lockManager'] ); |
61 | 63 | $this->readOnly = isset( $config['readOnly'] ) |
62 | 64 | ? (string)$config['readOnly'] |
63 | 65 | : ''; |
— | — | @@ -74,6 +76,24 @@ |
75 | 77 | } |
76 | 78 | |
77 | 79 | /** |
| 80 | + * Check if this backend is read-only |
| 81 | + * |
| 82 | + * @return bool |
| 83 | + */ |
| 84 | + final public function isReadOnly() { |
| 85 | + return ( $this->readOnly != '' ); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Get an explanatory message if this backend is read-only |
| 90 | + * |
| 91 | + * @return string|false Returns falls if the backend is not read-only |
| 92 | + */ |
| 93 | + final public function getReadOnlyReason() { |
| 94 | + return ( $this->readOnly != '' ) ? $this->readOnly : false; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
78 | 98 | * This is the main entry point into the backend for write operations. |
79 | 99 | * Callers supply an ordered list of operations to perform as a transaction. |
80 | 100 | * Files will be locked, the stat cache cleared, and then the operations attempted. |
— | — | @@ -160,7 +180,7 @@ |
161 | 181 | * @return Status |
162 | 182 | */ |
163 | 183 | final public function doOperations( array $ops, array $opts = array() ) { |
164 | | - if ( $this->readOnly != '' ) { |
| 184 | + if ( $this->isReadOnly() ) { |
165 | 185 | return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); |
166 | 186 | } |
167 | 187 | if ( empty( $opts['force'] ) ) { // sanity |
— | — | @@ -291,7 +311,7 @@ |
292 | 312 | * @return Status |
293 | 313 | */ |
294 | 314 | final public function prepare( array $params ) { |
295 | | - if ( $this->readOnly != '' ) { |
| 315 | + if ( $this->isReadOnly() ) { |
296 | 316 | return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); |
297 | 317 | } |
298 | 318 | return $this->doPrepare( $params ); |
— | — | @@ -318,7 +338,7 @@ |
319 | 339 | * @return Status |
320 | 340 | */ |
321 | 341 | final public function secure( array $params ) { |
322 | | - if ( $this->readOnly != '' ) { |
| 342 | + if ( $this->isReadOnly() ) { |
323 | 343 | return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); |
324 | 344 | } |
325 | 345 | $status = $this->doPrepare( $params ); // dir must exist to restrict it |
— | — | @@ -345,7 +365,7 @@ |
346 | 366 | * @return Status |
347 | 367 | */ |
348 | 368 | final public function clean( array $params ) { |
349 | | - if ( $this->readOnly != '' ) { |
| 369 | + if ( $this->isReadOnly() ) { |
350 | 370 | return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); |
351 | 371 | } |
352 | 372 | return $this->doClean( $params ); |