Index: trunk/phase3/index.php |
— | — | @@ -112,6 +112,7 @@ |
113 | 113 | wfSpecialSearch(); |
114 | 114 | } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) { |
115 | 115 | $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); |
| 116 | + $wgOut->setStatusCode( 404 ); |
116 | 117 | $wgOut->errorpage( 'badtitle', 'badtitletext' ); |
117 | 118 | } else if ( $wgTitle->getInterwiki() != '' ) { |
118 | 119 | if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) { |
— | — | @@ -124,6 +125,7 @@ |
125 | 126 | $wgOut->redirect( $url ); |
126 | 127 | } else { |
127 | 128 | $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); |
| 129 | + $wgOut->setStatusCode( 404 ); |
128 | 130 | $wgOut->errorpage( 'badtitle', 'badtitletext' ); |
129 | 131 | } |
130 | 132 | } else if ( ( $action == 'view' ) && |
— | — | @@ -141,6 +143,10 @@ |
142 | 144 | $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() ); |
143 | 145 | } |
144 | 146 | |
| 147 | + if ( !$wgTitle->exists() ) { |
| 148 | + $wgOut->setStatusCode( 404 ); |
| 149 | + } |
| 150 | + |
145 | 151 | $ns = $wgTitle->getNamespace(); |
146 | 152 | |
147 | 153 | // Namespace might change when using redirects |
— | — | @@ -166,6 +172,7 @@ |
167 | 173 | } |
168 | 174 | |
169 | 175 | if ( in_array( $action, $wgDisabledActions ) ) { |
| 176 | + $wgOut->setStatusCode( 404 ); |
170 | 177 | $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' ); |
171 | 178 | } else { |
172 | 179 | switch( $action ) { |
— | — | @@ -254,6 +261,7 @@ |
255 | 262 | break; |
256 | 263 | default: |
257 | 264 | if (wfRunHooks('UnknownAction', array($action, $wgArticle))) { |
| 265 | + $wgOut->setStatusCode( 404 ); |
258 | 266 | $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' ); |
259 | 267 | } |
260 | 268 | } |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -1461,6 +1461,7 @@ |
1462 | 1462 | |
1463 | 1463 | if ( !$wgUseValidation ) # Are we using article validation at all? |
1464 | 1464 | { |
| 1465 | + $wgOut->setStatusCode( 404 ); |
1465 | 1466 | $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" ); |
1466 | 1467 | return ; |
1467 | 1468 | } |
— | — | @@ -2429,6 +2430,7 @@ |
2430 | 2431 | $fname = 'Article::info'; |
2431 | 2432 | |
2432 | 2433 | if ( !$wgAllowPageInfo ) { |
| 2434 | + $wgOut->setStatusCode( 400 ); |
2433 | 2435 | $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' ); |
2434 | 2436 | return; |
2435 | 2437 | } |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | var $mHeaders, $mCookies, $mMetatags, $mKeywords; |
22 | 22 | var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext; |
23 | 23 | var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable; |
24 | | - var $mSubtitle, $mRedirect; |
| 24 | + var $mSubtitle, $mRedirect, $mStatusCode; |
25 | 25 | var $mLastModified, $mETag, $mCategoryLinks; |
26 | 26 | var $mScripts, $mLinkColours; |
27 | 27 | |
— | — | @@ -60,7 +60,8 @@ |
61 | 61 | function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; } |
62 | 62 | function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); } |
63 | 63 | function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; } |
64 | | - |
| 64 | + function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; } |
| 65 | + |
65 | 66 | # To add an http-equiv meta tag, precede the name with "http:" |
66 | 67 | function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); } |
67 | 68 | function addKeyword( $text ) { array_push( $this->mKeywords, $text ); } |
— | — | @@ -442,7 +443,60 @@ |
443 | 444 | wfProfileOut( $fname ); |
444 | 445 | return; |
445 | 446 | } |
| 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 | + ); |
446 | 497 | |
| 498 | + if ( $statusMessage[$this->mStatusCode] ) |
| 499 | + header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] ); |
| 500 | + } |
447 | 501 | |
448 | 502 | # Buffer output; final headers may depend on later processing |
449 | 503 | ob_start(); |
Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -257,8 +257,9 @@ |
258 | 258 | $retVal = $redir; |
259 | 259 | } else { |
260 | 260 | $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' ); |
263 | 264 | $retVal = false; |
264 | 265 | } |
265 | 266 | } |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -144,8 +144,8 @@ |
145 | 145 | * (bug 3617) Update for portuguese language (pt) |
146 | 146 | * Namespaces hacks on LanguagePl |
147 | 147 | * New preferences design and reorganisation |
| 148 | +* (bug 2585) Return proper 404 code when pages don't exist |
148 | 149 | |
149 | | - |
150 | 150 | === Caveats === |
151 | 151 | |
152 | 152 | Some output, particularly involving user-supplied inline HTML, may not |