X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiFormatJson.php;h=1d7e3dccd369cf4f0b01d8f797e1c033e2c2bdd9;hb=305179ffa3d141973d5ddb31261d8e1730c18684;hp=98c8e72afe855c7097adbd79535809eef3e95b3e;hpb=79d5225c0e864482269e2315f47b899697681e52;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index 98c8e72afe..1d7e3dccd3 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -29,7 +29,7 @@ if (!defined('MEDIAWIKI')) { } /** - * @addtogroup API + * @ingroup API */ class ApiFormatJson extends ApiFormatBase { @@ -41,12 +41,17 @@ class ApiFormatJson extends ApiFormatBase { } public function getMimeType() { - return 'application/json'; + return 'text/javascript'; } public function getNeedsRawData() { return $this->mIsRaw; } + + public function getWantsHelp() { + // Help is always ugly in JSON + return false; + } public function execute() { $prefix = $suffix = ""; @@ -58,11 +63,22 @@ class ApiFormatJson extends ApiFormatBase { $suffix = ")"; } - if (!function_exists('json_encode') || $this->getIsHtml()) { + // Some versions of PHP have a broken json_encode, see PHP bug + // 46944. Test encoding an affected character (U+20000) to + // avoid this. + $this->printText( $prefix . $this->getJsonEncode($this->getResultData(), $this->getIsHtml() ) . $suffix); + } + /* + * static to support static calls to json output (instead of json_encode function) + * @param array $results the results array to output as a json string + * @parm isHTML if the output is html + */ + public static function getJsonEncode($value, $isHtml=false){ + if (!function_exists('json_encode') || $isHtml || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') { $json = new Services_JSON(); - $this->printText($prefix . $json->encode($this->getResultData(), $this->getIsHtml()) . $suffix); + return $json->encode($value, $isHtml) ; } else { - $this->printText($prefix . json_encode($this->getResultData()) . $suffix); + return json_encode($value); } }