Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | } |
86 | 86 | |
87 | 87 | class ExtMobileFrontend { |
88 | | - const VERSION = '0.5.74'; |
| 88 | + const VERSION = '0.5.76'; |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @var DOMDocument |
— | — | @@ -200,10 +200,52 @@ |
201 | 201 | ); |
202 | 202 | |
203 | 203 | public function testCanonicalRedirect( $request, $title, $output ) { |
| 204 | + global $wgUsePathInfo, $wgMobileDomain; |
204 | 205 | $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
205 | 206 | if ( empty( $xDevice ) ) { |
206 | 207 | return true; // Let the redirect happen |
207 | 208 | } else { |
| 209 | + if ( $title->getNamespace() == NS_SPECIAL ) { |
| 210 | + list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() ); |
| 211 | + if ( $name ) { |
| 212 | + $title = SpecialPage::getTitleFor( $name, $subpage ); |
| 213 | + } |
| 214 | + } |
| 215 | + $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ); |
| 216 | + // Redirect to canonical url, make it a 301 to allow caching |
| 217 | + if ( $targetUrl == $request->getFullRequestURL() ) { |
| 218 | + $message = "Redirect loop detected!\n\n" . |
| 219 | + "This means the wiki got confused about what page was " . |
| 220 | + "requested; this sometimes happens when moving a wiki " . |
| 221 | + "to a new server or changing the server configuration.\n\n"; |
| 222 | + |
| 223 | + if ( $wgUsePathInfo ) { |
| 224 | + $message .= "The wiki is trying to interpret the page " . |
| 225 | + "title from the URL path portion (PATH_INFO), which " . |
| 226 | + "sometimes fails depending on the web server. Try " . |
| 227 | + "setting \"\$wgUsePathInfo = false;\" in your " . |
| 228 | + "LocalSettings.php, or check that \$wgArticlePath " . |
| 229 | + "is correct."; |
| 230 | + } else { |
| 231 | + $message .= "Your web server was detected as possibly not " . |
| 232 | + "supporting URL path components (PATH_INFO) correctly; " . |
| 233 | + "check your LocalSettings.php for a customized " . |
| 234 | + "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . |
| 235 | + "to true."; |
| 236 | + } |
| 237 | + throw new HttpError( 500, $message ); |
| 238 | + } else { |
| 239 | + $parsedUrl = wfParseUrl( $targetUrl ); |
| 240 | + if ( stristr( $parsedUrl['host'], $wgMobileDomain ) === FALSE ) { |
| 241 | + $hostParts = explode( '.', $parsedUrl['host'] ); |
| 242 | + $parsedUrl['host'] = $hostParts[0] . $wgMobileDomain . $hostParts[1] . '.' . $hostParts[2]; |
| 243 | + } |
| 244 | + $fragmentDelimiter = ( !empty( $parsedUrl['fragment'] ) ) ? '#' : ''; |
| 245 | + $queryDelimiter = ( !empty( $parsedUrl['query'] ) ) ? '?' : ''; |
| 246 | + $targetUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'] . $queryDelimiter . $parsedUrl['query'] . $fragmentDelimiter . $parsedUrl['fragment']; |
| 247 | + $output->setSquidMaxage( 1200 ); |
| 248 | + $output->redirect( $targetUrl, '301' ); |
| 249 | + } |
208 | 250 | return false; // Prevent the redirect from occuring |
209 | 251 | } |
210 | 252 | } |
— | — | @@ -484,8 +526,7 @@ |
485 | 527 | if ( self::$useFormat === 'mobile' || |
486 | 528 | self::$useFormat === 'mobile-wap' || |
487 | 529 | !empty( $xDevice ) ) { |
488 | | - if ( $action !== 'edit' && |
489 | | - $mobileAction !== 'view_normal_site' ) { |
| 530 | + if ( $action !== 'edit' ) { |
490 | 531 | $this->getMsg(); |
491 | 532 | $this->disableCaching(); |
492 | 533 | $this->sendXDeviceVaryHeader(); |