https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112285

Revision: 112285
Author:   awjrichards
Date:     2012-02-24 01:17:26 +0000 (Fri, 24 Feb 2012)
Log Message:
-----------
Added support and corresponding test for creating mobile URLs where the 
mobile-ness of the URL is denoted in its path. This just adds the method to do 
this - it is not implemented elsewhere in the MobileFrontend code.

Modified Paths:
--------------
    trunk/extensions/MobileFrontend/MobileFrontend.body.php
    trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php

Modified: trunk/extensions/MobileFrontend/MobileFrontend.body.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFrontend.body.php     2012-02-24 
01:16:18 UTC (rev 112284)
+++ trunk/extensions/MobileFrontend/MobileFrontend.body.php     2012-02-24 
01:17:26 UTC (rev 112285)
@@ -1329,7 +1329,7 @@
                global $wgMobileUrlTemplate;            
                $parsedUrl = wfParseUrl( $url );
                $this->updateMobileUrlHost( $parsedUrl );
-               $this->updateMobileUrlPath( $parsedUrl );               
+               $this->updateMobileUrlPath( $parsedUrl );
                return wfAssembleUrl( $parsedUrl );
        }
 
@@ -1373,11 +1373,24 @@
         *              Result of parseUrl() or wfParseUrl()
         */
        protected function updateMobileUrlPath( &$parsedUrl ) {
-               $mobileUrlHostTemplate = $this->parseMobileUrlTemplate( 'path' 
);
-               if ( !strlen( $mobileUrlHostTemplate ) ) {
+               global $wgScriptPath;
+
+               $mobileUrlPathTemplate = $this->parseMobileUrlTemplate( 'path' 
);
+               if ( !strlen( $mobileUrlPathTemplate ) ) {
                        return;
                }
-               return;
+               
+               // find out if we already have a templated path
+               $templatePathOffset = strpos( $mobileUrlPathTemplate, '%p' );
+               $templatePathSansToken = substr( $mobileUrlPathTemplate, 0, 
$templatePathOffset );
+               if ( substr_compare( $parsedUrl[ 'path' ], $wgScriptPath . 
$templatePathSansToken, 0 ) > 0 ) {
+                       return;
+               }
+
+               $scriptPathLength = strlen( $wgScriptPath );
+               // the "+ 1" removes the preceding "/" from the path sans 
$wgScriptPath
+               $pathSansScriptPath = substr( $parsedUrl[ 'path' ], 
$scriptPathLength + 1 );
+               $parsedUrl[ 'path' ] = $wgScriptPath . $templatePathSansToken . 
$pathSansScriptPath;    
        }
 
        /**

Modified: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
===================================================================
--- trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php        
2012-02-24 01:16:18 UTC (rev 112284)
+++ trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php        
2012-02-24 01:17:26 UTC (rev 112285)
@@ -85,4 +85,21 @@
                $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array( 
&$parsedUrl ) );
                $this->assertEquals( 
"http://en.m.wikipedia.org/wiki/Gustavus_Airport";, wfAssembleUrl( $parsedUrl ) 
);
        }
+       
+       public function testUpdateMobileUrlPath() {
+               global $wgMobileUrlTemplate, $wgExtMobileFrontend, 
$wgScriptPath;
+               $wgScriptPath = '/wiki';
+               $updateMobileUrlHost = self::getMethod( "updateMobileUrlPath" );
+               $wgMobileUrlTemplate = "/mobile/%p";
+               
+               // check for constructing a templated URL
+               $parsedUrl = wfParseUrl( 
"http://en.wikipedia.org/wiki/Gustavus_Airport"; );
+               $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array( 
&$parsedUrl ) );
+               $this->assertEquals( 
"http://en.wikipedia.org/wiki/mobile/Gustavus_Airport";, wfAssembleUrl( 
$parsedUrl ) );
+               
+               // check for maintaining an already templated URL
+               $parsedUrl = wfParseUrl( 
"http://en.wikipedia.org/wiki/mobile/Gustavus_Airport"; );
+               $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array( 
&$parsedUrl ) );
+               $this->assertEquals( 
"http://en.wikipedia.org/wiki/mobile/Gustavus_Airport";, wfAssembleUrl( 
$parsedUrl ) );
+       }
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to