r90477 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90476‎ | r90477 | r90478 >
Date:18:59, 20 June 2011
Author:preilly
Status:deferred
Tags:
Comment:
Added override to force mobile rendering of layout. Switched to using the WebRequest Class. Made section links work.
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/views/layout/_footmenu_default.html.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -48,7 +48,7 @@
4949 'onOutputPageBeforeHTML' );
5050
5151 class ExtMobileFrontend {
52 - const VERSION = '0.4.9';
 52+ const VERSION = '0.5.0';
5353
5454 private $doc;
5555
@@ -62,7 +62,11 @@
6363 public static $headings;
6464 public static $mainPageUrl;
6565 public static $randomPageUrl;
66 -
 66+ public static $requestedSegment;
 67+ public static $format;
 68+ public static $search;
 69+ public static $callback;
 70+
6771 public $itemsToRemove = array(
6872 '#contentSub', # redirection notice
6973 'div.messagebox', # cleanup data
@@ -98,7 +102,7 @@
99103 );
100104
101105 public function onOutputPageBeforeHTML( &$out, &$text ) {
102 - global $wgContLang;
 106+ global $wgContLang, $wgRequest;
103107
104108 // Need to stash the results of the "wfMsg" call before the Output Buffering handler
105109 // because at this point the database connection is shut down, etc.
@@ -131,6 +135,19 @@
132136 } catch (Exception $e) {
133137 //echo $e->getMessage();
134138 }
 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' );
135152
136153 $userAgent = $_SERVER['HTTP_USER_AGENT'];
137154 $acceptHeader = $_SERVER["HTTP_ACCEPT"];
@@ -144,8 +161,6 @@
145162 $this->contentFormat = 'XHTML';
146163 }
147164
148 - $mAction = isset( $_GET['m_action'] ) ? $_GET['m_action'] : '';
149 -
150165 if ( $mAction == 'disable_mobile_site' ) {
151166 if ( $this->contentFormat == 'XHTML' ) {
152167 echo $this->renderDisableMobileSiteXHTML();
@@ -158,6 +173,11 @@
159174 $props['is_tablet'] === 'false' ) {
160175 ob_start( array( $this, 'DOMParse' ) );
161176 }
 177+
 178+ if ($useFormat === 'mobile') {
 179+ ob_start( array( $this, 'DOMParse' ) );
 180+ }
 181+
162182 return true;
163183 }
164184
@@ -199,6 +219,13 @@
200220 }
201221
202222 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+
203230 static $headings = 0;
204231 $show = self::$messages['mobile-frontend-show'];
205232 $hide = self::$messages['mobile-frontend-hide'];
@@ -211,7 +238,7 @@
212239 // generate the HTML we are going to inject
213240 $buttons = "<button class='section_heading show' section_id='{$headings}'>{$show}</button>" .
214241 "<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}'>" .
216243 "{$matches[2]}</span></h2><div class='content_block' id='content_{$headings}'>";
217244
218245 if ( $headings > 1 ) {
@@ -253,8 +280,8 @@
254281 $segments = explode( $this->WMLSectionSeperator, $s );
255282 $card = '';
256283 $idx = 0;
257 -
258 - $requestedSegment = isset( $_GET['seg'] ) ? $_GET['seg'] : 0;
 284+ $requestedSegment = self::$requestedSegment;
 285+
259286 $card .= "<card id='{$idx}' title='{$title}'><p>{$segments[$requestedSegment]}</p>";
260287 $idx = $requestedSegment + 1;
261288 $segmentsCount = count($segments);
@@ -379,8 +406,6 @@
380407 $title = 'Wikipedia';
381408 }
382409
383 - $format = isset( $_GET['format'] ) ? $_GET['format'] : '';
384 -
385410 $dir = self::$dir;
386411 $code = self::$code;
387412 $regularWikipedia = self::$messages['mobile-frontend-regular-wikipedia'];
@@ -391,11 +416,9 @@
392417
393418 $cssFileName = ( isset( self::$device['css_file_name'] ) ) ? self::$device['css_file_name'] : 'default';
394419
395 - $search = isset( $_GET['search'] ) ? $_GET['search'] : '';
396 -
397420 if ( strlen( $contentHtml ) > 4000 && $this->contentFormat == 'XHTML'
398421 && self::$device['supports_javascript'] === true
399 - && empty( $search ) ) {
 422+ && empty( self::$search ) ) {
400423 $contentHtml = $this->javascriptize( $contentHtml );
401424 } elseif ( $this->contentFormat == 'WML' ) {
402425 $contentHtml = $this->javascriptize( $contentHtml );
@@ -403,25 +426,23 @@
404427 require( 'views/layout/application.wml.php' );
405428 }
406429
407 - if ( $this->contentFormat == 'XHTML' && $format != 'json' ) {
 430+ if ( $this->contentFormat == 'XHTML' && self::$format != 'json' ) {
408431 require( 'views/layout/_search_webkit.html.php' );
409432 require( 'views/layout/_footmenu_default.html.php' );
410433 require( 'views/layout/application.html.php' );
411434 }
412435
413 - if ( $format === 'json' ) {
 436+ if ( self::$format === 'json' ) {
414437 header( 'Content-Type: application/json' );
415438 header( 'Content-Disposition: attachment; filename="data.js";' );
416439 $json_data = array();
417440 $json_data['title'] = $title;
418441 $json_data['html'] = $contentHtml;
419442
420 - $callback = isset( $_GET['callback'] ) ? $_GET['callback'] : '';
421 -
422443 $json = json_encode( $json_data );
423444
424 - if ( !empty( $callback ) ) {
425 - $json = urlencode( $callback ) . '(' . $json . ')';
 445+ if ( !empty( self::$callback ) ) {
 446+ $json = urlencode( self::$callback ) . '(' . $json . ')';
426447 }
427448
428449 return $json;
Index: trunk/extensions/MobileFrontend/views/layout/_footmenu_default.html.php
@@ -6,7 +6,7 @@
77 <div class='mwm-notice'>
88 <a href="?m_action=view_normal_site">{$regularWikipedia}</a>
99 <div id="perm">
10 - <a href="?m_action=disable_mobile_site">{$permStopRedirect}</a>
 10+ <a href="?mAction=disable_mobile_site">{$permStopRedirect}</a>
1111 </div>
1212 </div>
1313 </div>

Status & tagging log