Index: branches/wmf/1.19wmf1/includes/Article.php |
— | — | @@ -988,6 +988,18 @@ |
989 | 989 | 'msgKey' => array( 'moveddeleted-notice' ) ) |
990 | 990 | ); |
991 | 991 | |
| 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 | + |
992 | 1004 | # Show error message |
993 | 1005 | $oldid = $this->getOldID(); |
994 | 1006 | if ( $oldid ) { |
— | — | @@ -1010,12 +1022,6 @@ |
1011 | 1023 | } |
1012 | 1024 | $text = "<div class='noarticletext'>\n$text\n</div>"; |
1013 | 1025 | |
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 | | - |
1020 | 1026 | $wgOut->addWikiText( $text ); |
1021 | 1027 | } |
1022 | 1028 | |
Index: branches/wmf/1.19wmf1/includes/filerepo/backend/FSFileBackend.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | * Sharding can be accomplished by using FileRepo-style hash paths. |
18 | 18 | * |
19 | 19 | * 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. |
21 | 21 | * |
22 | 22 | * @ingroup FileBackend |
23 | 23 | * @since 1.19 |
— | — | @@ -41,14 +41,13 @@ |
42 | 42 | parent::__construct( $config ); |
43 | 43 | |
44 | 44 | // Remove any possible trailing slash from directories |
45 | | - |
46 | 45 | if ( isset( $config['basePath'] ) ) { |
47 | 46 | $this->basePath = rtrim( $config['basePath'], '/' ); // remove trailing slash |
48 | 47 | } else { |
49 | 48 | $this->basePath = null; // none; containers must have explicit paths |
50 | 49 | } |
51 | 50 | |
52 | | - if( isset( $config['containerPaths'] ) ) { |
| 51 | + if ( isset( $config['containerPaths'] ) ) { |
53 | 52 | $this->containerPaths = (array)$config['containerPaths']; |
54 | 53 | foreach ( $this->containerPaths as &$path ) { |
55 | 54 | $path = rtrim( $path, '/' ); // remove trailing slash |
— | — | @@ -138,13 +137,11 @@ |
139 | 138 | } |
140 | 139 | $parentDir = dirname( $fsPath ); |
141 | 140 | |
142 | | - wfSuppressWarnings(); |
143 | 141 | if ( file_exists( $fsPath ) ) { |
144 | 142 | $ok = is_file( $fsPath ) && is_writable( $fsPath ); |
145 | 143 | } else { |
146 | 144 | $ok = is_dir( $parentDir ) && is_writable( $parentDir ); |
147 | 145 | } |
148 | | - wfRestoreWarnings(); |
149 | 146 | |
150 | 147 | return $ok; |
151 | 148 | } |
— | — | @@ -163,9 +160,7 @@ |
164 | 161 | |
165 | 162 | if ( file_exists( $dest ) ) { |
166 | 163 | if ( !empty( $params['overwrite'] ) ) { |
167 | | - wfSuppressWarnings(); |
168 | 164 | $ok = unlink( $dest ); |
169 | | - wfRestoreWarnings(); |
170 | 165 | if ( !$ok ) { |
171 | 166 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
172 | 167 | return $status; |
— | — | @@ -176,9 +171,7 @@ |
177 | 172 | } |
178 | 173 | } |
179 | 174 | |
180 | | - wfSuppressWarnings(); |
181 | 175 | $ok = copy( $params['src'], $dest ); |
182 | | - wfRestoreWarnings(); |
183 | 176 | if ( !$ok ) { |
184 | 177 | $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] ); |
185 | 178 | return $status; |
— | — | @@ -209,9 +202,7 @@ |
210 | 203 | |
211 | 204 | if ( file_exists( $dest ) ) { |
212 | 205 | if ( !empty( $params['overwrite'] ) ) { |
213 | | - wfSuppressWarnings(); |
214 | 206 | $ok = unlink( $dest ); |
215 | | - wfRestoreWarnings(); |
216 | 207 | if ( !$ok ) { |
217 | 208 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
218 | 209 | return $status; |
— | — | @@ -222,9 +213,7 @@ |
223 | 214 | } |
224 | 215 | } |
225 | 216 | |
226 | | - wfSuppressWarnings(); |
227 | 217 | $ok = copy( $source, $dest ); |
228 | | - wfRestoreWarnings(); |
229 | 218 | if ( !$ok ) { |
230 | 219 | $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); |
231 | 220 | return $status; |
— | — | @@ -257,9 +246,7 @@ |
258 | 247 | if ( !empty( $params['overwrite'] ) ) { |
259 | 248 | // Windows does not support moving over existing files |
260 | 249 | if ( wfIsWindows() ) { |
261 | | - wfSuppressWarnings(); |
262 | 250 | $ok = unlink( $dest ); |
263 | | - wfRestoreWarnings(); |
264 | 251 | if ( !$ok ) { |
265 | 252 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
266 | 253 | return $status; |
— | — | @@ -271,10 +258,8 @@ |
272 | 259 | } |
273 | 260 | } |
274 | 261 | |
275 | | - wfSuppressWarnings(); |
276 | 262 | $ok = rename( $source, $dest ); |
277 | 263 | clearstatcache(); // file no longer at source |
278 | | - wfRestoreWarnings(); |
279 | 264 | if ( !$ok ) { |
280 | 265 | $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] ); |
281 | 266 | return $status; |
— | — | @@ -302,9 +287,7 @@ |
303 | 288 | return $status; // do nothing; either OK or bad status |
304 | 289 | } |
305 | 290 | |
306 | | - wfSuppressWarnings(); |
307 | 291 | $ok = unlink( $source ); |
308 | | - wfRestoreWarnings(); |
309 | 292 | if ( !$ok ) { |
310 | 293 | $status->fatal( 'backend-fail-delete', $params['src'] ); |
311 | 294 | return $status; |
— | — | @@ -327,9 +310,7 @@ |
328 | 311 | |
329 | 312 | if ( file_exists( $dest ) ) { |
330 | 313 | if ( !empty( $params['overwrite'] ) ) { |
331 | | - wfSuppressWarnings(); |
332 | 314 | $ok = unlink( $dest ); |
333 | | - wfRestoreWarnings(); |
334 | 315 | if ( !$ok ) { |
335 | 316 | $status->fatal( 'backend-fail-delete', $params['dst'] ); |
336 | 317 | return $status; |
— | — | @@ -340,9 +321,7 @@ |
341 | 322 | } |
342 | 323 | } |
343 | 324 | |
344 | | - wfSuppressWarnings(); |
345 | 325 | $bytes = file_put_contents( $dest, $params['content'] ); |
346 | | - wfRestoreWarnings(); |
347 | 326 | if ( $bytes === false ) { |
348 | 327 | $status->fatal( 'backend-fail-create', $params['dst'] ); |
349 | 328 | return $status; |
— | — | @@ -381,9 +360,7 @@ |
382 | 361 | $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot; |
383 | 362 | // Seed new directories with a blank index.html, to prevent crawling... |
384 | 363 | if ( !empty( $params['noListing'] ) && !file_exists( "{$dir}/index.html" ) ) { |
385 | | - wfSuppressWarnings(); |
386 | 364 | $bytes = file_put_contents( "{$dir}/index.html", '' ); |
387 | | - wfRestoreWarnings(); |
388 | 365 | if ( !$bytes ) { |
389 | 366 | $status->fatal( 'backend-fail-create', $params['dir'] . '/index.html' ); |
390 | 367 | return $status; |
— | — | @@ -392,9 +369,7 @@ |
393 | 370 | // Add a .htaccess file to the root of the container... |
394 | 371 | if ( !empty( $params['noAccess'] ) ) { |
395 | 372 | if ( !file_exists( "{$contRoot}/.htaccess" ) ) { |
396 | | - wfSuppressWarnings(); |
397 | 373 | $bytes = file_put_contents( "{$contRoot}/.htaccess", "Deny from all\n" ); |
398 | | - wfRestoreWarnings(); |
399 | 374 | if ( !$bytes ) { |
400 | 375 | $storeDir = "mwstore://{$this->name}/{$shortCont}"; |
401 | 376 | $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" ); |
— | — | @@ -430,7 +405,7 @@ |
431 | 406 | return false; // invalid storage path |
432 | 407 | } |
433 | 408 | |
434 | | - $this->trapWarnings(); |
| 409 | + $this->trapWarnings(); // don't trust 'false' if there were errors |
435 | 410 | $stat = is_file( $source ) ? stat( $source ) : false; // regular files only |
436 | 411 | $hadError = $this->untrapWarnings(); |
437 | 412 | |
— | — | @@ -460,16 +435,12 @@ |
461 | 436 | list( $b, $shortCont, $r ) = FileBackend::splitStoragePath( $params['dir'] ); |
462 | 437 | $contRoot = $this->containerFSRoot( $shortCont, $fullCont ); // must be valid |
463 | 438 | $dir = ( $dirRel != '' ) ? "{$contRoot}/{$dirRel}" : $contRoot; |
464 | | - wfSuppressWarnings(); |
465 | 439 | $exists = is_dir( $dir ); |
466 | | - wfRestoreWarnings(); |
467 | 440 | if ( !$exists ) { |
468 | 441 | wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" ); |
469 | 442 | return array(); // nothing under this dir |
470 | 443 | } |
471 | | - wfSuppressWarnings(); |
472 | 444 | $readable = is_readable( $dir ); |
473 | | - wfRestoreWarnings(); |
474 | 445 | if ( !$readable ) { |
475 | 446 | wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" ); |
476 | 447 | return null; // bad permissions? |
— | — | @@ -506,9 +477,7 @@ |
507 | 478 | $tmpPath = $tmpFile->getPath(); |
508 | 479 | |
509 | 480 | // Copy the source file over the temp file |
510 | | - wfSuppressWarnings(); |
511 | 481 | $ok = copy( $source, $tmpPath ); |
512 | | - wfRestoreWarnings(); |
513 | 482 | if ( !$ok ) { |
514 | 483 | return null; |
515 | 484 | } |
— | — | @@ -533,17 +502,18 @@ |
534 | 503 | } |
535 | 504 | |
536 | 505 | /** |
537 | | - * Suppress E_WARNING errors and track whether any happen |
| 506 | + * Listen for E_WARNING errors and track whether any happen |
538 | 507 | * |
539 | | - * @return void |
| 508 | + * @return bool |
540 | 509 | */ |
541 | 510 | protected function trapWarnings() { |
542 | 511 | $this->hadWarningErrors[] = false; // push to stack |
543 | 512 | set_error_handler( array( $this, 'handleWarning' ), E_WARNING ); |
| 513 | + return false; // invoke normal PHP error handler |
544 | 514 | } |
545 | 515 | |
546 | 516 | /** |
547 | | - * Unsuppress E_WARNING errors and return true if any happened |
| 517 | + * Stop listening for E_WARNING errors and return true if any happened |
548 | 518 | * |
549 | 519 | * @return bool |
550 | 520 | */ |
Property changes on: branches/wmf/1.19wmf1/includes |
___________________________________________________________________ |
Modified: svn:mergeinfo |
551 | 521 | Merged /trunk/phase3/includes:r111427,112347 |
Index: branches/wmf/1.19wmf1/docs/hooks.txt |
— | — | @@ -587,6 +587,11 @@ |
588 | 588 | Change $bad and return false to override. If an image is "bad", it is not |
589 | 589 | rendered inline in wiki pages or galleries in category pages. |
590 | 590 | |
| 591 | +'BeforeDisplayNoArticleText': before displaying noarticletext or noarticletext-nopermission |
| 592 | +at Article::showMissingArticle() |
| 593 | + |
| 594 | +$article: article object |
| 595 | + |
591 | 596 | 'BeforeInitialize': before anything is initialized in MediaWiki::performRequest() |
592 | 597 | &$title: Title being used for request |
593 | 598 | $unused: null |
Property changes on: branches/wmf/1.19wmf1 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
594 | 599 | Merged /trunk/phase3:r111427,112347 |