From: Max Semenik Date: Fri, 25 May 2012 15:05:21 +0000 (+0400) Subject: `mobile` sub-directories for mobile-related code X-Git-Tag: 1.31.0-rc.0~23475 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=aa305c06fe685193a5bef55719f20fb2bc11f070;p=lhc%2Fweb%2Fwiklou.git `mobile` sub-directories for mobile-related code Move DeviceDetection.php and DeviceDetectionTest.php Change-Id: Ia4aaf7ad499dd2021ef9d2ebf7f6d829e8fc4656 --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d138aa7f14..58d5663362 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -71,8 +71,8 @@ $wgAutoloadLocalClasses = array( 'DeferredUpdates' => 'includes/DeferredUpdates.php', 'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php', 'DerivativeRequest' => 'includes/WebRequest.php', - 'DeviceDetection' => 'includes/DeviceDetection.php', - 'DeviceProperties' => 'includes/DeviceDetection.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 +138,8 @@ $wgAutoloadLocalClasses = array( 'HttpRequest' => 'includes/HttpFunctions.old.php', 'ICacheHelper' => 'includes/CacheHelper.php', 'IcuCollation' => 'includes/Collation.php', - 'IDeviceProperties' => 'includes/DeviceDetection.php', - 'IDeviceDetector' => 'includes/DeviceDetection.php', + 'IDeviceProperties' => 'includes/mobile/DeviceDetection.php', + 'IDeviceDetector' => 'includes/mobile/DeviceDetection.php', 'IdentityCollation' => 'includes/Collation.php', 'ImageGallery' => 'includes/ImageGallery.php', 'ImageHistoryList' => 'includes/ImagePage.php', diff --git a/includes/DeviceDetection.php b/includes/DeviceDetection.php deleted file mode 100644 index bca69851fb..0000000000 --- a/includes/DeviceDetection.php +++ /dev/null @@ -1,459 +0,0 @@ -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'; - } - } else if ( preg_match( '/MSIE 9.0/', $userAgent ) || - preg_match( '/MSIE 8.0/', $userAgent ) ) { - $deviceName = 'ie'; - } else if( preg_match( '/MSIE/', $userAgent ) ) { - $deviceName = 'html'; - } else if ( 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'; - } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) { - $deviceName = 'iphone'; - } else { - $deviceName = 'webkit'; - } - } 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/includes/mobile/DeviceDetection.php b/includes/mobile/DeviceDetection.php new file mode 100644 index 0000000000..bca69851fb --- /dev/null +++ b/includes/mobile/DeviceDetection.php @@ -0,0 +1,459 @@ +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'; + } + } else if ( preg_match( '/MSIE 9.0/', $userAgent ) || + preg_match( '/MSIE 8.0/', $userAgent ) ) { + $deviceName = 'ie'; + } else if( preg_match( '/MSIE/', $userAgent ) ) { + $deviceName = 'html'; + } else if ( 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'; + } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) { + $deviceName = 'iphone'; + } else { + $deviceName = 'webkit'; + } + } 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/DeviceDetectionTest.php b/tests/phpunit/includes/DeviceDetectionTest.php deleted file mode 100644 index 0e15653206..0000000000 --- a/tests/phpunit/includes/DeviceDetectionTest.php +++ /dev/null @@ -1,40 +0,0 @@ -assertEquals( $format, $detector->detectFormatName( $userAgent ) ); - } - - public 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' ), - ); - } -} diff --git a/tests/phpunit/includes/mobile/DeviceDetectionTest.php b/tests/phpunit/includes/mobile/DeviceDetectionTest.php new file mode 100644 index 0000000000..0e15653206 --- /dev/null +++ b/tests/phpunit/includes/mobile/DeviceDetectionTest.php @@ -0,0 +1,40 @@ +assertEquals( $format, $detector->detectFormatName( $userAgent ) ); + } + + public 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' ), + ); + } +}