jenkins-bot has submitted this change and it was merged.
Change subject: Fix MobileContext::getDesktopUrl()
......................................................................
Fix MobileContext::getDesktopUrl()
Uses $wgServer to reset desktop hostname rather than attempt to strip
out mobile-specific domain name elements as was done previously.
Bug: 50967
Change-Id: I18ae772e35bf34063538e987ea1d28d9517c51a2
---
M includes/MobileContext.php
M tests/MobileContextTest.php
2 files changed, 44 insertions(+), 18 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index f4ab145..e3a3ab4 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -768,16 +768,14 @@
* Result of parseUrl() or wfParseUrl()
*/
protected function updateDesktopUrlHost( &$parsedUrl ) {
+ global $wgServer;
$mobileUrlHostTemplate = $this->parseMobileUrlTemplate( 'host'
);
if ( !strlen( $mobileUrlHostTemplate ) ) {
return;
}
- // identify the mobile token by stripping out normal host parts
- $mobileToken = $this->getMobileHostToken(
$mobileUrlHostTemplate );
-
- // replace the mobile token with nothing, resulting in the
normal hostname
- $parsedUrl['host'] = str_replace( '.' . $mobileToken, '.',
$parsedUrl['host'] );
+ $parsedWgServer = wfParseUrl( $wgServer );
+ $parsedUrl['host'] = $parsedWgServer['host'];
}
/**
diff --git a/tests/MobileContextTest.php b/tests/MobileContextTest.php
index 2b051d2..52f2fe0 100644
--- a/tests/MobileContextTest.php
+++ b/tests/MobileContextTest.php
@@ -61,14 +61,32 @@
$this->assertEquals( array( 'host' => '%h0.m.%h1.%h2', 'path'
=> '/path/morepath' ), MobileContext::singleton()->parseMobileUrlTemplate() );
}
- public function testUpdateMobileUrlHost() {
+ /**
+ * @dataProvider updateMobileUrlHostProvider
+ */
+ public function testUpdateMobileUrlHost( $url, $expected, $urlTemplate
) {
global $wgMobileUrlTemplate;
$updateMobileUrlHost = self::getMethod( "updateMobileUrlHost" );
- $wgMobileUrlTemplate = "%h0.m.%h1.%h2";
- $parsedUrl = wfParseUrl(
"http://en.wikipedia.org/wiki/Gustavus_Airport" );
+ $wgMobileUrlTemplate = $urlTemplate;
+ $parsedUrl = wfParseUrl( $url );
$updateMobileUrlHost->invokeArgs( MobileContext::singleton(),
array( &$parsedUrl ) );
- $this->assertEquals(
"http://en.m.wikipedia.org/wiki/Gustavus_Airport", wfAssembleUrl( $parsedUrl )
);
+ $this->assertEquals( $expected, wfAssembleUrl( $parsedUrl ) );
+ }
+
+ public function updateMobileUrlHostProvider() {
+ return array(
+ array(
+ 'http://en.wikipedia.org/wiki/Gustavus_Airport',
+
'http://en.m.wikipedia.org/wiki/Gustavus_Airport',
+ '%h0.m.%h1.%h2',
+ ),
+ array(
+ 'https://wikimediafoundation.org/wiki/FAQ',
+ 'https://m.wikimediafoundation.org/wiki/FAQ',
+ 'm.%h0.%h1',
+ ),
+ );
}
/**
@@ -84,18 +102,21 @@
public function updateDesktopUrlQueryProvider() {
return array(
- array(
'http://en.m.wikipedia.org/wiki/Gustavus_Airport?useformat=mobile&mobileaction=toggle_desktop_view',
'http://en.m.wikipedia.org/wiki/Gustavus_Airport?mobileaction=toggle_desktop_view'
),
+ array(
+
'http://en.m.wikipedia.org/wiki/Gustavus_Airport?useformat=mobile&mobileaction=toggle_desktop_view',
+
'http://en.m.wikipedia.org/wiki/Gustavus_Airport?mobileaction=toggle_desktop_view'
+ ),
);
}
/**
* @dataProvider updateDesktopUrlHostProvider
*/
- public function testUpdateDesktopUrlHost( $mobile, $desktop ) {
- global $wgMobileUrlTemplate;
+ public function testUpdateDesktopUrlHost( $mobile, $desktop, $server ) {
+ global $wgServer;
$updateMobileUrlHost = self::getMethod( "updateDesktopUrlHost"
);
- $wgMobileUrlTemplate = "%h0.m.%h1.%h2";
+ $wgServer = $server;
$parsedUrl = wfParseUrl( $mobile );
$updateMobileUrlHost->invokeArgs(
MobileContext::singleton(),
@@ -105,13 +126,20 @@
public function updateDesktopUrlHostProvider() {
return array(
- array(
-
'http://en.m.wikipedia.org/wiki/Gustavus_Airport',
- 'http://en.wikipedia.org/wiki/Gustavus_Airport'
- ),
array(
'http://bm.m.wikipedia.org/wiki/' . urlencode(
'Nyɛ_fɔlɔ' ),
- 'http://bm.wikipedia.org/wiki/' . urlencode(
'Nyɛ_fɔlɔ' )
+ 'http://bm.wikipedia.org/wiki/' . urlencode(
'Nyɛ_fɔlɔ' ),
+ '//bm.wikipedia.org',
+ ),
+ array(
+
'http://en.m.wikipedia.org/wiki/Gustavus_Airport',
+ 'http://en.wikipedia.org/wiki/Gustavus_Airport',
+ '//en.wikipedia.org',
+ ),
+ array(
+ 'https://m.wikimediafoundation.org/wiki/FAQ',
+ 'https://wikimediafoundation.org/wiki/FAQ',
+ '//wikimediafoundation.org',
),
);
}
--
To view, visit https://gerrit.wikimedia.org/r/72612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I18ae772e35bf34063538e987ea1d28d9517c51a2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: awjrichards <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits