summaryrefslogtreecommitdiff
path: root/includes/json/FormatJson.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
commit222b01f5169f1c7e69762e0e8904c24f78f71882 (patch)
tree8e932e12546bb991357ec48eb1638d1770be7a35 /includes/json/FormatJson.php
parent00ab76a6b686e98a914afc1975812d2b1aaa7016 (diff)
update to MediaWiki 1.16.0
Diffstat (limited to 'includes/json/FormatJson.php')
-rw-r--r--includes/json/FormatJson.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/includes/json/FormatJson.php b/includes/json/FormatJson.php
new file mode 100644
index 00000000..6db4a23f
--- /dev/null
+++ b/includes/json/FormatJson.php
@@ -0,0 +1,32 @@
+<?php
+/*
+ * simple wrapper for json_econde and json_decode that falls back on Services_JSON class
+ */
+if( !(defined( 'MEDIAWIKI' ) ) ) {
+ die( 1 );
+}
+
+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 );
+ }
+ }
+}