jenkins-bot has submitted this change and it was merged.
Change subject: Renames MobileContext::getMobileHost() to getMobileHostToken()
......................................................................
Renames MobileContext::getMobileHost() to getMobileHostToken()
This method returns to the mobile-specific token from a mobile domain or
mobile domain template, so the rename aims to better clarify what this
method actually does. I updated the docblock to also help make it more
clear.
Also, added some test cases for this method.
Change-Id: Ibcc8b5082cdda8223f69c748c0713abaf8385fd1
---
M includes/MobileContext.php
M tests/MobileContextTest.php
2 files changed, 23 insertions(+), 4 deletions(-)
Approvals:
MaxSem: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index 2cbe2e5..89f7a0d 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -599,11 +599,14 @@
}
/**
- * Take a URL Host Template and return the host portion
+ * Take a URL Host Template and return the mobile token portion
+ *
+ * Eg if a desktop domain is en.wikipedia.org, but the mobile variant is
+ * en.m.wikipedia.org, the mobile token is 'm.'
* @param $mobileUrlHostTemplate string
* @return string
*/
- public function getMobileHost( $mobileUrlHostTemplate ) {
+ public function getMobileHostToken( $mobileUrlHostTemplate ) {
wfProfileIn( __METHOD__ );
$mobileToken = preg_replace( '/%h[0-9]\.{0,1}/', '',
$mobileUrlHostTemplate );
wfProfileOut( __METHOD__ );
@@ -625,7 +628,7 @@
if ( !empty( $subdomainTokenReplacement ) ) {
global $wgMobileUrlTemplate;
$mobileUrlHostTemplate =
$this->parseMobileUrlTemplate( 'host' );
- $mobileToken = $this->getMobileHost(
$mobileUrlHostTemplate );
+ $mobileToken =
$this->getMobileHostToken( $mobileUrlHostTemplate );
$wgMobileUrlTemplate = str_replace(
$mobileToken, $subdomainTokenReplacement, $wgMobileUrlTemplate );
}
}
@@ -699,7 +702,7 @@
}
// identify the mobile token by stripping out normal host parts
- $mobileToken = $this->getMobileHost( $mobileUrlHostTemplate );
+ $mobileToken = $this->getMobileHostToken(
$mobileUrlHostTemplate );
// replace the mobile token with nothing, resulting in the
normal hostname
$parsedUrl['host'] = str_replace( '.' . $mobileToken, '.',
$parsedUrl['host'] );
diff --git a/tests/MobileContextTest.php b/tests/MobileContextTest.php
index 37e33c3..5b37fc6 100644
--- a/tests/MobileContextTest.php
+++ b/tests/MobileContextTest.php
@@ -431,4 +431,20 @@
array( 'foo=bar+%24blat', 'foo', 'bar $blat' ),
);
}
+
+ /**
+ * @dataProvider getMobileHostTokenProvider
+ */
+ public function testGetMobileHostToken( $domainTemplate, $result ) {
+ $context = MobileContext::singleton();
+ $this->assertEquals( $context->getMobileHostToken(
$domainTemplate ), $result );
+ }
+
+ public function getMobileHostTokenProvider() {
+ return array(
+ array( '%h1.m.%h2.%h3', 'm.' ),
+ array( '', '' ),
+ array( 'bananas.%h2.%h3', 'bananas.' ),
+ );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/59710
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibcc8b5082cdda8223f69c748c0713abaf8385fd1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: awjrichards <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits