r89710 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89709‎ | r89710 | r89711 >
Date:23:05, 7 June 2011
Author:preilly
Status:deferred (Comments)
Tags:
Comment:
add back json support
Modified paths:
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php
@@ -39,7 +39,7 @@
4040 'onOutputPageBeforeHTML' );
4141
4242 class ExtPatchOutputMobile {
43 - const VERSION = '0.4.2';
 43+ const VERSION = '0.4.3';
4444
4545 private $doc;
4646
@@ -352,6 +352,8 @@
353353 $title = 'Wikipedia';
354354 }
355355
 356+ $format = isset( $_GET['format'] ) ? $_GET['format'] : '';
 357+
356358 $dir = self::$dir;
357359 $code = self::$code;
358360 $regularWikipedia = self::$messages['patch-output-mobile-regular-wikipedia'];
@@ -371,13 +373,22 @@
372374 require( 'views/layout/application.wml.php' );
373375 }
374376
375 - if ( $this->contentFormat == 'XHTML' ) {
 377+ if ( $this->contentFormat == 'XHTML' && $format != 'json' ) {
376378 require( 'views/notices/_donate.html.php' );
377379 require( 'views/layout/_search_webkit.html.php' );
378380 require( 'views/layout/_footmenu_default.html.php' );
379381 require( 'views/layout/application.html.php' );
380382 }
381383
 384+ if ( $format === 'json' ) {
 385+ header( 'Content-Type: application/json' );
 386+ header( 'Content-Disposition: attachment; filename="data.js";' );
 387+ $json_data = array();
 388+ $json_data['title'] = $title;
 389+ $json_data['html'] = $contentHtml;
 390+ return json_encode( $json_data );
 391+ }
 392+
382393 return $applicationHtml;
383394 }
384395 }

Comments

#Comment by 😂 (talk | contribs)   01:12, 8 June 2011
  • Please do not use $_GET or $_POST directly, use WebRequest (a global instance of which exists as $wgRequest).
  • Same thing with header(), do $wgRequest->response()->header() instead.
  • Don't use json_encode/decode() directly, use our FormatJson wrapper class.

Status & tagging log