Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | 'onOutputPageBeforeHTML' ); |
50 | 50 | |
51 | 51 | class ExtMobileFrontend { |
52 | | - const VERSION = '0.4.9'; |
| 52 | + const VERSION = '0.5.0'; |
53 | 53 | |
54 | 54 | private $doc; |
55 | 55 | |
— | — | @@ -62,7 +62,11 @@ |
63 | 63 | public static $headings; |
64 | 64 | public static $mainPageUrl; |
65 | 65 | public static $randomPageUrl; |
66 | | - |
| 66 | + public static $requestedSegment; |
| 67 | + public static $format; |
| 68 | + public static $search; |
| 69 | + public static $callback; |
| 70 | + |
67 | 71 | public $itemsToRemove = array( |
68 | 72 | '#contentSub', # redirection notice |
69 | 73 | 'div.messagebox', # cleanup data |
— | — | @@ -98,7 +102,7 @@ |
99 | 103 | ); |
100 | 104 | |
101 | 105 | public function onOutputPageBeforeHTML( &$out, &$text ) { |
102 | | - global $wgContLang; |
| 106 | + global $wgContLang, $wgRequest; |
103 | 107 | |
104 | 108 | // Need to stash the results of the "wfMsg" call before the Output Buffering handler |
105 | 109 | // because at this point the database connection is shut down, etc. |
— | — | @@ -131,6 +135,19 @@ |
132 | 136 | } catch (Exception $e) { |
133 | 137 | //echo $e->getMessage(); |
134 | 138 | } |
| 139 | + |
| 140 | + // Note: The WebRequest Class calls are made in this block because |
| 141 | + // since PHP 5.1.x, all objects have their destructors called |
| 142 | + // before the output buffer callback function executes. |
| 143 | + // Thus, globalized objects will not be available as expected in the function. |
| 144 | + // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104] |
| 145 | + |
| 146 | + $mAction = $wgRequest->getText( 'mAction' ); |
| 147 | + $useFormat = $wgRequest->getText( 'useFormat' ); |
| 148 | + self::$format = $wgRequest->getText( 'format' ); |
| 149 | + self::$requestedSegment = $wgRequest->getText( 'seg', 0 ); |
| 150 | + self::$search = $wgRequest->getText( 'search' ); |
| 151 | + self::$callback = $wgRequest->getText( 'callback' ); |
135 | 152 | |
136 | 153 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
137 | 154 | $acceptHeader = $_SERVER["HTTP_ACCEPT"]; |
— | — | @@ -144,8 +161,6 @@ |
145 | 162 | $this->contentFormat = 'XHTML'; |
146 | 163 | } |
147 | 164 | |
148 | | - $mAction = isset( $_GET['m_action'] ) ? $_GET['m_action'] : ''; |
149 | | - |
150 | 165 | if ( $mAction == 'disable_mobile_site' ) { |
151 | 166 | if ( $this->contentFormat == 'XHTML' ) { |
152 | 167 | echo $this->renderDisableMobileSiteXHTML(); |
— | — | @@ -158,6 +173,11 @@ |
159 | 174 | $props['is_tablet'] === 'false' ) { |
160 | 175 | ob_start( array( $this, 'DOMParse' ) ); |
161 | 176 | } |
| 177 | + |
| 178 | + if ($useFormat === 'mobile') { |
| 179 | + ob_start( array( $this, 'DOMParse' ) ); |
| 180 | + } |
| 181 | + |
162 | 182 | return true; |
163 | 183 | } |
164 | 184 | |
— | — | @@ -199,6 +219,13 @@ |
200 | 220 | } |
201 | 221 | |
202 | 222 | private function showHideCallbackXHTML( $matches ) { |
| 223 | + |
| 224 | + if ( isset( $matches[0] ) ) { |
| 225 | + preg_match('/id="([^"]*)"/', $matches[0], $headlineMatches); |
| 226 | + } |
| 227 | + |
| 228 | + $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : ''; |
| 229 | + |
203 | 230 | static $headings = 0; |
204 | 231 | $show = self::$messages['mobile-frontend-show']; |
205 | 232 | $hide = self::$messages['mobile-frontend-hide']; |
— | — | @@ -211,7 +238,7 @@ |
212 | 239 | // generate the HTML we are going to inject |
213 | 240 | $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button>" . |
214 | 241 | "<button class='section_heading hide' section_id='{$headings}'>{$hide}</button>"; |
215 | | - $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span>" . |
| 242 | + $base .= "<h2 class='section_heading' id='section_{$headings}'{$matches[1]}{$buttons} <span id='{$headlineId}'>" . |
216 | 243 | "{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>"; |
217 | 244 | |
218 | 245 | if ( $headings > 1 ) { |
— | — | @@ -253,8 +280,8 @@ |
254 | 281 | $segments = explode( $this->WMLSectionSeperator, $s ); |
255 | 282 | $card = ''; |
256 | 283 | $idx = 0; |
257 | | - |
258 | | - $requestedSegment = isset( $_GET['seg'] ) ? $_GET['seg'] : 0; |
| 284 | + $requestedSegment = self::$requestedSegment; |
| 285 | + |
259 | 286 | $card .= "<card id='{$idx}' title='{$title}'><p>{$segments[$requestedSegment]}</p>"; |
260 | 287 | $idx = $requestedSegment + 1; |
261 | 288 | $segmentsCount = count($segments); |
— | — | @@ -379,8 +406,6 @@ |
380 | 407 | $title = 'Wikipedia'; |
381 | 408 | } |
382 | 409 | |
383 | | - $format = isset( $_GET['format'] ) ? $_GET['format'] : ''; |
384 | | - |
385 | 410 | $dir = self::$dir; |
386 | 411 | $code = self::$code; |
387 | 412 | $regularWikipedia = self::$messages['mobile-frontend-regular-wikipedia']; |
— | — | @@ -391,11 +416,9 @@ |
392 | 417 | |
393 | 418 | $cssFileName = ( isset( self::$device['css_file_name'] ) ) ? self::$device['css_file_name'] : 'default'; |
394 | 419 | |
395 | | - $search = isset( $_GET['search'] ) ? $_GET['search'] : ''; |
396 | | - |
397 | 420 | if ( strlen( $contentHtml ) > 4000 && $this->contentFormat == 'XHTML' |
398 | 421 | && self::$device['supports_javascript'] === true |
399 | | - && empty( $search ) ) { |
| 422 | + && empty( self::$search ) ) { |
400 | 423 | $contentHtml = $this->javascriptize( $contentHtml ); |
401 | 424 | } elseif ( $this->contentFormat == 'WML' ) { |
402 | 425 | $contentHtml = $this->javascriptize( $contentHtml ); |
— | — | @@ -403,25 +426,23 @@ |
404 | 427 | require( 'views/layout/application.wml.php' ); |
405 | 428 | } |
406 | 429 | |
407 | | - if ( $this->contentFormat == 'XHTML' && $format != 'json' ) { |
| 430 | + if ( $this->contentFormat == 'XHTML' && self::$format != 'json' ) { |
408 | 431 | require( 'views/layout/_search_webkit.html.php' ); |
409 | 432 | require( 'views/layout/_footmenu_default.html.php' ); |
410 | 433 | require( 'views/layout/application.html.php' ); |
411 | 434 | } |
412 | 435 | |
413 | | - if ( $format === 'json' ) { |
| 436 | + if ( self::$format === 'json' ) { |
414 | 437 | header( 'Content-Type: application/json' ); |
415 | 438 | header( 'Content-Disposition: attachment; filename="data.js";' ); |
416 | 439 | $json_data = array(); |
417 | 440 | $json_data['title'] = $title; |
418 | 441 | $json_data['html'] = $contentHtml; |
419 | 442 | |
420 | | - $callback = isset( $_GET['callback'] ) ? $_GET['callback'] : ''; |
421 | | - |
422 | 443 | $json = json_encode( $json_data ); |
423 | 444 | |
424 | | - if ( !empty( $callback ) ) { |
425 | | - $json = urlencode( $callback ) . '(' . $json . ')'; |
| 445 | + if ( !empty( self::$callback ) ) { |
| 446 | + $json = urlencode( self::$callback ) . '(' . $json . ')'; |
426 | 447 | } |
427 | 448 | |
428 | 449 | return $json; |
Index: trunk/extensions/MobileFrontend/views/layout/_footmenu_default.html.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | <div class='mwm-notice'> |
8 | 8 | <a href="?m_action=view_normal_site">{$regularWikipedia}</a> |
9 | 9 | <div id="perm"> |
10 | | - <a href="?m_action=disable_mobile_site">{$permStopRedirect}</a> |
| 10 | + <a href="?mAction=disable_mobile_site">{$permStopRedirect}</a> |
11 | 11 | </div> |
12 | 12 | </div> |
13 | 13 | </div> |