Index: trunk/phase3/js2/mwEmbed/php/noMediaWikiConfig.php |
— | — | @@ -105,4 +105,29 @@ |
106 | 106 | return '<' . $msgKey . '>'; |
107 | 107 | } |
108 | 108 | } |
| 109 | +class FormatJson{ |
| 110 | + public static function encode($value, $isHtml=false){ |
| 111 | + // Some versions of PHP have a broken json_encode, see PHP bug |
| 112 | + // 46944. Test encoding an affected character (U+20000) to |
| 113 | + // avoid this. |
| 114 | + if (!function_exists('json_encode') || $isHtml || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') { |
| 115 | + $json = new Services_JSON(); |
| 116 | + return $json->encode($value, $isHtml) ; |
| 117 | + } else { |
| 118 | + return json_encode($value); |
| 119 | + } |
| 120 | + } |
| 121 | + public static function decode( $value, $assoc=false ){ |
| 122 | + if (!function_exists('json_decode') ) { |
| 123 | + $json = new Services_JSON(); |
| 124 | + $jsonDec = $json->decode( $value ); |
| 125 | + if( $assoc ) |
| 126 | + $jsonDec = wfObjectToArray( $jsonDec ); |
| 127 | + return $jsonDec; |
| 128 | + } else { |
| 129 | + return json_decode( $value, $assoc ); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
109 | 134 | ?> |