r112347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112346‎ | r112347 | r112348 >
Date:20:10, 24 February 2012
Author:aaron
Status:ok (Comments)
Tags:
Comment:
In FSFileBackend:
* Removed some error suppression as display_errors should never be enabled for production sites and the suppression hid useful log information.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -16,7 +16,7 @@
1717 * Sharding can be accomplished by using FileRepo-style hash paths.
1818 *
1919 * Status messages should avoid mentioning the internal FS paths.
20 - * Likewise, error suppression should be used to avoid path disclosure.
 20+ * PHP warnings are assumed to be logged rather than output.
2121 *
2222 * @ingroup FileBackend
2323 * @since 1.19
@@ -41,14 +41,13 @@
4242 parent::__construct( $config );
4343
4444 // Remove any possible trailing slash from directories
45 -
4645 if ( isset( $config['basePath'] ) ) {
4746 $this->basePath = rtrim( $config['basePath'], '/' ); // remove trailing slash
4847 } else {
4948 $this->basePath = null; // none; containers must have explicit paths
5049 }
5150
52 - if( isset( $config['containerPaths'] ) ) {
 51+ if ( isset( $config['containerPaths'] ) ) {
5352 $this->containerPaths = (array)$config['containerPaths'];
5453 foreach ( $this->containerPaths as &$path ) {
5554 $path = rtrim( $path, '/' ); // remove trailing slash
@@ -140,13 +139,11 @@
141140 }
142141 $parentDir = dirname( $fsPath );
143142
144 - wfSuppressWarnings();
145143 if ( file_exists( $fsPath ) ) {
146144 $ok = is_file( $fsPath ) && is_writable( $fsPath );
147145 } else {
148146 $ok = is_dir( $parentDir ) && is_writable( $parentDir );
149147 }
150 - wfRestoreWarnings();
151148
152149 return $ok;
153150 }
@@ -166,9 +163,7 @@
167164
168165 if ( file_exists( $dest ) ) {
169166 if ( !empty( $params['overwrite'] ) ) {
170 - wfSuppressWarnings();
171167 $ok = unlink( $dest );
172 - wfRestoreWarnings();
173168 if ( !$ok ) {
174169 $status->fatal( 'backend-fail-delete', $params['dst'] );
175170 return $status;
@@ -179,9 +174,7 @@
180175 }
181176 }
182177
183 - wfSuppressWarnings();
184178 $ok = copy( $params['src'], $dest );
185 - wfRestoreWarnings();
186179 if ( !$ok ) {
187180 $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
188181 return $status;
@@ -213,9 +206,7 @@
214207
215208 if ( file_exists( $dest ) ) {
216209 if ( !empty( $params['overwrite'] ) ) {
217 - wfSuppressWarnings();
218210 $ok = unlink( $dest );
219 - wfRestoreWarnings();
220211 if ( !$ok ) {
221212 $status->fatal( 'backend-fail-delete', $params['dst'] );
222213 return $status;
@@ -226,9 +217,7 @@
227218 }
228219 }
229220
230 - wfSuppressWarnings();
231221 $ok = copy( $source, $dest );
232 - wfRestoreWarnings();
233222 if ( !$ok ) {
234223 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
235224 return $status;
@@ -262,9 +251,7 @@
263252 if ( !empty( $params['overwrite'] ) ) {
264253 // Windows does not support moving over existing files
265254 if ( wfIsWindows() ) {
266 - wfSuppressWarnings();
267255 $ok = unlink( $dest );
268 - wfRestoreWarnings();
269256 if ( !$ok ) {
270257 $status->fatal( 'backend-fail-delete', $params['dst'] );
271258 return $status;
@@ -276,10 +263,8 @@
277264 }
278265 }
279266
280 - wfSuppressWarnings();
281267 $ok = rename( $source, $dest );
282268 clearstatcache(); // file no longer at source
283 - wfRestoreWarnings();
284269 if ( !$ok ) {
285270 $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
286271 return $status;
@@ -308,9 +293,7 @@
309294 return $status; // do nothing; either OK or bad status
310295 }
311296
312 - wfSuppressWarnings();
313297 $ok = unlink( $source );
314 - wfRestoreWarnings();
315298 if ( !$ok ) {
316299 $status->fatal( 'backend-fail-delete', $params['src'] );
317300 return $status;
@@ -334,9 +317,7 @@
335318
336319 if ( file_exists( $dest ) ) {
337320 if ( !empty( $params['overwrite'] ) ) {
338 - wfSuppressWarnings();
339321 $ok = unlink( $dest );
340 - wfRestoreWarnings();
341322 if ( !$ok ) {
342323 $status->fatal( 'backend-fail-delete', $params['dst'] );
343324 return $status;
@@ -347,9 +328,7 @@
348329 }
349330 }
350331
351 - wfSuppressWarnings();
352332 $bytes = file_put_contents( $dest, $params['content'] );
353 - wfRestoreWarnings();
354333 if ( $bytes === false ) {
355334 $status->fatal( 'backend-fail-create', $params['dst'] );
356335 return $status;
@@ -390,9 +369,7 @@
391370 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
392371 // Seed new directories with a blank index.html, to prevent crawling...
393372 if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) {
394 - wfSuppressWarnings();
395373 $bytes = file_put_contents( "{$dir}/index.html", '' );
396 - wfRestoreWarnings();
397374 if ( !$bytes ) {
398375 $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' );
399376 return $status;
@@ -401,9 +378,7 @@
402379 // Add a .htaccess file to the root of the container...
403380 if ( !empty( $params['noAccess'] ) ) {
404381 if ( !file_exists( "{$contRoot}/.htaccess" ) ) {
405 - wfSuppressWarnings();
406382 $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" );
407 - wfRestoreWarnings();
408383 if ( !$bytes ) {
409384 $storeDir = "mwstore://{$this->name}/{$shortCont}";
410385 $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" );
@@ -441,7 +416,7 @@
442417 return false; // invalid storage path
443418 }
444419
445 - $this->trapWarnings();
 420+ $this->trapWarnings(); // don't trust 'false' if there were errors
446421 $stat = is_file( $source ) ? stat( $source ) : false; // regular files only
447422 $hadError = $this->untrapWarnings();
448423
@@ -472,16 +447,12 @@
473448 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
474449 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
475450 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
476 - wfSuppressWarnings();
477451 $exists = is_dir( $dir );
478 - wfRestoreWarnings();
479452 if ( !$exists ) {
480453 wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
481454 return array(); // nothing under this dir
482455 }
483 - wfSuppressWarnings();
484456 $readable = is_readable( $dir );
485 - wfRestoreWarnings();
486457 if ( !$readable ) {
487458 wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
488459 return null; // bad permissions?
@@ -520,9 +491,7 @@
521492 $tmpPath = $tmpFile->getPath();
522493
523494 // Copy the source file over the temp file
524 - wfSuppressWarnings();
525495 $ok = copy( $source, $tmpPath );
526 - wfRestoreWarnings();
527496 if ( !$ok ) {
528497 return null;
529498 }
@@ -547,17 +516,18 @@
548517 }
549518
550519 /**
551 - * Suppress E_WARNING errors and track whether any happen
 520+ * Listen for E_WARNING errors and track whether any happen
552521 *
553 - * @return void
 522+ * @return bool
554523 */
555524 protected function trapWarnings() {
556525 $this->hadWarningErrors[] = false; // push to stack
557526 set_error_handler( array( $this, 'handleWarning' ), E_WARNING );
 527+ return false; // invoke normal PHP error handler
558528 }
559529
560530 /**
561 - * Unsuppress E_WARNING errors and return true if any happened
 531+ * Stop listening for E_WARNING errors and return true if any happened
562532 *
563533 * @return bool
564534 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r112850MFT r111427, r112347reedy23:14, 1 March 2012
r113040MFT r111427, r112347, r112374, r112383, r112700, r112750, r112855reedy15:15, 5 March 2012

Comments

#Comment by Hashar (talk | contribs)   10:56, 29 February 2012

1.19wmf1 too I supposed?

Status & tagging log