r11307 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11306‎ | r11307 | r11308 >
Date:03:12, 12 October 2005
Author:tomgilder
Status:old (Comments)
Tags:
Comment:
(bug 2585) Return proper 404 code when pages don't exist
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/index.php
@@ -112,6 +112,7 @@
113113 wfSpecialSearch();
114114 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
115115 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
 116+ $wgOut->setStatusCode( 404 );
116117 $wgOut->errorpage( 'badtitle', 'badtitletext' );
117118 } else if ( $wgTitle->getInterwiki() != '' ) {
118119 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
@@ -124,6 +125,7 @@
125126 $wgOut->redirect( $url );
126127 } else {
127128 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
 129+ $wgOut->setStatusCode( 404 );
128130 $wgOut->errorpage( 'badtitle', 'badtitletext' );
129131 }
130132 } else if ( ( $action == 'view' ) &&
@@ -141,6 +143,10 @@
142144 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
143145 }
144146
 147+ if ( !$wgTitle->exists() ) {
 148+ $wgOut->setStatusCode( 404 );
 149+ }
 150+
145151 $ns = $wgTitle->getNamespace();
146152
147153 // Namespace might change when using redirects
@@ -166,6 +172,7 @@
167173 }
168174
169175 if ( in_array( $action, $wgDisabledActions ) ) {
 176+ $wgOut->setStatusCode( 404 );
170177 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
171178 } else {
172179 switch( $action ) {
@@ -254,6 +261,7 @@
255262 break;
256263 default:
257264 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
 265+ $wgOut->setStatusCode( 404 );
258266 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
259267 }
260268 }
Index: trunk/phase3/includes/Article.php
@@ -1461,6 +1461,7 @@
14621462
14631463 if ( !$wgUseValidation ) # Are we using article validation at all?
14641464 {
 1465+ $wgOut->setStatusCode( 404 );
14651466 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
14661467 return ;
14671468 }
@@ -2429,6 +2430,7 @@
24302431 $fname = 'Article::info';
24312432
24322433 if ( !$wgAllowPageInfo ) {
 2434+ $wgOut->setStatusCode( 400 );
24332435 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
24342436 return;
24352437 }
Index: trunk/phase3/includes/OutputPage.php
@@ -20,7 +20,7 @@
2121 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
2222 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
2323 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
24 - var $mSubtitle, $mRedirect;
 24+ var $mSubtitle, $mRedirect, $mStatusCode;
2525 var $mLastModified, $mETag, $mCategoryLinks;
2626 var $mScripts, $mLinkColours;
2727
@@ -60,7 +60,8 @@
6161 function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
6262 function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); }
6363 function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
64 -
 64+ function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
 65+
6566 # To add an http-equiv meta tag, precede the name with "http:"
6667 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
6768 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
@@ -442,7 +443,60 @@
443444 wfProfileOut( $fname );
444445 return;
445446 }
 447+ elseif ( $this->mStatusCode )
 448+ {
 449+ $statusMessage = array(
 450+ 100 => 'Continue',
 451+ 101 => 'Switching Protocols',
 452+ 102 => 'Processing',
 453+ 200 => 'OK',
 454+ 201 => 'Created',
 455+ 202 => 'Accepted',
 456+ 203 => 'Non-Authoritative Information',
 457+ 204 => 'No Content',
 458+ 205 => 'Reset Content',
 459+ 206 => 'Partial Content',
 460+ 207 => 'Multi-Status',
 461+ 300 => 'Multiple Choices',
 462+ 301 => 'Moved Permanently',
 463+ 302 => 'Found',
 464+ 303 => 'See Other',
 465+ 304 => 'Not Modified',
 466+ 305 => 'Use Proxy',
 467+ 307 => 'Temporary Redirect',
 468+ 400 => 'Bad Request',
 469+ 401 => 'Unauthorized',
 470+ 402 => 'Payment Required',
 471+ 403 => 'Forbidden',
 472+ 404 => 'Not Found',
 473+ 405 => 'Method Not Allowed',
 474+ 406 => 'Not Acceptable',
 475+ 407 => 'Proxy Authentication Required',
 476+ 408 => 'Request Timeout',
 477+ 409 => 'Conflict',
 478+ 410 => 'Gone',
 479+ 411 => 'Length Required',
 480+ 412 => 'Precondition Failed',
 481+ 413 => 'Request Entity Too Large',
 482+ 414 => 'Request-URI Too Large',
 483+ 415 => 'Unsupported Media Type',
 484+ 416 => 'Request Range Not Satisfiable',
 485+ 417 => 'Expectation Failed',
 486+ 422 => 'Unprocessable Entity',
 487+ 423 => 'Locked',
 488+ 424 => 'Failed Dependency',
 489+ 500 => 'Internal Server Error',
 490+ 501 => 'Not Implemented',
 491+ 502 => 'Bad Gateway',
 492+ 503 => 'Service Unavailable',
 493+ 504 => 'Gateway Timeout',
 494+ 505 => 'HTTP Version Not Supported',
 495+ 507 => 'Insufficient Storage'
 496+ );
446497
 498+ if ( $statusMessage[$this->mStatusCode] )
 499+ header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
 500+ }
447501
448502 # Buffer output; final headers may depend on later processing
449503 ob_start();
Index: trunk/phase3/includes/SpecialPage.php
@@ -257,8 +257,9 @@
258258 $retVal = $redir;
259259 } else {
260260 $wgOut->setArticleRelated( false );
261 - $wgOut->setRobotpolicy( "noindex,follow" );
262 - $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
 261+ $wgOut->setRobotpolicy( 'noindex,follow' );
 262+ $wgOut->setStatusCode( 404 );
 263+ $wgOut->errorpage( 'nosuchspecialpage', 'nospecialpagetext' );
263264 $retVal = false;
264265 }
265266 }
Index: trunk/phase3/RELEASE-NOTES
@@ -144,8 +144,8 @@
145145 * (bug 3617) Update for portuguese language (pt)
146146 * Namespaces hacks on LanguagePl
147147 * New preferences design and reorganisation
 148+* (bug 2585) Return proper 404 code when pages don't exist
148149
149 -
150150 === Caveats ===
151151
152152 Some output, particularly involving user-supplied inline HTML, may not

Follow-up revisions

RevisionCommit summaryAuthorDate
r44919* (bug 2585) HTTP 404 return code is now given for a page view if the page...brion23:38, 22 December 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   23:39, 22 December 2008

Was reverted in r11474 due to problems with edit pages reported by a fair number of editors, though we were never able to fully track it down.

Reimplemented a bit differently in r44919

Status & tagging log