Index: trunk/phase3/includes/FeedUtils.php |
— | — | @@ -31,16 +31,15 @@ |
32 | 32 | * @return Boolean |
33 | 33 | */ |
34 | 34 | public static function checkFeedOutput( $type ) { |
35 | | - global $wgFeed, $wgFeedClasses; |
| 35 | + global $wgOut, $wgFeed, $wgFeedClasses; |
36 | 36 | |
37 | 37 | if ( !$wgFeed ) { |
38 | | - global $wgOut; |
39 | 38 | $wgOut->addWikiMsg( 'feed-unavailable' ); |
40 | 39 | return false; |
41 | 40 | } |
42 | 41 | |
43 | 42 | if( !isset( $wgFeedClasses[$type] ) ) { |
44 | | - wfHttpError( 500, "Internal Server Error", "Unsupported feed type." ); |
| 43 | + $wgOut->addWikiMsg( 'feed-invalid' ); |
45 | 44 | return false; |
46 | 45 | } |
47 | 46 | |
Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -874,7 +874,7 @@ |
875 | 875 | return false; |
876 | 876 | } |
877 | 877 | } |
878 | | - wfHttpError( 403, 'Forbidden', |
| 878 | + throw new HttpError( 403, |
879 | 879 | 'Invalid file extension found in the path info or query string.' ); |
880 | 880 | |
881 | 881 | return false; |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -210,7 +210,7 @@ |
211 | 211 | "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . |
212 | 212 | "to true."; |
213 | 213 | } |
214 | | - wfHttpError( 500, "Internal error", $message ); |
| 214 | + throw new HttpError( 500, $message ); |
215 | 215 | } else { |
216 | 216 | $output->setSquidMaxage( 1200 ); |
217 | 217 | $output->redirect( $targetUrl, '301' ); |
Index: trunk/phase3/includes/specials/SpecialUserlogout.php |
— | — | @@ -33,31 +33,30 @@ |
34 | 34 | } |
35 | 35 | |
36 | 36 | function execute( $par ) { |
37 | | - global $wgUser, $wgOut; |
38 | | - |
39 | 37 | /** |
40 | 38 | * Some satellite ISPs use broken precaching schemes that log people out straight after |
41 | 39 | * they're logged in (bug 17790). Luckily, there's a way to detect such requests. |
42 | 40 | */ |
43 | 41 | if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '&' ) !== false ) { |
44 | 42 | wfDebug( "Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n" ); |
45 | | - wfHttpError( 400, wfMsg( 'loginerror' ), wfMsg( 'suspicious-userlogout' ) ); |
46 | | - return; |
| 43 | + throw new HttpError( 400, wfMessage( 'suspicious-userlogout' ), wfMessage( 'loginerror' ) ); |
47 | 44 | } |
48 | 45 | |
49 | 46 | $this->setHeaders(); |
50 | 47 | $this->outputHeader(); |
51 | 48 | |
52 | | - $oldName = $wgUser->getName(); |
53 | | - $wgUser->logout(); |
| 49 | + $user = $this->getUser(); |
| 50 | + $oldName = $user->getName(); |
| 51 | + $user->logout(); |
54 | 52 | |
55 | | - $wgOut->addWikiMsg( 'logouttext' ); |
| 53 | + $out = $this->getOutput(); |
| 54 | + $out->addWikiMsg( 'logouttext' ); |
56 | 55 | |
57 | 56 | // Hook. |
58 | 57 | $injected_html = ''; |
59 | | - wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) ); |
60 | | - $wgOut->addHTML( $injected_html ); |
| 58 | + wfRunHooks( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) ); |
| 59 | + $out->addHTML( $injected_html ); |
61 | 60 | |
62 | | - $wgOut->returnToMain(); |
| 61 | + $out->returnToMain(); |
63 | 62 | } |
64 | 63 | } |
Index: trunk/phase3/includes/specials/SpecialUploadStash.php |
— | — | @@ -95,8 +95,7 @@ |
96 | 96 | $message = $e->getMessage(); |
97 | 97 | } |
98 | 98 | |
99 | | - wfHttpError( $code, HttpStatus::getMessage( $code ), $message ); |
100 | | - return false; |
| 99 | + throw new HttpError( $code, $message ); |
101 | 100 | } |
102 | 101 | |
103 | 102 | /** |
Index: trunk/phase3/includes/Metadata.php |
— | — | @@ -41,14 +41,13 @@ |
42 | 42 | $rdftype = wfNegotiateType( wfAcceptToPrefs( $httpaccept ), wfAcceptToPrefs( self::RDF_TYPE_PREFS ) ); |
43 | 43 | |
44 | 44 | if( !$rdftype ){ |
45 | | - wfHttpError( 406, 'Not Acceptable', wfMsg( 'notacceptable' ) ); |
46 | | - return false; |
47 | | - } else { |
48 | | - $wgOut->disable(); |
49 | | - $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" ); |
50 | | - $wgOut->sendCacheControl(); |
51 | | - return true; |
| 45 | + throw new HttpError( 406, wfMessage( 'notacceptable' ) ); |
52 | 46 | } |
| 47 | + |
| 48 | + $wgOut->disable(); |
| 49 | + $wgRequest->response()->header( "Content-type: {$rdftype}; charset=utf-8" ); |
| 50 | + $wgOut->sendCacheControl(); |
| 51 | + return true; |
53 | 52 | } |
54 | 53 | |
55 | 54 | protected function reallyFullUrl() { |
Index: trunk/phase3/includes/Exception.php |
— | — | @@ -367,6 +367,55 @@ |
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
| 371 | + * Show an error that looks like an HTTP server error. |
| 372 | + * Replacement for wfHttpError(). |
| 373 | + * |
| 374 | + * @ingroup Exception |
| 375 | + */ |
| 376 | +class HttpError extends MWException { |
| 377 | + private $httpCode, $header, $content; |
| 378 | + |
| 379 | + /** |
| 380 | + * Constructor |
| 381 | + * |
| 382 | + * @param $httpCode Integer: HTTP status code to send to the client |
| 383 | + * @param $content String|Message: content of the message |
| 384 | + * @param $header String|Message: content of the header (\<title\> and \<h1\>) |
| 385 | + */ |
| 386 | + public function __construct( $httpCode, $content, $header = null ){ |
| 387 | + parent::__construct( $content ); |
| 388 | + $this->httpCode = (int)$httpCode; |
| 389 | + $this->header = $header; |
| 390 | + $this->content = $content; |
| 391 | + } |
| 392 | + |
| 393 | + public function reportHTML() { |
| 394 | + $httpMessage = HttpStatus::getMessage( $this->httpCode ); |
| 395 | + |
| 396 | + header( "Status: {$this->httpCode} {$httpMessage}" ); |
| 397 | + header( 'Content-type: text/html; charset=utf-8' ); |
| 398 | + |
| 399 | + if ( $this->header === null ) { |
| 400 | + $header = $httpMessage; |
| 401 | + } elseif ( $this->header instanceof Message ) { |
| 402 | + $header = $this->header->escaped(); |
| 403 | + } else { |
| 404 | + $header = htmlspecialchars( $this->header ); |
| 405 | + } |
| 406 | + |
| 407 | + if ( $this->content instanceof Message ) { |
| 408 | + $content = $this->content->escaped(); |
| 409 | + } else { |
| 410 | + $content = htmlspecialchars( $this->content ); |
| 411 | + } |
| 412 | + |
| 413 | + print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n". |
| 414 | + "<html><head><title>$header</title></head>\n" . |
| 415 | + "<body><h1>$header</h1><p>$content</p></body></html>\n"; |
| 416 | + } |
| 417 | +} |
| 418 | + |
| 419 | +/** |
371 | 420 | * Handler class for MWExceptions |
372 | 421 | * @ingroup Exception |
373 | 422 | */ |