Index: trunk/phase3/includes/upload/UploadFromChunks.php |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | // c) (we need the token to validate chunks are coming from a non-xss request) |
169 | 169 | $token = urlencode( $wgUser->editToken() ); |
170 | 170 | ob_clean(); |
171 | | - echo ApiFormatJson::getJsonEncode( array( |
| 171 | + echo FormatJson::encode( array( |
172 | 172 | 'uploadUrl' => wfExpandUrl( wfScript( 'api' ) ) . "?action=upload&". |
173 | 173 | "token={$token}&format=json&enablechunks=true&chunksessionkey=". |
174 | 174 | $this->setupChunkSession( $summary, $comment, $watch ) ) ); |
— | — | @@ -179,7 +179,7 @@ |
180 | 180 | // firefogg expects a specific result per: |
181 | 181 | // http://www.firefogg.org/dev/chunk_post.html |
182 | 182 | ob_clean(); |
183 | | - echo ApiFormatJson::getJsonEncode( array( |
| 183 | + echo FormatJson::encode( array( |
184 | 184 | 'result' => 1, |
185 | 185 | 'filesize' => filesize( $this->getRealPath( $this->mTempAppendPath ) ) |
186 | 186 | ) |
— | — | @@ -209,7 +209,7 @@ |
210 | 210 | // firefogg expects a specific result per: |
211 | 211 | // http://www.firefogg.org/dev/chunk_post.html |
212 | 212 | ob_clean(); |
213 | | - echo ApiFormatJson::getJsonEncode( array( |
| 213 | + echo FormatJson::encode( array( |
214 | 214 | 'result' => 1, |
215 | 215 | 'done' => 1, |
216 | 216 | 'resultUrl' => $file->getDescriptionUrl() |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -3344,3 +3344,27 @@ |
3345 | 3345 | $langCode = implode ( '-' , $codeBCP ); |
3346 | 3346 | return $langCode; |
3347 | 3347 | } |
| 3348 | +class FormatJson{ |
| 3349 | + public static function encode($value, $isHtml=false){ |
| 3350 | + // Some versions of PHP have a broken json_encode, see PHP bug |
| 3351 | + // 46944. Test encoding an affected character (U+20000) to |
| 3352 | + // avoid this. |
| 3353 | + if (!function_exists('json_encode') || $isHtml || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') { |
| 3354 | + $json = new Services_JSON(); |
| 3355 | + return $json->encode($value, $isHtml) ; |
| 3356 | + } else { |
| 3357 | + return json_encode($value); |
| 3358 | + } |
| 3359 | + } |
| 3360 | + public static function decode($value, $assoc=false){ |
| 3361 | + if (!function_exists('json_decode') ) { |
| 3362 | + $json = new Services_JSON(); |
| 3363 | + $jsonDec = $json->decode($value); |
| 3364 | + if($assoc) |
| 3365 | + $jsonDec = (array) $jsonDec; |
| 3366 | + return $jsonDec; |
| 3367 | + } else { |
| 3368 | + return json_decode($value, $assoc); |
| 3369 | + } |
| 3370 | + } |
| 3371 | +} |
\ No newline at end of file |
Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php |
— | — | @@ -130,7 +130,7 @@ |
131 | 131 | } |
132 | 132 | $this->mQueryCache[$url] = $data; |
133 | 133 | } |
134 | | - return json_decode( $this->mQueryCache[$url], true ); |
| 134 | + return FormatJson::decode( $this->mQueryCache[$url], true ); |
135 | 135 | } |
136 | 136 | |
137 | 137 | function getImageInfo( $title, $time = false ) { |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -227,34 +227,49 @@ |
228 | 228 | * gets the scriptLoader javascript include |
229 | 229 | * @param $forcClassAry Boolean: false by default |
230 | 230 | */ |
231 | | - function getScriptLoaderJs( $forceClassAry = false ){ |
| 231 | + function getScriptLoaderJs( $classAry = array() ){ |
232 | 232 | global $wgRequest, $wgDebugJavaScript; |
233 | | - |
234 | | - if( !$forceClassAry ){ |
235 | | - $class_list = implode( ',', $this->mScriptLoaderClassList ); |
236 | | - } else { |
237 | | - $class_list = implode( ',', $forceClassAry ); |
| 233 | + //if no class array provided use the mScriptLoaderClassList var |
| 234 | + if( !count($classAry) ){ |
| 235 | + $classAry = $this->mScriptLoaderClassList; |
238 | 236 | } |
| 237 | + $class_list = implode(',', $classAry); |
239 | 238 | |
240 | 239 | $debug_param = ( $wgDebugJavaScript || |
241 | 240 | $wgRequest->getVal( 'debug' ) == 'true' || |
242 | 241 | $wgRequest->getVal( 'debug' ) == '1' ) |
243 | 242 | ? '&debug=true' : ''; |
244 | 243 | |
245 | | - //@@todo intelligent unique id generation based on svn version of file (rather than just grabbing the $wgStyleVersion var) |
246 | | - //@@todo we should check the packaged message text in this javascript file for updates and update the $mScriptLoaderURID id (in getJsClassFromPath) |
247 | | - |
248 | | - //generate the unique request param (combine with the most recent revision id of any wiki page with the $wgStyleVersion var) |
249 | | - |
250 | | - return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam() ); |
| 244 | + return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam( $classAry) ); |
251 | 245 | } |
252 | 246 | |
253 | | - function getURIDparam(){ |
254 | | - global $wgDebugJavaScript, $wgStyleVersion; |
| 247 | + function getURIDparam( $classAry=array() ){ |
| 248 | + global $wgDebugJavaScript, $wgStyleVersion, $IP, $wgScriptModifiedCheck; |
255 | 249 | if( $wgDebugJavaScript ){ |
256 | 250 | return 'urid=' . time(); |
257 | 251 | } else { |
258 | | - return "urid={$wgStyleVersion}_{$this->mLatestScriptRevID}"; |
| 252 | + $ftime=0; |
| 253 | + if($wgScriptModifiedCheck){ |
| 254 | + foreach( $classAry as $class ){ |
| 255 | + $js_path = jsScriptLoader::getJsPathFromClass( $class ); |
| 256 | + if( $js_path ){ |
| 257 | + $cur_ftime = filemtime ( $IP ."/". $js_path ); |
| 258 | + if( $cur_ftime > $ftime ) |
| 259 | + $ftime = $cur_ftime; |
| 260 | + } |
| 261 | + } |
| 262 | + } |
| 263 | + //set up the urid: |
| 264 | + $urid = "urid={$wgStyleVersion}"; |
| 265 | + |
| 266 | + //if we have a $this->mLatestScriptRevID (wiki page revision ids) |
| 267 | + if($this->mLatestScriptRevID != 0 ) |
| 268 | + $urid .= "_{$this->mLatestScriptRevID}"; |
| 269 | + |
| 270 | + if( $ftime != 0 ) |
| 271 | + $urid .= "_".$ftime; |
| 272 | + |
| 273 | + return $urid; |
259 | 274 | } |
260 | 275 | } |
261 | 276 | |
Index: trunk/phase3/includes/api/ApiFormatJson.php |
— | — | @@ -67,24 +67,7 @@ |
68 | 68 | $prefix = preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", "", $callback ) . "("; |
69 | 69 | $suffix = ")"; |
70 | 70 | } |
71 | | - |
72 | | - // Some versions of PHP have a broken json_encode, see PHP bug |
73 | | - // 46944. Test encoding an affected character (U+20000) to |
74 | | - // avoid this. |
75 | | - $this->printText( $prefix . $this->getJsonEncode($this->getResultData(), $this->getIsHtml() ) . $suffix); |
76 | | - } |
77 | | - /* |
78 | | - * static to support static calls to json output (instead of json_encode function) |
79 | | - * @param array $results the results array to output as a json string |
80 | | - * @parm isHTML if the output is html |
81 | | - */ |
82 | | - public static function getJsonEncode($value, $isHtml=false){ |
83 | | - if (!function_exists('json_encode') || $isHtml || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') { |
84 | | - $json = new Services_JSON(); |
85 | | - return $json->encode($value, $isHtml) ; |
86 | | - } else { |
87 | | - return json_encode($value); |
88 | | - } |
| 71 | + $this->printText( $prefix . FormatJson::encode( $this->getResultData(), $this->getIsHtml() ) . $suffix); |
89 | 72 | } |
90 | 73 | |
91 | 74 | public function getAllowedParams() { |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2743,6 +2743,18 @@ |
2744 | 2744 | $wgEnableScriptLoader = false; |
2745 | 2745 | |
2746 | 2746 | /* |
| 2747 | + * $wgScriptModifiedCheck should run a file modified check on javascript files when |
| 2748 | + * generating unique request ids for javascript include using the script-loader |
| 2749 | + * |
| 2750 | + * note this will only check core scripts that are directly included on the page. |
| 2751 | + * (not scripts loaded after the initial page display since after initial page |
| 2752 | + * display scripts inherit the unique request id) |
| 2753 | + * |
| 2754 | + * and or you can update $wgStyleVersion |
| 2755 | + */ |
| 2756 | +$wgScriptModifiedCheck = true; |
| 2757 | + |
| 2758 | +/* |
2747 | 2759 | * enable js2 Script System |
2748 | 2760 | * if enabled we include jquery, mv_embed and js2 versions of editPage.js |
2749 | 2761 | */ |