Kill DeviceDetection
authorMax Semenik <maxsem.wiki@gmail.com>
Wed, 14 Nov 2012 19:24:11 +0000 (23:24 +0400)
committerMax Semenik <maxsem.wiki@gmail.com>
Thu, 15 Nov 2012 15:57:00 +0000 (19:57 +0400)
The project to integrate MobileFrontend into core has
been stashed for now, and this leftoff is preventing
further work on MF by creating a class name conflict.

Change-Id: I6a9a25877bf75496fb4074acc83e12b7cb8dd86a

includes/AutoLoader.php
includes/DefaultSettings.php
includes/mobile/DeviceDetection.php [deleted file]
tests/phpunit/includes/mobile/DeviceDetectionTest.php [deleted file]

index a49d901..53a66ca 100644 (file)
@@ -71,8 +71,6 @@ $wgAutoloadLocalClasses = array(
        'DeferredUpdates' => 'includes/DeferredUpdates.php',
        'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php',
        'DerivativeRequest' => 'includes/WebRequest.php',
-       'DeviceDetection' => 'includes/mobile/DeviceDetection.php',
-       'DeviceProperties' => 'includes/mobile/DeviceDetection.php',
        'DiffHistoryBlob' => 'includes/HistoryBlob.php',
        'DoubleReplacer' => 'includes/StringUtils.php',
        'DummyLinker' => 'includes/Linker.php',
@@ -138,8 +136,6 @@ $wgAutoloadLocalClasses = array(
        'HttpRequest' => 'includes/HttpFunctions.old.php',
        'ICacheHelper' => 'includes/CacheHelper.php',
        'IcuCollation' => 'includes/Collation.php',
-       'IDeviceProperties' => 'includes/mobile/DeviceDetection.php',
-       'IDeviceDetector' => 'includes/mobile/DeviceDetection.php',
        'IdentityCollation' => 'includes/Collation.php',
        'ImageGallery' => 'includes/ImageGallery.php',
        'ImageHistoryList' => 'includes/ImagePage.php',
index 494b2a3..7ac5c04 100644 (file)
@@ -6207,20 +6207,6 @@ $wgCompiledFiles = array();
 
 /** @} */ # End of HipHop compilation }
 
-
-/************************************************************************//**
- * @name   Mobile support
- * @{
- */
-
-/**
- * Name of the class used for mobile device detection, must be inherited from
- * IDeviceDetector.
- */
-$wgDeviceDetectionClass = 'DeviceDetection';
-
-/** @} */ # End of Mobile support }
-
 /************************************************************************//**
  * @name   Miscellaneous
  * @{
diff --git a/includes/mobile/DeviceDetection.php b/includes/mobile/DeviceDetection.php
deleted file mode 100644 (file)
index 262665b..0000000
+++ /dev/null
@@ -1,459 +0,0 @@
-<?php
-/**
- * Mobile device detection code
- *
- * Copyright © 2011 Patrick Reilly
- * http://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
- * @since 1.20
- */
-interface IDeviceProperties {
-       /**
-        * @return string: 'html' or 'wml'
-        */
-       function format();
-
-       /**
-        * @return bool
-        */
-       function supportsJavaScript();
-
-       /**
-        * @return bool
-        */
-       function supportsJQuery();
-
-       /**
-        * @return bool
-        */
-       function disableZoom();
-}
-
-/**
- * @since 1.20
- */
-interface IDeviceDetector {
-       /**
-        * @param $userAgent
-        * @param string $acceptHeader
-        * @return IDeviceProperties
-        */
-       function detectDeviceProperties( $userAgent, $acceptHeader = '' );
-
-       /**
-        * @param $deviceName
-        * @return IDeviceProperties
-        */
-       function getDeviceProperties( $deviceName );
-
-       /**
-        * @param $userAgent string
-        * @param $acceptHeader string
-        * @return string
-        */
-       function detectDeviceName( $userAgent, $acceptHeader = '' );
-}
-
-/**
- * MediaWiki's default IDeviceProperties implementation
- */
-final class DeviceProperties implements IDeviceProperties {
-       private $device;
-
-       public function __construct( array $deviceCapabilities ) {
-               $this->device = $deviceCapabilities;
-       }
-
-       /**
-        * @return string
-        */
-       function format() {
-               return $this->device['view_format'];
-       }
-
-       /**
-        * @return bool
-        */
-       function supportsJavaScript() {
-               return $this->device['supports_javascript'];
-       }
-
-       /**
-        * @return bool
-        */
-       function supportsJQuery() {
-               return $this->device['supports_jquery'];
-       }
-
-       /**
-        * @return bool
-        */
-       function disableZoom() {
-               return $this->device['disable_zoom'];
-       }
-}
-
-/**
- * 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.
- * @since 1.20
- */
-class DeviceDetection implements IDeviceDetector {
-
-       private static $formats = array (
-                       'html' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'default',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'capable' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'default',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => true,
-                       ),
-                       'webkit' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'webkit',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => false,
-                       ),
-                       'ie' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'default',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => false,
-                       ),
-                       'android' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'android',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => false,
-                       ),
-                       'iphone' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'iphone',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => false,
-                       ),
-                       'iphone2' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'iphone2',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => true,
-                       ),
-                       'native_iphone' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'default',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => false,
-                       ),
-                       'palm_pre' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'palm_pre',
-                               'supports_javascript' => true,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'kindle' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'kindle',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'kindle2' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'kindle',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'blackberry' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'blackberry',
-                               'supports_javascript' => true,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'blackberry-lt5' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'blackberry',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'netfront' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'simple',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'wap2' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'simple',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'psp' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'psp',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'ps3' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'simple',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'wii' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'wii',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => true,
-                       ),
-                       'operamini' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'operamini',
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'operamobile' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'operamobile',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => true,
-                       ),
-                       'nokia' => array (
-                               'view_format' => 'html',
-                               'css_file_name' => 'nokia',
-                               'supports_javascript' => true,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-                       'wml' => array (
-                               'view_format' => 'wml',
-                               'css_file_name' => null,
-                               'supports_javascript' => false,
-                               'supports_jquery' => false,
-                               'disable_zoom' => true,
-                       ),
-               );
-
-       /**
-        * Returns an instance of detection class, overridable by extensions
-        * @return IDeviceDetector
-        */
-       public static function factory() {
-               global $wgDeviceDetectionClass;
-
-               static $instance = null;
-               if ( !$instance ) {
-                       $instance = new $wgDeviceDetectionClass();
-               }
-               return $instance;
-       }
-
-       /**
-        * @deprecated: Deprecated, will be removed once detectDeviceProperties() will be deployed everywhere on WMF
-        * @param $userAgent
-        * @param string $acceptHeader
-        * @return array
-        */
-       public function detectDevice( $userAgent, $acceptHeader = '' ) {
-               $formatName = $this->detectFormatName( $userAgent, $acceptHeader );
-               return $this->getDevice( $formatName );
-       }
-
-       /**
-        * @param $userAgent
-        * @param string $acceptHeader
-        * @return IDeviceProperties
-        */
-       public function detectDeviceProperties( $userAgent, $acceptHeader = '' ) {
-               $deviceName = $this->detectDeviceName( $userAgent, $acceptHeader );
-               return $this->getDeviceProperties( $deviceName );
-       }
-
-       /**
-        * @deprecated: Deprecated, will be removed once detectDeviceProperties() will be deployed everywhere on WMF
-        * @param $formatName
-        * @return array
-        */
-       public function getDevice( $formatName ) {
-               return ( isset( self::$formats[$formatName] ) ) ? self::$formats[$formatName] : array();
-       }
-
-       /**
-        * @param $deviceName
-        * @return IDeviceProperties
-        */
-       public function getDeviceProperties( $deviceName ) {
-               if ( isset( self::$formats[$deviceName] ) ) {
-                       return new DeviceProperties( self::$formats[$deviceName] );
-               } else {
-                       return new DeviceProperties( array(
-                               'view_format' => 'html',
-                               'css_file_name' => 'default',
-                               'supports_javascript' => true,
-                               'supports_jquery' => true,
-                               'disable_zoom' => true,
-                       ) );
-               }
-       }
-
-       /**
-        * @deprecated: Renamed to detectDeviceName()
-        * @param $userAgent string
-        * @param $acceptHeader string
-        * @return string
-        */
-       public function detectFormatName( $userAgent, $acceptHeader = '' ) {
-               return $this->detectDeviceName( $userAgent, $acceptHeader );
-       }
-
-       /**
-        * @param $userAgent string
-        * @param $acceptHeader string
-        * @return string
-        */
-       public function detectDeviceName( $userAgent, $acceptHeader = '' ) {
-               wfProfileIn( __METHOD__ );
-
-               $deviceName = '';
-               if ( preg_match( '/Android/', $userAgent ) ) {
-                       $deviceName = 'android';
-                       if ( strpos( $userAgent, 'Opera Mini' ) !== false ) {
-                               $deviceName = 'operamini';
-                       } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) {
-                               $deviceName = 'operamobile';
-                       }
-               } elseif ( preg_match( '/MSIE 9.0/', $userAgent ) ||
-                               preg_match( '/MSIE 8.0/', $userAgent ) ) {
-                       $deviceName = 'ie';
-               } elseif( preg_match( '/MSIE/', $userAgent ) ) {
-                       $deviceName = 'html';
-               } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) {
-                       $deviceName = 'operamobile';
-               } elseif ( preg_match( '/iPad.* Safari/', $userAgent ) ) {
-                       $deviceName = 'iphone';
-               } elseif ( preg_match( '/iPhone.* Safari/', $userAgent ) ) {
-                       if ( strpos( $userAgent, 'iPhone OS 2' ) !== false ) {
-                               $deviceName = 'iphone2';
-                       } else {
-                               $deviceName = 'iphone';
-                       }
-               } elseif ( preg_match( '/iPhone/', $userAgent ) ) {
-                       if ( strpos( $userAgent, 'Opera' ) !== false ) {
-                               $deviceName = 'operamini';
-                       } else {
-                               $deviceName = 'native_iphone';
-                       }
-               } elseif ( preg_match( '/WebKit/', $userAgent ) ) {
-                       if ( preg_match( '/Series60/', $userAgent ) ) {
-                               $deviceName = 'nokia';
-                       } elseif ( preg_match( '/webOS/', $userAgent ) ) {
-                               $deviceName = 'palm_pre';
-                       } else {
-                               $deviceName = 'webkit';
-                       }
-               } elseif ( preg_match( '/Opera/', $userAgent ) ) {
-                       if ( strpos( $userAgent, 'Nintendo Wii' ) !== false ) {
-                               $deviceName = 'wii';
-                       } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) {
-                               $deviceName = 'operamini';
-                       } else {
-                               $deviceName = 'operamobile';
-                       }
-               } elseif ( preg_match( '/Kindle\/1.0/', $userAgent ) ) {
-                       $deviceName = 'kindle';
-               } elseif ( preg_match( '/Kindle\/2.0/', $userAgent ) ) {
-                       $deviceName = 'kindle2';
-               } elseif ( preg_match( '/Firefox/', $userAgent ) ) {
-                       $deviceName = 'capable';
-               } elseif ( preg_match( '/NetFront/', $userAgent ) ) {
-                       $deviceName = 'netfront';
-               } elseif ( preg_match( '/SEMC-Browser/', $userAgent ) ) {
-                       $deviceName = 'wap2';
-               } elseif ( preg_match( '/Series60/', $userAgent ) ) {
-                       $deviceName = 'wap2';
-               } elseif ( preg_match( '/PlayStation Portable/', $userAgent ) ) {
-                       $deviceName = 'psp';
-               } elseif ( preg_match( '/PLAYSTATION 3/', $userAgent ) ) {
-                       $deviceName = 'ps3';
-               } elseif ( preg_match( '/SAMSUNG/', $userAgent ) ) {
-                       $deviceName = 'capable';
-               } elseif ( preg_match( '/BlackBerry/', $userAgent ) ) {
-                       if( preg_match( '/BlackBerry[^\/]*\/[1-4]\./', $userAgent ) ) {
-                               $deviceName = 'blackberry-lt5';
-                       } else {
-                               $deviceName = 'blackberry';
-                       }
-               }
-
-               if ( $deviceName === '' ) {
-                       if ( strpos( $acceptHeader, 'application/vnd.wap.xhtml+xml' ) !== false ) {
-                               // Should be wap2
-                               $deviceName = 'html';
-                       } elseif ( strpos( $acceptHeader, 'vnd.wap.wml' ) !== false ) {
-                               $deviceName = 'wml';
-                       } else {
-                               $deviceName = 'html';
-                       }
-               }
-               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 );
-       }
-}
diff --git a/tests/phpunit/includes/mobile/DeviceDetectionTest.php b/tests/phpunit/includes/mobile/DeviceDetectionTest.php
deleted file mode 100644 (file)
index 2588691..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/**
- * @group Mobile
- */
- class DeviceDetectionTest extends MediaWikiTestCase {
-
-       /**
-        * @dataProvider provideTestFormatName
-        */
-       public function testFormatName( $format, $userAgent ) {
-               $detector = new DeviceDetection();
-               $this->assertEquals( $format, $detector->detectFormatName( $userAgent ) );
-       }
-
-       public static function provideTestFormatName() {
-               return array(
-                       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( 'iphone2',   '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( 'wii',       '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( 'operamobile',    'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)' ),
-                       array( 'kindle',    'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)' ),
-                       array( 'kindle2',   'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)' ),
-                       array( 'capable',   'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1' ),
-                       array( 'netfront',  'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2' ),
-                       array( 'wap2',      'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
-                       array( 'wap2',      'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
-                       array( 'psp',       'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)' ),
-                       array( 'ps3',       'Mozilla/5.0 (PLAYSTATION 3; 1.00)' ),
-                       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( 'blackberry', 'BlackBerry9300/5.0.0.716 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/133' ),
-                       array( 'blackberry-lt5', 'BlackBerry7250/4.0.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
-               );
-       }
-}