PHP 5.4 has JSON_PRETTY_PRINT
authorReedy <reedy@wikimedia.org>
Sun, 12 Aug 2012 19:31:01 +0000 (20:31 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Tue, 14 Aug 2012 16:57:40 +0000 (18:57 +0200)
Use this conditionally when $isHtml is true, and is
also running on PHP > = 5.4. Else return default 0

Change-Id: Ief775720a99d1a305c3f9f4ba7cc04eb96817fb3

includes/json/FormatJson.php

index bbcc185..aa60fbd 100644 (file)
@@ -41,11 +41,11 @@ class FormatJson {
         * @return string
         */
        public static function encode( $value, $isHtml = false ) {
-               if ( !function_exists( 'json_encode' ) || $isHtml ) {
+               if ( !function_exists( 'json_encode' ) || ( $isHtml && version_compare( PHP_VERSION, '5.4.0', '<' ) ) ) {
                        $json = new Services_JSON();
                        return $json->encode( $value, $isHtml );
                } else {
-                       return json_encode( $value );
+                       return json_encode( $value, $isHtml ? JSON_PRETTY_PRINT : 0 );
                }
        }