r110731 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110730‎ | r110731 | r110732 >
Date:05:25, 6 February 2012
Author:aaron
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -316,9 +316,9 @@
317317 }
318318
319319 wfSuppressWarnings();
320 - $ok = file_put_contents( $dest, $params['content'] );
 320+ $bytes = file_put_contents( $dest, $params['content'] );
321321 wfRestoreWarnings();
322 - if ( !$ok ) {
 322+ if ( $bytes === false ) {
323323 $status->fatal( 'backend-fail-create', $params['dst'] );
324324 return $status;
325325 }
@@ -357,9 +357,9 @@
358358 // Seed new directories with a blank index.html, to prevent crawling...
359359 if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) {
360360 wfSuppressWarnings();
361 - $ok = file_put_contents( "{$dir}/index.html", '' );
 361+ $bytes = file_put_contents( "{$dir}/index.html", '' );
362362 wfRestoreWarnings();
363 - if ( !$ok ) {
 363+ if ( !$bytes ) {
364364 $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' );
365365 return $status;
366366 }
@@ -368,9 +368,9 @@
369369 if ( !empty( $params['noAccess'] ) ) {
370370 if ( !file_exists( "{$contRoot}/.htaccess" ) ) {
371371 wfSuppressWarnings();
372 - $ok = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" );
 372+ $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" );
373373 wfRestoreWarnings();
374 - if ( !$ok ) {
 374+ if ( !$bytes ) {
375375 $storeDir = "mwstore://{$this->name}/{$shortCont}";
376376 $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" );
377377 return $status;
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -56,7 +56,9 @@
5757 $this->wikiId = isset( $config['wikiId'] )
5858 ? $config['wikiId']
5959 : 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'] );
6163 $this->readOnly = isset( $config['readOnly'] )
6264 ? (string)$config['readOnly']
6365 : '';
@@ -74,6 +76,24 @@
7577 }
7678
7779 /**
 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+ /**
7898 * This is the main entry point into the backend for write operations.
7999 * Callers supply an ordered list of operations to perform as a transaction.
80100 * Files will be locked, the stat cache cleared, and then the operations attempted.
@@ -160,7 +180,7 @@
161181 * @return Status
162182 */
163183 final public function doOperations( array $ops, array $opts = array() ) {
164 - if ( $this->readOnly != '' ) {
 184+ if ( $this->isReadOnly() ) {
165185 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
166186 }
167187 if ( empty( $opts['force'] ) ) { // sanity
@@ -291,7 +311,7 @@
292312 * @return Status
293313 */
294314 final public function prepare( array $params ) {
295 - if ( $this->readOnly != '' ) {
 315+ if ( $this->isReadOnly() ) {
296316 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
297317 }
298318 return $this->doPrepare( $params );
@@ -318,7 +338,7 @@
319339 * @return Status
320340 */
321341 final public function secure( array $params ) {
322 - if ( $this->readOnly != '' ) {
 342+ if ( $this->isReadOnly() ) {
323343 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
324344 }
325345 $status = $this->doPrepare( $params ); // dir must exist to restrict it
@@ -345,7 +365,7 @@
346366 * @return Status
347367 */
348368 final public function clean( array $params ) {
349 - if ( $this->readOnly != '' ) {
 369+ if ( $this->isReadOnly() ) {
350370 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
351371 }
352372 return $this->doClean( $params );

Follow-up revisions

RevisionCommit summaryAuthorDate
r110732Added missing tests from r110731aaron05:26, 6 February 2012

Status & tagging log