https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114306
Revision: 114306
Author: awjrichards
Date: 2012-03-20 20:41:11 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
Added methods to return a desktop view URL (reversing the URL using the mobile
URL template); Changed 'Desktop view' URL to use new methods; Added
corresponding test
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-03-20
20:30:29 UTC (rev 114305)
+++ trunk/extensions/MobileFrontend/MobileFrontend.body.php 2012-03-20
20:41:11 UTC (rev 114306)
@@ -231,7 +231,7 @@
self::$disableImagesURL = $wgRequest->escapeAppendQuery(
'disableImages=1' );
self::$enableImagesURL = $wgRequest->escapeAppendQuery(
'enableImages=1' );
- self::$viewNormalSiteURL = $wgRequest->escapeAppendQuery(
'useformat=desktop' );
+ self::$viewNormalSiteURL = $this->getDesktopUrl( wfExpandUrl(
$wgRequest->escapeAppendQuery( 'useformat=desktop' ) ) );
self::$currentURL = $wgRequest->getFullRequestURL();
self::$leaveFeedbackURL = $wgRequest->escapeAppendQuery(
'mobileaction=leave_feedback' );
@@ -1257,6 +1257,17 @@
}
return wfAssembleUrl( $parsedUrl );
}
+
+ /**
+ * Take a URL and return a copy that removes any mobile tokens
+ * @param string
+ * @return string
+ */
+ public function getDesktopUrl( $url ) {
+ $parsedUrl = wfParseUrl( $url );
+ $this->updateDesktopUrlHost( $parsedUrl );
+ return wfAssembleUrl( $parsedUrl );
+ }
/**
* Update host of given URL to conform to mobile URL template.
@@ -1290,6 +1301,24 @@
}
/**
+ * Update the host of a given URL to strip out any mobile tokens
+ * @param $parsedUrl array
+ * Result of parseUrl() or wfParseUrl()
+ */
+ protected function updateDesktopUrlHost( &$parsedUrl ) {
+ $mobileUrlHostTemplate = $this->parseMobileUrlTemplate( 'host'
);
+ if ( !strlen( $mobileUrlHostTemplate ) ) {
+ return;
+ }
+
+ // identify the mobile token by stripping out normal host parts
+ $mobileToken = preg_replace( "/%h[0-9]\.{0,1}/", "",
$mobileUrlHostTemplate );
+
+ // replace the mobile token with nothing, resulting in the
normal hostname
+ $parsedUrl['host'] = str_replace( $mobileToken, '',
$parsedUrl['host'] );
+ }
+
+ /**
* Update path of given URL to conform to mobile URL template.
*
* NB: this is not actually being used anywhere at the moment. It will
Modified: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
===================================================================
--- trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
2012-03-20 20:30:29 UTC (rev 114305)
+++ trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
2012-03-20 20:41:11 UTC (rev 114306)
@@ -87,6 +87,15 @@
$this->assertEquals(
"http://en.m.wikipedia.org/wiki/Gustavus_Airport", wfAssembleUrl( $parsedUrl )
);
}
+ public function testUpdateDesktopUrlHost() {
+ global $wgMobileUrlTemplate, $wgExtMobileFrontend;
+ $updateMobileUrlHost = self::getMethod( "updateDesktopUrlHost"
);
+ $wgMobileUrlTemplate = "%h0.m.%h1.%h2";
+ $parsedUrl = wfParseUrl(
"http://en.m.wikipedia.org/wiki/Gustavus_Airport" );
+ $updateMobileUrlHost->invokeArgs( $wgExtMobileFrontend, array(
&$parsedUrl ) );
+ $this->assertEquals(
"http://en.wikipedia.org/wiki/Gustavus_Airport", wfAssembleUrl( $parsedUrl ) );
+ }
+
public function testUpdateMobileUrlPath() {
global $wgMobileUrlTemplate, $wgExtMobileFrontend,
$wgScriptPath;
$wgScriptPath = '/wiki';
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs