Index: trunk/phase3/includes/Setup.php |
— | — | @@ -167,6 +167,10 @@ |
168 | 168 | $wgLoadBalancer = new StubObject( 'wgLoadBalancer', 'LoadBalancer', |
169 | 169 | array( $wgDBservers, false, $wgMasterWaitTimeout, true ) ); |
170 | 170 | $wgContLang = new StubContLang; |
| 171 | + |
| 172 | +// Now that variant lists may be available... |
| 173 | +$wgRequest->interpolateTitle(); |
| 174 | + |
171 | 175 | $wgUser = new StubUser; |
172 | 176 | $wgLang = new StubUserLang; |
173 | 177 | $wgOut = new StubObject( 'wgOut', 'OutputPage' ); |
Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -44,44 +44,93 @@ |
45 | 45 | class WebRequest { |
46 | 46 | function __construct() { |
47 | 47 | $this->checkMagicQuotes(); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Check for title, action, and/or variant data in the URL |
| 52 | + * and interpolate it into the GET variables. |
| 53 | + * This should only be run after $wgContLang is available, |
| 54 | + * as we may need the list of language variants to determine |
| 55 | + * available variant URLs. |
| 56 | + */ |
| 57 | + function interpolateTitle() { |
48 | 58 | global $wgUsePathInfo; |
49 | 59 | if ( $wgUsePathInfo ) { |
50 | 60 | // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892 |
51 | 61 | // And also by Apache 2.x, double slashes are converted to single slashes. |
52 | 62 | // So we will use REQUEST_URI if possible. |
53 | | - $title = ''; |
| 63 | + $matches = array(); |
54 | 64 | if ( !empty( $_SERVER['REQUEST_URI'] ) ) { |
55 | | - global $wgArticlePath, $wgActionPaths; |
56 | | - $paths["view"] = $wgArticlePath; |
57 | | - $paths = array_merge( $paths, $wgActionPaths ); |
58 | | - $title = $this->extractActionPaths( $paths ); |
| 65 | + // Slurp out the path portion to examine... |
| 66 | + $url = $_SERVER['REQUEST_URI']; |
| 67 | + if ( !preg_match( '!^https?://!', $url ) ) { |
| 68 | + $url = 'http://unused' . $url; |
| 69 | + } |
| 70 | + $a = parse_url( $url ); |
| 71 | + if( $a ) { |
| 72 | + $path = $a['path']; |
| 73 | + |
| 74 | + global $wgArticlePath; |
| 75 | + $matches = $this->extractTitle( $path, $wgArticlePath ); |
| 76 | + |
| 77 | + global $wgActionPaths; |
| 78 | + if( !$matches && $wgActionPaths) { |
| 79 | + $matches = $this->extractTitle( $path, $wgActionPaths, 'action' ); |
| 80 | + } |
| 81 | + |
| 82 | + global $wgVariantArticlePath, $wgContLang; |
| 83 | + if( !$matches && $wgVariantArticlePath ) { |
| 84 | + $variantPaths = array(); |
| 85 | + foreach( $wgContLang->getVariants() as $variant ) { |
| 86 | + $variantPaths[$variant] = |
| 87 | + str_replace( '$2', $variant, $wgVariantArticlePath ); |
| 88 | + } |
| 89 | + $matches = $this->extractTitle( $path, $variantPaths, 'variant' ); |
| 90 | + } |
| 91 | + } |
59 | 92 | } elseif ( isset( $_SERVER['ORIG_PATH_INFO'] ) && $_SERVER['ORIG_PATH_INFO'] != '' ) { |
60 | | - # Mangled PATH_INFO |
61 | | - # http://bugs.php.net/bug.php?id=31892 |
62 | | - # Also reported when ini_get('cgi.fix_pathinfo')==false |
63 | | - $title = substr( $_SERVER['ORIG_PATH_INFO'], 1 ); |
64 | | - } elseif ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != '') && $wgUsePathInfo ) { |
65 | | - $title = substr( $_SERVER['PATH_INFO'], 1 ); |
| 93 | + // Mangled PATH_INFO |
| 94 | + // http://bugs.php.net/bug.php?id=31892 |
| 95 | + // Also reported when ini_get('cgi.fix_pathinfo')==false |
| 96 | + $matches['title'] = substr( $_SERVER['ORIG_PATH_INFO'], 1 ); |
| 97 | + |
| 98 | + } elseif ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != '') ) { |
| 99 | + // Regular old PATH_INFO yay |
| 100 | + $matches['title'] = substr( $_SERVER['PATH_INFO'], 1 ); |
66 | 101 | } |
67 | | - if ( strval( $title ) != '' ) { |
68 | | - $_GET['title'] = $_REQUEST['title'] = $title; |
| 102 | + foreach( $matches as $key => $val) { |
| 103 | + $_GET[$key] = $_REQUEST[$key] = $val; |
69 | 104 | } |
70 | 105 | } |
71 | 106 | } |
72 | 107 | |
73 | | - private function extractActionPaths( $paths ) { |
74 | | - $url = $_SERVER['REQUEST_URI']; |
75 | | - if ( !preg_match( '!^https?://!', $url ) ) { |
76 | | - $url = 'http://unused' . $url; |
77 | | - } |
78 | | - $a = parse_url( $url ); |
79 | | - foreach( $paths as $action => $path ) { |
| 108 | + /** |
| 109 | + * Internal URL rewriting function; tries to extract page title and, |
| 110 | + * optionally, one other fixed parameter value from a URL path. |
| 111 | + * |
| 112 | + * @param string $path the URL path given from the client |
| 113 | + * @param array $bases one or more URLs, optionally with $1 at the end |
| 114 | + * @param string $key if provided, the matching key in $bases will be |
| 115 | + * passed on as the value of this URL parameter |
| 116 | + * @return array of URL variables to interpolate; empty if no match |
| 117 | + */ |
| 118 | + private function extractTitle( $path, $bases, $key=false ) { |
| 119 | + foreach( (array)$bases as $keyValue => $base ) { |
80 | 120 | // Find the part after $wgArticlePath |
81 | | - $base = str_replace( '$1', '', $path ); |
82 | | - if ( $a && substr( $a['path'], 0, strlen( $base ) ) == $base ) { |
83 | | - return urldecode( substr( $a['path'], strlen( $base ) ) ); |
| 121 | + $base = str_replace( '$1', '', $base ); |
| 122 | + $baseLen = strlen( $base ); |
| 123 | + if( substr( $path, 0, $baseLen ) == $base ) { |
| 124 | + $raw = substr( $path, $baseLen ); |
| 125 | + if( $raw !== '' ) { |
| 126 | + $matches = array( 'title' => urldecode( $raw ) ); |
| 127 | + if( $key ) { |
| 128 | + $matches[$key] = $keyValue; |
| 129 | + } |
| 130 | + return $matches; |
| 131 | + } |
84 | 132 | } |
85 | 133 | } |
| 134 | + return array(); |
86 | 135 | } |
87 | 136 | |
88 | 137 | private $_response; |