r56819 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56818‎ | r56819 | r56820 >
Date:15:00, 23 September 2009
Author:dale
Status:deferred
Tags:
Comment:
before processing wikipage js ::
* make sure its a valid wikipage
* in the User or MediaWiki namespace
* and ends with .js

* removed $wgEnableScriptLoaderJsFile support for "file" based includes. (was a off by default config option that I don't see much use for)
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/js2/mwEmbed/jsScriptLoader.php (modified) (history)
  • /trunk/phase3/js2/mwEmbed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -2787,13 +2787,7 @@
27882788 $wgEnableJS2system = false;
27892789
27902790 /*
2791 - * boolean; if relative file paths can be used (in addition to the autoload
2792 - * js classes listed in: $wgJSAutoloadClasses)
2793 - */
2794 -$wgEnableScriptLoaderJsFile = false;
2795 -
2796 -/*
2797 - * boolean; if we should minify the output. (note if you send ?debug=true in
 2791+ * boolean; if we should minify the output. (note if you send ?debug=true in
27982792 * the page request it will automatically not group and not minify)
27992793 */
28002794 $wgEnableScriptMinify = true;
Index: trunk/phase3/js2/mwEmbed/mv_embed.js
@@ -554,29 +554,32 @@
555555 _this.doLoad([
556556 'window.jQuery'
557557 ], function() {
558 - _global['$j'] = jQuery.noConflict();
559 -
560 - //setup our global settings using the (jQuery helper)
561 - $j.extend( mwConfig, mwConfigOptions);
562 -
563 - // Set up the skin path
564 - _global['mv_jquery_skin_path'] = mv_embed_path + 'jquery/jquery.ui/themes/' +mwConfig['jui_skin'] + '/';
565 - _global['mv_skin_img_path'] = mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/images/';
566 - _global['mv_default_thumb_url'] = mv_skin_img_path + 'vid_default_thumb.jpg';
567 -
568 - // Make sure the skin/style sheets are always available:
569 - loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
570 - loadExternalCss( mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/styles.css' );
571 -
572 - // Set up AJAX to not send dynamic URLs for loading scripts (we control that with
573 - // the scriptLoader)
574 - $j.ajaxSetup({
575 - cache: true
576 - });
577 -
578 - js_log( 'jQuery loaded into $j' );
579 - // Set up mvEmbed jQuery bindings:
580 - mv_jqueryBindings();
 558+ //only do the $j setup once:
 559+ if(!_global['$j']){
 560+ _global['$j'] = jQuery.noConflict();
 561+
 562+ //setup our global settings using the (jQuery helper)
 563+ $j.extend( mwConfig, mwConfigOptions);
 564+
 565+ // Set up the skin path
 566+ _global['mv_jquery_skin_path'] = mv_embed_path + 'jquery/jquery.ui/themes/' +mwConfig['jui_skin'] + '/';
 567+ _global['mv_skin_img_path'] = mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/images/';
 568+ _global['mv_default_thumb_url'] = mv_skin_img_path + 'vid_default_thumb.jpg';
 569+
 570+ // Make sure the skin/style sheets are always available:
 571+ loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
 572+ loadExternalCss( mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/styles.css' );
 573+
 574+ // Set up AJAX to not send dynamic URLs for loading scripts (we control that with
 575+ // the scriptLoader)
 576+ $j.ajaxSetup({
 577+ cache: true
 578+ });
 579+
 580+ js_log( 'jQuery loaded into $j' );
 581+ // Set up mvEmbed jQuery bindings:
 582+ mv_jqueryBindings();
 583+ }
581584 // Run the callback
582585 if( callback ) {
583586 callback();
Index: trunk/phase3/js2/mwEmbed/jsScriptLoader.php
@@ -22,11 +22,11 @@
2323 var $jsvarurl = false; // whether we should include generated JS (special class '-')
2424 var $doProcReqFlag = true;
2525
26 - //@@todo fix: will break down if someone does }); in their msg text
 26+ //@@todo fix: will break down if someone does }) in their msg text
2727 const loadGMregEx = '/loadGM\s*\(\s*{(.*)}\s*\)\s*/siU';
2828
2929 function doScriptLoader() {
30 - global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgEnableScriptLoaderJsFile, $IP,
 30+ global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $IP,
3131 $wgEnableScriptMinify, $wgUseFileCache;
3232
3333 // Process the request
@@ -168,7 +168,7 @@
169169 */
170170 function procRequestVars() {
171171 global $wgContLanguageCode, $wgEnableScriptMinify, $wgJSAutoloadClasses,
172 - $wgJSAutoloadLocalClasses, $wgStyleVersion, $wgEnableScriptLoaderJsFile;
 172+ $wgJSAutoloadLocalClasses, $wgStyleVersion;
173173
174174 // Set debug flag
175175 if ( ( isset( $_GET['debug'] ) && $_GET['debug'] == 'true' ) || ( isset( $wgEnableScriptDebug ) && $wgEnableScriptDebug == true ) ) {
@@ -194,11 +194,27 @@
195195 // Clean the class list and populate jsFileList
196196 foreach ( $reqClassList as $reqClass ) {
197197 if ( trim( $reqClass ) != '' ) {
198 - // Check for special case '-' class for user-generated JS
199198 if ( substr( $reqClass, 0, 3 ) == 'WT:' ) {
200 - $this->jsFileList[$reqClass] = true;
201 - $this->rKey .= $reqClass;
202 - $this->jsvarurl = true;
 199+ $doAddWT = false;
 200+ // Check for special case '-' class for user-generated JS
 201+ if( substr( $reqClass, 3, 1) == '-'){
 202+ $doAddWT = true;
 203+ }else{
 204+ if( strtolower( substr( $reqClass, -3) ) == '.js'){
 205+ //make sure its a valid wikipage before doing processing
 206+ $t = Title::newFromDBkey( substr( $reqClass, 3) );
 207+ if( $t->exists()
 208+ && $t->getNamespace == NS_MEDIAWIKI
 209+ && $t->getNamespace == NS_USER){
 210+ $doAddWT = true;
 211+ }
 212+ }
 213+ }
 214+ if( $doAddWT ){
 215+ $this->jsFileList[$reqClass] = true;
 216+ $this->rKey .= $reqClass;
 217+ $this->jsvarurl = true;
 218+ }
203219 continue;
204220 }
205221
@@ -215,29 +231,7 @@
216232 }
217233 }
218234
219 - // Check for requested files, if enabled
220 - if ( $wgEnableScriptLoaderJsFile ) {
221 - if ( isset( $_GET['files'] ) ) {
222 - $reqFileList = explode( ',', isset( $_GET['files'] ) );
223 - // Clean the file list and populate jsFileList
224 - foreach ( $reqFileList as $reqFile ) {
225 - // No jumping dirs
226 - $reqFile = str_replace( '../', '', $reqFile );
227 - // Only allow alphanumeric underscores periods and ending with .js
228 - $reqFile = ereg_replace( "[^A-Za-z0-9_\-\/\.]", '', $reqFile );
229 - if ( substr( $reqFile, - 3 ) == '.js' ) {
230 - // Don't add it twice:
231 - if ( !in_array( $reqFile, $jsFileList ) ) {
232 - $this->jsFileList[] = $IP . $reqFile;
233 - $this->rKey .= $reqFile;
234 - }
235 - } else {
236 - $this->error_msg .= 'Not valid requested JavaScript file' . "\n";
237 - }
238 - }
239 - }
240 - }
241 -
 235+
242236 // Add the language code to the rKey:
243237 $this->rKey .= '_' . $wgContLanguageCode;
244238
@@ -311,8 +305,6 @@
312306 // Return the updated loadGM JSON with updated msgs:
313307 return 'loadGM( ' . FormatJson::encode( $jmsg ) . ')';
314308 } else {
315 - print_r($jvar);
316 -
317309 // Could not parse JSON return error: (maybe a alert?)
318310 //we just make a note in the code, visitors will get the fallback language,
319311 //developers will read the js source when its not behaving as expected.

Status & tagging log