Index: trunk/phase3/includes/api/ApiFormatBase.php |
— | — | @@ -145,11 +145,10 @@ |
146 | 146 | if ( is_null( $mime ) ) { |
147 | 147 | return; // skip any initialization |
148 | 148 | } |
149 | | - |
150 | | - if( !$this->getMain()->isInternalMode() ) { |
151 | | - header( "Content-Type: $mime; charset=utf-8" ); |
152 | | - } |
153 | 149 | |
| 150 | + global $wgRequest; |
| 151 | + $wgRequest->response()->header( "Content-Type: $mime; charset=utf-8" ); |
| 152 | + |
154 | 153 | if ( $isHtml ) { |
155 | 154 | ?> |
156 | 155 | <!DOCTYPE HTML> |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -370,11 +370,13 @@ |
371 | 371 | // Error results should not be cached |
372 | 372 | $this->setCacheMode( 'private' ); |
373 | 373 | |
| 374 | + global $wgRequest; |
| 375 | + $response = $wgRequest->response(); |
374 | 376 | $headerStr = 'MediaWiki-API-Error: ' . $errCode; |
375 | 377 | if ( $e->getCode() === 0 ) { |
376 | | - header( $headerStr ); |
| 378 | + $response->header( $headerStr ); |
377 | 379 | } else { |
378 | | - header( $headerStr, true, $e->getCode() ); |
| 380 | + $response->header( $headerStr, true, $e->getCode() ); |
379 | 381 | } |
380 | 382 | |
381 | 383 | // Reset and print just the error message |
— | — | @@ -397,26 +399,29 @@ |
398 | 400 | } |
399 | 401 | |
400 | 402 | protected function sendCacheHeaders() { |
| 403 | + global $wgRequest; |
| 404 | + $response = $wgRequest->response(); |
| 405 | + |
401 | 406 | if ( $this->mCacheMode == 'private' ) { |
402 | | - header( 'Cache-Control: private' ); |
| 407 | + $response->header( 'Cache-Control: private' ); |
403 | 408 | return; |
404 | 409 | } |
405 | 410 | |
406 | 411 | if ( $this->mCacheMode == 'anon-public-user-private' ) { |
407 | 412 | global $wgUseXVO, $wgOut; |
408 | | - header( 'Vary: Accept-Encoding, Cookie' ); |
| 413 | + $response->header( 'Vary: Accept-Encoding, Cookie' ); |
409 | 414 | if ( $wgUseXVO ) { |
410 | | - header( $wgOut->getXVO() ); |
| 415 | + $response->header( $wgOut->getXVO() ); |
411 | 416 | if ( $wgOut->haveCacheVaryCookies() ) { |
412 | 417 | // Logged in, mark this request private |
413 | | - header( 'Cache-Control: private' ); |
| 418 | + $response->header( 'Cache-Control: private' ); |
414 | 419 | return; |
415 | 420 | } |
416 | 421 | // Logged out, send normal public headers below |
417 | 422 | } elseif ( session_id() != '' ) { |
418 | 423 | // Logged in or otherwise has session (e.g. anonymous users who have edited) |
419 | 424 | // Mark request private |
420 | | - header( 'Cache-Control: private' ); |
| 425 | + $response->header( 'Cache-Control: private' ); |
421 | 426 | return; |
422 | 427 | } // else no XVO and anonymous, send public headers below |
423 | 428 | } |
— | — | @@ -433,7 +438,7 @@ |
434 | 439 | // Public cache not requested |
435 | 440 | // Sending a Vary header in this case is harmless, and protects us |
436 | 441 | // against conditional calls of setCacheMaxAge(). |
437 | | - header( 'Cache-Control: private' ); |
| 442 | + $response->header( 'Cache-Control: private' ); |
438 | 443 | return; |
439 | 444 | } |
440 | 445 | |
— | — | @@ -442,7 +447,7 @@ |
443 | 448 | // Send an Expires header |
444 | 449 | $maxAge = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] ); |
445 | 450 | $expiryUnixTime = ( $maxAge == 0 ? 1 : time() + $maxAge ); |
446 | | - header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) ); |
| 451 | + $response->header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) ); |
447 | 452 | |
448 | 453 | // Construct the Cache-Control header |
449 | 454 | $ccHeader = ''; |
— | — | @@ -459,7 +464,7 @@ |
460 | 465 | } |
461 | 466 | } |
462 | 467 | |
463 | | - header( "Cache-Control: $ccHeader" ); |
| 468 | + $response->header( "Cache-Control: $ccHeader" ); |
464 | 469 | } |
465 | 470 | |
466 | 471 | /** |
— | — | @@ -588,8 +593,12 @@ |
589 | 594 | $maxLag = $params['maxlag']; |
590 | 595 | list( $host, $lag ) = wfGetLB()->getMaxLag(); |
591 | 596 | if ( $lag > $maxLag ) { |
592 | | - header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); |
593 | | - header( 'X-Database-Lag: ' . intval( $lag ) ); |
| 597 | + global $wgRequest; |
| 598 | + $response = $wgRequest->response(); |
| 599 | + |
| 600 | + $response->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); |
| 601 | + $response->header( 'X-Database-Lag: ' . intval( $lag ) ); |
| 602 | + |
594 | 603 | if ( $wgShowHostnames ) { |
595 | 604 | $this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' ); |
596 | 605 | } else { |
Index: trunk/phase3/includes/WebResponse.php |
— | — | @@ -17,12 +17,14 @@ |
18 | 18 | * header() |
19 | 19 | * @param $string String: header to output |
20 | 20 | * @param $replace Bool: replace current similar header |
| 21 | + * @param $http_response_code null|int Forces the HTTP response code to the specified value. |
21 | 22 | */ |
22 | | - public function header($string, $replace=true) { |
23 | | - header($string,$replace); |
| 23 | + public function header( $string, $replace = true, $http_response_code = null ) { |
| 24 | + header( $string, $replace, $http_response_code ); |
24 | 25 | } |
25 | 26 | |
26 | | - /** Set the browser cookie |
| 27 | + /** |
| 28 | + * Set the browser cookie |
27 | 29 | * @param $name String: name of cookie |
28 | 30 | * @param $value String: value to give cookie |
29 | 31 | * @param $expire Int: number of seconds til cookie expires |
— | — | @@ -59,15 +61,15 @@ |
60 | 62 | private $headers; |
61 | 63 | private $cookies; |
62 | 64 | |
63 | | - public function header($string, $replace=true) { |
64 | | - list($key, $val) = explode(":", $string, 2); |
| 65 | + public function header( $string, $replace = true, $http_response_code = null ) { |
| 66 | + list( $key, $val ) = explode( ":", $string, 2 ); |
65 | 67 | |
66 | | - if($replace || !isset($this->headers[$key])) { |
| 68 | + if( $replace || !isset( $this->headers[$key] ) ) { |
67 | 69 | $this->headers[$key] = $val; |
68 | 70 | } |
69 | 71 | } |
70 | 72 | |
71 | | - public function getheader($key) { |
| 73 | + public function getheader( $key ) { |
72 | 74 | return $this->headers[$key]; |
73 | 75 | } |
74 | 76 | |
— | — | @@ -76,7 +78,7 @@ |
77 | 79 | } |
78 | 80 | |
79 | 81 | public function getcookie( $name ) { |
80 | | - if ( isset($this->cookies[$name]) ) { |
| 82 | + if ( isset( $this->cookies[$name] ) ) { |
81 | 83 | return $this->cookies[$name]; |
82 | 84 | } |
83 | 85 | } |