r110001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110000‎ | r110001 | r110002 >
Date:10:51, 25 January 2012
Author:hashar
Status:ok (Comments)
Tags:core, todo 
Comment:
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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -123,6 +123,7 @@
124124 * (bug 27775) Namespace has it's own XML tag in the XML dump file.
125125 * (bug 30513) Redirect tag is now resolved in XML dump file.
126126 * sha1 xml tag added to XML dump file.
 127+* (bug 33646) Badtitle error page now emits a 400 HTTP status.
127128
128129 === Bug fixes in 1.19 ===
129130 * $wgUploadNavigationUrl should be used for file redlinks if.
Index: trunk/phase3/includes/Wiki.php
@@ -167,7 +167,7 @@
168168 {
169169 $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
170170 wfProfileOut( __METHOD__ );
171 - throw new ErrorPageError( 'badtitle', 'badtitletext' );
 171+ throw new BadTitleError();
172172 }
173173
174174 // Check user's permissions to read this page.
@@ -214,7 +214,7 @@
215215 } else {
216216 $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
217217 wfProfileOut( __METHOD__ );
218 - throw new ErrorPageError( 'badtitle', 'badtitletext' );
 218+ throw new BadTitleError();
219219 }
220220 // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
221221 } elseif ( $request->getVal( 'action', 'view' ) == 'view' && !$request->wasPosted()
Index: trunk/phase3/includes/Exception.php
@@ -266,12 +266,43 @@
267267 function report() {
268268 global $wgOut;
269269
 270+
270271 $wgOut->showErrorPage( $this->title, $this->msg, $this->params );
271272 $wgOut->output();
272273 }
273274 }
274275
275276 /**
 277+ * Show an error page on a badtitle.
 278+ * Similar to ErrorPage, but emit a 400 HTTP error code to let mobile
 279+ * browser it is not really a valid content.
 280+ */
 281+class BadTitleError extends ErrorPageError {
 282+
 283+ /**
 284+ * @param $msg string A message key (default: 'badtitletext')
 285+ * @param $params Array parameter to wfMsg()
 286+ */
 287+ function __construct( $msg = 'badtitletext', $params = null ) {
 288+ parent::__construct( 'badtitle', $msg, $params );
 289+ }
 290+
 291+ /**
 292+ * Just like ErrorPageError::report() but additionally set
 293+ * a 400 HTTP status code (bug 33646).
 294+ */
 295+ function report() {
 296+ global $wgOut;
 297+
 298+ // bug 33646: a badtitle error page need to return an error code
 299+ // to let mobile browser now that it is not a normal page.
 300+ $wgOut->setStatusCode( 400 );
 301+ parent::report();
 302+ }
 303+
 304+}
 305+
 306+/**
276307 * Show an error when a user tries to do something they do not have the necessary
277308 * permissions for.
278309 * @ingroup Exception

Follow-up revisions

RevisionCommit summaryAuthorDate
r1103681.18wmf1: MFT r110001catrope09:22, 31 January 2012
r110396Followup r110001...reedy15:56, 31 January 2012

Comments

#Comment by 😂 (talk | contribs)   14:01, 26 January 2012

How about passing the context to BadTitleError so you don't have to use $wgOut?

#Comment by Hashar (talk | contribs)   08:23, 30 January 2012

> How about passing the context to BadTitleError so you don't have to use $wgOut?

The idea was to keep the change as simple as possible to have it merged on live site ASAP. I have just duplicated the rest of Error exception which do not use Context. I guess that is because a Context object is not always available whereas wgOut is probably "always" available.

Status & tagging log