r105645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105644‎ | r105645 | r105646 >
Date:04:31, 9 December 2011
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPageFactory.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialPageFactory.php
@@ -429,7 +429,12 @@
430430 if ( !$page ) {
431431 $context->getOutput()->setArticleRelated( false );
432432 $context->getOutput()->setRobotPolicy( 'noindex,nofollow' );
433 - $context->getOutput()->setStatusCode( 404 );
 433+
 434+ global $wgSend404Code;
 435+ if ( $wgSend404Code ) {
 436+ $context->getOutput()->setStatusCode( 404 );
 437+ }
 438+
434439 $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
435440 wfProfileOut( __METHOD__ );
436441 return false;
Index: trunk/phase3/includes/Article.php
@@ -917,7 +917,7 @@
918918 * namespace, show the default message text. To be called from Article::view().
919919 */
920920 public function showMissingArticle() {
921 - global $wgOut, $wgRequest, $wgUser;
 921+ global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
922922
923923 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
924924 if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) {
@@ -979,7 +979,7 @@
980980 }
981981 $text = "<div class='noarticletext'>\n$text\n</div>";
982982
983 - if ( !$this->mPage->hasViewableContent() ) {
 983+ if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
984984 // If there's no backing content, send a 404 Not Found
985985 // for better machine handling of broken links.
986986 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
Index: trunk/phase3/includes/ImagePage.php
@@ -262,7 +262,7 @@
263263
264264 protected function openShowImage() {
265265 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
266 - $wgLang, $wgEnableUploads;
 266+ $wgLang, $wgEnableUploads, $wgSend404Code;
267267
268268 $this->loadFile();
269269
@@ -481,7 +481,7 @@
482482 // by Article::View().
483483 $wgOut->setRobotPolicy( 'noindex,nofollow' );
484484 $wgOut->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
485 - if ( !$this->getID() ) {
 485+ if ( !$this->getID() && $wgSend404Code ) {
486486 // If there is no image, no shared image, and no description page,
487487 // output a 404, to be consistent with articles.
488488 $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2471,6 +2471,18 @@
24722472 */
24732473 $wgBetterDirectionality = true;
24742474
 2475+/**
 2476+ * Some web hosts attempt to rewrite all responses with a 404 (not found)
 2477+ * status code, mangling or hiding MediaWiki's output. If you are using such a
 2478+ * host, you should start looking for a better one. While you're doing that,
 2479+ * set this to false to convert some of MediaWiki's 404 responses to 200 so
 2480+ * that the generated error pages can be seen.
 2481+ *
 2482+ * In cases where for technical reasons it is more important for MediaWiki to
 2483+ * send the correct status code than for the body to be transmitted intact,
 2484+ * this configuration variable is ignored.
 2485+ */
 2486+$wgSend404Code = true;
24752487
24762488 /** @} */ # End of output format settings }
24772489

Follow-up revisions

RevisionCommit summaryAuthorDate
r106929Release notes for r105645.tstarling05:49, 21 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   17:30, 12 December 2011

Release notes for new configuration variables?

#Comment by MarkAHershberger (talk | contribs)   19:08, 14 December 2011

fixme for release notes

#Comment by Hashar (talk | contribs)   13:55, 21 December 2011

Looks like we have the same issue with SpecialFilepath, SpecialUploadStash. Each throw a 404 when a file is not found but also show a form to let the user lookup for or upload another file.

#Comment by Tim Starling (talk | contribs)   22:28, 21 December 2011

In cases where the response is intended for an <img> tag, it's probably better for us to send a 404 any way we can, so that the browser can tell the user that the image link is broken, instead of the download succeeding but with an incorrect (non-image) content type. It's not an ideal situation either way, which is why I recommend finding a new web host in the doc comment.

#Comment by Hashar (talk | contribs)   10:35, 22 December 2011

Perfect! Looks fine to me 8-)

Status & tagging log