00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ('ApiFormatBase.php');
00029 }
00030
00034 class ApiFormatJson extends ApiFormatBase {
00035
00036 private $mIsRaw;
00037
00038 public function __construct($main, $format) {
00039 parent :: __construct($main, $format);
00040 $this->mIsRaw = ($format === 'rawfm');
00041 }
00042
00043 public function getMimeType() {
00044 return 'application/json';
00045 }
00046
00047 public function getNeedsRawData() {
00048 return $this->mIsRaw;
00049 }
00050
00051 public function execute() {
00052 $prefix = $suffix = "";
00053
00054 $params = $this->extractRequestParams();
00055 $callback = $params['callback'];
00056 if(!is_null($callback)) {
00057 $prefix = preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "(";
00058 $suffix = ")";
00059 }
00060
00061
00062
00063
00064 if (!function_exists('json_encode') || $this->getIsHtml() || strtolower(json_encode("\xf0\xa0\x80\x80")) != '"\ud840\udc00"') {
00065 $json = new Services_JSON();
00066 $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix);
00067 } else {
00068 $this->printText($prefix . json_encode($this->getResultData()) . $suffix);
00069 }
00070 }
00071
00072 public function getAllowedParams() {
00073 return array (
00074 'callback' => null
00075 );
00076 }
00077
00078 public function getParamDescription() {
00079 return array (
00080 'callback' => 'If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.',
00081 );
00082 }
00083
00084 public function getDescription() {
00085 if ($this->mIsRaw)
00086 return 'Output data with the debuging elements in JSON format' . parent :: getDescription();
00087 else
00088 return 'Output data in JSON format' . parent :: getDescription();
00089 }
00090
00091 public function getVersion() {
00092 return __CLASS__ . ': $Id: ApiFormatJson.php 48713 2009-03-23 19:58:07Z catrope $';
00093 }
00094 }