Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/228294

Change subject: Implement a way in MobileContext::getMobileUrl() to work with 
local URLs
......................................................................

Implement a way in MobileContext::getMobileUrl() to work with local URLs

Currently, if local URLs are passed to MobileContext::getMobileUrl(), it will 
return
an empty string. The underlying funtions to parse the host part and built the
mobile Url expect to get a fully qualified Url.

If parsing the URL with wfParseUrl fails (~false), try to expand the URL to a 
fully
qualified one and try to parse it again, if it could be expanded. If the Url 
can be
parsed, use this one to build the mobile url.

Bug: T107505
Change-Id: I092032002f7cb8949f7dc58d7602234764a46d7e
---
M includes/MobileContext.php
M tests/phpunit/MobileContextTest.php
2 files changed, 17 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/94/228294/1

diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index ee0d329..ae6f784 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -756,6 +756,15 @@
                }
 
                $parsedUrl = wfParseUrl( $url );
+               // if parsing failed, maybe it's a local Url, try to expand and 
reparse it - task T107505
+               if ( !$parsedUrl ) {
+                       $expandedUrl = wfExpandUrl( $url );
+                       // if Url could not be expanded or parsed, return 
false, instead of an empty string
+                       if ( !$expandedUrl || !$parsedUrl = wfParseUrl( 
$expandedUrl ) ) {
+                               return false;
+                       }
+               }
+
                $this->updateMobileUrlHost( $parsedUrl );
                if ( $forceHttps ) {
                        $parsedUrl['scheme'] = 'https';
diff --git a/tests/phpunit/MobileContextTest.php 
b/tests/phpunit/MobileContextTest.php
index fb1e4c0..a6f7e9d 100644
--- a/tests/phpunit/MobileContextTest.php
+++ b/tests/phpunit/MobileContextTest.php
@@ -78,7 +78,8 @@
        public function testGetMobileUrl() {
                $this->setMwGlobals( array(
                        'wgMFMobileHeader' => 'X-WAP',
-                       'wgMobileUrlTemplate' => '%h0.m.%h1.%h2'
+                       'wgMobileUrlTemplate' => '%h0.m.%h1.%h2',
+                       'wgServer' => '//en.wikipedia.org',
                ) );
                $invokes = 0;
                $context = $this->makeContext();
@@ -102,7 +103,12 @@
                        '//en.m.wikipedia.org/wiki/Article',
                        $context->getMobileUrl( 
'//en.wikipedia.org/wiki/Article' )
                );
-               $this->assertEquals( 2, $invokes, 'Ensure that hook got the 
right context' );
+               // test local Urls - task T107505
+               $this->assertEquals(
+                       'http://en.m.wikipedia.org/wiki/Article',
+                       $context->getMobileUrl( '/wiki/Article' )
+               );
+               $this->assertEquals( 3, $invokes, 'Ensure that hook got the 
right context' );
        }
 
        public function testParseMobileUrlTemplate() {

-- 
To view, visit https://gerrit.wikimedia.org/r/228294
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I092032002f7cb8949f7dc58d7602234764a46d7e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>

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

Reply via email to