From: Michael Dale Date: Wed, 9 Sep 2009 22:26:16 +0000 (+0000) Subject: * (bug 20336) changed json_decode json_encode to static class in global functions X-Git-Tag: 1.31.0-rc.0~39811 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=7efc871cba8dc24aff2cd13d3ad4c8a20902bad7;p=lhc%2Fweb%2Fwiklou.git * (bug 20336) changed json_decode json_encode to static class in global functions ** we should update extensions as well * added config for fileCheckModify date check to scriptLoader unique script id generation --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 2765e3f35e..8b216f08de 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2742,6 +2742,18 @@ $wgJSAutoloadClasses = array(); */ $wgEnableScriptLoader = false; +/* + * $wgScriptModifiedCheck should run a file modified check on javascript files when + * generating unique request ids for javascript include using the script-loader + * + * note this will only check core scripts that are directly included on the page. + * (not scripts loaded after the initial page display since after initial page + * display scripts inherit the unique request id) + * + * and or you can update $wgStyleVersion + */ +$wgScriptModifiedCheck = true; + /* * enable js2 Script System * if enabled we include jquery, mv_embed and js2 versions of editPage.js diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4cbed9e5a7..b6de6f0e56 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3344,3 +3344,27 @@ 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/OutputPage.php b/includes/OutputPage.php index cbbd3a8aca..ebdbcc687b 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -227,34 +227,49 @@ class OutputPage { * gets the scriptLoader javascript include * @param $forcClassAry Boolean: false by default */ - function getScriptLoaderJs( $forceClassAry = false ){ + function getScriptLoaderJs( $classAry = array() ){ global $wgRequest, $wgDebugJavaScript; - - if( !$forceClassAry ){ - $class_list = implode( ',', $this->mScriptLoaderClassList ); - } else { - $class_list = implode( ',', $forceClassAry ); + //if no class array provided use the mScriptLoaderClassList var + if( !count($classAry) ){ + $classAry = $this->mScriptLoaderClassList; } + $class_list = implode(',', $classAry); $debug_param = ( $wgDebugJavaScript || $wgRequest->getVal( 'debug' ) == 'true' || $wgRequest->getVal( 'debug' ) == '1' ) ? '&debug=true' : ''; - //@@todo intelligent unique id generation based on svn version of file (rather than just grabbing the $wgStyleVersion var) - //@@todo we should check the packaged message text in this javascript file for updates and update the $mScriptLoaderURID id (in getJsClassFromPath) - - //generate the unique request param (combine with the most recent revision id of any wiki page with the $wgStyleVersion var) - - return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam() ); + return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam( $classAry) ); } - function getURIDparam(){ - global $wgDebugJavaScript, $wgStyleVersion; + function getURIDparam( $classAry=array() ){ + global $wgDebugJavaScript, $wgStyleVersion, $IP, $wgScriptModifiedCheck; if( $wgDebugJavaScript ){ return 'urid=' . time(); } else { - return "urid={$wgStyleVersion}_{$this->mLatestScriptRevID}"; + $ftime=0; + if($wgScriptModifiedCheck){ + foreach( $classAry as $class ){ + $js_path = jsScriptLoader::getJsPathFromClass( $class ); + if( $js_path ){ + $cur_ftime = filemtime ( $IP ."/". $js_path ); + if( $cur_ftime > $ftime ) + $ftime = $cur_ftime; + } + } + } + //set up the urid: + $urid = "urid={$wgStyleVersion}"; + + //if we have a $this->mLatestScriptRevID (wiki page revision ids) + if($this->mLatestScriptRevID != 0 ) + $urid .= "_{$this->mLatestScriptRevID}"; + + if( $ftime != 0 ) + $urid .= "_".$ftime; + + return $urid; } } diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php index c789fbb378..d8318104d3 100644 --- a/includes/api/ApiFormatJson.php +++ b/includes/api/ApiFormatJson.php @@ -67,24 +67,7 @@ class ApiFormatJson extends ApiFormatBase { $prefix = preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "("; $suffix = ")"; } - - // Some versions of PHP have a broken json_encode, see PHP bug - // 46944. Test encoding an affected character (U+20000) to - // avoid this. - $this->printText( $prefix . $this->getJsonEncode($this->getResultData(), $this->getIsHtml() ) . $suffix); - } - /* - * static to support static calls to json output (instead of json_encode function) - * @param array $results the results array to output as a json string - * @parm isHTML if the output is html - */ - public static function getJsonEncode($value, $isHtml=false){ - 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); - } + $this->printText( $prefix . FormatJson::encode( $this->getResultData(), $this->getIsHtml() ) . $suffix); } public function getAllowedParams() { diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 2f1c391c1f..0fb5097201 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -130,7 +130,7 @@ class ForeignAPIRepo extends FileRepo { } $this->mQueryCache[$url] = $data; } - return json_decode( $this->mQueryCache[$url], true ); + return FormatJson::decode( $this->mQueryCache[$url], true ); } function getImageInfo( $title, $time = false ) { diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 83b2734ecd..478b8f52d5 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -167,7 +167,7 @@ class UploadFromChunks extends UploadBase { // c) (we need the token to validate chunks are coming from a non-xss request) $token = urlencode( $wgUser->editToken() ); ob_clean(); - echo ApiFormatJson::getJsonEncode( array( + echo FormatJson::encode( array( 'uploadUrl' => wfExpandUrl( wfScript( 'api' ) ) . "?action=upload&". "token={$token}&format=json&enablechunks=true&chunksessionkey=". $this->setupChunkSession( $summary, $comment, $watch ) ) ); @@ -179,7 +179,7 @@ class UploadFromChunks extends UploadBase { // firefogg expects a specific result per: // http://www.firefogg.org/dev/chunk_post.html ob_clean(); - echo ApiFormatJson::getJsonEncode( array( + echo FormatJson::encode( array( 'result' => 1, 'filesize' => filesize( $this->getRealPath( $this->mTempAppendPath ) ) ) @@ -209,7 +209,7 @@ class UploadFromChunks extends UploadBase { // firefogg expects a specific result per: // http://www.firefogg.org/dev/chunk_post.html ob_clean(); - echo ApiFormatJson::getJsonEncode( array( + echo FormatJson::encode( array( 'result' => 1, 'done' => 1, 'resultUrl' => $file->getDescriptionUrl()