jenkins-bot has submitted this change and it was merged.
Change subject: Remove device specific stylesheets
......................................................................
Remove device specific stylesheets
Create a happy Max.
Removes $wgMFVaryResources as not needed
Change-Id: I9e45dc82690ee2e73f5d022b9a96efabc314f21f
---
M MobileFrontend.php
M includes/DeviceDetection.php
M includes/MobileContext.php
M includes/MobileFrontend.body.php
M includes/Resources.php
D includes/modules/MobileDeviceDetectModule.php
M includes/skins/SkinMobile.php
M tests/DeviceDetectionTest.php
M tests/MobileContextTest.php
M tests/MobileFrontendTest.php
10 files changed, 121 insertions(+), 372 deletions(-)
Approvals:
Kaldari: Looks good to me, approved
Jdlrobson: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/MobileFrontend.php b/MobileFrontend.php
index 003bc26..5fcb53f 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -34,12 +34,13 @@
// autoload extension classes
$autoloadClasses = array (
'ExtMobileFrontend' => 'MobileFrontend.body',
- 'MobileFrontendDeviceDetectModule' => 'MobileFrontend.body',
'MobileFrontendHooks' => 'MobileFrontend.hooks',
'DeviceDetection' => 'DeviceDetection',
+ 'HtmlDeviceProperties' => 'DeviceDetection',
'MobileContext' => 'MobileContext',
'WmlContext' => 'WmlContext',
+ 'WmlDeviceProperties' => 'DeviceDetection',
'HtmlFormatter' => 'formatters/HtmlFormatter',
'MobileFormatter' => 'formatters/MobileFormatter',
@@ -52,7 +53,6 @@
'MFResourceLoaderModule' => 'modules/MFResourceLoaderModule',
'MobileSiteModule' => 'modules/MobileSiteModule',
- 'MobileDeviceDetectModule' => 'modules/MobileDeviceDetectModule',
'SpecialUploads' => 'specials/SpecialUploads',
'SpecialMobileUserlogin' => 'specials/SpecialMobileUserlogin',
@@ -368,12 +368,6 @@
* @var bool
*/
$wgMFEnableXAnalyticsLogging = false;
-
-/**
- * If set to true, mobile skin's resources are varied by X-Device.
- * Otherwise, page HTML will be varied on it.
- */
-$wgMFVaryResources = false;
/**
* Whether or not anonymous (not logged in) users should be able to edit.
diff --git a/includes/DeviceDetection.php b/includes/DeviceDetection.php
index 81e0321..8557771 100644
--- a/includes/DeviceDetection.php
+++ b/includes/DeviceDetection.php
@@ -37,15 +37,6 @@
*/
function isMobileDevice();
- /**
- * @return string
- */
- function moduleName();
-
- /**
- * @return string
- */
- function cssFileName();
}
interface IDeviceDetector {
@@ -55,39 +46,54 @@
* @return IDeviceProperties
*/
function detectDeviceProperties( $userAgent, $acceptHeader = '' );
-
- /**
- * @param $deviceName
- * @param $userAgent
- *
- * @return IDeviceProperties
- */
- function getDeviceProperties( $deviceName, $userAgent );
-
- /**
- * @return array
- */
- function getCssFiles();
}
/**
- * MediaWiki's default IDeviceProperties implementation
+ * MobileFrontend's default IDeviceProperties implementation
*/
-final class DeviceProperties implements IDeviceProperties {
- private $device,
- $userAgent,
- $isMobile = null;
+class DeviceProperties implements IDeviceProperties {
+ private $userAgent,
+ $acceptHeader,
+ $isMobile = null,
+ $format = null;
- public function __construct( array $deviceCapabilities, $userAgent ) {
- $this->device = $deviceCapabilities;
+ public function __construct( $userAgent, $acceptHeader ) {
$this->userAgent = $userAgent;
+ $this->acceptHeader = $acceptHeader;
}
/**
* @return string
*/
public function format() {
- return $this->device['view_format'];
+ wfProfileIn( __METHOD__ );
+ if ( !$this->format ) {
+ $this->format = $this->detectFormat( $this->userAgent,
$this->acceptHeader );
+ }
+ wfProfileOut( __METHOD__ );
+ return $this->format;
+ }
+
+ /**
+ * @return string
+ */
+ protected function detectFormat() {
+ if ( strpos( $this->userAgent, 'WebKit' ) !== false
+ || strpos( $this->userAgent, 'Opera/' ) !== false
+ || strpos( $this->userAgent, 'BlackBerry' ) !== false
+ || strpos( $this->userAgent, 'NetFront' ) !== false
+ || strpos( $this->userAgent, 'Kindle' ) !== false
+ || strpos( $this->userAgent, 'MSIE' ) !== false )
+ {
+ return 'html';
+ }
+
+ if ( strpos( $this->acceptHeader, 'vnd.wap.wml' ) !== false
+ && strpos( $this->acceptHeader,
'application/vnd.wap.xhtml+xml' ) === false )
+ {
+ return 'wml';
+ }
+ return 'html';
}
/**
@@ -168,29 +174,39 @@
wfProfileOut( __METHOD__ );
return $isMobile;
}
+}
+
+class HtmlDeviceProperties implements IDeviceProperties {
/**
* @return string
*/
- public function moduleName() {
- if ( isset( $this->device['css_file_name'] ) &&
- $this->device['css_file_name'] ) {
- return "mobile.device.{$this->device['css_file_name']}";
- } else {
- return '';
- }
+ function format() {
+ return 'html';
}
/**
+ * @return bool
+ */
+ function isMobileDevice() {
+ return true;
+ }
+}
+
+class WmlDeviceProperties implements IDeviceProperties {
+
+ /**
* @return string
*/
- public function cssFileName() {
- if ( isset( $this->device['css_file_name'] ) &&
- $this->device['css_file_name'] ) {
- return "{$this->device['css_file_name']}.css";
- } else {
- return '';
- }
+ function format() {
+ return 'wml';
+ }
+
+ /**
+ * @return bool
+ */
+ function isMobileDevice() {
+ return true;
}
}
@@ -200,49 +216,6 @@
* may be extended to provide access to particular device functionality.
*/
class DeviceDetection implements IDeviceDetector {
-
- private static $formats = array (
- 'generic' => array (
- 'view_format' => 'html',
- ),
-
- 'android' => array (
- 'view_format' => 'html',
- ),
- 'blackberry' => array (
- 'view_format' => 'html',
- ),
- 'ie' => array (
- 'view_format' => 'html',
- ),
- 'iphone' => array (
- 'view_format' => 'html',
- ),
- 'kindle' => array (
- 'view_format' => 'html',
- ),
- 'netfront' => array (
- 'view_format' => 'html',
- ),
- 'nokia' => array (
- 'view_format' => 'html',
- ),
- 'operamini' => array (
- 'view_format' => 'html',
- ),
- 'operamobile' => array (
- 'view_format' => 'html',
- ),
- 'palm_pre' => array (
- 'view_format' => 'html',
- ),
- 'webkit' => array (
- 'view_format' => 'html',
- ),
- 'wml' => array (
- 'view_format' => 'wml',
- ),
- );
/**
* Returns an instance of detection class, overridable by extensions
@@ -264,96 +237,6 @@
* @return IDeviceProperties
*/
public function detectDeviceProperties( $userAgent, $acceptHeader = ''
) {
- $deviceName = $this->detectDeviceName( $userAgent,
$acceptHeader );
- return $this->getDeviceProperties( $deviceName, $userAgent );
- }
-
- /**
- * @param $deviceName
- * @param $userAgent
- *
- * @return IDeviceProperties
- */
- public function getDeviceProperties( $deviceName, $userAgent ) {
- if ( !isset( self::$formats[$deviceName] ) ) {
- $deviceName = 'generic';
- }
- return new DeviceProperties( self::$formats[$deviceName],
$userAgent );
- }
-
- /**
- * @param $userAgent string
- * @param $acceptHeader string
- * @return string
- */
- public function detectDeviceName( $userAgent, $acceptHeader = '' ) {
- wfProfileIn( __METHOD__ );
-
- $deviceName = '';
-
- // These regexes come roughly in order of popularity per
- //
http://stats.wikimedia.org/wikimedia/squids/SquidReportClients.htm
- // to reduce the average number of regexes per user-agent.
- if ( strpos( $userAgent, 'Safari' ) !== false ) {
- if ( strpos( $userAgent, 'iPhone' ) !== false
- || strpos( $userAgent, 'iPad' ) !== false
- ) {
- $deviceName = 'iphone';
- } elseif ( strpos( $userAgent, 'Android' ) !== false ) {
- $deviceName = 'android';
- } elseif ( strpos( $userAgent, 'Series60' ) !== false )
{
- $deviceName = 'nokia';
- } elseif ( strpos( $userAgent, 'webOS' ) !== false ) {
- $deviceName = 'palm_pre';
- } else {
- $deviceName = 'webkit';
- }
- } elseif ( strpos( $userAgent, 'Opera/' ) !== false ) {
- if ( strpos( $userAgent, 'Opera Mini' ) !== false ) {
- $deviceName = 'operamini';
- } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false
) {
- $deviceName = 'operamobile';
- } elseif ( strpos( $userAgent, 'Wii' ) !== false ) {
- $deviceName = 'operamobile';
- } else {
- $deviceName = 'generic'; // Desktop Opera
- }
- } elseif ( strpos( $userAgent, 'BlackBerry' ) !== false ) {
- $deviceName = 'blackberry';
- } elseif ( strpos( $userAgent, 'NetFront' ) !== false ) {
- if ( strpos( $userAgent, 'Kindle' ) !== false ) {
- $deviceName = 'kindle';
- } else {
- $deviceName = 'netfront';
- }
- } elseif ( strpos( $userAgent, 'MSIE' ) !== false ) {
- $deviceName = 'ie';
- }
-
- if ( $deviceName === '' ) {
- if ( strpos( $acceptHeader,
'application/vnd.wap.xhtml+xml' ) !== false ) {
- $deviceName = 'generic';
- } elseif ( strpos( $acceptHeader, 'vnd.wap.wml' ) !==
false ) {
- $deviceName = 'wml';
- } else {
- $deviceName = 'generic';
- }
- }
- wfProfileOut( __METHOD__ );
- return $deviceName;
- }
-
- /**
- * @return array: List of all device-specific stylesheets
- */
- public function getCssFiles() {
- $files = array();
-
- foreach ( self::$formats as $dev ) {
- if ( isset( $dev['css_file_name'] ) ) {
- $files[] = $dev['css_file_name'];
- }
- }
- return array_unique( $files );
+ return new DeviceProperties( $userAgent, $acceptHeader );
}
}
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index f4ab145..a07efa9 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -14,10 +14,6 @@
*/
protected $analyticsLogItems = array();
- /**
- * @var string xDevice header information
- */
- private $xDevice;
/** @var IDeviceProperties */
private $device;
@@ -68,12 +64,12 @@
$detector = DeviceDetection::factory();
$request = $this->getRequest();
- $xDevice = $this->getXDevice();
- $userAgent = $request->getHeader( 'User-agent' );
- if ( $xDevice ) {
- $formatName = $xDevice;
- $this->device = $detector->getDeviceProperties(
$formatName, $userAgent );
+ $wap = $this->getRequest()->getHeader( 'X-WAP' );
+ if ( $wap ) {
+ $className = ( $wap === 'no' ) ? 'HtmlDeviceProperties'
: 'WmlDeviceProperties';
+ $this->device = new $className;
} else {
+ $userAgent = $request->getHeader( 'User-agent' );
$acceptHeader = $request->getHeader( 'Accept' );
$acceptHeader = $acceptHeader === false ? '' :
$acceptHeader;
$this->device = $detector->detectDeviceProperties(
$userAgent, $acceptHeader );
@@ -126,9 +122,8 @@
public function isMobileDevice() {
global $wgMFAutodetectMobileView;
- return $this->getXDevice()
- || $this->getAMF()
- || ( $wgMFAutodetectMobileView &&
$this->getDevice()->isMobileDevice() );
+ return ( $wgMFAutodetectMobileView &&
$this->getDevice()->isMobileDevice() )
+ || $this->getAMF();
}
/**
@@ -324,14 +319,14 @@
/**
* If a mobile-domain is specified by the $wgMobileUrlTemplate
and
- * there's an X-Device header, then we assume the user is
accessing
+ * there's an X-WAP header, then we assume the user is accessing
* the site from the mobile-specific domain (because why would
the
- * desktop site set X-Device header?). If a user is accessing
the
+ * desktop site set X-WAP header?). If a user is accessing the
* site from a mobile domain, then we should always display the
mobile
* version of the site (otherwise, the cache may get polluted).
See
* https://bugzilla.wikimedia.org/show_bug.cgi?id=46473
*/
- if ( $wgMobileUrlTemplate && $this->getXDevice() ) {
+ if ( $wgMobileUrlTemplate && $this->getRequest()->getHeader(
'X-WAP' ) ) {
return true;
}
@@ -351,26 +346,6 @@
}
return false;
- }
-
- public function getXDevice() {
- if ( is_null( $this->xDevice ) ) {
- $request = $this->getRequest();
- $xDevice = $request->getHeader( 'X-Device' );
-
- global $wgMFVaryResources;
- if ( $wgMFVaryResources ) {
- if ( $xDevice ) {
- $xWap = $request->getHeader( 'X-WAP' );
- if ( $xWap === 'yes' && $xDevice !==
'wml' ) {
- wfDebugLog( 'mobile',
"Unexpected combination of headers: X-Device = $xDevice, X-WAP = $xWap" );
- }
- }
- }
- $this->xDevice = $xDevice === false ? '' : $xDevice;
- }
-
- return $this->xDevice;
}
public function getMobileAction() {
diff --git a/includes/MobileFrontend.body.php b/includes/MobileFrontend.body.php
index 1286d51..e351be9 100644
--- a/includes/MobileFrontend.body.php
+++ b/includes/MobileFrontend.body.php
@@ -7,17 +7,11 @@
}
private function sendHeaders() {
- global $wgMFVaryResources;
-
wfProfileIn( __METHOD__ );
$out = $this->getOutput();
- $xDevice = MobileContext::singleton()->getXDevice();
$request = $this->getRequest();
$xWap = $request->getHeader( 'X-WAP' );
- if ( $xDevice !== '' && !$wgMFVaryResources ) {
- $request->response()->header( "X-Device: {$xDevice}" );
- $out->addVaryHeader( 'X-Device' );
- } elseif ( $xWap ) {
+ if ( $xWap ) {
$out->addVaryHeader( 'X-WAP' );
$request->response()->header( "X-WAP: $xWap" );
}
diff --git a/includes/Resources.php b/includes/Resources.php
index 40534be..033d074 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -756,9 +756,4 @@
),
'position' => 'top',
),
-
- //@hack: xdevice instead of device to force this module to be last in a
link
- 'mobile.xdevice.detect' => $wgMFMobileResourceBoilerplate + array(
- 'class' => 'MobileDeviceDetectModule',
- ),
) );
diff --git a/includes/modules/MobileDeviceDetectModule.php
b/includes/modules/MobileDeviceDetectModule.php
deleted file mode 100644
index b5f40c5..0000000
--- a/includes/modules/MobileDeviceDetectModule.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-/**
- * Provides device-specific CSS
- * Only added to output when $wgMFVaryResources = true
- */
-class MobileDeviceDetectModule extends ResourceLoaderFileModule {
- // dummy for now
-}
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index 69b1222..bafacc1 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -114,21 +114,8 @@
return $vars;
}
- // FIXME: move addModuleStyles calls to initPage get should not have
side effects
public function getDefaultModules() {
- global $wgMFVaryResources;
-
- $ctx = MobileContext::singleton();
$out = $this->getOutput();
- $device = $ctx->getDevice();
-
- // add device specific css file - add separately to avoid cache
fragmentation
- if ( $wgMFVaryResources ) {
- $out->addModuleStyles( 'mobile.xdevice.detect' );
- } elseif ( $device->moduleName() ) {
- $out->addModuleStyles( $device->moduleName() );
- }
-
$modules = parent::getDefaultModules();
// flush unnecessary modules
diff --git a/tests/DeviceDetectionTest.php b/tests/DeviceDetectionTest.php
index cd8a25d..9f0bce9 100644
--- a/tests/DeviceDetectionTest.php
+++ b/tests/DeviceDetectionTest.php
@@ -6,20 +6,21 @@
class DeviceDetectionTest extends MediaWikiTestCase {
/**
- * @dataProvider provideTestFormatName
+ * @dataProvider provideTestFormat
*/
- public function testFormatName( $format, $userAgent, $acceptHeader = ''
) {
+ public function testFormat( $format, $userAgent, $acceptHeader = '' ) {
$detector = new DeviceDetection();
- $this->assertEquals( $format, $detector->detectDeviceName(
$userAgent, $acceptHeader ) );
+ $device = $detector->detectDeviceProperties( $userAgent,
$acceptHeader );
+ $this->assertEquals( $format, $device->format() );
}
- public function provideTestFormatName() {
+ public function provideTestFormat() {
$mobileDevices = $this->mobileDevices();
// These are desktop browsers that still need to be served with
sane CSS
return array_merge( $mobileDevices, array(
- array( 'ie', 'Mozilla/5.0 (compatible; MSIE
9.0; Windows NT 6.1; Trident/5.0)' ),
- array( 'ie', 'Mozilla/4.0 (compatible; MSIE
8.0; Windows NT 6.0)' ),
- array( 'generic', 'Mozilla/5.0 (X11; Linux
i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1' ),
+ array( 'html', 'Mozilla/5.0 (compatible; MSIE
9.0; Windows NT 6.1; Trident/5.0)' ),
+ array( 'html', 'Mozilla/4.0 (compatible; MSIE
8.0; Windows NT 6.0)' ),
+ array( 'html', 'Mozilla/5.0 (X11; Linux i686;
rv:2.0.1) Gecko/20100101 Firefox/4.0.1' ),
)
);
}
@@ -27,70 +28,43 @@
private function mobileDevices() {
return array(
// Firefox OS (bug 40919)
- array( 'generic', 'Mozilla/5.0 (Mobile; rv:14.0)
Gecko/14.0 Firefox/14.0' ),
- array( 'generic', 'Mozilla/5.0 (Android; Mobile;
rv:20.0) Gecko/20.0 Firefox/20.0' ),
+ array( 'html', 'Mozilla/5.0 (Mobile; rv:14.0)
Gecko/14.0 Firefox/14.0' ),
+ array( 'html', 'Mozilla/5.0 (Android; Mobile; rv:20.0)
Gecko/20.0 Firefox/20.0' ),
// Blackberry 10 (bug 40513)
- array( 'webkit', 'Mozilla/5.0 (BB10; Touch)
AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.386 Mobile Safari/537.3+'
),
- array( 'webkit', 'Mozilla/5.0 (BlackBerry; U;
BlackBerry 9850; en-US) AppleWebKit/534.11+ (KHTML, like Gecko)
Version/7.0.0.254 Mobile Safari/534.11+' ),
+ array( 'html', 'Mozilla/5.0 (BB10; Touch)
AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.386 Mobile Safari/537.3+'
),
+ array( 'html', 'Mozilla/5.0 (BlackBerry; U; BlackBerry
9850; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.254 Mobile
Safari/534.11+' ),
// Windows Phone 8 / IE 10 (bug 41517)
- array( 'ie', 'Mozilla/5.0 (compatible; MSIE 10.0;
Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>;
<Device> [;<Operator>])' ),
+ array( 'html', 'Mozilla/5.0 (compatible; MSIE 10.0;
Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>;
<Device> [;<Operator>])' ),
// Others
- array( 'android', 'Mozilla/5.0 (Linux; U; Android
2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko)
Version/4.0 Mobile Safari/530.17' ),
- array( 'iphone', 'Mozilla/5.0 (ipod: U;CPU iPhone
OS 2_2 like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko)
Version/3.0 Mobile/3B48b Safari/419.3' ),
- array( 'iphone', 'Mozilla/5.0 (iPhone; U; CPU like
Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b
Safari/419.3' ),
- array( 'nokia', 'Mozilla/5.0 (SymbianOS/9.1; U;
[en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko)
Safari/413' ),
- array( 'palm_pre', 'Mozilla/5.0 (webOS/1.0; U;
en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1
Pre/1.0' ),
+ array( 'html', 'Mozilla/5.0 (Linux; U; Android 2.1;
en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko)
Version/4.0 Mobile Safari/530.17' ),
+ array( 'html', 'Mozilla/5.0 (ipod: U;CPU iPhone OS 2_2
like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.0
Mobile/3B48b Safari/419.3' ),
+ array( 'html', 'Mozilla/5.0 (iPhone; U; CPU like Mac OS
X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b
Safari/419.3' ),
+ array( 'html', 'Mozilla/5.0 (SymbianOS/9.1; U; [en];
SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413' ),
+ array( 'html', 'Mozilla/5.0 (webOS/1.0; U; en-US)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0' ),
// Opera
- array( 'operamobile', 'Opera/9.00 (Nintendo Wii; U; ;
1309-9; en)' ),
- array( 'operamini', 'Opera/9.50 (J2ME/MIDP; Opera
Mini/4.0.10031/298; U; en)' ),
- array( 'operamini', 'Opera/9.80 (iPhone; Opera
Mini/7.0.4/28.2555; U; fr) Presto/2.8.119 Version/11.10' ),
- array( 'operamobile', 'Opera/9.51 Beta (Microsoft
Windows; PPC; Opera Mobi/1718; U; en)' ),
- array( 'operamobile', 'Opera/9.80 (Android 4.1.1;
Linux; Opera Mobi/ADR-1301080958) Presto/2.11.355 Version/12.10' ),
- array( 'kindle', 'Mozilla/4.0 (compatible; Linux
2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)' ),
- array( 'kindle', 'Mozilla/4.0 (compatible; Linux
2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)' ),
+ array( 'html', 'Opera/9.00 (Nintendo Wii; U; ; 1309-9;
en)' ),
+ array( 'html', 'Opera/9.50 (J2ME/MIDP; Opera
Mini/4.0.10031/298; U; en)' ),
+ array( 'html', 'Opera/9.80 (iPhone; Opera
Mini/7.0.4/28.2555; U; fr) Presto/2.8.119 Version/11.10' ),
+ array( 'html', 'Opera/9.51 Beta (Microsoft Windows;
PPC; Opera Mobi/1718; U; en)' ),
+ array( 'html', 'Opera/9.80 (Android 4.1.1; Linux; Opera
Mobi/ADR-1301080958) Presto/2.11.355 Version/12.10' ),
+ array( 'html', 'Mozilla/4.0 (compatible; Linux 2.6.10)
NetFront/3.3 Kindle/1.0 (screen 600x800)' ),
+ array( 'html', 'Mozilla/4.0 (compatible; Linux 2.6.22)
NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)' ),
// Later Kindles use WebKit
- array( 'webkit', 'Mozilla/5.0 (Linux; U; en-US)
AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0
(screen 600X800; rotate)' ),
- array( 'netfront', 'Mozilla/4.08 (Windows; Mobile
Content Viewer/1.0) NetFront/3.2' ),
- array( 'generic',
'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2
Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
- array( 'generic', 'NokiaN73-2/3.0-630.0.2
Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
- array( 'generic', 'Mozilla/4.0 (PSP (PlayStation
Portable); 2.00)' ),
- array( 'generic', 'Mozilla/5.0 (PLAYSTATION 3;
1.00)' ),
+ array( 'html', 'Mozilla/5.0 (Linux; U; en-US)
AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0
(screen 600X800; rotate)' ),
+ array( 'html', 'Mozilla/4.08 (Windows; Mobile Content
Viewer/1.0) NetFront/3.2' ),
+ array( 'html', 'SonyEricssonK608i/R2L/SN356841000828910
Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( 'html', 'NokiaN73-2/3.0-630.0.2 Series60/3.0
Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( 'html', 'Mozilla/4.0 (PSP (PlayStation
Portable); 2.00)' ),
+ array( 'html', 'Mozilla/5.0 (PLAYSTATION 3; 1.00)' ),
// Blackberry
- array( 'blackberry', 'BlackBerry9300/5.0.0.716
Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/133' ),
- array( 'blackberry', 'BlackBerry7250/4.0.0
Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( 'html', 'BlackBerry9300/5.0.0.716
Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/133' ),
+ array( 'html', 'BlackBerry7250/4.0.0 Profile/MIDP-2.0
Configuration/CLDC-1.1' ),
// https://bugzilla.wikimedia.org/show_bug.cgi?id=30827
- array( 'generic', 'SAMSUNG-S8000/S800MXEJA1
SHP/VPP/R5 Jasmine/1.0 Nextreaming SMM-MMS/1.2.0 profile/MIDP-2.1
configuration/CLDC-1.1 SS-Widget/S8000-FM',
+ array( 'html', 'SAMSUNG-S8000/S800MXEJA1 SHP/VPP/R5
Jasmine/1.0 Nextreaming SMM-MMS/1.2.0 profile/MIDP-2.1 configuration/CLDC-1.1
SS-Widget/S8000-FM',
'text/html, application/xml,
image/vnd.wap.wbmp, image/png, image/jpeg, image/gif, image/bmp,
application/vnd.wap.xhtml+xml, application/xhtml+xml,
application/vnd.wap.multipart.mixed, multipart/mixed, text/vnd.wap.wml,
application/vnd.wap.wmlc, application/vnd.oma.dd+xml,
text/vnd.sun.j2me.app-descriptor, application/java-archive, */*'
),
- // @todo:
- // Chrome browser
- //array( 'webkit', 'Mozilla/5.0 (Linux; Android 4.1.1;
Galaxy Nexus Build/JRO03C) AppleWebKit/535.19 (KHTML, like Gecko)
Chrome/18.0.1025.166 Mobile Safari/535.19' ),
- //array( 'operamobile', 'Opera/9.80 (Android 2.3.7;
Linux; Opera Tablet/35779; U; en) Presto/2.10.254 Version/12.00' ),
- //array( 'generic', 'Mozilla/5.0 (Macintosh; U; Intel
Mac OS X 10.7; en-US; rv:1.9.2.1pre) Gecko/20100126 Namoroka/3.6.1pre
Fennec/1.0pre)' ),
- );
- }
-
- /**
- * @dataProvider provideTestModuleName
- */
- public function testModuleName( $format, $moduleName ) {
- $detector = new DeviceDetection();
- $device = $detector->getDeviceProperties( $format, '' );
- $this->assertEquals( $device->moduleName(), $moduleName );
- }
-
- public function provideTestModuleName() {
- return array(
- array( 'webkit', '' ),
- array( 'android', '' ),
- array( 'palm_pre', '' ),
- array( 'generic', '' ),
- array( 'ie', '' ),
- array( 'iphone', '' ),
- array( 'kindle', '' ),
- array( 'blackberry', '' ),
- array( 'nokia', '' ),
- array( 'wml', '' )
+ // WML
+ array( 'wml', 'KDDI-KC31 UP.Browser/6.2.0.5 (GUI)
MMP/2.0', 'text/bullshit, text/vnd.wap.wml' ),
);
}
diff --git a/tests/MobileContextTest.php b/tests/MobileContextTest.php
index 2b051d2..47604cd 100644
--- a/tests/MobileContextTest.php
+++ b/tests/MobileContextTest.php
@@ -21,13 +21,10 @@
}
protected function setUp() {
- global $wgMFAutodetectMobileView;
-
parent::setUp();
$this->savedGlobals = $GLOBALS;
$context = new DerivativeContext( RequestContext::getMain() );
$context->setRequest( new FauxRequest() );
- $wgMFAutodetectMobileView = false;
MobileContext::singleton()->setContext( $context );
}
@@ -185,7 +182,7 @@
/**
* @dataProvider shouldDisplayMobileViewProvider
*/
- public function testShouldDisplayMobileView( $shouldDisplay, $xDevice =
null, $requestVal = array(), $msg = null ) {
+ public function testShouldDisplayMobileView( $shouldDisplay, $xWap =
null, $requestVal = array(), $msg = null ) {
$testMethod = ( $shouldDisplay ) ? 'assertTrue' : 'assertFalse';
$request = MobileContext::singleton()->getRequest();
@@ -199,8 +196,8 @@
}
}
- if ( !is_null( $xDevice ) ) {
- MobileContext::singleton()->getRequest()->setHeader(
'X-Device', $xDevice );
+ if ( !is_null( $xWap ) ) {
+ MobileContext::singleton()->getRequest()->setHeader(
'X-WAP', $xWap );
}
$this->$testMethod(
MobileContext::singleton()->shouldDisplayMobileView(), $msg );
@@ -209,9 +206,10 @@
public function shouldDisplayMobileViewProvider() {
return array(
array( false, null, array() ),
- array( true, 'webkit', array() ),
- array( false, 'webkit', array( 'action' => 'edit' ) ),
- array( false, 'webkit', array( 'useformat' => 'desktop'
) ),
+ array( true, 'yes', array() ),
+ array( true, 'no', array() ),
+ array( false, 'yes', array( 'action' => 'edit' ) ),
+ array( false, 'yes', array( 'useformat' => 'desktop' )
),
array( true, null, array( 'useformat' => 'mobile-wap' )
),
array( false, null, array( 'useformat' => 'mobile-wap',
'action' => 'edit' ) ),
array( false, null, array( 'useformat' => 'mobile-wap',
'action' => 'history' ) ),
@@ -219,47 +217,6 @@
array( true, null, array( 'useformat' => 'mobile' ) ),
array( false, null, array( 'useformat' => 'mobile',
'action' => 'edit' ) ),
array( false, null, array( 'useformat' => 'mobile',
'action' => 'history' ) ),
- );
- }
-
- /**
- * @dataProvider getXDeviceProvider
- */
- public function testGetXDevice( $xDevice ) {
- global $wgMFVaryResources;
- $wgMFVaryResources = false;
- if ( is_null( $xDevice ) ) {
- MobileContext::singleton()->getRequest()->setHeader(
'X-Device', $xDevice );
- $assert = $xDevice;
- } else {
- $assert = '';
- }
- $this->assertEquals( $assert,
MobileContext::singleton()->getXDevice() );
- }
-
- public function getXDeviceProvider() {
- return array(
- array( 'webkit' ),
- array( null ),
- );
- }
-
- /**
- * @dataProvider getXDeviceInVaryModeProvider
- */
- public function testGetXDeviceInVaryMode( $xDevice, $xWap, $expected ) {
- global $wgMFVaryResources;
- $wgMFVaryResources = true;
- MobileContext::singleton()->getRequest()->setHeader(
'X-Device', $xDevice );
- MobileContext::singleton()->getRequest()->setHeader( 'X-WAP',
$xWap );
- $this->assertEquals( $expected,
MobileContext::singleton()->getXDevice() );
- }
-
- public function getXDeviceInVaryModeProvider() {
- return array(
- array( 'webkit', 'no', 'webkit' ),
- array( 'capable', 'no', 'capable' ),
- array( 'wap', 'yes', 'wap' ),
);
}
diff --git a/tests/MobileFrontendTest.php b/tests/MobileFrontendTest.php
index 78af19c..2a37783 100644
--- a/tests/MobileFrontendTest.php
+++ b/tests/MobileFrontendTest.php
@@ -26,13 +26,12 @@
}
public function testSendHeaders() {
- global $wgExtMobileFrontend, $wgMFVaryResources;
- $wgMFVaryResources = false;
+ global $wgExtMobileFrontend;
$sendHeaders = self::getMethod( 'sendHeaders' );
- MobileContext::singleton()->getRequest()->setHeader(
'X-Device', 'device' );
+ MobileContext::singleton()->getRequest()->setHeader( 'X-WAP',
'yessir!' );
$sendHeaders->invokeArgs( $wgExtMobileFrontend, array() );
- $this->assertEquals( 'device',
MobileContext::singleton()->getRequest()->
- response()->getheader( 'X-Device' ) );
+ $this->assertEquals( 'yessir!',
MobileContext::singleton()->getRequest()->
+ response()->getheader( 'X-WAP' ) );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/71731
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e45dc82690ee2e73f5d022b9a96efabc314f21f
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[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