r66984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66983‎ | r66984 | r66985 >
Date:01:45, 28 May 2010
Author:dale
Status:deferred
Tags:
Comment:
documentation updates for clarity
fixes to better support a packager ( $wgUseMwEmbedLoaderModuleList and $wgScriptLoaderRelativeCss )
minor fixes to parser / language: static variable scope and no fail for empty argument list in replaceStringArgs
Modified paths:
  • /trunk/extensions/JS2Support/JS2AutoLoader.php (modified) (history)
  • /trunk/extensions/JS2Support/JS2Support.php (modified) (history)
  • /trunk/extensions/JS2Support/README (modified) (history)
  • /trunk/extensions/JS2Support/ScriptLoaderOutputPage.php (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/jsScriptLoader.php (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/languages/mw.Language.js (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/languages/mw.Parser.js (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/mwEmbed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/JS2Support/ScriptLoaderOutputPage.php
@@ -566,7 +566,7 @@
567567
568568 // Included script without script-loader
569569 // Generate the localized msgs inline since we can't rely on ScriptLoader to localize
570 - $inlineMsg = $this->mScriptLoader->getInlineMsgFromClass( $className );
 570+ $inlineMsg = $this->mScriptLoader->getAddMessagesFromClass( $className );
571571 if( $inlineMsg != '' ) {
572572 $this->addScript( Html::inlineScript( $inlineMsg ) );
573573 }
Index: trunk/extensions/JS2Support/mwEmbed/languages/mw.Language.js
@@ -184,10 +184,13 @@
185185 * Swap in an array of values for $1, $2, $n for a given msg key
186186 *
187187 * @param string messageKey The msg key to lookup
188 - * @param {Array} args An array of string or jquery objects to be swapped in
 188+ * @param {Array} args An array of string or jQuery objects to be swapped in
189189 * @return string
190190 */
191 - replaceStringArgs : function() {
 191+ replaceStringArgs : function() {
 192+ if( ! this.arguments ) {
 193+ return ;
 194+ }
192195 // Replace Values
193196 for ( var v = 0; v < this.arguments.length; v++ ) {
194197 if( typeof this.arguments[v] == 'undefined' ) {
Index: trunk/extensions/JS2Support/mwEmbed/languages/mw.Parser.js
@@ -2,12 +2,11 @@
33 * Mediawiki language text parser
44 */
55
6 - // Setup jQuery swap string constant
 6+// Setup swap string constants
 7+var JQUERY_SWAP_STRING = 'ZjQuerySwapZ';
 8+var LINK_SWAP_STRING = 'ZreplaceZ';
79
8 -
910 ( function( mw ) {
10 - var JQUERY_SWAP_STRING = 'ZjQuerySwapZ';
11 - var LINK_SWAP_STRING = 'ZreplaceZ';
1211
1312 // The parser magic global
1413 var pMagicSet = { };
Index: trunk/extensions/JS2Support/mwEmbed/mwEmbed.js
@@ -300,7 +300,7 @@
301301 load: function( loadRequest, instanceCallback ) {
302302 // Ensure the callback is only called once per load instance
303303 var callback = function(){
304 - if( instanceCallback ){
 304+ if( instanceCallback ) {
305305 instanceCallback( loadRequest );
306306 instanceCallback = null;
307307 }
@@ -563,7 +563,7 @@
564564 // Issue the request to load the class (include class name in result callback:
565565 mw.getScript( scriptRequest, function( scriptRequest ) {
566566
567 - // If its a "syle sheet" manually set its class to true
 567+ // If its a "style sheet" manually set its class to true
568568 var ext = scriptRequest.substr( scriptRequest.split('?')[0].lastIndexOf( '.' ), 4 ).toLowerCase();
569569 if( ext == '.css' && className.substr(0,8) == 'mw.style' ){
570570 mw.style[ className.substr( 9 ) ] = true;
@@ -578,36 +578,27 @@
579579
580580 // If ( debug mode ) and the script include is missing class messages
581581 // do a separate request to retrieve the msgs
582 - if( mw.currentClassMissingMessages ){
583 - mw.loadClassMessages( className, function(){
584 - //reset the currentClassMissingMessages flag
 582+ if( mw.currentClassMissingMessages ) {
 583+ mw.loadClassMessages( className, function() {
 584+ // Reset the currentClassMissingMessages flag
585585 mw.currentClassMissingMessages = false;
586 - // Run the onDone callback
 586+
 587+ // Run the onDone callback
587588 mw.loadDone( className );
588589 });
589590 } else {
590 - // Call load done ( when in debug mode the scriptLoader
591 - // is not able to append the loadDone call
592 - mw.loadDone( className );
 591+ // If not using the script-loader make sure the className is avaliable before firing the loadDone
 592+ if( !mw.getScriptLoaderPath() ) {
 593+ mw.waitForObject( className, function( className ) {
 594+ // Once object is ready run loadDone
 595+ mw.loadDone( className );
 596+ } );
 597+ } else {
 598+ // loadDone should be appended to the bottom of the script-loader response
 599+ //mw.loadDone( className );
 600+ }
593601 }
594 - } );
595 - //mw.log( 'done with running getScript request ' );
596 -
597 - /*
598 - * ( If scriptLoader is not enabled )
599 - *
600 - * Check if the class is ready:
601 - * ( not all browsers support onLoad script attribute )
602 - * In the case of a "class" we can pull the javascript state until its ready
603 - */
604 - if( !mw.getScriptLoaderPath() ) {
605 - setTimeout( function() {
606 - mw.waitForObject( className, function( className ) {
607 - // Once object is ready run loadDone
608 - mw.loadDone( className );
609 - } );
610 - }, 25 );
611 - }
 602+ } );
612603 },
613604
614605 /**
@@ -1961,8 +1952,9 @@
19621953 // Set up mvEmbed utility jQuery bindings
19631954 mw.dojQueryBindings();
19641955
1965 - // Speical Hack for condtional jquery ui inclution ( once Usability extension
1966 - // registers the jquery.ui skin in mw.sytle this won't be needed:
 1956+
 1957+ // Special Hack for conditional jquery ui inclusion ( once Usability extension
 1958+ // registers the jquery.ui skin in mw.style this won't be needed:
19671959 if( mw.hasJQueryUiCss() ){
19681960 mw.style[ mw.getConfig( 'jQueryUISkin' ) ] = true;
19691961 }
@@ -1995,8 +1987,8 @@
19961988
19971989 /**
19981990 * Checks for jquery ui css by name jquery-ui-1.7.2.css
1999 - * NOTE: this is kind of a hack for usability jquery-ui
2000 - * in the future usability should register the class in mw.skin
 1991+ * NOTE: this is a hack for usability jquery-ui
 1992+ * in the future usability should register a class in mw.skin
20011993 *
20021994 * @return true if found, return false if not found
20031995 */
@@ -2004,7 +1996,7 @@
20051997 var hasUiCss = false;
20061998 // Load the jQuery ui skin if usability skin not set
20071999 $j( 'link' ).each( function( na, linkNode ){
2008 - if( $j( linkNode ).attr( 'href' ).indexOf('jquery-ui-1.7.2.css') != -1 ) {
 2000+ if( $j( linkNode ).attr( 'href' ).indexOf( 'jquery-ui-1.7.2.css' ) != -1 ) {
20092001 hasUiCss = true;
20102002 return false;
20112003 }
@@ -2250,7 +2242,7 @@
22512243 ' class="ui-state-default ui-corner-all ui-icon_link ' +
22522244 className + '"><span class="ui-icon ui-icon-' + iconId + '" ></span>' +
22532245 '<span class="btnText">' + msg + '</span></a>';
2254 - }
 2246+ };
22552247
22562248 // Shortcut to jQuery button ( should replace all btnHtml with button )
22572249 var mw_default_button_options = {
@@ -2265,7 +2257,8 @@
22662258
22672259 // The icon id that precceeds the button link:
22682260 'icon_id' : 'carat-1-n'
2269 - }
 2261+ };
 2262+
22702263 $.button = function( options ) {
22712264 var options = $j.extend( mw_default_button_options, options);
22722265
@@ -2288,7 +2281,7 @@
22892282 .text( options.text )
22902283 );
22912284 return $btn;
2292 - }
 2285+ };
22932286
22942287 // Shortcut to bind hover state
22952288 $.fn.buttonHover = function() {
@@ -2301,7 +2294,7 @@
23022295 }
23032296 )
23042297 return this;
2305 - }
 2298+ };
23062299
23072300 /**
23082301 * Resize a dialog to fit the window
@@ -2322,9 +2315,9 @@
23232316 'right':'0px',
23242317 'bottom':'0px'
23252318 } );
2326 - }
 2319+ };
23272320
2328 - } )( jQuery );
 2321+ } )( $j );
23292322 }
23302323
23312324 } )( window.mw );
@@ -2443,4 +2436,4 @@
24442437 if( dollarFlag ) {
24452438 window[ '$' ] = jQuery.noConflict();
24462439 }
2447 -}
\ No newline at end of file
 2440+}
Index: trunk/extensions/JS2Support/mwEmbed/jsScriptLoader.php
@@ -51,7 +51,7 @@
5252 // The raw requested class
5353 private static $rawClassList = '';
5454
55 - // The includeAllModuleMessages string regular expresion
 55+ // The includeAllModuleMessages string regular expression
5656 private static $includeAllMsgsRegEx = "/mw\.includeAllModuleMessages\s*\(\s*\)\;?/";
5757
5858 /**
@@ -131,7 +131,7 @@
132132
133133 // Output the loaders js
134134 $loaderJS = jsClassLoader::getCombinedLoaderJs();
135 - // Transform the loader text to remove debug statments and
 135+ // Transform the loader text to remove debug statements and
136136 // update language msgs if any are present
137137 $this->output .= $this->transformScriptText( $loaderJS , 'mwEmbed');
138138
@@ -148,7 +148,7 @@
149149 }
150150
151151 // Output "special" IE comment tag to support "special" mwEmbed tags.
152 - $this->notMinifiedTopOutput .='/*@cc_on\'video source itext playlist\'.replace(/\w+/g,function(n){document.createElement(n)})@*/'."\n";
 152+ $this->notMinifiedTopOutput .='/*@cc_on@if(@_jscript_version<9){\'video audio source itext playlist\'.replace(/\w+/g,function(n){document.createElement(n)})}@end@*/'."\n";
153153 }
154154 }
155155
@@ -387,25 +387,24 @@
388388 * Special function to transform css output and wrap in js call
389389 */
390390 private function transformCssOutput( $classKey, $cssString , $path ='') {
 391+ global $wgScriptLoaderRelativeCss;
391392 // Minify and update paths on cssString:
392393 $cssOptions = array();
393394
394395 // Set comments preservation based on debug state
395396 $cssOptions[ 'preserveComments' ] = ( $this->debug );
396397
397 - $serverUri = $this->getScriptLoaderUri();
398 -
399398 // Check for the two jsScriptLoader entry points:
400 - if( strpos( $serverUri, 'mwScriptLoader.php') !== false ){
 399+ if( $wgScriptLoaderRelativeCss ) {
401400 // Using the local mediaWiki entry point we should have our $wgScriptPath global
402401 global $wgScriptPath;
403 - $cssOptions[ 'prependRelativePath' ] = $wgScriptPath . '/' . dirname( $path ) . '/';
404 - } else if( strpos( $serverUri, 'jsScriptLoader.php') !== false ){
405 - // NOTE:: We HAVE to use an absolute url remote jsScriptLoader.php entry point.
406 - // this is because relative urls won't work when inserted into the DOM head
407 - // ( ie we package the css with javascript )
408 - $cssOptions[ 'prependRelativePath' ] =
409 - str_replace('jsScriptLoader.php', '', $serverUri)
 402+ $prePendPath = ( $wgScriptPath == '' ) ? '' : $wgScriptPath . '/';
 403+ $cssOptions[ 'prependRelativePath' ] = $prePendPath . dirname( $path ) . '/';
 404+ } else {
 405+ // Get the server URL
 406+ $serverUri = $this->getScriptLoaderUri();
 407+
 408+ $cssOptions[ 'prependRelativePath' ] = str_replace('jsScriptLoader.php', '', $serverUri)
410409 . dirname( $path ) . '/';
411410 }
412411
@@ -789,6 +788,7 @@
790789 /*
791790 * Transform script text with language key substitution
792791 * and clear out debug lines if present.
 792+ * @param {String} $scriptText Text string to be transformed
793793 */
794794 function transformScriptText( $scriptText , $moduleName){
795795 global $wgEnableScriptLocalization;
@@ -801,7 +801,6 @@
802802 if ( $wgEnableScriptLocalization ){
803803 // Get the mw.addMessage javascript from scriptText and moduleName
804804 $addMessageJs = $this->getAddMessagesFromScriptText( & $scriptText , $moduleName);
805 -
806805 //@@NOTE getAddMessagesFromClass could identify which mode we are in and we would not need to
807806 // try each of these search patterns in the same order as before.
808807
@@ -950,7 +949,7 @@
951950 * @param {String} $class Name of class to get inline messages for.
952951 * @return in-line msg javascript text or empty string if no msgs need to be localized.
953952 */
954 - function getAddMessagesFromClass( $class ) {
 953+ function getAddMessagesFromClass( $className ) {
955954 $scriptText = $this->getScriptText( $className );
956955 $moduleName = jsClassLoader::getClassModuleName( $className );
957956 return $this->getAddMessagesFromScriptText( $scriptText, $moduleName );
@@ -981,11 +980,10 @@
982981 * @return {Array} decoded json array of message key value pairs
983982 */
984983 function getMsgKeysFromScriptText( & $scriptString , $moduleName){
985 - global $wgExtensionJavascriptModules, $wgExtensionMessagesFiles;
 984+ global $wgExtensionMessagesFiles;
986985
987986 // Try for includeAllModuleMsgs function call
988 - if ( preg_match ( self::$includeAllMsgsRegEx, $scriptString ) !== false ) {
989 -
 987+ if ( preg_match ( self::$includeAllMsgsRegEx, $scriptString ) !== 0 ) {
990988 // Get the module $messages keys
991989 if( $moduleName && isset( $wgExtensionMessagesFiles[ $moduleName ] ) ) {
992990
@@ -1033,7 +1031,7 @@
10341032 * @param {Array} $jmsg Associative array of message key -> message value pairs
10351033 * @param {String} $langCode Language code override
10361034 */
1037 - static public function updateMessageValues(& $messegeArray, $langCode = false){
 1035+ static public function updateMessageValues( & $messegeArray, $langCode = false ){
10381036 global $wgLang;
10391037 // Check the langCode
10401038 if(!$langCode && $wgLang) {
Index: trunk/extensions/JS2Support/JS2Support.php
@@ -56,6 +56,13 @@
5757 $wgExtensionJavascriptModules = array();
5858
5959 /**
 60+* If the mwEmbed loader.js javascript should be used to get a list of enabled modules
 61+* This is for stand-alone usage and is set to false for mediaWiki.
 62+* ( all modules should be loaded from $wgExtensionJavascriptModules var )
 63+*/
 64+$wgUseMwEmbedLoaderModuleList = false;
 65+
 66+/**
6067 * The set of script-loader Named Paths, populated via extensions and javascript module loaders
6168 */
6269 $wgScriptLoaderNamedPaths = array();
@@ -114,9 +121,15 @@
115122 */
116123 $wgScriptModifiedMsgCheck = false;
117124
 125+/**
 126+ * If the scriptloader should output relative css paths
 127+ * Should be set to false if the script-loader is on a different domain
 128+ * from your css
 129+ */
 130+$wgScriptLoaderRelativeCss = true;
118131
119132 /**
120 - * boolean; if we should enable javascript localization (it loads mw.addMessages json
 133+ * boolean; if scriptLoader should localize script text(it loads mw.addMessages json
121134 * call with mediaWiki msgs)
122135 */
123136 $wgEnableScriptLocalization = true;
Index: trunk/extensions/JS2Support/JS2AutoLoader.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /****************************
5 -* JS2 AutoLoader.php
 5+* JS2 AutoLoader php files
66 *****************************/
77 $wgAutoloadClasses = array_merge( $wgAutoloadClasses, array(
88 'JSMin' => $js2Dir . 'mwEmbed/includes/library/JSMin.php',
Index: trunk/extensions/JS2Support/README
@@ -48,10 +48,11 @@
4949 Once you include the extension you can use the following:
5050
5151 To add a javascript or css to the named paths ( so that the script loader can load it by name )
52 -$wgScriptLoaderNamedPaths[ 'myExtension' ] = 'extensions/myExtension/myExtension.js';
 52+$wgScriptLoaderNamedPaths[ 'myJavascriptFile' ] = 'extensions/myExtension/myJavascriptFile.js';
5353
5454 Then in your php you can include your with the following line:
55 -$wgOut->addScriptClass( 'myExtension' /* scriptloader named path */ , 'page'/* group bucket id */ );
 55+$wgOut->addScriptClass( 'myJavascriptFile' /* scriptloader named path */ , 'page'/* group bucket id */ );
 56+
5657 This lets you use the named-path for includes and gives you control over script grouping with the
5758 grouping argument. If for example your script is included on a set of special pages then you could
5859 create a bucket id string for that set to not mangle the cache of each special page .
@@ -63,9 +64,10 @@
6465 If you would like to keep compatibility with non-js2 extension support you can use the base outputPage
6566 addScriptFile method:
6667 $wgOut->addScriptFile( 'extensions/myExtension/myExtension.js' )
 68+
6769 This way regardless of if your running the js2support extension or not script-includes will continue to work.
6870 But you won't be able to control the script bucket, and the script-loader will have to guess
69 -what group to put it in. ( This should be resolved with updates to the trunk output page)
 71+what group to put it in.
7072
7173 For more info see ScriptLoaderOutputPage.php $mScriptLoaderClassList
7274

Status & tagging log