Index: trunk/extensions/MobileFrontend/DeviceDetection.php |
— | — | @@ -9,14 +9,14 @@ |
10 | 10 | * @licence GNU General Public Licence 2.0 or later |
11 | 11 | */ |
12 | 12 | |
13 | | -// Provides an abstraction for a device |
| 13 | +// Provides an abstraction for a device |
14 | 14 | // A device can select which format a request should recieve and |
15 | 15 | // may be extended to provide access to particular devices functionality |
16 | 16 | class DeviceDetection { |
17 | | - |
18 | | - public function availableFormats() { |
| 17 | + |
| 18 | + public function availableFormats() { |
19 | 19 | $formats = array ( |
20 | | - 'html' => |
| 20 | + 'html' => |
21 | 21 | array ( |
22 | 22 | 'view_format' => 'html', |
23 | 23 | 'search_bar' => 'default', |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | 'parser' => 'html', |
30 | 30 | 'disable_links' => true, |
31 | 31 | ), |
32 | | - 'capable' => |
| 32 | + 'capable' => |
33 | 33 | array ( |
34 | 34 | 'view_format' => 'html', |
35 | 35 | 'search_bar' => 'default', |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | 'parser' => 'html', |
42 | 42 | 'disable_links' => true, |
43 | 43 | ), |
44 | | - 'simplehtml' => |
| 44 | + 'simplehtml' => |
45 | 45 | array ( |
46 | 46 | 'view_format' => 'html', |
47 | 47 | 'search_bar' => 'simple', |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | 'parser' => 'html', |
54 | 54 | 'disable_links' => true, |
55 | 55 | ), |
56 | | - 'webkit' => |
| 56 | + 'webkit' => |
57 | 57 | array ( |
58 | 58 | 'view_format' => 'html', |
59 | 59 | 'search_bar' => 'webkit', |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | 'parser' => 'html', |
66 | 66 | 'disable_links' => true, |
67 | 67 | ), |
68 | | - 'webkit_old' => |
| 68 | + 'webkit_old' => |
69 | 69 | array ( |
70 | 70 | 'view_format' => 'html', |
71 | 71 | 'search_bar' => 'default', |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | 'parser' => 'html', |
78 | 78 | 'disable_links' => true, |
79 | 79 | ), |
80 | | - 'android' => |
| 80 | + 'android' => |
81 | 81 | array ( |
82 | 82 | 'view_format' => 'html', |
83 | 83 | 'search_bar' => 'default', |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | 'parser' => 'html', |
90 | 90 | 'disable_links' => true, |
91 | 91 | ), |
92 | | - 'iphone' => |
| 92 | + 'iphone' => |
93 | 93 | array ( |
94 | 94 | 'view_format' => 'html', |
95 | 95 | 'search_bar' => 'webkit', |
— | — | @@ -100,7 +100,7 @@ |
101 | 101 | 'parser' => 'html', |
102 | 102 | 'disable_links' => true, |
103 | 103 | ), |
104 | | - 'iphone2' => |
| 104 | + 'iphone2' => |
105 | 105 | array ( |
106 | 106 | 'view_format' => 'html', |
107 | 107 | 'search_bar' => 'default', |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | 'parser' => 'html', |
114 | 114 | 'disable_links' => true, |
115 | 115 | ), |
116 | | - 'native_iphone' => |
| 116 | + 'native_iphone' => |
117 | 117 | array ( |
118 | 118 | 'view_format' => 'html', |
119 | 119 | 'search_bar' => false, |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | 'parser' => 'html', |
126 | 126 | 'disable_links' => false, |
127 | 127 | ), |
128 | | - 'palm_pre' => |
| 128 | + 'palm_pre' => |
129 | 129 | array ( |
130 | 130 | 'view_format' => 'html', |
131 | 131 | 'search_bar' => 'default', |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | 'parser' => 'html', |
138 | 138 | 'disable_links' => true, |
139 | 139 | ), |
140 | | - 'kindle' => |
| 140 | + 'kindle' => |
141 | 141 | array ( |
142 | 142 | 'view_format' => 'html', |
143 | 143 | 'search_bar' => 'kindle', |
— | — | @@ -148,7 +148,7 @@ |
149 | 149 | 'parser' => 'html', |
150 | 150 | 'disable_links' => true, |
151 | 151 | ), |
152 | | - 'kindle2' => |
| 152 | + 'kindle2' => |
153 | 153 | array ( |
154 | 154 | 'view_format' => 'html', |
155 | 155 | 'search_bar' => 'kindle', |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | 'parser' => 'html', |
162 | 162 | 'disable_links' => true, |
163 | 163 | ), |
164 | | - 'blackberry' => |
| 164 | + 'blackberry' => |
165 | 165 | array ( |
166 | 166 | 'view_format' => 'html', |
167 | 167 | 'search_bar' => 'default', |
— | — | @@ -172,7 +172,7 @@ |
173 | 173 | 'parser' => 'html', |
174 | 174 | 'disable_links' => true, |
175 | 175 | ), |
176 | | - 'netfront' => |
| 176 | + 'netfront' => |
177 | 177 | array ( |
178 | 178 | 'view_format' => 'html', |
179 | 179 | 'search_bar' => 'simple', |
— | — | @@ -184,7 +184,7 @@ |
185 | 185 | 'parser' => 'html', |
186 | 186 | 'disable_links' => true, |
187 | 187 | ), |
188 | | - 'wap2' => |
| 188 | + 'wap2' => |
189 | 189 | array ( |
190 | 190 | 'view_format' => 'html', |
191 | 191 | 'search_bar' => 'simple', |
— | — | @@ -196,7 +196,7 @@ |
197 | 197 | 'parser' => 'html', |
198 | 198 | 'disable_links' => true, |
199 | 199 | ), |
200 | | - 'psp' => |
| 200 | + 'psp' => |
201 | 201 | array ( |
202 | 202 | 'view_format' => 'html', |
203 | 203 | 'search_bar' => 'simple', |
— | — | @@ -208,7 +208,7 @@ |
209 | 209 | 'parser' => 'html', |
210 | 210 | 'disable_links' => true, |
211 | 211 | ), |
212 | | - 'ps3' => |
| 212 | + 'ps3' => |
213 | 213 | array ( |
214 | 214 | 'view_format' => 'html', |
215 | 215 | 'search_bar' => 'simple', |
— | — | @@ -220,7 +220,7 @@ |
221 | 221 | 'parser' => 'html', |
222 | 222 | 'disable_links' => true, |
223 | 223 | ), |
224 | | - 'wii' => |
| 224 | + 'wii' => |
225 | 225 | array ( |
226 | 226 | 'view_format' => 'html', |
227 | 227 | 'search_bar' => 'wii', |
— | — | @@ -232,7 +232,7 @@ |
233 | 233 | 'parser' => 'html', |
234 | 234 | 'disable_links' => true, |
235 | 235 | ), |
236 | | - 'operamini' => |
| 236 | + 'operamini' => |
237 | 237 | array ( |
238 | 238 | 'view_format' => 'html', |
239 | 239 | 'search_bar' => 'simple', |
— | — | @@ -244,7 +244,7 @@ |
245 | 245 | 'parser' => 'html', |
246 | 246 | 'disable_links' => true, |
247 | 247 | ), |
248 | | - 'nokia' => |
| 248 | + 'nokia' => |
249 | 249 | array ( |
250 | 250 | 'view_format' => 'html', |
251 | 251 | 'search_bar' => 'webkit', |
— | — | @@ -256,7 +256,7 @@ |
257 | 257 | 'parser' => 'html', |
258 | 258 | 'disable_links' => true, |
259 | 259 | ), |
260 | | - 'wml' => |
| 260 | + 'wml' => |
261 | 261 | array ( |
262 | 262 | 'view_format' => 'wml', |
263 | 263 | 'search_bar' => 'wml', |
— | — | @@ -266,15 +266,15 @@ |
267 | 267 | ); |
268 | 268 | return $formats; |
269 | 269 | } |
270 | | - |
| 270 | + |
271 | 271 | public function format( $formatName ) { |
272 | 272 | $format = $this->availableFormats(); |
273 | 273 | return ( isset( $format[$formatName] ) ) ? $format[$formatName] : array(); |
274 | 274 | } |
275 | | - |
| 275 | + |
276 | 276 | public function testFormatName() { |
277 | 277 | $testResults = ''; |
278 | | - |
| 278 | + |
279 | 279 | $userAgents = array(); |
280 | 280 | $userAgents['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'; |
281 | 281 | $userAgents['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'; |
— | — | @@ -292,19 +292,24 @@ |
293 | 293 | $userAgents['wap2'] = 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
294 | 294 | $userAgents['psp'] = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'; |
295 | 295 | $userAgents['ps3'] = 'Mozilla/5.0 (PLAYSTATION 3; 1.00)'; |
296 | | - |
| 296 | + |
297 | 297 | foreach ( $userAgents as $formatName => $userAgent ) { |
298 | 298 | if ( $this->formatName( $userAgent ) === $formatName ) { |
299 | 299 | $result = ' has PASSED!'; |
300 | 300 | } else { |
301 | 301 | $result = ' has FAILED!'; |
302 | 302 | } |
303 | | - |
| 303 | + |
304 | 304 | $testResults .= $formatName . $result . '<br/>' . PHP_EOL; |
305 | 305 | } |
306 | 306 | return $testResults; |
307 | 307 | } |
308 | 308 | |
| 309 | + /** |
| 310 | + * @param $userAgent string |
| 311 | + * @param $acceptHeader string |
| 312 | + * @return string |
| 313 | + */ |
309 | 314 | public function formatName( $userAgent, $acceptHeader = '' ) { |
310 | 315 | $formatName = ''; |
311 | 316 | |
— | — | @@ -333,7 +338,7 @@ |
334 | 339 | } elseif ( preg_match( '/Opera/', $userAgent ) ) { |
335 | 340 | if ( strpos( $userAgent, 'Nintendo Wii' ) !== false ) { |
336 | 341 | $formatName = 'wii'; |
337 | | - } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) { |
| 342 | + } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) { |
338 | 343 | $formatName = 'operamini'; |
339 | 344 | } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) { |
340 | 345 | $formatName = 'iphone'; |
— | — | @@ -361,7 +366,7 @@ |
362 | 367 | } elseif ( preg_match( '/BlackBerry/', $userAgent ) ) { |
363 | 368 | $formatName = 'blackberry'; |
364 | 369 | } |
365 | | - |
| 370 | + |
366 | 371 | if ( $formatName === '' ) { |
367 | 372 | if ( strpos( $acceptHeader, 'application/vnd.wap.xhtml+xml' ) !== false ) { |
368 | 373 | // Should be wap2 or in WURFL xhtmlmp |
Index: trunk/extensions/MobileFrontend/CssDetection.php |
— | — | @@ -11,6 +11,12 @@ |
12 | 12 | |
13 | 13 | class CssDetection { |
14 | 14 | |
| 15 | + /** |
| 16 | + * @param $snippet |
| 17 | + * @param $type |
| 18 | + * @param $rawName |
| 19 | + * @return string |
| 20 | + */ |
15 | 21 | public static function detectIdCssOrTag( $snippet, &$type, &$rawName ) { |
16 | 22 | $output = ''; |
17 | 23 | |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -49,14 +49,21 @@ |
50 | 50 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' ); |
51 | 51 | |
52 | 52 | class ExtMobileFrontend { |
53 | | - const VERSION = '0.5.9'; |
| 53 | + const VERSION = '0.5.10'; |
54 | 54 | |
| 55 | + /** |
| 56 | + * @var DOMDocument |
| 57 | + */ |
55 | 58 | private $doc; |
56 | 59 | |
57 | 60 | public static $messages = array(); |
58 | 61 | |
59 | 62 | public $contentFormat = ''; |
60 | 63 | public $WMLSectionSeperator = '***************************************************************************'; |
| 64 | + |
| 65 | + /** |
| 66 | + * @var Title |
| 67 | + */ |
61 | 68 | public static $title; |
62 | 69 | public static $htmlTitle; |
63 | 70 | public static $dir; |
— | — | @@ -132,15 +139,15 @@ |
133 | 140 | |
134 | 141 | // Need to get copyright footer from skin. The footer changes depending |
135 | 142 | // on whether we're using the WikimediaMessages extension or not. |
136 | | - $skin=$wgUser->getSkin(); |
137 | | - $copyright=$skin->getCopyright(); |
| 143 | + $skin = $wgUser->getSkin(); |
| 144 | + $copyright = $skin->getCopyright(); |
138 | 145 | |
139 | 146 | // Need to stash the results of the "wfMsg" call before the Output Buffering handler |
140 | 147 | // because at this point the database connection is shut down, etc. |
141 | 148 | self::$messages['mobile-frontend-show'] = wfMsg( 'mobile-frontend-show-button' ); |
142 | 149 | self::$messages['mobile-frontend-hide'] = wfMsg( 'mobile-frontend-hide-button' ); |
143 | 150 | self::$messages['mobile-frontend-back-to-top'] = wfMsg( 'mobile-frontend-back-to-top-of-section' ); |
144 | | - self::$messages['mobile-frontend-regular-site'] = wfMsg( 'mobile-frontend-regular-site' ); |
| 151 | + self::$messages['mobile-frontend-regular-site'] = wfMsg( 'mobile-frontend-regular-site' ); |
145 | 152 | self::$messages['mobile-frontend-perm-stop-redirect'] = wfMsg( 'mobile-frontend-perm-stop-redirect' ); |
146 | 153 | self::$messages['mobile-frontend-copyright'] = $copyright; |
147 | 154 | self::$messages['mobile-frontend-home-button'] = wfMsg( 'mobile-frontend-home-button' ); |
— | — | @@ -156,7 +163,7 @@ |
157 | 164 | self::$disableImages = $wgRequest->getText( 'disableImages', 0 ); |
158 | 165 | |
159 | 166 | self::$mainPageUrl = Title::newMainPage()->getLocalUrl(); |
160 | | - self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl(); |
| 167 | + self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl(); |
161 | 168 | |
162 | 169 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
163 | 170 | $uAmd5 = md5($userAgent); |
— | — | @@ -234,7 +241,7 @@ |
235 | 242 | |
236 | 243 | // WURFL documentation: http://wurfl.sourceforge.net/help_doc.php |
237 | 244 | // Determine the kind of markup |
238 | | - if( is_array($props) && $props['preferred_markup'] ) { |
| 245 | + if( is_array( $props ) && $props['preferred_markup'] ) { |
239 | 246 | wfDebug( __METHOD__ . ": preferred markup for this device: " . $props['preferred_markup'] ); |
240 | 247 | // xhtml/html: html_web_3_2, html_web_4_0 |
241 | 248 | // xthml basic/xhtmlmp (wap 2.0): html_wi_w3_xhtmlbasic html_wi_oma_xhtmlmp_1_0 |
— | — | @@ -297,6 +304,7 @@ |
298 | 305 | require( 'views/layout/application.html.php' ); |
299 | 306 | return $applicationHtml; |
300 | 307 | } |
| 308 | + return ''; |
301 | 309 | } |
302 | 310 | |
303 | 311 | private function headingTransformCallbackWML( $matches ) { |
— | — | @@ -344,6 +352,10 @@ |
345 | 353 | return $base; |
346 | 354 | } |
347 | 355 | |
| 356 | + /** |
| 357 | + * @param $s string |
| 358 | + * @return string |
| 359 | + */ |
348 | 360 | public function headingTransform( $s ) { |
349 | 361 | $callback = 'headingTransformCallback'; |
350 | 362 | $callback .= $this->contentFormat; |
Index: trunk/extensions/MobileFrontend/views/layout/application.html.php |
— | — | @@ -2,31 +2,31 @@ |
3 | 3 | global $wgExtensionAssetsPath, $wgAppleTouchIcon; |
4 | 4 | |
5 | 5 | if( $wgAppleTouchIcon !== false ) { |
6 | | - $appleTouchIconTag = Html::element( 'link', array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );; |
| 6 | + $appleTouchIconTag = Html::element( 'link', array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) ); |
7 | 7 | } else { |
8 | 8 | $appleTouchIconTag = ""; |
9 | 9 | } |
10 | 10 | |
11 | 11 | $applicationHtml = <<<EOT |
12 | | -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
13 | | -<html lang='{$code}' dir='{$dir}' xml:lang='{$code}' xmlns='http://www.w3.org/1999/xhtml'> |
14 | | - <head> |
15 | | - <title>{$htmlTitle}</title> |
16 | | - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
17 | | - <link href='{$wgExtensionAssetsPath}/MobileFrontend/stylesheets/{$cssFileName}.css' media='all' rel='Stylesheet' type='text/css' /> |
18 | | - <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> |
19 | | - <meta name = "viewport" content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> |
20 | | - ${appleTouchIconTag} |
21 | | - <script type='text/javascript'> |
| 12 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 13 | +<html lang='{$code}' dir='{$dir}' xml:lang='{$code}' xmlns='http://www.w3.org/1999/xhtml'> |
| 14 | + <head> |
| 15 | + <title>{$htmlTitle}</title> |
| 16 | + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
| 17 | + <link href='{$wgExtensionAssetsPath}/MobileFrontend/stylesheets/{$cssFileName}.css' media='all' rel='Stylesheet' type='text/css' /> |
| 18 | + <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> |
| 19 | + <meta name = "viewport" content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> |
| 20 | + ${appleTouchIconTag} |
| 21 | + <script type='text/javascript'> |
22 | 22 | //<![CDATA[ |
23 | 23 | var title = "{$title}"; |
24 | 24 | function shouldCache() { |
25 | 25 | return true; |
26 | 26 | } |
27 | 27 | //]]> |
28 | | - </script> |
29 | | - <script type="text/javascript" language="javascript" SRC="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/jquery.js"></script> |
30 | | - <script type="text/javascript" language="javascript" SRC="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js"></script> |
| 28 | + </script> |
| 29 | + <script type="text/javascript" language="javascript" SRC="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/jquery.js"></script> |
| 30 | + <script type="text/javascript" language="javascript" SRC="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js"></script> |
31 | 31 | </head> |
32 | 32 | <body> |
33 | 33 | {$searchWebkitHtml} |