MaxSem has uploaded a new change for review.
https://gerrit.wikimedia.org/r/73018
Change subject: Simplify WAPness detection
......................................................................
Simplify WAPness detection
Now only Accept header is used for WAP detection,
User-agent is used for mobileness.
Change-Id: Ib180b72de810f0f1be57ee82dded48cd870cee40
---
M includes/DeviceDetection.php
M tests/DeviceDetectionTest.php
2 files changed, 43 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/18/73018/1
diff --git a/includes/DeviceDetection.php b/includes/DeviceDetection.php
index 8557771..35af383 100644
--- a/includes/DeviceDetection.php
+++ b/includes/DeviceDetection.php
@@ -41,11 +41,11 @@
interface IDeviceDetector {
/**
- * @param $userAgent
+ * @param string $userAgent
* @param string $acceptHeader
* @return IDeviceProperties
*/
- function detectDeviceProperties( $userAgent, $acceptHeader = '' );
+ function detectDeviceProperties( $userAgent, $acceptHeader );
}
/**
@@ -78,17 +78,8 @@
* @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, 'text/html' ) === false
&& strpos( $this->acceptHeader,
'application/vnd.wap.xhtml+xml' ) === false )
{
return 'wml';
@@ -232,11 +223,11 @@
}
/**
- * @param $userAgent
+ * @param string $userAgent
* @param string $acceptHeader
* @return IDeviceProperties
*/
- public function detectDeviceProperties( $userAgent, $acceptHeader = ''
) {
+ public function detectDeviceProperties( $userAgent, $acceptHeader ) {
return new DeviceProperties( $userAgent, $acceptHeader );
}
}
diff --git a/tests/DeviceDetectionTest.php b/tests/DeviceDetectionTest.php
index 9f0bce9..3d7ce3f 100644
--- a/tests/DeviceDetectionTest.php
+++ b/tests/DeviceDetectionTest.php
@@ -8,61 +8,61 @@
/**
* @dataProvider provideTestFormat
*/
- public function testFormat( $format, $userAgent, $acceptHeader = '' ) {
+ public function testFormat( $format, $acceptHeader ) {
$detector = new DeviceDetection();
- $device = $detector->detectDeviceProperties( $userAgent,
$acceptHeader );
+ $device = $detector->detectDeviceProperties( '', $acceptHeader
);
$this->assertEquals( $format, $device->format() );
}
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( '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' ),
- )
+ return array(
+ // Typical WebKit-based mobile browser, e.g. Android
+ array( 'html',
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' ),
+ // Opera Mini
+ array( 'html', 'text/html, application/xml;q=0.9,
application/xhtml+xml, image/png,image/webp, image/jpeg,image/gif,
image/x-xbitmap, */*;q=0.1' ),
+ // Samsung JET,
https://bugzilla.wikimedia.org/show_bug.cgi?id=30827
+ array( 'html', '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, */*' ),
+ // Some average WAP browser
+ array( 'wml', 'text/vnd.wap.wml, image/vnd.wap.wbmp,
image/png, image/jpeg, image/gif, image/bmp' )
);
}
private function mobileDevices() {
return array(
// Firefox OS (bug 40919)
- 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' ),
+ array( true, 'Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0
Firefox/14.0' ),
+ array( true, 'Mozilla/5.0 (Android; Mobile; rv:20.0)
Gecko/20.0 Firefox/20.0' ),
// Blackberry 10 (bug 40513)
- 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+' ),
+ array( true, 'Mozilla/5.0 (BB10; Touch)
AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.386 Mobile Safari/537.3+'
),
+ array( true, '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( 'html', 'Mozilla/5.0 (compatible; MSIE 10.0;
Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>;
<Device> [;<Operator>])' ),
+ array( true, 'Mozilla/5.0 (compatible; MSIE 10.0;
Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>;
<Device> [;<Operator>])' ),
// Others
- 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' ),
+ array( true, '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( true, '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( true, '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( true, 'Mozilla/5.0 (SymbianOS/9.1; U; [en];
SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413' ),
+ array( true, '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( '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)' ),
+ array( true, 'Opera/9.00 (Nintendo Wii; U; ; 1309-9;
en)' ),
+ array( true, 'Opera/9.50 (J2ME/MIDP; Opera
Mini/4.0.10031/298; U; en)' ),
+ array( true, 'Opera/9.80 (iPhone; Opera
Mini/7.0.4/28.2555; U; fr) Presto/2.8.119 Version/11.10' ),
+ array( true, 'Opera/9.51 Beta (Microsoft Windows; PPC;
Opera Mobi/1718; U; en)' ),
+ array( true, 'Opera/9.80 (Android 4.1.1; Linux; Opera
Mobi/ADR-1301080958) Presto/2.11.355 Version/12.10' ),
+ array( true, 'Mozilla/4.0 (compatible; Linux 2.6.10)
NetFront/3.3 Kindle/1.0 (screen 600x800)' ),
+ array( true, 'Mozilla/4.0 (compatible; Linux 2.6.22)
NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)' ),
// Later Kindles use WebKit
- 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)' ),
+ array( true, '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( true, 'Mozilla/4.08 (Windows; Mobile Content
Viewer/1.0) NetFront/3.2' ),
+ array( true, 'SonyEricssonK608i/R2L/SN356841000828910
Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( true, 'NokiaN73-2/3.0-630.0.2 Series60/3.0
Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
+ array( true, 'Mozilla/4.0 (PSP (PlayStation Portable);
2.00)' ),
+ array( true, 'Mozilla/5.0 (PLAYSTATION 3; 1.00)' ),
// Blackberry
- 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' ),
+ array( true, 'BlackBerry9300/5.0.0.716 Profile/MIDP-2.1
Configuration/CLDC-1.1 VendorID/133' ),
+ array( true, 'BlackBerry7250/4.0.0 Profile/MIDP-2.0
Configuration/CLDC-1.1' ),
// https://bugzilla.wikimedia.org/show_bug.cgi?id=30827
- 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, */*'
- ),
+ array( true, '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' ),
// WML
array( 'wml', 'KDDI-KC31 UP.Browser/6.2.0.5 (GUI)
MMP/2.0', 'text/bullshit, text/vnd.wap.wml' ),
);
@@ -73,7 +73,7 @@
*/
public function testIsMobileDevice( $expected, $userAgent ) {
$detector = new DeviceDetection();
- $device = $detector->detectDeviceProperties( $userAgent );
+ $device = $detector->detectDeviceProperties( $userAgent, '' );
$this->assertEquals( (bool)$expected, $device->isMobileDevice()
);
}
--
To view, visit https://gerrit.wikimedia.org/r/73018
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib180b72de810f0f1be57ee82dded48cd870cee40
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits