r112850 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112849‎ | r112850 | r112851 >
Date:23:14, 1 March 2012
Author:reedy
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1 (modified) (history)
  • /branches/wmf/1.19wmf1/docs/hooks.txt (modified) (history)
  • /branches/wmf/1.19wmf1/includes (modified) (history)
  • /branches/wmf/1.19wmf1/includes/Article.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/filerepo/backend/FSFileBackend.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/includes/Article.php
@@ -988,6 +988,18 @@
989989 'msgKey' => array( 'moveddeleted-notice' ) )
990990 );
991991
 992+ if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
 993+ // If there's no backing content, send a 404 Not Found
 994+ // for better machine handling of broken links.
 995+ $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
 996+ }
 997+
 998+ $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
 999+
 1000+ if ( ! $hookResult ) {
 1001+ return;
 1002+ }
 1003+
9921004 # Show error message
9931005 $oldid = $this->getOldID();
9941006 if ( $oldid ) {
@@ -1010,12 +1022,6 @@
10111023 }
10121024 $text = "<div class='noarticletext'>\n$text\n</div>";
10131025
1014 - if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
1015 - // If there's no backing content, send a 404 Not Found
1016 - // for better machine handling of broken links.
1017 - $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1018 - }
1019 -
10201026 $wgOut->addWikiText( $text );
10211027 }
10221028
Index: branches/wmf/1.19wmf1/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
@@ -138,13 +137,11 @@
139138 }
140139 $parentDir = dirname( $fsPath );
141140
142 - wfSuppressWarnings();
143141 if ( file_exists( $fsPath ) ) {
144142 $ok = is_file( $fsPath ) && is_writable( $fsPath );
145143 } else {
146144 $ok = is_dir( $parentDir ) && is_writable( $parentDir );
147145 }
148 - wfRestoreWarnings();
149146
150147 return $ok;
151148 }
@@ -163,9 +160,7 @@
164161
165162 if ( file_exists( $dest ) ) {
166163 if ( !empty( $params['overwrite'] ) ) {
167 - wfSuppressWarnings();
168164 $ok = unlink( $dest );
169 - wfRestoreWarnings();
170165 if ( !$ok ) {
171166 $status->fatal( 'backend-fail-delete', $params['dst'] );
172167 return $status;
@@ -176,9 +171,7 @@
177172 }
178173 }
179174
180 - wfSuppressWarnings();
181175 $ok = copy( $params['src'], $dest );
182 - wfRestoreWarnings();
183176 if ( !$ok ) {
184177 $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
185178 return $status;
@@ -209,9 +202,7 @@
210203
211204 if ( file_exists( $dest ) ) {
212205 if ( !empty( $params['overwrite'] ) ) {
213 - wfSuppressWarnings();
214206 $ok = unlink( $dest );
215 - wfRestoreWarnings();
216207 if ( !$ok ) {
217208 $status->fatal( 'backend-fail-delete', $params['dst'] );
218209 return $status;
@@ -222,9 +213,7 @@
223214 }
224215 }
225216
226 - wfSuppressWarnings();
227217 $ok = copy( $source, $dest );
228 - wfRestoreWarnings();
229218 if ( !$ok ) {
230219 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
231220 return $status;
@@ -257,9 +246,7 @@
258247 if ( !empty( $params['overwrite'] ) ) {
259248 // Windows does not support moving over existing files
260249 if ( wfIsWindows() ) {
261 - wfSuppressWarnings();
262250 $ok = unlink( $dest );
263 - wfRestoreWarnings();
264251 if ( !$ok ) {
265252 $status->fatal( 'backend-fail-delete', $params['dst'] );
266253 return $status;
@@ -271,10 +258,8 @@
272259 }
273260 }
274261
275 - wfSuppressWarnings();
276262 $ok = rename( $source, $dest );
277263 clearstatcache(); // file no longer at source
278 - wfRestoreWarnings();
279264 if ( !$ok ) {
280265 $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
281266 return $status;
@@ -302,9 +287,7 @@
303288 return $status; // do nothing; either OK or bad status
304289 }
305290
306 - wfSuppressWarnings();
307291 $ok = unlink( $source );
308 - wfRestoreWarnings();
309292 if ( !$ok ) {
310293 $status->fatal( 'backend-fail-delete', $params['src'] );
311294 return $status;
@@ -327,9 +310,7 @@
328311
329312 if ( file_exists( $dest ) ) {
330313 if ( !empty( $params['overwrite'] ) ) {
331 - wfSuppressWarnings();
332314 $ok = unlink( $dest );
333 - wfRestoreWarnings();
334315 if ( !$ok ) {
335316 $status->fatal( 'backend-fail-delete', $params['dst'] );
336317 return $status;
@@ -340,9 +321,7 @@
341322 }
342323 }
343324
344 - wfSuppressWarnings();
345325 $bytes = file_put_contents( $dest, $params['content'] );
346 - wfRestoreWarnings();
347326 if ( $bytes === false ) {
348327 $status->fatal( 'backend-fail-create', $params['dst'] );
349328 return $status;
@@ -381,9 +360,7 @@
382361 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
383362 // Seed new directories with a blank index.html, to prevent crawling...
384363 if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) {
385 - wfSuppressWarnings();
386364 $bytes = file_put_contents( "{$dir}/index.html", '' );
387 - wfRestoreWarnings();
388365 if ( !$bytes ) {
389366 $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' );
390367 return $status;
@@ -392,9 +369,7 @@
393370 // Add a .htaccess file to the root of the container...
394371 if ( !empty( $params['noAccess'] ) ) {
395372 if ( !file_exists( "{$contRoot}/.htaccess" ) ) {
396 - wfSuppressWarnings();
397373 $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" );
398 - wfRestoreWarnings();
399374 if ( !$bytes ) {
400375 $storeDir = "mwstore://{$this->name}/{$shortCont}";
401376 $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" );
@@ -430,7 +405,7 @@
431406 return false; // invalid storage path
432407 }
433408
434 - $this->trapWarnings();
 409+ $this->trapWarnings(); // don't trust 'false' if there were errors
435410 $stat = is_file( $source ) ? stat( $source ) : false; // regular files only
436411 $hadError = $this->untrapWarnings();
437412
@@ -460,16 +435,12 @@
461436 list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] );
462437 $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid
463438 $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot;
464 - wfSuppressWarnings();
465439 $exists = is_dir( $dir );
466 - wfRestoreWarnings();
467440 if ( !$exists ) {
468441 wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" );
469442 return array(); // nothing under this dir
470443 }
471 - wfSuppressWarnings();
472444 $readable = is_readable( $dir );
473 - wfRestoreWarnings();
474445 if ( !$readable ) {
475446 wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" );
476447 return null; // bad permissions?
@@ -506,9 +477,7 @@
507478 $tmpPath = $tmpFile->getPath();
508479
509480 // Copy the source file over the temp file
510 - wfSuppressWarnings();
511481 $ok = copy( $source, $tmpPath );
512 - wfRestoreWarnings();
513482 if ( !$ok ) {
514483 return null;
515484 }
@@ -533,17 +502,18 @@
534503 }
535504
536505 /**
537 - * Suppress E_WARNING errors and track whether any happen
 506+ * Listen for E_WARNING errors and track whether any happen
538507 *
539 - * @return void
 508+ * @return bool
540509 */
541510 protected function trapWarnings() {
542511 $this->hadWarningErrors[] = false; // push to stack
543512 set_error_handler( array( $this, 'handleWarning' ), E_WARNING );
 513+ return false; // invoke normal PHP error handler
544514 }
545515
546516 /**
547 - * Unsuppress E_WARNING errors and return true if any happened
 517+ * Stop listening for E_WARNING errors and return true if any happened
548518 *
549519 * @return bool
550520 */
Property changes on: branches/wmf/1.19wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
551521 Merged /trunk/phase3/includes:r111427,112347
Index: branches/wmf/1.19wmf1/docs/hooks.txt
@@ -587,6 +587,11 @@
588588 Change $bad and return false to override. If an image is "bad", it is not
589589 rendered inline in wiki pages or galleries in category pages.
590590
 591+'BeforeDisplayNoArticleText': before displaying noarticletext or noarticletext-nopermission
 592+at Article::showMissingArticle()
 593+
 594+$article: article object
 595+
591596 'BeforeInitialize': before anything is initialized in MediaWiki::performRequest()
592597 &$title: Title being used for request
593598 $unused: null
Property changes on: branches/wmf/1.19wmf1
___________________________________________________________________
Modified: svn:mergeinfo
594599 Merged /trunk/phase3:r111427,112347

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111427Port (with changes) r110866 to trunk. Reviewed by Brion before commit.werdna22:32, 13 February 2012
r112347In FSFileBackend:...aaron20:10, 24 February 2012

Status & tagging log