From: Tim Starling Date: Fri, 9 Dec 2011 04:31:10 +0000 (+0000) Subject: Add a configuration variable to work around the issue that has been reported at least... X-Git-Tag: 1.31.0-rc.0~26117 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=ddbf20c0ba1a9f489cd55de0e91724bfb301a551;p=lhc%2Fweb%2Fwiklou.git Add a configuration variable to work around the issue that has been reported at least twice on IRC: pages from MW with a 404 status code have the last block of their body replaced, and their headers appended to, resulting in totally broken output for page views of non-existent pages. BizLand or some reseller is probably at fault. --- diff --git a/includes/Article.php b/includes/Article.php index edd9369444..5945db7247 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -917,7 +917,7 @@ class Article extends Page { * namespace, show the default message text. To be called from Article::view(). */ public function showMissingArticle() { - global $wgOut, $wgRequest, $wgUser; + global $wgOut, $wgRequest, $wgUser, $wgSend404Code; # Show info in user (talk) namespace. Does the user exist? Is he blocked? if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) { @@ -979,7 +979,7 @@ class Article extends Page { } $text = "
\n$text\n
"; - if ( !$this->mPage->hasViewableContent() ) { + if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) { // If there's no backing content, send a 404 Not Found // for better machine handling of broken links. $wgRequest->response()->header( "HTTP/1.1 404 Not Found" ); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 932cf83c96..58f1b327db 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2471,6 +2471,18 @@ $wgEdititis = false; */ $wgBetterDirectionality = true; +/** + * Some web hosts attempt to rewrite all responses with a 404 (not found) + * status code, mangling or hiding MediaWiki's output. If you are using such a + * host, you should start looking for a better one. While you're doing that, + * set this to false to convert some of MediaWiki's 404 responses to 200 so + * that the generated error pages can be seen. + * + * In cases where for technical reasons it is more important for MediaWiki to + * send the correct status code than for the body to be transmitted intact, + * this configuration variable is ignored. + */ +$wgSend404Code = true; /** @} */ # End of output format settings } diff --git a/includes/ImagePage.php b/includes/ImagePage.php index a599ab76d7..3e356489b6 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -262,7 +262,7 @@ class ImagePage extends Article { protected function openShowImage() { global $wgOut, $wgUser, $wgImageLimits, $wgRequest, - $wgLang, $wgEnableUploads; + $wgLang, $wgEnableUploads, $wgSend404Code; $this->loadFile(); @@ -481,7 +481,7 @@ EOT // by Article::View(). $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->wrapWikiMsg( "", $nofile ); - if ( !$this->getID() ) { + if ( !$this->getID() && $wgSend404Code ) { // If there is no image, no shared image, and no description page, // output a 404, to be consistent with articles. $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' ); diff --git a/includes/SpecialPageFactory.php b/includes/SpecialPageFactory.php index b6aa42308a..a307575f18 100644 --- a/includes/SpecialPageFactory.php +++ b/includes/SpecialPageFactory.php @@ -429,7 +429,12 @@ class SpecialPageFactory { if ( !$page ) { $context->getOutput()->setArticleRelated( false ); $context->getOutput()->setRobotPolicy( 'noindex,nofollow' ); - $context->getOutput()->setStatusCode( 404 ); + + global $wgSend404Code; + if ( $wgSend404Code ) { + $context->getOutput()->setStatusCode( 404 ); + } + $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' ); wfProfileOut( __METHOD__ ); return false;