Index: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php |
— | — | @@ -85,4 +85,21 @@ |
86 | 86 | $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array( &$parsedUrl ) ); |
87 | 87 | $this->assertEquals( "http://en.m.wikipedia.org/wiki/Gustavus_Airport", wfAssembleUrl( $parsedUrl ) ); |
88 | 88 | } |
| 89 | + |
| 90 | + public function testUpdateMobileUrlPath() { |
| 91 | + global $wgMobileUrlTemplate, $wgExtMobileFrontend, $wgScriptPath; |
| 92 | + $wgScriptPath = '/wiki'; |
| 93 | + $updateMobileUrlHost = self::getMethod( "updateMobileUrlPath" ); |
| 94 | + $wgMobileUrlTemplate = "/mobile/%p"; |
| 95 | + |
| 96 | + // check for constructing a templated URL |
| 97 | + $parsedUrl = wfParseUrl( "http://en.wikipedia.org/wiki/Gustavus_Airport" ); |
| 98 | + $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array( &$parsedUrl ) ); |
| 99 | + $this->assertEquals( "http://en.wikipedia.org/wiki/mobile/Gustavus_Airport", wfAssembleUrl( $parsedUrl ) ); |
| 100 | + |
| 101 | + // check for maintaining an already templated URL |
| 102 | + $parsedUrl = wfParseUrl( "http://en.wikipedia.org/wiki/mobile/Gustavus_Airport" ); |
| 103 | + $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array( &$parsedUrl ) ); |
| 104 | + $this->assertEquals( "http://en.wikipedia.org/wiki/mobile/Gustavus_Airport", wfAssembleUrl( $parsedUrl ) ); |
| 105 | + } |
89 | 106 | } |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -1329,7 +1329,7 @@ |
1330 | 1330 | global $wgMobileUrlTemplate; |
1331 | 1331 | $parsedUrl = wfParseUrl( $url ); |
1332 | 1332 | $this->updateMobileUrlHost( $parsedUrl ); |
1333 | | - $this->updateMobileUrlPath( $parsedUrl ); |
| 1333 | + $this->updateMobileUrlPath( $parsedUrl ); |
1334 | 1334 | return wfAssembleUrl( $parsedUrl ); |
1335 | 1335 | } |
1336 | 1336 | |
— | — | @@ -1373,11 +1373,24 @@ |
1374 | 1374 | * Result of parseUrl() or wfParseUrl() |
1375 | 1375 | */ |
1376 | 1376 | protected function updateMobileUrlPath( &$parsedUrl ) { |
1377 | | - $mobileUrlHostTemplate = $this->parseMobileUrlTemplate( 'path' ); |
1378 | | - if ( !strlen( $mobileUrlHostTemplate ) ) { |
| 1377 | + global $wgScriptPath; |
| 1378 | + |
| 1379 | + $mobileUrlPathTemplate = $this->parseMobileUrlTemplate( 'path' ); |
| 1380 | + if ( !strlen( $mobileUrlPathTemplate ) ) { |
1379 | 1381 | return; |
1380 | 1382 | } |
1381 | | - return; |
| 1383 | + |
| 1384 | + // find out if we already have a templated path |
| 1385 | + $templatePathOffset = strpos( $mobileUrlPathTemplate, '%p' ); |
| 1386 | + $templatePathSansToken = substr( $mobileUrlPathTemplate, 0, $templatePathOffset ); |
| 1387 | + if ( substr_compare( $parsedUrl[ 'path' ], $wgScriptPath . $templatePathSansToken, 0 ) > 0 ) { |
| 1388 | + return; |
| 1389 | + } |
| 1390 | + |
| 1391 | + $scriptPathLength = strlen( $wgScriptPath ); |
| 1392 | + // the "+ 1" removes the preceding "/" from the path sans $wgScriptPath |
| 1393 | + $pathSansScriptPath = substr( $parsedUrl[ 'path' ], $scriptPathLength + 1 ); |
| 1394 | + $parsedUrl[ 'path' ] = $wgScriptPath . $templatePathSansToken . $pathSansScriptPath; |
1382 | 1395 | } |
1383 | 1396 | |
1384 | 1397 | /** |