bug 33646 Badtitle error page now emits a 400 HTTP status.
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 25 Jan 2012 10:51:37 +0000 (10:51 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 25 Jan 2012 10:51:37 +0000 (10:51 +0000)
Sending a 200 OK status on bad title, prevents mobile browsers to
actually now the page is an error page.

Tested using:
 curl -I http://localhost/wiki/\]\]
 curl -I http://localhost/wiki/Special:BadTitle

RELEASE-NOTES-1.19
includes/Exception.php
includes/Wiki.php

index 17f93f7..ace2409 100644 (file)
@@ -123,6 +123,7 @@ production.
 * (bug 27775) Namespace has it's own XML tag in the XML dump file. 
 * (bug 30513) Redirect tag is now resolved in XML dump file.
 * sha1 xml tag added to XML dump file. 
+* (bug 33646) Badtitle error page now emits a 400 HTTP status.
 
 === Bug fixes in 1.19 ===
 * $wgUploadNavigationUrl should be used for file redlinks if.
index 08a63ee..3bd89b6 100644 (file)
@@ -266,11 +266,42 @@ class ErrorPageError extends MWException {
        function report() {
                global $wgOut;
 
+
                $wgOut->showErrorPage( $this->title, $this->msg, $this->params );
                $wgOut->output();
        }
 }
 
+/**
+ * Show an error page on a badtitle.
+ * Similar to ErrorPage, but emit a 400 HTTP error code to let mobile
+ * browser it is not really a valid content.
+ */
+class BadTitleError extends ErrorPageError {
+
+       /**
+        * @param $msg string A message key (default: 'badtitletext')
+        * @param $params Array parameter to wfMsg()
+        */
+       function __construct( $msg = 'badtitletext', $params = null ) {
+               parent::__construct( 'badtitle', $msg, $params );
+       }
+
+       /**
+        * Just like ErrorPageError::report() but additionally set
+        * a 400 HTTP status code (bug 33646).
+        */
+       function report() {
+               global $wgOut;
+
+               // bug 33646: a badtitle error page need to return an error code
+               // to let mobile browser now that it is not a normal page.
+               $wgOut->setStatusCode( 400 );
+               parent::report();
+       }
+
+}
+
 /**
  * Show an error when a user tries to do something they do not have the necessary
  * permissions for.
index bea3061..e5be1da 100644 (file)
@@ -167,7 +167,7 @@ class MediaWiki {
                {
                        $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
                        wfProfileOut( __METHOD__ );
-                       throw new ErrorPageError( 'badtitle', 'badtitletext' );
+                       throw new BadTitleError();
                }
 
                // Check user's permissions to read this page.
@@ -214,7 +214,7 @@ class MediaWiki {
                        } else {
                                $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
                                wfProfileOut( __METHOD__ );
-                               throw new ErrorPageError( 'badtitle', 'badtitletext' );
+                               throw new BadTitleError();
                        }
                // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
                } elseif ( $request->getVal( 'action', 'view' ) == 'view' && !$request->wasPosted()