r93655 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93654‎ | r93655 | r93656 >
Date:21:11, 1 August 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Whitespace, documentation

Bump version 0.5.10
Modified paths:
  • /trunk/extensions/MobileFrontend/CssDetection.php (modified) (history)
  • /trunk/extensions/MobileFrontend/DeviceDetection.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/views/layout/application.html.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/DeviceDetection.php
@@ -9,14 +9,14 @@
1010 * @licence GNU General Public Licence 2.0 or later
1111 */
1212
13 -// Provides an abstraction for a device
 13+// Provides an abstraction for a device
1414 // A device can select which format a request should recieve and
1515 // may be extended to provide access to particular devices functionality
1616 class DeviceDetection {
17 -
18 - public function availableFormats() {
 17+
 18+ public function availableFormats() {
1919 $formats = array (
20 - 'html' =>
 20+ 'html' =>
2121 array (
2222 'view_format' => 'html',
2323 'search_bar' => 'default',
@@ -28,7 +28,7 @@
2929 'parser' => 'html',
3030 'disable_links' => true,
3131 ),
32 - 'capable' =>
 32+ 'capable' =>
3333 array (
3434 'view_format' => 'html',
3535 'search_bar' => 'default',
@@ -40,7 +40,7 @@
4141 'parser' => 'html',
4242 'disable_links' => true,
4343 ),
44 - 'simplehtml' =>
 44+ 'simplehtml' =>
4545 array (
4646 'view_format' => 'html',
4747 'search_bar' => 'simple',
@@ -52,7 +52,7 @@
5353 'parser' => 'html',
5454 'disable_links' => true,
5555 ),
56 - 'webkit' =>
 56+ 'webkit' =>
5757 array (
5858 'view_format' => 'html',
5959 'search_bar' => 'webkit',
@@ -64,7 +64,7 @@
6565 'parser' => 'html',
6666 'disable_links' => true,
6767 ),
68 - 'webkit_old' =>
 68+ 'webkit_old' =>
6969 array (
7070 'view_format' => 'html',
7171 'search_bar' => 'default',
@@ -76,7 +76,7 @@
7777 'parser' => 'html',
7878 'disable_links' => true,
7979 ),
80 - 'android' =>
 80+ 'android' =>
8181 array (
8282 'view_format' => 'html',
8383 'search_bar' => 'default',
@@ -88,7 +88,7 @@
8989 'parser' => 'html',
9090 'disable_links' => true,
9191 ),
92 - 'iphone' =>
 92+ 'iphone' =>
9393 array (
9494 'view_format' => 'html',
9595 'search_bar' => 'webkit',
@@ -100,7 +100,7 @@
101101 'parser' => 'html',
102102 'disable_links' => true,
103103 ),
104 - 'iphone2' =>
 104+ 'iphone2' =>
105105 array (
106106 'view_format' => 'html',
107107 'search_bar' => 'default',
@@ -112,7 +112,7 @@
113113 'parser' => 'html',
114114 'disable_links' => true,
115115 ),
116 - 'native_iphone' =>
 116+ 'native_iphone' =>
117117 array (
118118 'view_format' => 'html',
119119 'search_bar' => false,
@@ -124,7 +124,7 @@
125125 'parser' => 'html',
126126 'disable_links' => false,
127127 ),
128 - 'palm_pre' =>
 128+ 'palm_pre' =>
129129 array (
130130 'view_format' => 'html',
131131 'search_bar' => 'default',
@@ -136,7 +136,7 @@
137137 'parser' => 'html',
138138 'disable_links' => true,
139139 ),
140 - 'kindle' =>
 140+ 'kindle' =>
141141 array (
142142 'view_format' => 'html',
143143 'search_bar' => 'kindle',
@@ -148,7 +148,7 @@
149149 'parser' => 'html',
150150 'disable_links' => true,
151151 ),
152 - 'kindle2' =>
 152+ 'kindle2' =>
153153 array (
154154 'view_format' => 'html',
155155 'search_bar' => 'kindle',
@@ -160,7 +160,7 @@
161161 'parser' => 'html',
162162 'disable_links' => true,
163163 ),
164 - 'blackberry' =>
 164+ 'blackberry' =>
165165 array (
166166 'view_format' => 'html',
167167 'search_bar' => 'default',
@@ -172,7 +172,7 @@
173173 'parser' => 'html',
174174 'disable_links' => true,
175175 ),
176 - 'netfront' =>
 176+ 'netfront' =>
177177 array (
178178 'view_format' => 'html',
179179 'search_bar' => 'simple',
@@ -184,7 +184,7 @@
185185 'parser' => 'html',
186186 'disable_links' => true,
187187 ),
188 - 'wap2' =>
 188+ 'wap2' =>
189189 array (
190190 'view_format' => 'html',
191191 'search_bar' => 'simple',
@@ -196,7 +196,7 @@
197197 'parser' => 'html',
198198 'disable_links' => true,
199199 ),
200 - 'psp' =>
 200+ 'psp' =>
201201 array (
202202 'view_format' => 'html',
203203 'search_bar' => 'simple',
@@ -208,7 +208,7 @@
209209 'parser' => 'html',
210210 'disable_links' => true,
211211 ),
212 - 'ps3' =>
 212+ 'ps3' =>
213213 array (
214214 'view_format' => 'html',
215215 'search_bar' => 'simple',
@@ -220,7 +220,7 @@
221221 'parser' => 'html',
222222 'disable_links' => true,
223223 ),
224 - 'wii' =>
 224+ 'wii' =>
225225 array (
226226 'view_format' => 'html',
227227 'search_bar' => 'wii',
@@ -232,7 +232,7 @@
233233 'parser' => 'html',
234234 'disable_links' => true,
235235 ),
236 - 'operamini' =>
 236+ 'operamini' =>
237237 array (
238238 'view_format' => 'html',
239239 'search_bar' => 'simple',
@@ -244,7 +244,7 @@
245245 'parser' => 'html',
246246 'disable_links' => true,
247247 ),
248 - 'nokia' =>
 248+ 'nokia' =>
249249 array (
250250 'view_format' => 'html',
251251 'search_bar' => 'webkit',
@@ -256,7 +256,7 @@
257257 'parser' => 'html',
258258 'disable_links' => true,
259259 ),
260 - 'wml' =>
 260+ 'wml' =>
261261 array (
262262 'view_format' => 'wml',
263263 'search_bar' => 'wml',
@@ -266,15 +266,15 @@
267267 );
268268 return $formats;
269269 }
270 -
 270+
271271 public function format( $formatName ) {
272272 $format = $this->availableFormats();
273273 return ( isset( $format[$formatName] ) ) ? $format[$formatName] : array();
274274 }
275 -
 275+
276276 public function testFormatName() {
277277 $testResults = '';
278 -
 278+
279279 $userAgents = array();
280280 $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';
281281 $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 @@
293293 $userAgents['wap2'] = 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1';
294294 $userAgents['psp'] = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)';
295295 $userAgents['ps3'] = 'Mozilla/5.0 (PLAYSTATION 3; 1.00)';
296 -
 296+
297297 foreach ( $userAgents as $formatName => $userAgent ) {
298298 if ( $this->formatName( $userAgent ) === $formatName ) {
299299 $result = ' has PASSED!';
300300 } else {
301301 $result = ' has FAILED!';
302302 }
303 -
 303+
304304 $testResults .= $formatName . $result . '<br/>' . PHP_EOL;
305305 }
306306 return $testResults;
307307 }
308308
 309+ /**
 310+ * @param $userAgent string
 311+ * @param $acceptHeader string
 312+ * @return string
 313+ */
309314 public function formatName( $userAgent, $acceptHeader = '' ) {
310315 $formatName = '';
311316
@@ -333,7 +338,7 @@
334339 } elseif ( preg_match( '/Opera/', $userAgent ) ) {
335340 if ( strpos( $userAgent, 'Nintendo Wii' ) !== false ) {
336341 $formatName = 'wii';
337 - } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) {
 342+ } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) {
338343 $formatName = 'operamini';
339344 } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) {
340345 $formatName = 'iphone';
@@ -361,7 +366,7 @@
362367 } elseif ( preg_match( '/BlackBerry/', $userAgent ) ) {
363368 $formatName = 'blackberry';
364369 }
365 -
 370+
