Phuedx has uploaded a new change for review. https://gerrit.wikimedia.org/r/314001
Change subject: Hygiene: Remove superseded device detection code ...................................................................... Hygiene: Remove superseded device detection code Bug: T143891 Change-Id: I183b04a0318a9884a6ddbee193ecbd810c4fa1a8 --- M README.md M extension.json D includes/DeviceDetection.php D tests/phpunit/DeviceDetectionTest.php 4 files changed, 0 insertions(+), 438 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/01/314001/1 diff --git a/README.md b/README.md index 8b5fd92..37cca1a 100644 --- a/README.md +++ b/README.md @@ -565,14 +565,6 @@ * Type: `Boolean` * Default: `false` -#### $wgDeviceDetectionClass - -Name of the class used for mobile device detection, must be inherited from -`IDeviceDetector`. - -* Type: `String` -* Default: `'DeviceDetection'` - #### $wgMFEnableBeta Whether beta mode is enabled. diff --git a/extension.json b/extension.json index 54e3720..69cfd65 100644 --- a/extension.json +++ b/extension.json @@ -52,12 +52,6 @@ "ExtMobileFrontend": "includes/MobileFrontend.body.php", "MobileFrontendHooks": "includes/MobileFrontend.hooks.php", "MobileFrontendSkinHooks": "includes/MobileFrontend.skin.hooks.php", - "IDeviceProperties": "includes/DeviceDetection.php", - "IDeviceDetector": "includes/DeviceDetection.php", - "DeviceProperties": "includes/DeviceDetection.php", - "PredefinedDeviceProperties": "includes/DeviceDetection.php", - "DeviceDetection": "includes/DeviceDetection.php", - "HtmlDeviceProperties": "includes/DeviceDetection.php", "MobileContext": "includes/MobileContext.php", "MobileFormatter": "includes/MobileFormatter.php", "MobileCollection": "includes/models/MobileCollection.php", @@ -2014,7 +2008,6 @@ "MFCustomLogos": [], "MobileFrontendLogo": false, "MFTrademarkSitename": false, - "DeviceDetectionClass": "DeviceDetection", "MFEnableBeta": false, "MFDonationUrl": false, "MFContentNamespace": 0, diff --git a/includes/DeviceDetection.php b/includes/DeviceDetection.php deleted file mode 100644 index d184001..0000000 --- a/includes/DeviceDetection.php +++ /dev/null @@ -1,263 +0,0 @@ -<?php -/** - * Mobile device detection code - * - * Copyright © 2011 Patrick Reilly - * https://www.mediawiki.org/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * @file - */ - -/** - * Base for classes describing devices and their capabilities - */ -interface IDeviceProperties { - /** - * Default implementation of isMobileDevice() - * @return bool - */ - function isMobileDevice(); - - /** - * Whether the device is tablet. If this is true, isMobileDevice() is also true - * @return bool - */ - function isTablet(); -} - -/** - * Base for classes for device detection - */ -interface IDeviceDetector { - /** - * default implementation of detectDeviceProperties() - * @param string $userAgent - * @param string $acceptHeader - * @return IDeviceProperties - */ - function detectDeviceProperties( $userAgent, $acceptHeader ); -} - -/** - * MobileFrontend's default IDeviceProperties implementation - */ -class DeviceProperties implements IDeviceProperties { - /** - * The user gaent string of current device - * @var string - */ - private $userAgent; - /** - * Stores the accept headers of current browser. - * @var string - */ - private $acceptHeader; - /** - * Is this device is a mobile device? - * @var boolean - */ - private $isMobile = null; - /** - * Stores the answer: Is this device a tablet? - * @var boolean - */ - private $tablet = null; - - /** - * Set parameters to class variables - * - * @param string $userAgent UserAgent string - * @param string $acceptHeader Accept Header - */ - public function __construct( $userAgent, $acceptHeader ) { - $this->userAgent = $userAgent; - $this->acceptHeader = $acceptHeader; - } - - /** - * Check if device is a mobile device based on current user agent string. - * @return bool - */ - public function isMobileDevice() { - if ( is_null( $this->isMobile ) ) { - $this->isMobile = $this->detectMobileDevice(); - } - return $this->isMobile; - } - - /** - * Check if device is a tablet based on current user agent string. - * @return bool - */ - public function isTablet() { - if ( is_null( $this->tablet ) ) { - $this->tablet = $this->detectTablet(); - } - return $this->tablet; - } - - /** - * Detect mobile devices using useragent string - * @return bool - */ - private function detectMobileDevice() { - $patterns = [ - 'mobi', - '240x240', - '240x320', - '320x320', - 'alcatel', - 'android', - 'audiovox', - 'bada', - 'benq', - 'blackberry', - 'cdm-', - 'compal-', - 'docomo', - 'ericsson', - 'hiptop', - 'htc[-_]', - 'huawei', - 'ipod', - 'kddi-', - 'kindle', - 'meego', - 'midp', - 'mitsu', - 'mmp\/', - 'mot-', - 'motor', - 'ngm_', - 'nintendo', - 'opera.m', - 'palm', - 'panasonic', - 'philips', - 'phone', - 'playstation', - 'portalmmm', - 'sagem-', - 'samsung', - 'sanyo', - 'sec-', - 'sendo', - 'sharp', - 'silk', - 'softbank', - 'symbian', - 'teleca', - 'up.browser', - 'webos', - ]; - $patternsStart = [ - 'lg-', - 'sie-', - 'nec-', - 'lge-', - 'sgh-', - 'pg-', - ]; - $regex = '/^(' . implode( '|', $patternsStart ) . ')|(' . implode( '|', $patterns ) . ')/i'; - $exceptionRegex = '/SMART-TV.*SamsungBrowser/'; - $isMobile = preg_match( $regex, $this->userAgent ) - && !preg_match( $exceptionRegex, $this->userAgent ); - - return $isMobile; - } - - /** - * Detect mobile devices using useragent string - * @return bool - */ - private function detectTablet() { - // The only way to distinguish Android browsers on tablet from Android browsers on - // mobile is that Android browsers on tablet usually don't include the word - // "mobile". We look for "mobi" instead of "mobile" due to Opera Mobile. Note that - // this test fails to detect some obscure tablets such as older Xoom tablets and - // Portablet tablets. See http://stackoverflow.com/questions/5341637. - $isAndroid = (bool)preg_match( '/Android/i', $this->userAgent ); - if ( $isAndroid ) { - $isTablet = !(bool)preg_match( '/mobi/i', $this->userAgent ); - } else { - $pattern = '/(iPad|Tablet|PlayBook|Wii|Silk)/i'; - $isTablet = (bool)preg_match( $pattern, $this->userAgent ); - } - - return $isTablet; - } -} - -/** - * This class's descendants should only be instantiated with $wgMFAutodetectMobileView set to true, - * otherwise all attempts to check for tabletness will lie - */ -abstract class PredefinedDeviceProperties implements IDeviceProperties { - /** - * Overrides isTablet function to create Exception. - */ - function isTablet() { - throw new Exception( __METHOD__ . '() called!' ); - } -} - -/** - * implementation of PredefinedDeviceProperties - */ -class HtmlDeviceProperties extends PredefinedDeviceProperties { - /** - * Returns always true - * @return bool - */ - function isMobileDevice() { - return true; - } -} - -/** - * Provides abstraction for a device. - * A device can select which format a request should receive and - * may be extended to provide access to particular device functionality. - */ -class DeviceDetection implements IDeviceDetector { - - /** - * Returns an instance of detection class, overridable by extensions - * @return IDeviceDetector - */ - public static function factory() { - $deviceDetectionClass = MobileContext::singleton()->getMFConfig() - ->get( 'DeviceDetectionClass' ); - - static $instance = null; - if ( !$instance ) { - $instance = new $deviceDetectionClass(); - } - return $instance; - } - - /** - * Create instance of DeviceProperties - * @param string $userAgent - * @param string $acceptHeader - * @return IDeviceProperties - */ - public function detectDeviceProperties( $userAgent, $acceptHeader ) { - return new DeviceProperties( $userAgent, $acceptHeader ); - } -} diff --git a/tests/phpunit/DeviceDetectionTest.php b/tests/phpunit/DeviceDetectionTest.php deleted file mode 100644 index c4699dc..0000000 --- a/tests/phpunit/DeviceDetectionTest.php +++ /dev/null @@ -1,160 +0,0 @@ -<?php - -/** - * @group MobileFrontend - */ -class DeviceDetectionTest extends MediaWikiTestCase { - // @codingStandardsIgnoreStart Ignore long lines. - private $mobiles = array( - // Android - 'Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', - 'Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', - // Firefox OS (bug 40919) - 'Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0', - 'Mozilla/5.0 (Android; Mobile; rv:20.0) Gecko/20.0 Firefox/20.0', - // Blackberry 10 (bug 40513) - 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.386 Mobile Safari/537.3+', - '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) - 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; <Manufacturer>; <Device> [;<Operator>])', - // Others - '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', - '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', - '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', - 'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413', - '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 - 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)', - 'Opera/9.80 (iPhone; Opera Mini/7.0.4/28.2555; U; fr) Presto/2.8.119 Version/11.10', - 'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)', - 'Opera/9.80 (Android 4.1.1; Linux; Opera Mobi/ADR-1301080958) Presto/2.11.355 Version/12.10', - 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)', - 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)', - // Later Kindles use 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)', - 'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2', - 'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1', - 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1', - 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)', - 'Mozilla/5.0 (PLAYSTATION 3; 1.00)', - // Blackberry - 'BlackBerry9300/5.0.0.716 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/133', - 'BlackBerry7250/4.0.0 Profile/MIDP-2.0 Configuration/CLDC-1.1', - // https://bugzilla.wikimedia.org/show_bug.cgi?id=30827 - '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( 'KDDI-KC31 UP.Browser/6.2.0.5 (GUI) MMP/2.0', 'text/bullshit, text/vnd.wap.wml' ), - ); - private $tablets = array( - // iPad - 'Mozilla/5.0 (iPad; CPU OS 7_0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A501 Safari/9537.53', - // Motorola Xoom - 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13', - // Opera Mobile running on a tablet - 'Opera/9.80 (Android 4.0.4; Linux; Opera Tablet/ADR-1301080958) Presto/2.11.355 Version/12.10', - // Firefox running on a tablet - 'Mozilla/5.0 (Android; Tablet; rv:24.0) Gecko/24.0 Firefox/24.0', - // Nintendo Wii - 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)', - 'Mozilla/5.0 (Nintendo WiiU) AppleWebKit/536.28 (KHTML, like Gecko) NX/3.0.3.12.6 NintendoBrowser/2.0.0.9362.EU', - // Samsung Galaxy Tab - 'Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-P5210 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30', - // Kindle Fire, Silk browser operating in "desktop" mode - // (Silk operating in "mobile" mode will only be detected as a mobile device.) - 'Mozilla/5.0 (Linux; U; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Safari/535.19 Silk-Accelerated=true', - // @todo: - //'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+', - //'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDR; .NET4.0C; .NET4.0E; .NET CLR 1.1.4322; Tablet PC 2.0); 360Spider', - //'Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Portablet 01 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', - ); - // @codingStandardsIgnoreEnd - - private function map( $array, $flag ) { - return array_map( - function ( $ua ) use ( $flag ) { - if ( is_array( $ua ) ) { - array_unshift( $ua, $flag ); - - return $ua; - } - - return [ $flag, $ua ]; - }, - $array - ); - } - - private function mobileDevices() { - return $this->map( array_merge( $this->mobiles, $this->tablets ), true ); - } - - /** - * @dataProvider provideTestIsMobileDevice - * @covers DeviceDetection::detectDeviceProperties - */ - public function testIsMobileDevice( $expected, $userAgent ) { - $detector = new DeviceDetection(); - $device = $detector->detectDeviceProperties( $userAgent, '' ); - $this->assertEquals( (bool)$expected, $device->isMobileDevice() ); - } - - public function provideTestIsMobileDevice() { - // Borrow mobile user agent strings from another test... - $input = $this->mobileDevices(); - - // @codingStandardsIgnoreStart Ignore long lines. - return array_merge( $input, - array( - // add more obscure mobile devices - array( true, 'Vodafone/1.0/LG-KU990/V10iBrowser/Obigo-Q05A/3.6 MMS/LG-MMS-V1.0/1.2 Java/ASVM/1.0 Profile/MIDP-2.0Configuration/CLDC-1.1' ), - array( true, 'Vodafone/1.0/0Vodafone543/ V010 05/MIDP-2.0 Configuration/CLDC-1.1 ObigoInternetBrowser/Q03C' ), - array( true, 'DoCoMo/2.0 P07A3(c500;TB;W24H15)' ), - array( true, 'KDDI-HI31 UP.Browser/6.2.0.5 (GUI) MMP/2.0' ), - array( true, 'Mozilla/4.0 (compatible; MSIE 6.0; KDDI-SA39) Opera 8.60 [ja]' ), - // ...and some desktop browsers - array( false, 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060928 (Debian|Debian-1.8.0.7-1) Epiphany/2.14' ), - array( false, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)' ), - array( false, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)' ), - array( false, 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16' ), - array( false, 'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.6) Gecko/20070817 IceWeasel/2.0.0.6-g2' ), - array( false, 'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.11) Gecko/20071203 IceCat/2.0.0.11-g1' ), - array( false, 'Mozilla/5.0 (compatible; Konqueror/4.3; Linux) KHTML/4.3.5 (like Gecko)' ), - array( false, 'Links (2.2; GNU/kFreeBSD 6.3-1-486 i686; 80x25)' ), # Jidanni made me put this here - array( false, 'Lynx/2.8.6rel.4 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.8g' ), - array( false, 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20120815 Firefox/16.0' ), - array( false, 'Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.8.131 Version/11.10' ), - array( false, 'Mozilla/5.0 (Macintosh; I; Intel Mac OS X 10_6_7; ru-ru) AppleWebKit/534.31+ (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1' ), - array( false, 'w3m/0.5.1' ), - array( false, 'Googlebot/2.1 (+http://www.google.com/bot.html)' ), - array( false, 'Mozilla/5.0 (compatible; googlebot/2.1; +http://www.google.com/bot.html)' ), - array( false, 'Wget/1.9' ), - array( false, 'Mozilla/5.0 (compatible; YandexBot/3.0)' ), - - // T127021 - array( false, 'Mozilla/5.0 (SMART-TV; Linux; Tizen 2.3) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.0 TV Safari/538.1' ), - array( true, 'Mozilla/5.0 (Linux; Android 4.2.2; nl-nl; SAMSUNG GT-I9505 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari/535.19' ), - ) - ); - // @codingStandardsIgnoreEnd - } - - /** - * @dataProvider provideTestIsTablet - * @covers DeviceDetection::isMobileDevice - */ - public function testIsTablet( $expected, $userAgent ) { - $detector = new DeviceDetection(); - $device = $detector->detectDeviceProperties( $userAgent, '' ); - $this->assertEquals( (bool)$expected, $device->isTablet() ); - if ( $expected ) { - $this->assertTrue( $device->isMobileDevice(), 'Tablets are always mobile devices' ); - } - } - - public function provideTestIsTablet() { - return array_merge( - $this->map( $this->tablets, true ), - $this->map( $this->mobiles, false ) - ); - } -} -- To view, visit https://gerrit.wikimedia.org/r/314001 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I183b04a0318a9884a6ddbee193ecbd810c4fa1a8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Phuedx <g...@samsmith.io> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits