From a15b11d3a5fa5d736f1c17e219b1e33369601307 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 25 Jan 2012 10:51:37 +0000 Subject: [PATCH] bug 33646 Badtitle error page now emits a 400 HTTP status. 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 | 1 + includes/Exception.php | 31 +++++++++++++++++++++++++++++++ includes/Wiki.php | 4 ++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 17f93f7798..ace2409bc9 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -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. diff --git a/includes/Exception.php b/includes/Exception.php index 08a63ee6bf..3bd89b6e12 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -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. diff --git a/includes/Wiki.php b/includes/Wiki.php index bea306101b..e5be1dafa3 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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() -- 2.20.1