From 1e4165061b83f99fbcf173b3ca908bef23c08108 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Thu, 10 Sep 2009 14:33:25 +0000 Subject: [PATCH] more (bug 20336) * added json folder * moved Services_JSON.php there * moved Format JSON into its own class * updated AutoLoader --- includes/AutoLoader.php | 8 +++-- includes/GlobalFunctions.php | 24 -------------- includes/HttpFunctions.php | 2 +- includes/OutputPage.php | 2 +- includes/json/FormatJson.php | 33 +++++++++++++++++++ .../Services_JSON.php} | 0 js2/mwEmbed/php/languages/mwEmbed.i18n.php | 2 +- .../php/maintenance/mergeJavascriptMsg.php | 6 ++-- js2/mwEmbed/skins/ctrlBuilder.js | 2 +- 9 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 includes/json/FormatJson.php rename includes/{api/ApiFormatJson_json.php => json/Services_JSON.php} (100%) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 2368247663..5051ad389c 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -318,11 +318,15 @@ $wgAutoloadLocalClasses = array( 'ApiUserrights' => 'includes/api/ApiUserrights.php', 'ApiUpload' => 'includes/api/ApiUpload.php', 'ApiWatch' => 'includes/api/ApiWatch.php', - 'Services_JSON' => 'includes/api/ApiFormatJson_json.php', - 'Services_JSON_Error' => 'includes/api/ApiFormatJson_json.php', + 'Spyc' => 'includes/api/ApiFormatYaml_spyc.php', 'UsageException' => 'includes/api/ApiMain.php', + # includes/json + 'Services_JSON' => 'includes/json/Services_JSON.php', + 'Services_JSON_Error' => 'includes/json/Services_JSON.php', + 'FormatJson' => 'includes/json/FormatJson.php', + # includes/db 'Blob' => 'includes/db/Database.php', 'ChronologyProtector' => 'includes/db/LBFactory.php', diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 8efa1f2df0..726a0a3e79 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3342,28 +3342,4 @@ function wfBCP47( $code ) { } $langCode = implode ( '-' , $codeBCP ); return $langCode; -} -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 = (array) $jsonDec; - return $jsonDec; - } else { - return json_decode($value, $assoc); - } - } } \ No newline at end of file diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 8f15d199ba..51c142fe4b 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -206,7 +206,7 @@ class Http { $sd =& $_SESSION['wsDownload'][$upload_session_key]; // if error update status: if( !$status->isOK() ) { - $sd['apiUploadResult'] = ApiFormatJson::getJsonEncode( + $sd['apiUploadResult'] = FormatJson::encode( array( 'error' => $status->getWikiText() ) ); } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index de839bf7ca..3843787c8b 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -16,7 +16,7 @@ class OutputPage { var $mScriptLoaderClassList = array(); - // The most recent revision ID of any script that is grouped in the script request + // The most recent revision ID of any wikiPage script that is grouped in the script request var $mLatestScriptRevID = 0; var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array(); diff --git a/includes/json/FormatJson.php b/includes/json/FormatJson.php new file mode 100644 index 0000000000..f79d399975 --- /dev/null +++ b/includes/json/FormatJson.php @@ -0,0 +1,33 @@ +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 = (array) $jsonDec; + return $jsonDec; + } else { + return json_decode($value, $assoc); + } + } +} +?> \ No newline at end of file diff --git a/includes/api/ApiFormatJson_json.php b/includes/json/Services_JSON.php similarity index 100% rename from includes/api/ApiFormatJson_json.php rename to includes/json/Services_JSON.php diff --git a/js2/mwEmbed/php/languages/mwEmbed.i18n.php b/js2/mwEmbed/php/languages/mwEmbed.i18n.php index 3554951430..396fdf1439 100644 --- a/js2/mwEmbed/php/languages/mwEmbed.i18n.php +++ b/js2/mwEmbed/php/languages/mwEmbed.i18n.php @@ -34,7 +34,7 @@ $messages['en'] = array( 'mwe-set_in_out_points' => 'Set in-out points', 'mwe-start_time' => 'Start time', 'mwe-end_time' => 'End time', - 'mwe-preview_inout' => 'Preview/play in-out points', + 'mwe-preview_inout' => 'Preview in-out points', /* * js file: /libTimedText/mvTextInterface.js diff --git a/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php b/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php index 58b8d7184e..91a97323b1 100644 --- a/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php +++ b/js2/mwEmbed/php/maintenance/mergeJavascriptMsg.php @@ -112,14 +112,14 @@ function doJsonMerge( $json_txt ) { } // merge the jsLanguage array back in and wrap the output if ( $mergeToJS && $doReplaceFlag ) { - $json = json_encode( $jsMsgAry ); + $json = FormatJson::encode( $jsMsgAry ); $json_txt = jsonReadable( $json ); // escape $1 for preg replace: $json_txt = str_replace( '$', '\$', $json_txt ); // print "json:\n$json_txt \n"; $str = preg_replace ( '/loadGM\s*\(\s*{(.*)}\s*\)\s*/siU', - "loadGM(" . $json_txt . ")", - $jsFileText ); + "loadGM(" . $json_txt . ")", + $jsFileText ); // print substr($str, 0, 600); diff --git a/js2/mwEmbed/skins/ctrlBuilder.js b/js2/mwEmbed/skins/ctrlBuilder.js index a757d41f62..aa4fbe4520 100644 --- a/js2/mwEmbed/skins/ctrlBuilder.js +++ b/js2/mwEmbed/skins/ctrlBuilder.js @@ -331,4 +331,4 @@ var ctrlBuilder = { } } } -} \ No newline at end of file +}; -- 2.20.1