Index: trunk/phase3/includes/Setup.php |
— | — | @@ -308,37 +308,16 @@ |
309 | 309 | if ( $wgCommandLineMode ) { |
310 | 310 | wfDebug( "\n\nStart command line script $self\n" ); |
311 | 311 | } else { |
312 | | - wfDebug( "Start request\n\n" ); |
313 | | - # Output the REQUEST_URI. This is not supported by IIS in rewrite mode, |
314 | | - # so use an alternative |
315 | | - if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
316 | | - $requestUri = $_SERVER['REQUEST_URI']; |
317 | | - } elseif ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { |
318 | | - $requestUri = $_SERVER['HTTP_X_ORIGINAL_URL']; |
319 | | - } else { |
320 | | - $requestUri = $_SERVER['PHP_SELF']; |
321 | | - } |
| 312 | + $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}"; |
322 | 313 | |
323 | | - wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" ); |
324 | | - |
325 | 314 | if ( $wgDebugPrintHttpHeaders ) { |
326 | | - $headerOut = "HTTP HEADERS:\n"; |
| 315 | + $debug .= "\nHTTP HEADERS:\n"; |
327 | 316 | |
328 | | - if ( function_exists( 'getallheaders' ) ) { |
329 | | - $headers = getallheaders(); |
330 | | - foreach ( $headers as $name => $value ) { |
331 | | - $headerOut .= "$name: $value\n"; |
332 | | - } |
333 | | - } else { |
334 | | - $headers = $_SERVER; |
335 | | - foreach ( $headers as $name => $value ) { |
336 | | - if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue; |
337 | | - $name = substr( $name, 5 ); |
338 | | - $headerOut .= "$name: $value\n"; |
339 | | - } |
| 317 | + foreach ( $wgRequest->getAllHeaders() as $name => $value ) { |
| 318 | + $debug .= "$name: $value\n"; |
340 | 319 | } |
341 | | - wfDebug( "$headerOut\n" ); |
342 | 320 | } |
| 321 | + wfDebug( "$debug\n" ); |
343 | 322 | } |
344 | 323 | |
345 | 324 | wfProfileOut( $fname . '-misc1' ); |
Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -492,10 +492,12 @@ |
493 | 493 | * @return String |
494 | 494 | */ |
495 | 495 | public function getRequestURL() { |
496 | | - if( isset( $_SERVER['REQUEST_URI']) && strlen($_SERVER['REQUEST_URI']) ) { |
| 496 | + if( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) { |
497 | 497 | $base = $_SERVER['REQUEST_URI']; |
| 498 | + } elseif ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) && strlen( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { |
| 499 | + // Probably IIS; doesn't set REQUEST_URI |
| 500 | + $base = $_SERVER['HTTP_X_ORIGINAL_URL']; |
498 | 501 | } elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) { |
499 | | - // Probably IIS; doesn't set REQUEST_URI |
500 | 502 | $base = $_SERVER['SCRIPT_NAME']; |
501 | 503 | if( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] != '' ) { |
502 | 504 | $base .= '?' . $_SERVER['QUERY_STRING']; |
— | — | @@ -503,8 +505,8 @@ |
504 | 506 | } else { |
505 | 507 | // This shouldn't happen! |
506 | 508 | throw new MWException( "Web server doesn't provide either " . |
507 | | - "REQUEST_URI or SCRIPT_NAME. Report details of your " . |
508 | | - "web server configuration to http://bugzilla.wikimedia.org/" ); |
| 509 | + "REQUEST_URI, HTTP_X_ORIGINAL_URL or SCRIPT_NAME. Report details " . |
| 510 | + "of your web server configuration to http://bugzilla.wikimedia.org/" ); |
509 | 511 | } |
510 | 512 | // User-agents should not send a fragment with the URI, but |
511 | 513 | // if they do, and the web server passes it on to us, we |
— | — | @@ -701,32 +703,50 @@ |
702 | 704 | } |
703 | 705 | |
704 | 706 | /** |
| 707 | + * Initialise the header list |
| 708 | + */ |
| 709 | + private function initHeaders() { |
| 710 | + if ( count( $this->headers ) ) { |
| 711 | + return; |
| 712 | + } |
| 713 | + |
| 714 | + if ( function_exists( 'apache_request_headers' ) ) { |
| 715 | + foreach ( apache_request_headers() as $tempName => $tempValue ) { |
| 716 | + $this->headers[ strtoupper( $tempName ) ] = $tempValue; |
| 717 | + } |
| 718 | + } else { |
| 719 | + $headers = $_SERVER; |
| 720 | + foreach ( $_SERVER as $name => $value ) { |
| 721 | + if ( substr( $name, 0, 5 ) === 'HTTP_' ) { |
| 722 | + $name = str_replace( '_', '-', substr( $name, 5 ) ); |
| 723 | + $this->headers[$name] = $value; |
| 724 | + } elseif ( $name === 'CONTENT_LENGTH' ) { |
| 725 | + $this->headers['CONTENT-LENGTH'] = $value; |
| 726 | + } |
| 727 | + } |
| 728 | + } |
| 729 | + } |
| 730 | + |
| 731 | + /** |
| 732 | + * Get an array containing all request headers |
| 733 | + * |
| 734 | + * @return Array mapping header name to its value |
| 735 | + */ |
| 736 | + public function getAllHeaders() { |
| 737 | + $this->initHeaders(); |
| 738 | + return $this->headers; |
| 739 | + } |
| 740 | + |
| 741 | + /** |
705 | 742 | * Get a request header, or false if it isn't set |
706 | 743 | * @param $name String: case-insensitive header name |
707 | 744 | */ |
708 | 745 | public function getHeader( $name ) { |
709 | 746 | $name = strtoupper( $name ); |
710 | | - if ( function_exists( 'apache_request_headers' ) ) { |
711 | | - if ( !$this->headers ) { |
712 | | - foreach ( apache_request_headers() as $tempName => $tempValue ) { |
713 | | - $this->headers[ strtoupper( $tempName ) ] = $tempValue; |
714 | | - } |
715 | | - } |
716 | | - if ( isset( $this->headers[$name] ) ) { |
717 | | - return $this->headers[$name]; |
718 | | - } else { |
719 | | - return false; |
720 | | - } |
| 747 | + if ( isset( $this->headers[$name] ) ) { |
| 748 | + return $this->headers[$name]; |
721 | 749 | } else { |
722 | | - $name = 'HTTP_' . str_replace( '-', '_', $name ); |
723 | | - if ( $name === 'HTTP_CONTENT_LENGTH' && !isset( $_SERVER[$name] ) ) { |
724 | | - $name = 'CONTENT_LENGTH'; |
725 | | - } |
726 | | - if ( isset( $_SERVER[$name] ) ) { |
727 | | - return $_SERVER[$name]; |
728 | | - } else { |
729 | | - return false; |
730 | | - } |
| 750 | + return false; |
731 | 751 | } |
732 | 752 | } |
733 | 753 | |