366371 if ( $formatName === '' ) {
367372 if ( strpos( $acceptHeader, 'application/vnd.wap.xhtml+xml' ) !== false ) {
368373 // Should be wap2 or in WURFL xhtmlmp
Index: trunk/extensions/MobileFrontend/CssDetection.php
@@ -11,6 +11,12 @@
1212
1313 class CssDetection {
1414
 15+ /**
 16+ * @param $snippet
 17+ * @param $type
 18+ * @param $rawName
 19+ * @return string
 20+ */
1521 public static function detectIdCssOrTag( $snippet, &$type, &$rawName ) {
1622 $output = '';
1723
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -49,14 +49,21 @@
5050 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' );
5151
5252 class ExtMobileFrontend {
53 - const VERSION = '0.5.9';
 53+ const VERSION = '0.5.10';
5454
 55+ /**
 56+ * @var DOMDocument
 57+ */
5558 private $doc;
5659
5760 public static $messages = array();
5861
5962 public $contentFormat = '';
6063 public $WMLSectionSeperator = '***************************************************************************';
 64+
 65+ /**
 66+ * @var Title
 67+ */
6168 public static $title;
6269 public static $htmlTitle;
6370 public static $dir;
@@ -132,15 +139,15 @@
133140
134141 // Need to get copyright footer from skin. The footer changes depending
135142 // 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();
138145
139146 // Need to stash the results of the "wfMsg" call before the Output Buffering handler
140147 // because at this point the database connection is shut down, etc.
141148 self::$messages['mobile-frontend-show'] = wfMsg( 'mobile-frontend-show-button' );
142149 self::$messages['mobile-frontend-hide'] = wfMsg( 'mobile-frontend-hide-button' );
143150 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' );
145152 self::$messages['mobile-frontend-perm-stop-redirect'] = wfMsg( 'mobile-frontend-perm-stop-redirect' );
146153 self::$messages['mobile-frontend-copyright'] = $copyright;
147154 self::$messages['mobile-frontend-home-button'] = wfMsg( 'mobile-frontend-home-button' );
@@ -156,7 +163,7 @@
157164 self::$disableImages = $wgRequest->getText( 'disableImages', 0 );
158165
159166 self::$mainPageUrl = Title::newMainPage()->getLocalUrl();
160 - self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl();
 167+ self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl();
161168
162169 $userAgent = $_SERVER['HTTP_USER_AGENT'];
163170 $uAmd5 = md5($userAgent);
@@ -234,7 +241,7 @@
235242
236243 // WURFL documentation: http://wurfl.sourceforge.net/help_doc.php
237244 // Determine the kind of markup
238 - if( is_array($props) && $props['preferred_markup'] ) {
 245+ if( is_array( $props ) && $props['preferred_markup'] ) {
239246 wfDebug( __METHOD__ . ": preferred markup for this device: " . $props['preferred_markup'] );
240247 // xhtml/html: html_web_3_2, html_web_4_0
241248 // xthml basic/xhtmlmp (wap 2.0): html_wi_w3_xhtmlbasic html_wi_oma_xhtmlmp_1_0
@@ -297,6 +304,7 @@
298305 require( 'views/layout/application.html.php' );
299306 return $applicationHtml;
300307 }
 308+ return '';
301309 }
302310
303311 private function headingTransformCallbackWML( $matches ) {
@@ -344,6 +352,10 @@
345353 return $base;
346354 }
347355
 356+ /**
 357+ * @param $s string
 358+ * @return string
 359+ */
348360 public function headingTransform( $s ) {
349361 $callback = 'headingTransformCallback';
350362 $callback .= $this->contentFormat;
Index: trunk/extensions/MobileFrontend/views/layout/application.html.php
@@ -2,31 +2,31 @@
33 global $wgExtensionAssetsPath, $wgAppleTouchIcon;
44
55 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 ) );
77 } else {
88 $appleTouchIconTag = "";
99 }
1010
1111 $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'>
2222 //<![CDATA[
2323 var title = "{$title}";
2424 function shouldCache() {
2525 return true;
2626 }
2727 //]]>
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>
3131 </head>
3232 <body>
3333 {$searchWebkitHtml}

Comments

#Comment by Aaron Schulz (talk | contribs)   22:27, 1 August 2011

Why the change to renderDisableMobileSiteXHTML()?

#Comment by Aaron Schulz (talk | contribs)   18:58, 2 August 2011

OK, I guess.

#Comment by TheDJ (talk | contribs)   19:03, 2 August 2011

I guess it's cleaner, but in theory, that return should be unreachable of course. renderDisableMobileSiteXHTML()... If the format is not XHTML, then the function should be renamed :D

Still better safe than sorry.

Status & tagging log