added missing json function in stand alone usage
authorMichael Dale <dale@users.mediawiki.org>
Tue, 22 Sep 2009 19:22:26 +0000 (19:22 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Tue, 22 Sep 2009 19:22:26 +0000 (19:22 +0000)
js2/mwEmbed/php/noMediaWikiConfig.php

index b7326ae..e6b3f7d 100644 (file)
@@ -105,4 +105,29 @@ function wfMsgNoTrans( $msgKey ) {
         return '&lt;' . $msgKey . '&gt;';
     }
 }
+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 );
+               }
+       }
+}
+
 ?>