Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/DeviceDetection.php |
— | — | @@ -16,8 +16,7 @@ |
17 | 17 | |
18 | 18 | public function availableFormats() { |
19 | 19 | $formats = array ( |
20 | | - 'html' => |
21 | | - array ( |
| 20 | + 'html' => array ( |
22 | 21 | 'view_format' => 'html', |
23 | 22 | 'search_bar' => 'default', |
24 | 23 | 'footmenu' => 'default', |
— | — | @@ -27,9 +26,8 @@ |
28 | 27 | 'disable_zoom' => true, |
29 | 28 | 'parser' => 'html', |
30 | 29 | 'disable_links' => true, |
31 | | - ), |
32 | | - 'capable' => |
33 | | - array ( |
| 30 | + ), |
| 31 | + 'capable' => array ( |
34 | 32 | 'view_format' => 'html', |
35 | 33 | 'search_bar' => 'default', |
36 | 34 | 'footmenu' => 'default', |
— | — | @@ -39,9 +37,8 @@ |
40 | 38 | 'disable_zoom' => true, |
41 | 39 | 'parser' => 'html', |
42 | 40 | 'disable_links' => true, |
43 | | - ), |
44 | | - 'simplehtml' => |
45 | | - array ( |
| 41 | + ), |
| 42 | + 'simplehtml' => array ( |
46 | 43 | 'view_format' => 'html', |
47 | 44 | 'search_bar' => 'simple', |
48 | 45 | 'footmenu' => 'simple', |
— | — | @@ -51,9 +48,8 @@ |
52 | 49 | 'disable_zoom' => true, |
53 | 50 | 'parser' => 'html', |
54 | 51 | 'disable_links' => true, |
55 | | - ), |
56 | | - 'webkit' => |
57 | | - array ( |
| 52 | + ), |
| 53 | + 'webkit' => array ( |
58 | 54 | 'view_format' => 'html', |
59 | 55 | 'search_bar' => 'webkit', |
60 | 56 | 'footmenu' => 'default', |
— | — | @@ -63,9 +59,8 @@ |
64 | 60 | 'disable_zoom' => true, |
65 | 61 | 'parser' => 'html', |
66 | 62 | 'disable_links' => true, |
67 | | - ), |
68 | | - 'webkit_old' => |
69 | | - array ( |
| 63 | + ), |
| 64 | + 'webkit_old' => array ( |
70 | 65 | 'view_format' => 'html', |
71 | 66 | 'search_bar' => 'default', |
72 | 67 | 'footmenu' => 'default', |
— | — | @@ -75,9 +70,8 @@ |
76 | 71 | 'disable_zoom' => true, |
77 | 72 | 'parser' => 'html', |
78 | 73 | 'disable_links' => true, |
79 | | - ), |
80 | | - 'android' => |
81 | | - array ( |
| 74 | + ), |
| 75 | + 'android' => array ( |
82 | 76 | 'view_format' => 'html', |
83 | 77 | 'search_bar' => 'default', |
84 | 78 | 'footmenu' => 'default', |
— | — | @@ -87,9 +81,8 @@ |
88 | 82 | 'disable_zoom' => false, |
89 | 83 | 'parser' => 'html', |
90 | 84 | 'disable_links' => true, |
91 | | - ), |
92 | | - 'iphone' => |
93 | | - array ( |
| 85 | + ), |
| 86 | + 'iphone' => array ( |
94 | 87 | 'view_format' => 'html', |
95 | 88 | 'search_bar' => 'webkit', |
96 | 89 | 'footmenu' => 'default', |
— | — | @@ -99,9 +92,8 @@ |
100 | 93 | 'disable_zoom' => true, |
101 | 94 | 'parser' => 'html', |
102 | 95 | 'disable_links' => true, |
103 | | - ), |
104 | | - 'iphone2' => |
105 | | - array ( |
| 96 | + ), |
| 97 | + 'iphone2' => array ( |
106 | 98 | 'view_format' => 'html', |
107 | 99 | 'search_bar' => 'default', |
108 | 100 | 'footmenu' => 'default', |
— | — | @@ -111,9 +103,8 @@ |
112 | 104 | 'disable_zoom' => true, |
113 | 105 | 'parser' => 'html', |
114 | 106 | 'disable_links' => true, |
115 | | - ), |
116 | | - 'native_iphone' => |
117 | | - array ( |
| 107 | + ), |
| 108 | + 'native_iphone' => array ( |
118 | 109 | 'view_format' => 'html', |
119 | 110 | 'search_bar' => false, |
120 | 111 | 'footmenu' => 'default', |
— | — | @@ -123,9 +114,8 @@ |
124 | 115 | 'disable_zoom' => true, |
125 | 116 | 'parser' => 'html', |
126 | 117 | 'disable_links' => false, |
127 | | - ), |
128 | | - 'palm_pre' => |
129 | | - array ( |
| 118 | + ), |
| 119 | + 'palm_pre' => array ( |
130 | 120 | 'view_format' => 'html', |
131 | 121 | 'search_bar' => 'default', |
132 | 122 | 'footmenu' => 'default', |
— | — | @@ -135,9 +125,8 @@ |
136 | 126 | 'disable_zoom' => true, |
137 | 127 | 'parser' => 'html', |
138 | 128 | 'disable_links' => true, |
139 | | - ), |
140 | | - 'kindle' => |
141 | | - array ( |
| 129 | + ), |
| 130 | + 'kindle' => array ( |
142 | 131 | 'view_format' => 'html', |
143 | 132 | 'search_bar' => 'kindle', |
144 | 133 | 'footmenu' => 'default', |
— | — | @@ -147,9 +136,8 @@ |
148 | 137 | 'disable_zoom' => true, |
149 | 138 | 'parser' => 'html', |
150 | 139 | 'disable_links' => true, |
151 | | - ), |
152 | | - 'kindle2' => |
153 | | - array ( |
| 140 | + ), |
| 141 | + 'kindle2' => array ( |
154 | 142 | 'view_format' => 'html', |
155 | 143 | 'search_bar' => 'kindle', |
156 | 144 | 'footmenu' => 'default', |
— | — | @@ -159,9 +147,8 @@ |
160 | 148 | 'disable_zoom' => true, |
161 | 149 | 'parser' => 'html', |
162 | 150 | 'disable_links' => true, |
163 | | - ), |
164 | | - 'blackberry' => |
165 | | - array ( |
| 151 | + ), |
| 152 | + 'blackberry' => array ( |
166 | 153 | 'view_format' => 'html', |
167 | 154 | 'search_bar' => 'default', |
168 | 155 | 'footmenu' => 'default', |
— | — | @@ -171,9 +158,8 @@ |
172 | 159 | 'disable_zoom' => true, |
173 | 160 | 'parser' => 'html', |
174 | 161 | 'disable_links' => true, |
175 | | - ), |
176 | | - 'netfront' => |
177 | | - array ( |
| 162 | + ), |
| 163 | + 'netfront' => array ( |
178 | 164 | 'view_format' => 'html', |
179 | 165 | 'search_bar' => 'simple', |
180 | 166 | 'footmenu' => 'simple', |
— | — | @@ -183,9 +169,8 @@ |
184 | 170 | 'disable_zoom' => true, |
185 | 171 | 'parser' => 'html', |
186 | 172 | 'disable_links' => true, |
187 | | - ), |
188 | | - 'wap2' => |
189 | | - array ( |
| 173 | + ), |
| 174 | + 'wap2' => array ( |
190 | 175 | 'view_format' => 'html', |
191 | 176 | 'search_bar' => 'simple', |
192 | 177 | 'footmenu' => 'simple', |
— | — | @@ -195,9 +180,8 @@ |
196 | 181 | 'disable_zoom' => true, |
197 | 182 | 'parser' => 'html', |
198 | 183 | 'disable_links' => true, |
199 | | - ), |
200 | | - 'psp' => |
201 | | - array ( |
| 184 | + ), |
| 185 | + 'psp' => array ( |
202 | 186 | 'view_format' => 'html', |
203 | 187 | 'search_bar' => 'simple', |
204 | 188 | 'footmenu' => 'simple', |
— | — | @@ -207,9 +191,8 @@ |
208 | 192 | 'disable_zoom' => true, |
209 | 193 | 'parser' => 'html', |
210 | 194 | 'disable_links' => true, |
211 | | - ), |
212 | | - 'ps3' => |
213 | | - array ( |
| 195 | + ), |
| 196 | + 'ps3' => array ( |
214 | 197 | 'view_format' => 'html', |
215 | 198 | 'search_bar' => 'simple', |
216 | 199 | 'footmenu' => 'simple', |
— | — | @@ -219,9 +202,8 @@ |
220 | 203 | 'disable_zoom' => true, |
221 | 204 | 'parser' => 'html', |
222 | 205 | 'disable_links' => true, |
223 | | - ), |
224 | | - 'wii' => |
225 | | - array ( |
| 206 | + ), |
| 207 | + 'wii' => array ( |
226 | 208 | 'view_format' => 'html', |
227 | 209 | 'search_bar' => 'wii', |
228 | 210 | 'footmenu' => 'default', |
— | — | @@ -231,9 +213,8 @@ |
232 | 214 | 'disable_zoom' => true, |
233 | 215 | 'parser' => 'html', |
234 | 216 | 'disable_links' => true, |
235 | | - ), |
236 | | - 'operamini' => |
237 | | - array ( |
| 217 | + ), |
| 218 | + 'operamini' => array ( |
238 | 219 | 'view_format' => 'html', |
239 | 220 | 'search_bar' => 'simple', |
240 | 221 | 'footmenu' => 'simple', |
— | — | @@ -243,9 +224,8 @@ |
244 | 225 | 'disable_zoom' => true, |
245 | 226 | 'parser' => 'html', |
246 | 227 | 'disable_links' => true, |
247 | | - ), |
248 | | - 'nokia' => |
249 | | - array ( |
| 228 | + ), |
| 229 | + 'nokia' => array ( |
250 | 230 | 'view_format' => 'html', |
251 | 231 | 'search_bar' => 'webkit', |
252 | 232 | 'footmenu' => 'default', |
— | — | @@ -255,15 +235,14 @@ |
256 | 236 | 'disable_zoom' => true, |
257 | 237 | 'parser' => 'html', |
258 | 238 | 'disable_links' => true, |
259 | | - ), |
260 | | - 'wml' => |
261 | | - array ( |
| 239 | + ), |
| 240 | + 'wml' => array ( |
262 | 241 | 'view_format' => 'wml', |
263 | 242 | 'search_bar' => 'wml', |
264 | 243 | 'supports_javascript' => false, |
265 | 244 | 'parser' => 'wml', |
266 | | - ), |
267 | | - ); |
| 245 | + ), |
| 246 | + ); |
268 | 247 | return $formats; |
269 | 248 | } |
270 | 249 | |
— | — | @@ -315,6 +294,9 @@ |
316 | 295 | |
317 | 296 | if ( preg_match( '/Android/', $userAgent ) ) { |
318 | 297 | $formatName = 'android'; |
| 298 | + if ( strpos( $userAgent, 'Opera Mini' ) !== false ) { |
| 299 | + $formatName = 'operamini'; |
| 300 | + } |
319 | 301 | } elseif ( preg_match( '/iPhone.* Safari/', $userAgent ) ) { |
320 | 302 | if ( strpos( $userAgent, 'iPhone OS 2' ) !== false ) { |
321 | 303 | $formatName = 'iphone2'; |
— | — | @@ -362,7 +344,7 @@ |
363 | 345 | } elseif ( preg_match( '/PLAYSTATION 3/', $userAgent ) ) { |
364 | 346 | $formatName = 'ps3'; |
365 | 347 | } elseif ( preg_match( '/SAMSUNG/', $userAgent ) ) { |
366 | | - $formatName = 'capable'; |
| 348 | + $formatName = 'capable'; |
367 | 349 | } elseif ( preg_match( '/BlackBerry/', $userAgent ) ) { |
368 | 350 | $formatName = 'blackberry'; |
369 | 351 | } |
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | ); |
67 | 67 | |
68 | 68 | class ExtMobileFrontend { |
69 | | - const VERSION = '0.5.46'; |
| 69 | + const VERSION = '0.5.50'; |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @var DOMDocument |
— | — | @@ -103,6 +103,36 @@ |
104 | 104 | public static $disableMobileSiteURL; |
105 | 105 | public static $viewNormalSiteURL; |
106 | 106 | public static $currentURL; |
| 107 | + |
| 108 | + public static $messageKeys = array( |
| 109 | + 'mobile-frontend-show-button', |
| 110 | + 'mobile-frontend-hide-button', |
| 111 | + 'mobile-frontend-back-to-top-of-section', |
| 112 | + 'mobile-frontend-regular-site', |
| 113 | + 'mobile-frontend-perm-stop-redirect', |
| 114 | + 'mobile-frontend-home-button', |
| 115 | + 'mobile-frontend-random-button', |
| 116 | + 'mobile-frontend-are-you-sure', |
| 117 | + 'mobile-frontend-explain-disable', |
| 118 | + 'mobile-frontend-disable-button', |
| 119 | + 'mobile-frontend-back-button', |
| 120 | + 'mobile-frontend-opt-in-message', |
| 121 | + 'mobile-frontend-opt-in-yes-button', |
| 122 | + 'mobile-frontend-opt-in-no-button', |
| 123 | + 'mobile-frontend-opt-in-title', |
| 124 | + 'mobile-frontend-opt-out-message', |
| 125 | + 'mobile-frontend-opt-out-yes-button', |
| 126 | + 'mobile-frontend-opt-out-no-button', |
| 127 | + 'mobile-frontend-opt-out-title', |
| 128 | + 'mobile-frontend-opt-in-explain', |
| 129 | + 'mobile-frontend-opt-out-explain', |
| 130 | + 'mobile-frontend-disable-images', |
| 131 | + 'mobile-frontend-wml-continue', |
| 132 | + 'mobile-frontend-wml-back', |
| 133 | + 'mobile-frontend-enable-images', |
| 134 | + 'mobile-frontend-featured-article', |
| 135 | + 'mobile-frontend-news-items', |
| 136 | + ); |
107 | 137 | |
108 | 138 | public $itemsToRemove = array( |
109 | 139 | '#contentSub', # redirection notice |
— | — | @@ -118,7 +148,7 @@ |
119 | 149 | 'form', |
120 | 150 | 'div.sister-project', |
121 | 151 | 'script', |
122 | | - 'div.magnify', # stupid magnify thing |
| 152 | + 'div.magnify', # magnify object |
123 | 153 | '.editsection', |
124 | 154 | 'span.t', |
125 | 155 | 'sup[style*="help"]', |
— | — | @@ -139,18 +169,20 @@ |
140 | 170 | |
141 | 171 | public function addMobileFooter( &$obj, &$tpl ) { |
142 | 172 | global $wgRequest; |
| 173 | + wfProfileIn( __METHOD__ ); |
143 | 174 | $footerlinks = $tpl->data['footerlinks']; |
144 | 175 | $mobileViewUrl = $wgRequest->escapeAppendQuery( 'useformat=mobile' ); |
145 | 176 | |
146 | 177 | $tpl->set('mobileview', "<a href='{$mobileViewUrl}'>".wfMsg( 'mobile-frontend-view')."</a>"); |
147 | 178 | $footerlinks['places'][] = 'mobileview'; |
148 | 179 | $tpl->set('footerlinks', $footerlinks); |
149 | | - |
| 180 | + wfProfileOut( __METHOD__ ); |
150 | 181 | return true; |
151 | 182 | } |
152 | 183 | |
153 | 184 | public function getMsg() { |
154 | 185 | global $wgUser, $wgContLang, $wgRequest; |
| 186 | + wfProfileIn( __METHOD__ ); |
155 | 187 | |
156 | 188 | self::$disableImagesURL = $wgRequest->escapeAppendQuery( 'disableImages=1' ); |
157 | 189 | self::$enableImagesURL = $wgRequest->escapeAppendQuery( 'enableImages=1' ); |
— | — | @@ -162,40 +194,19 @@ |
163 | 195 | $copyright = $skin->getCopyright(); |
164 | 196 | // Need to stash the results of the "wfMsg" call before the Output Buffering handler |
165 | 197 | // because at this point the database connection is shut down, etc. |
166 | | - self::$messages['mobile-frontend-show'] = wfMsg( 'mobile-frontend-show-button' ); |
167 | | - self::$messages['mobile-frontend-hide'] = wfMsg( 'mobile-frontend-hide-button' ); |
168 | | - self::$messages['mobile-frontend-back-to-top'] = wfMsg( 'mobile-frontend-back-to-top-of-section' ); |
169 | | - self::$messages['mobile-frontend-regular-site'] = wfMsg( 'mobile-frontend-regular-site' ); |
170 | | - self::$messages['mobile-frontend-perm-stop-redirect'] = wfMsg( 'mobile-frontend-perm-stop-redirect' ); |
| 198 | + |
171 | 199 | self::$messages['mobile-frontend-copyright'] = $copyright; |
172 | | - self::$messages['mobile-frontend-home-button'] = wfMsg( 'mobile-frontend-home-button' ); |
173 | | - self::$messages['mobile-frontend-random-button'] = wfMsg( 'mobile-frontend-random-button' ); |
174 | | - self::$messages['mobile-frontend-are-you-sure'] = wfMsg( 'mobile-frontend-are-you-sure' ); |
175 | | - self::$messages['mobile-frontend-explain-disable'] = wfMsg( 'mobile-frontend-explain-disable' ); |
176 | | - self::$messages['mobile-frontend-disable-button'] = wfMsg( 'mobile-frontend-disable-button' ); |
177 | | - self::$messages['mobile-frontend-back-button'] = wfMsg( 'mobile-frontend-back-button' ); |
178 | | - self::$messages['mobile-frontend-opt-in-message'] = wfMsg( 'mobile-frontend-opt-in-message' ); |
179 | | - self::$messages['mobile-frontend-opt-in-yes-button'] = wfMsg( 'mobile-frontend-opt-in-yes-button' ); |
180 | | - self::$messages['mobile-frontend-opt-in-no-button'] = wfMsg( 'mobile-frontend-opt-in-no-button' ); |
181 | | - self::$messages['mobile-frontend-opt-in-title'] = wfMsg( 'mobile-frontend-opt-in-title' ); |
182 | | - self::$messages['mobile-frontend-opt-out-message'] = wfMsg( 'mobile-frontend-opt-out-message' ); |
183 | | - self::$messages['mobile-frontend-opt-out-yes-button'] = wfMsg( 'mobile-frontend-opt-out-yes-button' ); |
184 | | - self::$messages['mobile-frontend-opt-out-no-button'] = wfMsg( 'mobile-frontend-opt-out-no-button' ); |
185 | | - self::$messages['mobile-frontend-opt-out-title'] = wfMsg( 'mobile-frontend-opt-out-title' ); |
186 | | - self::$messages['mobile-frontend-opt-in-explain'] = wfMsg( 'mobile-frontend-opt-in-explain' ); |
187 | | - self::$messages['mobile-frontend-opt-out-explain'] = wfMsg( 'mobile-frontend-opt-out-explain' ); |
188 | | - self::$messages['mobile-frontend-disable-images'] = wfMsg( 'mobile-frontend-disable-images' ); |
189 | | - self::$messages['mobile-frontend-wml-continue'] = wfMsg( 'mobile-frontend-wml-continue' ); |
190 | | - self::$messages['mobile-frontend-wml-back'] = wfMsg( 'mobile-frontend-wml-back' ); |
191 | | - self::$messages['mobile-frontend-enable-images'] = wfMsg( 'mobile-frontend-enable-images' ); |
192 | | - self::$messages['mobile-frontend-featured-article'] = wfMsg( 'mobile-frontend-featured-article' ); |
193 | | - self::$messages['mobile-frontend-news-items'] = wfMsg( 'mobile-frontend-news-items' ); |
| 200 | + |
| 201 | + foreach ( self::$messageKeys as $messageKey ) { |
| 202 | + self::$messages[$messageKey] = wfMsg( $messageKey ); |
| 203 | + } |
194 | 204 | |
195 | 205 | self::$dir = $wgContLang->getDir(); |
196 | 206 | self::$code = $wgContLang->getCode(); |
197 | 207 | |
198 | 208 | self::$mainPageUrl = Title::newMainPage()->getLocalUrl(); |
199 | 209 | self::$randomPageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalUrl(); |
| 210 | + wfProfileOut( __METHOD__ ); |
200 | 211 | } |
201 | 212 | |
202 | 213 | /** |
— | — | @@ -205,7 +216,7 @@ |
206 | 217 | */ |
207 | 218 | public function beforePageDisplayHTML( &$out, &$text ) { |
208 | 219 | global $wgContLang, $wgRequest, $wgMemc, $wgUser; |
209 | | - |
| 220 | + wfProfileIn( __METHOD__ ); |
210 | 221 | // The title |
211 | 222 | self::$title = $out->getTitle(); |
212 | 223 | |
— | — | @@ -281,10 +292,18 @@ |
282 | 293 | self::$search = $wgRequest->getText( 'search' ); |
283 | 294 | self::$callback = $wgRequest->getText( 'callback' ); |
284 | 295 | self::$searchField = $wgRequest->getText( 'search', '' ); |
| 296 | + |
| 297 | + $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
285 | 298 | |
286 | 299 | $acceptHeader = $_SERVER["HTTP_ACCEPT"]; |
287 | 300 | $device = new DeviceDetection(); |
288 | | - $formatName = $device->formatName( $userAgent, $acceptHeader ); |
| 301 | + |
| 302 | + if ( !empty( $xDevice ) ) { |
| 303 | + $formatName = $xDevice; |
| 304 | + } else { |
| 305 | + $formatName = $device->formatName( $userAgent, $acceptHeader ); |
| 306 | + } |
| 307 | + |
289 | 308 | self::$device = $device->format( $formatName ); |
290 | 309 | |
291 | 310 | if ( self::$device['view_format'] === 'wml' ) { |
— | — | @@ -300,6 +319,7 @@ |
301 | 320 | if ( $mobileAction == 'disable_mobile_site' ) { |
302 | 321 | if ( $this->contentFormat == 'XHTML' ) { |
303 | 322 | echo $this->renderDisableMobileSiteXHTML(); |
| 323 | + wfProfileOut( __METHOD__ ); |
304 | 324 | exit(); |
305 | 325 | } |
306 | 326 | } |
— | — | @@ -307,6 +327,7 @@ |
308 | 328 | if ( $mobileAction == 'opt_in_mobile_site' ) { |
309 | 329 | if ( $this->contentFormat == 'XHTML' ) { |
310 | 330 | echo $this->renderOptInMobileSiteXHTML(); |
| 331 | + wfProfileOut( __METHOD__ ); |
311 | 332 | exit(); |
312 | 333 | } |
313 | 334 | } |
— | — | @@ -314,6 +335,7 @@ |
315 | 336 | if ( $mobileAction == 'opt_out_mobile_site' ) { |
316 | 337 | if ( $this->contentFormat == 'XHTML' ) { |
317 | 338 | echo $this->renderOptOutMobileSiteXHTML(); |
| 339 | + wfProfileOut( __METHOD__ ); |
318 | 340 | exit(); |
319 | 341 | } |
320 | 342 | } |
— | — | @@ -321,7 +343,7 @@ |
322 | 344 | if ( $mobileAction == 'opt_in_cookie' ) { |
323 | 345 | $this->setOptInOutCookie( '1' ); |
324 | 346 | $this->disableCaching(); |
325 | | - $location = Title::newMainPage()->getFullURL(); |
| 347 | + $location = wfExpandUrl( Title::newMainPage()->getFullURL(), PROTO_CURRENT ); |
326 | 348 | $wgRequest->response()->header( 'Location: ' . $location ); |
327 | 349 | } |
328 | 350 | |
— | — | @@ -352,8 +374,6 @@ |
353 | 375 | |
354 | 376 | // Determine |
355 | 377 | |
356 | | - $xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ? $_SERVER['HTTP_X_DEVICE'] : ''; |
357 | | - |
358 | 378 | if (self::$useFormat === 'mobile' || |
359 | 379 | self::$useFormat === 'mobile-wap' || |
360 | 380 | !empty( $xDevice ) ) { |
— | — | @@ -366,49 +386,59 @@ |
367 | 387 | } |
368 | 388 | } |
369 | 389 | |
| 390 | + wfProfileOut( __METHOD__ ); |
370 | 391 | return true; |
371 | 392 | } |
372 | 393 | |
373 | 394 | private function setOptInOutCookie( $value ) { |
374 | 395 | global $wgCookieDomain, $wgRequest; |
| 396 | + wfProfileIn( __METHOD__ ); |
375 | 397 | $tempWgCookieDomain = $wgCookieDomain; |
376 | 398 | $wgCookieDomain = $this->getBaseDomain(); |
377 | 399 | $wgRequest->response()->setcookie( 'optin', $value ); |
378 | 400 | $wgCookieDomain = $tempWgCookieDomain; |
| 401 | + wfProfileOut( __METHOD__ ); |
379 | 402 | } |
380 | 403 | |
381 | 404 | private function getBaseDomain() { |
| 405 | + wfProfileIn( __METHOD__ ); |
382 | 406 | //Validates value as IP address |
383 | 407 | if( !IP::isValid( $_SERVER['HTTP_HOST'] ) ) { |
384 | 408 | $domainParts = explode( '.', $_SERVER['HTTP_HOST'] ); |
385 | 409 | $domainParts = array_reverse( $domainParts ); |
386 | 410 | //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included. |
| 411 | + wfProfileOut( __METHOD__ ); |
387 | 412 | return '.' . $domainParts[1] . '.' . $domainParts[0]; |
388 | 413 | } else { |
| 414 | + wfProfileOut( __METHOD__ ); |
389 | 415 | return $_SERVER['HTTP_HOST']; |
390 | 416 | } |
391 | 417 | } |
392 | 418 | |
393 | 419 | private function disableCaching() { |
394 | 420 | global $wgRequest; |
| 421 | + wfProfileIn( __METHOD__ ); |
395 | 422 | if ( isset( $_SERVER['HTTP_VIA'] ) && |
396 | 423 | stripos( $_SERVER['HTTP_VIA'], '.wikimedia.org:3128' ) !== false ) { |
397 | 424 | $wgRequest->response()->header( 'Cache-Control: no-cache, must-revalidate' ); |
398 | 425 | $wgRequest->response()->header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); |
399 | 426 | $wgRequest->response()->header( 'Pragma: no-cache' ); |
400 | 427 | } |
| 428 | + wfProfileOut( __METHOD__ ); |
401 | 429 | } |
402 | 430 | |
403 | 431 | private function sendXDeviceVaryHeader() { |
404 | 432 | global $wgOut, $wgRequest; |
405 | | - |
| 433 | + wfProfileIn( __METHOD__ ); |
406 | 434 | if ( !empty( $_SERVER['HTTP_X_DEVICE'] ) ) { |
407 | 435 | $wgRequest->response()->header( 'X-Device: ' . $_SERVER['HTTP_X_DEVICE'] ); |
408 | 436 | $wgOut->addVaryHeader( 'X-Device' ); |
409 | 437 | } |
| 438 | + wfProfileOut( __METHOD__ ); |
410 | 439 | } |
411 | 440 | |
412 | 441 | private function renderOptInMobileSiteXHTML() { |
| 442 | + wfProfileIn( __METHOD__ ); |
413 | 443 | if ( $this->contentFormat == 'XHTML' ) { |
414 | 444 | $this->getMsg(); |
415 | 445 | $yesButton = self::$messages['mobile-frontend-opt-in-yes-button']; |
— | — | @@ -421,12 +451,15 @@ |
422 | 452 | require( 'views/information/optin.html.php' ); |
423 | 453 | $contentHtml = $optInHtml; |
424 | 454 | require( 'views/layout/application.html.php' ); |
| 455 | + wfProfileOut( __METHOD__ ); |
425 | 456 | return $applicationHtml; |
426 | 457 | } |
| 458 | + wfProfileOut( __METHOD__ ); |
427 | 459 | return ''; |
428 | 460 | } |
429 | 461 | |
430 | 462 | private function renderOptOutMobileSiteXHTML() { |
| 463 | + wfProfileIn( __METHOD__ ); |
431 | 464 | if ( $this->contentFormat == 'XHTML' ) { |
432 | 465 | $this->getMsg(); |
433 | 466 | $yesButton = self::$messages['mobile-frontend-opt-out-yes-button']; |
— | — | @@ -439,12 +472,15 @@ |
440 | 473 | require( 'views/information/optout.html.php' ); |
441 | 474 | $contentHtml = $optOutHtml; |
442 | 475 | require( 'views/layout/application.html.php' ); |
| 476 | + wfProfileOut( __METHOD__ ); |
443 | 477 | return $applicationHtml; |
444 | 478 | } |
| 479 | + wfProfileOut( __METHOD__ ); |
445 | 480 | return ''; |
446 | 481 | } |
447 | 482 | |
448 | 483 | private function renderDisableMobileSiteXHTML() { |
| 484 | + wfProfileIn( __METHOD__ ); |
449 | 485 | if ( $this->contentFormat == 'XHTML' ) { |
450 | 486 | $this->getMsg(); |
451 | 487 | $areYouSure = self::$messages['mobile-frontend-are-you-sure']; |
— | — | @@ -458,12 +494,15 @@ |
459 | 495 | require( 'views/information/disable.html.php' ); |
460 | 496 | $contentHtml = $disableHtml; |
461 | 497 | require( 'views/layout/application.html.php' ); |
| 498 | + wfProfileOut( __METHOD__ ); |
462 | 499 | return $applicationHtml; |
463 | 500 | } |
| 501 | + wfProfileOut( __METHOD__ ); |
464 | 502 | return ''; |
465 | 503 | } |
466 | 504 | |
467 | 505 | private function headingTransformCallbackWML( $matches ) { |
| 506 | + wfProfileIn( __METHOD__ ); |
468 | 507 | static $headings = 0; |
469 | 508 | ++$headings; |
470 | 509 | |
— | — | @@ -471,12 +510,12 @@ |
472 | 511 | "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>"; |
473 | 512 | |
474 | 513 | self::$headings = $headings; |
475 | | - |
| 514 | + wfProfileOut( __METHOD__ ); |
476 | 515 | return $base; |
477 | 516 | } |
478 | 517 | |
479 | 518 | private function headingTransformCallbackXHTML( $matches ) { |
480 | | - |
| 519 | + wfProfileIn( __METHOD__ ); |
481 | 520 | if ( isset( $matches[0] ) ) { |
482 | 521 | preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches); |
483 | 522 | } |
— | — | @@ -484,27 +523,48 @@ |
485 | 524 | $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : ''; |
486 | 525 | |
487 | 526 | static $headings = 0; |
488 | | - $show = self::$messages['mobile-frontend-show']; |
489 | | - $hide = self::$messages['mobile-frontend-hide']; |
490 | | - $backToTop = self::$messages['mobile-frontend-back-to-top']; |
| 527 | + $show = self::$messages['mobile-frontend-show-button']; |
| 528 | + $hide = self::$messages['mobile-frontend-hide-button']; |
| 529 | + $backToTop = self::$messages['mobile-frontend-back-to-top-of-section']; |
491 | 530 | ++$headings; |
492 | 531 | // Back to top link |
493 | | - $base = "<div class='section_anchors' id='anchor_" . intval( $headings - 1 ) . |
494 | | - "'><a href='#section_" . intval( $headings - 1 ) . |
495 | | - "' class='back_to_top'>↑ {$backToTop}</a></div>"; |
| 532 | + $base = Html::openElement( 'div', |
| 533 | + array( 'id' => 'anchor_' . intval( $headings - 1 ), |
| 534 | + 'class' => 'section_anchors', ) |
| 535 | + ) . |
| 536 | + Html::rawElement( 'a', |
| 537 | + array( 'href' => '#section_' . intval( $headings - 1 ), |
| 538 | + 'class' => 'back_to_top' ), |
| 539 | + '↑' . $backToTop ) . |
| 540 | + Html::closeElement( 'div' ); |
496 | 541 | // generate the HTML we are going to inject |
497 | | - $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button>" . |
498 | | - "<button class='section_heading hide' section_id='{$headings}'>{$hide}</button>"; |
499 | | - $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span id='{$headlineId}'>" . |
500 | | - "{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>"; |
| 542 | + $buttons = Html::element( 'button', |
| 543 | + array('class' => 'section_heading show', |
| 544 | + 'section_id' => $headings ), |
| 545 | + $show ) . |
| 546 | + Html::element( 'button', |
| 547 | + array('class' => 'section_heading hide', |
| 548 | + 'section_id' => $headings ), |
| 549 | + $hide ); |
| 550 | + $base .= Html::openElement( 'h2', |
| 551 | + array('class' => 'section_heading', |
| 552 | + 'id' => 'section_' . $headings) ) . |
| 553 | + $buttons . |
| 554 | + Html::element( 'span', |
| 555 | + array( 'id' => $headlineId), |
| 556 | + $matches[2] ) . |
| 557 | + Html::closeElement( 'h2' ) . |
| 558 | + Html::openElement( 'div', |
| 559 | + array('class' => 'content_block', |
| 560 | + 'id' => 'content_' . $headings) ); |
501 | 561 | |
502 | 562 | if ( $headings > 1 ) { |
503 | 563 | // Close it up here |
504 | | - $base = '</div>' . $base; |
| 564 | + $base = Html::closeElement( 'div' ) . $base; |
505 | 565 | } |
506 | 566 | |
507 | 567 | self::$headings = $headings; |
508 | | - |
| 568 | + wfProfileOut( __METHOD__ ); |
509 | 569 | return $base; |
510 | 570 | } |
511 | 571 | |
— | — | @@ -513,6 +573,7 @@ |
514 | 574 | * @return string |
515 | 575 | */ |
516 | 576 | public function headingTransform( $s ) { |
| 577 | + wfProfileIn( __METHOD__ ); |
517 | 578 | $callback = 'headingTransformCallback'; |
518 | 579 | $callback .= $this->contentFormat; |
519 | 580 | |
— | — | @@ -533,15 +594,16 @@ |
534 | 595 | $s |
535 | 596 | ); |
536 | 597 | } |
537 | | - |
| 598 | + wfProfileOut( __METHOD__ ); |
538 | 599 | return $s; |
539 | 600 | } |
540 | 601 | |
541 | 602 | private function createWMLCard( $s ) { |
| 603 | + wfProfileIn( __METHOD__ ); |
542 | 604 | $segments = explode( $this->WMLSectionSeperator, $s ); |
543 | 605 | $card = ''; |
544 | 606 | $idx = 0; |
545 | | - $requestedSegment = self::$requestedSegment; |
| 607 | + $requestedSegment = htmlspecialchars( self::$requestedSegment ); |
546 | 608 | $title = htmlspecialchars( self::$title->getText() ); |
547 | 609 | |
548 | 610 | $card .= "<card id='{$idx}' title='{$title}'><p>{$segments[$requestedSegment]}</p>"; |
— | — | @@ -563,11 +625,13 @@ |
564 | 626 | } |
565 | 627 | |
566 | 628 | $card .= '</card>'; |
| 629 | + wfProfileOut( __METHOD__ ); |
567 | 630 | return $card; |
568 | 631 | } |
569 | 632 | |
570 | 633 | private function parseItemsToRemove() { |
571 | 634 | global $wgMFRemovableClasses; |
| 635 | + wfProfileIn( __METHOD__ ); |
572 | 636 | $itemToRemoveRecords = array(); |
573 | 637 | |
574 | 638 | foreach ( array_merge( $this->itemsToRemove, $wgMFRemovableClasses ) |
— | — | @@ -578,11 +642,13 @@ |
579 | 643 | CssDetection::detectIdCssOrTag( $itemToRemove, $type, $rawName ); |
580 | 644 | $itemToRemoveRecords[$type][] = $rawName; |
581 | 645 | } |
582 | | - |
| 646 | + |
| 647 | + wfProfileOut( __METHOD__ ); |
583 | 648 | return $itemToRemoveRecords; |
584 | 649 | } |
585 | 650 | |
586 | 651 | public function DOMParseMainPage( $html ) { |
| 652 | + wfProfileIn( __METHOD__ ); |
587 | 653 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
588 | 654 | libxml_use_internal_errors( true ); |
589 | 655 | $this->mainPage = new DOMDocument(); |
— | — | @@ -613,13 +679,13 @@ |
614 | 680 | } |
615 | 681 | |
616 | 682 | $contentHtml = $this->mainPage->saveXML( $content, LIBXML_NOEMPTYTAG ); |
617 | | - |
| 683 | + wfProfileOut( __METHOD__ ); |
618 | 684 | return $contentHtml; |
619 | 685 | } |
620 | 686 | |
621 | 687 | public function DOMParse( $html ) { |
622 | 688 | global $wgSitename; |
623 | | - |
| 689 | + wfProfileIn( __METHOD__ ); |
624 | 690 | $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); |
625 | 691 | libxml_use_internal_errors( true ); |
626 | 692 | $this->doc = new DOMDocument(); |
— | — | @@ -756,18 +822,20 @@ |
757 | 823 | header( 'Content-Type: application/json' ); |
758 | 824 | header( 'Content-Disposition: attachment; filename="data.js";' ); |
759 | 825 | $json_data = array(); |
760 | | - $json_data['title'] = self::$title->getText(); |
| 826 | + $json_data['title'] = htmlspecialchars ( self::$title->getText() ); |
761 | 827 | $json_data['html'] = $contentHtml; |
762 | 828 | |
763 | | - $json = json_encode( $json_data ); |
| 829 | + $json = FormatJson::encode( $json_data ); |
764 | 830 | |
765 | 831 | if ( !empty( self::$callback ) ) { |
766 | | - $json = urlencode( self::$callback ) . '(' . $json . ')'; |
| 832 | + $json = urlencode( htmlspecialchars( self::$callback ) ) . '(' . $json . ')'; |
767 | 833 | } |
768 | 834 | |
| 835 | + wfProfileOut( __METHOD__ ); |
769 | 836 | return $json; |
770 | 837 | } |
771 | | - |
| 838 | + |
| 839 | + wfProfileOut( __METHOD__ ); |
772 | 840 | return $applicationHtml; |
773 | 841 | } |
774 | 842 | |
— | — | @@ -776,8 +844,10 @@ |
777 | 845 | */ |
778 | 846 | public function setDefaultLogo() { |
779 | 847 | global $wgMobileFrontendLogo, $wgExtensionAssetsPath; |
| 848 | + wfProfileIn( __METHOD__ ); |
780 | 849 | if ( $wgMobileFrontendLogo === false ) { |
781 | 850 | $wgMobileFrontendLogo = $wgExtensionAssetsPath . '/MobileFrontend/stylesheets/images/mw.png'; |
782 | 851 | } |
| 852 | + wfProfileOut( __METHOD__ ); |
783 | 853 | } |
784 | 854 | } |
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/_search_webkit.html.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | global $wgExtensionAssetsPath, $wgMobileFrontendLogo; |
4 | 4 | |
5 | | -$searchField = self::$searchField; |
| 5 | +$searchField = htmlspecialchars( self::$searchField ); |
6 | 6 | $mainPageUrl = self::$mainPageUrl; |
7 | 7 | $randomPageUrl = self::$randomPageUrl; |
8 | 8 | $homeButton = self::$messages['mobile-frontend-home-button']; |
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/_footmenu_default.html.php |
— | — | @@ -6,15 +6,15 @@ |
7 | 7 | $disableImages = self::$messages['mobile-frontend-disable-images']; |
8 | 8 | $enableImages = self::$messages['mobile-frontend-enable-images']; |
9 | 9 | |
10 | | -$disableMobileSiteURL = self::$disableMobileSiteURL; |
11 | | -$viewNormalSiteURL = self::$viewNormalSiteURL; |
| 10 | +$disableMobileSiteURL = htmlspecialchars( self::$disableMobileSiteURL ); |
| 11 | +$viewNormalSiteURL = htmlspecialchars( self::$viewNormalSiteURL ); |
12 | 12 | |
13 | 13 | if ( self::$disableImages == 0 ) { |
14 | 14 | $imagesToggle = $disableImages; |
15 | | - $imagesURL = self::$disableImagesURL; |
| 15 | + $imagesURL = htmlspecialchars( self::$disableImagesURL ); |
16 | 16 | } else { |
17 | 17 | $imagesToggle = $enableImages; |
18 | | - $imagesURL = self::$enableImagesURL; |
| 18 | + $imagesURL = htmlspecialchars( self::$enableImagesURL ); |
19 | 19 | } |
20 | 20 | |
21 | 21 | $footerHtml = <<<EOD |