*/
$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
$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
* 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;
}
}
$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() {
}
$this->mQueryCache[$url] = $data;
}
- return json_decode( $this->mQueryCache[$url], true );
+ return FormatJson::decode( $this->mQueryCache[$url], true );
}
function getImageInfo( $title, $time = false ) {
// 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 ) ) );
// 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 ) )
)
// 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()