From 204b53d3a2c0eedb35e4faac0abc61712ffbdb57 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Tue, 22 Sep 2009 19:22:26 +0000 Subject: [PATCH] added missing json function in stand alone usage --- js2/mwEmbed/php/noMediaWikiConfig.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/js2/mwEmbed/php/noMediaWikiConfig.php b/js2/mwEmbed/php/noMediaWikiConfig.php index b7326ae5f7..e6b3f7d800 100644 --- a/js2/mwEmbed/php/noMediaWikiConfig.php +++ b/js2/mwEmbed/php/noMediaWikiConfig.php @@ -105,4 +105,29 @@ function wfMsgNoTrans( $msgKey ) { return '<' . $msgKey . '>'; } } +class FormatJson{ + public static function encode($value, $isHtml=false){ + // Some versions of PHP have a broken json_encode, see PHP bug + // 46944. Test encoding an affected character (U+20000) to + // avoid this. + if (!function_exists('json_encode') || $isHtml || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') { + $json = new Services_JSON(); + return $json->encode($value, $isHtml) ; + } else { + return json_encode($value); + } + } + public static function decode( $value, $assoc=false ){ + if (!function_exists('json_decode') ) { + $json = new Services_JSON(); + $jsonDec = $json->decode( $value ); + if( $assoc ) + $jsonDec = wfObjectToArray( $jsonDec ); + return $jsonDec; + } else { + return json_decode( $value, $assoc ); + } + } +} + ?> -- 2.20.1