r66443 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66442‎ | r66443 | r66444 >
Date:21:38, 14 May 2010
Author:dale
Status:deferred
Tags:
Comment:
* refined wgExtensionJavascriptModules global to add javascript modules from extensions.
* added support for mw.includeAllModuleMsgs
** usage documented in JS2Support/README
** lets you issue a single call to include all your module messages from php )
** avoids listing out all message keys for modules that don't have subcomponents.
Modified paths:
  • /branches/UsabilityInitiativeJS2/.project (added) (history)
  • /branches/UsabilityInitiativeJS2/UsabilityInitiative.php (modified) (history)
  • /branches/UsabilityInitiativeJS2/loader.js (modified) (history)
  • /trunk/extensions/AddMediaWizard/AddMedia/mw.FirefoggGUI.js (modified) (history)
  • /trunk/extensions/AddMediaWizard/AddMediaWizard.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/maintenance/MergeJavascriptMsg.php (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/includes/cache (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/includes/jsClassLoader.php (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/includes/noMediaWikiConfig.php (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/jsScriptLoader.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedText/mw.TimedTextEdit.js (modified) (history)

Diff [purge]

Index: trunk/extensions/AddMediaWizard/AddMediaWizard.php
@@ -45,10 +45,10 @@
4646
4747
4848 // Add the javascript loader for "AddMedia module"
49 -$wgExtensionJavascriptLoader[] = 'extensions/AddMediaWizard/AddMedia/loader.js';
 49+$wgExtensionJavascriptModules['AddMedia'] = 'extensions/AddMediaWizard/AddMedia';
5050
5151 // Add the javascript loader for "ClipEdit module"
52 -$wgExtensionJavascriptLoader[] = 'extensions/AddMediaWizard/ClipEdit/loader.js';
 52+$wgExtensionJavascriptModules['ClipEdit'] = 'extensions/AddMediaWizard/ClipEdit';
5353
5454 class AddMediaWizard {
5555 public static function addJS( $toolbar) {
Index: trunk/extensions/AddMediaWizard/AddMedia/mw.FirefoggGUI.js
@@ -487,7 +487,7 @@
488488 'maxlength="' + maxDigits + '" ' +
489489 'size="' + maxDigits + '" ' +
490490 'class="_' + configKey + ' text ui-widget-content ui-corner-all" ' +
491 - 'style="display:inline;border:0; color:#f6931f; font-weight:bold;" ' +
 491+ 'style="display:inline; color:#f6931f; padding: 2px; font-weight:bold;" ' +
492492 'value="' + defaultValue + '" >' +
493493 '<div class="slider_' + configKey + '"></div>';
494494 break;
@@ -574,7 +574,7 @@
575575 $j( this.target_input_file_name ).width( 250 );
576576
577577 // Special preset action
578 - $j( this.selector + ' ._preset_select' ).change( function() {
 578+ $j( this.selector + ' ._preset_select' ).change( function() {
579579 _this.updatePresetSelection( $j( this ).val() );
580580 });
581581
@@ -634,7 +634,7 @@
635635 $j( this.selector + ' ._' + configKey)
636636 .click( function() {
637637 _this.updateLocalValue( _this.getClassId( this ),
638 - $j( this ).is( ":checked" ) );
 638+ $j( this ).is( ":checked" ) );
639639 _this.updatePresetSelection( 'custom' );
640640 });
641641 break;
@@ -643,10 +643,11 @@
644644 case 'int':
645645 case 'float':
646646 // Check if we have a validate function on the string
647 - $j( this.selector + ' ._' + configKey ).change( function() {
 647+ $j( this.selector + ' ._' + configKey ).change( function() {
648648 $j( this ).val( _this.updateLocalValue(
649649 _this.getClassId( this ),
650 - $j( this ).val() ) );
 650+ $j( this ).val() )
 651+ );
651652 _this.updatePresetSelection( 'custom' );
652653 })
653654 break;
@@ -660,8 +661,30 @@
661662 }
662663 });
663664 break;
664 - case 'slider':
665 - //var sliderId = _this.getClassId( this, 'slider_' );
 665+ case 'slider':
 666+ /**
 667+ * Return true or false of out of range and update the related value
 668+ */
 669+ var keepAspectRatio = function( sliderId, value ){
 670+ // Maintain source video aspect ratio
 671+ if ( sliderId == 'width' ) {
 672+ var sourceHeight = _this.sourceFileInfo.video[0]['height'];
 673+ var sourceWidth = _this.sourceFileInfo.video[0]['width'];
 674+ var newHeight = parseInt( sourceHeight / sourceWidth * value );
 675+ // Reject the update if the new height is above the maximum
 676+ if ( newHeight > _this.updateInterfaceValue( 'height', newHeight ) )
 677+ return false;
 678+ }
 679+ if ( sliderId == 'height' ) {
 680+ var sourceHeight = _this.sourceFileInfo.video[0]['height'];
 681+ var sourceWidth = _this.sourceFileInfo.video[0]['width'];
 682+ var newWidth = parseInt( sourceWidth / sourceHeight * value );
 683+ // Reject the update if the new width is above the maximum
 684+ if ( newWidth > _this.updateInterfaceValue( 'width', newWidth ) )
 685+ return false;
 686+ }
 687+ };
 688+
666689 $j( this.selector + ' .slider_' + configKey ).slider({
667690 range: "min",
668691 animate: true,
@@ -670,27 +693,13 @@
671694 min: this.default_encoder_config[ configKey ].range.min,
672695 max: this.default_encoder_config[ configKey ].range.max,
673696 slide: function( event, ui ) {
 697+ var sliderId = _this.getClassId( this, 'slider_' );
674698 $j( _this.selector + ' ._' + sliderId ).val( ui.value );
675699
676 - // Maintain source video aspect ratio
677 - if ( sliderId == 'width' ) {
678 - var sourceHeight = _this.sourceFileInfo.video[0]['height'];
679 - var sourceWidth = _this.sourceFileInfo.video[0]['width'];
680 - var newHeight = parseInt( sourceHeight / sourceWidth * ui.value );
681 - // Reject the update if the new height is above the maximum
682 - if ( newHeight > _this.updateInterfaceValue( 'height', newHeight ) )
683 - return false;
684 - }
685 - if ( sliderId == 'height' ) {
686 - var sourceHeight = _this.sourceFileInfo.video[0]['height'];
687 - var sourceWidth = _this.sourceFileInfo.video[0]['width'];
688 - var newWidth = parseInt( sourceWidth / sourceHeight * ui.value );
689 - // Reject the update if the new width is above the maximum
690 - if ( newWidth > _this.updateInterfaceValue( 'width', wv ) )
691 - return false;
692 - }
 700+ keepAspectRatio( sliderId, ui.value );
693701 },
694702 change: function( event, ui ) {
 703+ var sliderId = _this.getClassId( this, 'slider_' );
695704 _this.updateLocalValue( sliderId, ui.value );
696705 _this.updatePresetSelection( 'custom' );
697706 }
@@ -698,15 +707,18 @@
699708
700709 $j( this.selector + ' ._' + configKey ).change( function() {
701710 var classId = _this.getClassId( this );
702 - var validValue = _this.updateLocalValue( classId.substr( 1 ),
703 - $j( this ).val() );
 711+ var validValue = _this.updateLocalValue( classId,
 712+ $j( this ).val()
 713+ );
704714 _this.updatePresetSelection( 'custom' );
705715 // Change it to the validated value
706716 $j( this ).val( validValue );
707717 // update the slider
708 - mw.log( "update: " + _this.selector + ' .slider' + classId );
709 - $j( _this.selector + ' .slider' + classId )
710 - .slider( 'option', 'value', validValue );
 718+ //mw.log( "update: " + _this.selector + ' .slider' + classId );
 719+ $j( _this.selector + ' .slider_' + classId )
 720+ .slider('value', validValue );
 721+ // Keep aspect ratio:
 722+ keepAspectRatio( classId, validValue );
711723 });
712724 break;
713725 }
@@ -729,7 +741,7 @@
730742 updatePresetSelection: function( presetKey ) {
731743 // Update the local configuration
732744 this.local_settings['default'] = presetKey;
733 - // mw.log( 'update preset desc: ' + presetKey );
 745+ mw.log( 'update preset desc: ' + presetKey );
734746 var presetDesc = '';
735747 if ( this.local_settings.presets[presetKey].desc ) {
736748 presetDesc = this.local_settings.presets[presetKey].desc;
@@ -778,8 +790,8 @@
779791 * range if required. Update the configuration with the validated value and
780792 * return it.
781793 */
782 - updateLocalValue: function( confKey, value ) {
783 - if ( typeof this.default_encoder_config[confKey] == 'undefined' ) {
 794+ updateLocalValue: function( confKey, value ) {
 795+ if ( typeof this.default_encoder_config[confKey] == 'undefined' ) {
784796 mw.log( "Error: could not update conf key: " + confKey )
785797 return value;
786798 }
@@ -824,14 +836,14 @@
825837 * If no prefix is given, "_" is assumed.
826838 */
827839 getClassId: function( element, prefix ) {
828 - var eltClass = $j( element ).attr( "class" ).split( ' ' ).slice( 0, 1 ).toString();
829 -
 840+
 841+ var eltClass = $j( element ).attr( "class" ).split( ' ' ).slice( 0, 1 ).toString();
830842 if ( !prefix ) {
831843 prefix = '_';
832844 }
833845 if ( eltClass.substr( 0, prefix.length ) == prefix ) {
834846 eltClass = eltClass.substr( prefix.length );
835 - }
 847+ }
836848 return eltClass;
837849 },
838850
@@ -985,7 +997,7 @@
986998 var pKey = this.local_settings[ 'default' ];
987999 this.updatePresetSelection( pKey );
9881000
989 - // set the actual HTML & widgets based on any local settings values:
 1001+ // Set the actual HTML & widgets based on any local settings values:
9901002 $j.each( _this.local_settings.presets['custom']['conf'], function( inx, val ) {
9911003 if ( $j( _this.selector + ' ._' + inx ).length != 0 ) {
9921004 $j( _this.selector + ' ._' + inx ).val( val );
Index: trunk/extensions/JS2Support/ScriptLoaderOutputPage.php
@@ -337,7 +337,7 @@
338338 * @since 1.17
339339 */
340340 public function includeAllPageJS ( ) {
341 - global $wgExtensionJavascriptLoader, $wgEnableScriptLoader,
 341+ global $wgExtensionJavascriptModules, $wgEnableScriptLoader,
342342 $wgScriptLoaderNamedPaths, $wgScriptPath;
343343
344344 // Set core Classes
@@ -362,28 +362,28 @@
363363 $this->mScripts = "\n<!-- Script bucket: allpage --> \n";
364364 $this->mScripts = $this->getLinkedScriptLoaderJs( $coreClasses );
365365 } else {
366 - // No ScriptLoader manually add the classes:
 366+ // No ScriptLoader manually add classes that are normally part of mwEmbed core request.
367367 $so = '';
368368 foreach( $coreClasses as $className ){
369369 $this->addScriptClass( $className );
370370 }
371371
372 - // Add the mwEmbed "core-components" ( language, parsing etc )
 372+ // Add the mwEmbed "core-components" ( language, parsing etc. )
373373 $coreComponets = jsClassLoader::getComponentsList();
374374 foreach( $coreComponets as $className ) {
375375 $this->addScriptClass( $className );
376376 }
377377
378 - // Also add the "loader" classes ( script-loader won't run them )
379 - foreach( $wgExtensionJavascriptLoader as $loaderPath){
 378+ // Also add the "loader" classes
 379+ foreach( $wgExtensionJavascriptModules as $modulePath ){
380380 // Set the loader context for each loader javascript file
381381 // ( so that javascript modules can use relative paths )
382 - $loaderDir = dirname( "$wgScriptPath/$loaderPath" ) . "/";
 382+ $loaderDir = $modulePath . "/";
383383 $this->addScript( Html::inlineScript(
384384 "mw.setConfig( 'loaderContext', '" . xml::escapeJsString( $loaderDir ) . "');"
385385 ) );
386386 $this->addScriptFile(
387 - "$wgScriptPath/$loaderPath"
 387+ "$wgScriptPath/$modulePath/loader.js"
388388 );
389389 }
390390 }
@@ -525,7 +525,7 @@
526526 if( $path == false ){
527527 // NOTE:: could throw an error here
528528 //print "could not find: $className\n";
529 - print( __METHOD__ . ' scriptLoader could not find class: ' . $className );
 529+ print( __METHOD__ . ' scriptLoader could not find class: ' . $className . "\n");
530530 return false; // could not find the class
531531 }
532532 // Valid path add it to script-loader or "link" directly
Index: trunk/extensions/JS2Support/mwEmbed/includes/jsClassLoader.php
@@ -25,11 +25,17 @@
2626 // The current directory context. Used in loading javascript modules outside of the mwEmbed folder
2727 private static $directoryContext = '';
2828
 29+ // Stores class parent moduleName
 30+ private static $classParentModuleName = array();
 31+
 32+ // The current module name used for callback functions in regular expressions
 33+ private static $currentModuleName = '';
 34+
2935 /**
3036 * Get the javascript class paths from javascript files
3137 */
3238 public static function loadClassPaths(){
33 - global $wgMwEmbedDirectory, $wgExtensionJavascriptLoader,
 39+ global $wgMwEmbedDirectory, $wgExtensionJavascriptModules,
3440 $wgScriptLoaderNamedPaths, $wgExtensionMessagesFiles, $IP;
3541
3642 // Only run once
@@ -55,12 +61,10 @@
5662 return false;
5763 }
5864
59 - // Read the mwEmbed loader file:
 65+ // Proccess the mwEmbed loader file:
6066 $fileContent = file_get_contents( $mwEmbedAbsolutePath . '/loader.js' );
61 -
62 - // Get class paths from mwEmbed.js
6367 self::$directoryContext = $wgMwEmbedDirectory;
64 - self::proccessLoaderContent( $fileContent );
 68+ self::proccessLoaderContent( $fileContent , 'mwEmbed' );
6569
6670 // Get the list of core component into self::$coreComponentsList
6771 preg_replace_callback(
@@ -86,14 +90,13 @@
8791 // Get all the classes from the enabled mwEmbed modules folder
8892 foreach( self::$moduleList as $na => $moduleName){
8993 $relativeSlash = ( $wgMwEmbedDirectory == '' )? '' : '/';
90 - self::proccessModulePath( $wgMwEmbedDirectory . $relativeSlash . 'modules/' . $moduleName );
 94+ $modulePath = $wgMwEmbedDirectory . $relativeSlash . 'modules/' . $moduleName;
 95+ self::proccessModulePath( $moduleName, $modulePath );
9196 }
9297
9398 // Get all the extension loader paths registered mwEmbed modules
94 - foreach( $wgExtensionJavascriptLoader as $na => $loaderPath){
95 - // Setup the directory context for extensions relative to loader.js file:
96 - $modulePath = str_replace('/loader.js', '' , $loaderPath);
97 - self::proccessModulePath( $modulePath );
 99+ foreach( $wgExtensionJavascriptModules as $moduleName => $modulePath ){
 100+ self::proccessModulePath( $moduleName, $modulePath );
98101 }
99102
100103 if( defined( 'DO_MAINTENANCE' ) ) {
@@ -105,31 +108,34 @@
106109 /**
107110 * Process a loader path, passes off to proccessLoaderContent
108111 *
109 - * @param String $path Path to module to be processed
 112+ * @param String $moduleName Name of module to be processed
 113+ * @param String $modulePath Path to module to be processed
110114 */
111 - private static function proccessModulePath( $path ){
 115+ private static function proccessModulePath( $moduleName, $modulePath ){
112116 global $wgExtensionMessagesFiles;
113117
114118 // Get the module name
115 - $moduleName = end( explode('/', $path ) );
 119+ $moduleName = end( explode('/', $modulePath ) );
116120
117121 // Set the directory context for relative js/css paths
118 - self::$directoryContext = $path;
 122+ self::$directoryContext = $modulePath;
119123
120124 // Check for the loader.js
121 - if( !is_file( $path . '/loader.js' ) ){
 125+ if( !is_file( $modulePath . '/loader.js' ) ){
122126 throw new MWException( "Javascript Module $moduleName missing loader.js file\n" );
123127 return false;
124128 }
125129
126 - $fileContent = file_get_contents( $path . '/loader.js');
127 - self::proccessLoaderContent( $fileContent );
 130+ $fileContent = file_get_contents( $modulePath . '/loader.js');
 131+ self::proccessLoaderContent( $fileContent, $moduleName );
128132
129 - $i18nPath = realpath( $path . '/' . $moduleName . '.i18n.php' );
 133+ $i18nPath = realpath( $modulePath . '/' . $moduleName . '.i18n.php' );
130134
131135 // Add the module localization file if present:
132136 if( is_file( $i18nPath ) ) {
133137 $wgExtensionMessagesFiles[ $moduleName ] = $i18nPath;
 138+ } else {
 139+ // Module has no message file
134140 }
135141 }
136142
@@ -140,10 +146,14 @@
141147 *
142148 * @param String $fileContent content of loader.js file
143149 */
144 - private static function proccessLoaderContent( & $fileContent ){
 150+ private static function proccessLoaderContent( & $fileContent , $moduleName){
145151 // Add the mwEmbed loader js to its global collector:
146152 self::$combinedLoadersJs .= $fileContent;
147153
 154+ // Is there a way to pass arguments in preg_replace_callback ?
 155+ self::$currentModuleName = $moduleName;
 156+
 157+ // Run the replace callback:
148158 preg_replace_callback(
149159 self::$classReplaceExp,
150160 'jsClassLoader::preg_classPathLoader',
@@ -276,8 +286,38 @@
277287 // Strip $ from class (as they are stripped on URL request parameter input)
278288 $className = str_replace( '$', '', $className );
279289 $classPath = ( self::$directoryContext == '' )? $classPath : self::$directoryContext . '/' . $classPath;
 290+
 291+ // Throw an error if we already have defined this class:
 292+ // This prevents a module from registering a shared class
 293+ // or multiple modules using the same className
 294+ if( isset( $wgScriptLoaderNamedPaths[ $className ] ) ){
 295+
 296+ // Presently extensions don't register were the named path parent module
 297+ // so we just have a gnneral extension error.
 298+ $setInModuleError = ( self::$classParentModuleName [ $className ] )
 299+ ? " set in module: " . self::$classParentModuleName [ $className ]
 300+ : " set in an extension ";
 301+
 302+ throw new MWException( "Error class $className already $setInModuleError \n" );
 303+ }
 304+
 305+ // Else update the global $wgScriptLoaderNamedPaths ( all scriptloader named paths )
280306 $wgScriptLoaderNamedPaths[ $className ] = $classPath;
 307+
 308+ // Register the parent module ( javascript module specific )
 309+ self::$classParentModuleName [ $className ] = self::$currentModuleName ;
281310 }
282311 }
 312+ /**
 313+ * Return the module name for a given class or false if not found
 314+ * @param $className Class to get the module for
 315+ */
 316+ public function getClassModuleName( $className ){
 317+ if( isset( self::$classParentModuleName [ $className ] ) ){
 318+ return self::$classParentModuleName [ $className ];
 319+ } else {
 320+ return false;
 321+ }
 322+ }
283323 }
284324
Property changes on: trunk/extensions/JS2Support/mwEmbed/includes/cache
___________________________________________________________________
Name: svn:ignore
285325 + 0
1
2
3
4
5
6
7
8
9
a
b
c
d
e
Index: trunk/extensions/JS2Support/mwEmbed/includes/noMediaWikiConfig.php
@@ -28,8 +28,8 @@
2929 // Named paths for the script loader
3030 $wgScriptLoaderNamedPaths = array();
3131
32 -// Added Modules
33 -$wgExtensionJavascriptLoader = array();
 32+// Named Module Paths
 33+$wgExtensionJavascriptModules = array();
3434
3535 // Extension Messages Files
3636 $wgExtensionMessagesFiles = array();
Index: trunk/extensions/JS2Support/mwEmbed/jsScriptLoader.php
@@ -51,6 +51,8 @@
5252 // The raw requested class
5353 private static $rawClassList = '';
5454
 55+ private static $includeAllMsgsRegEx = "/mw\.includeAllModuleMsgs\s*\(\s*\)\;?/";
 56+
5557 /**
5658 * Output the javascript from cache
5759 *
@@ -782,9 +784,18 @@
783785
784786 // Do language swap by index:
785787 if ( $wgEnableScriptLocalization ){
786 - // Get the mw.addMessage javascript from class name
 788+ // Get the localized mw.addMessage javascript call from class name
787789 $translatedJs = "\n" . $this->getInlineMsgFromClass( $className ) . "\n";
788790
 791+ //@@NOTE getInlineMsgFromClass could identify which mode we are in and we would not need to
 792+ // try each of these search patterns in the same order as before.
 793+
 794+ // Check for mw.includeAllModuleMsgs() call to be replaced with all the msgs
 795+ $scriptText = preg_replace( self::$includeAllMsgsRegEx, $translatedJs, $scriptText, 1, $count );
 796+ if( $count != 0 ){
 797+ return $scriptText;
 798+ }
 799+
789800 // Replace mw.addMessages with localized msgs in javascript string
790801 $inx = self::getAddMessagesIndex( $scriptText );
791802 if( $inx ){
@@ -799,7 +810,7 @@
800811 return substr($scriptText, 0, $inx['sfull']) . $translatedJs . substr($scriptText, $inx['efull']+1 );
801812 }
802813 }
803 - // Return the js str unmodified if we did not transform with the localisation.
 814+ // Return the javascript str unmodified if we did not transform with the localisation
804815 return $scriptText;
805816 }
806817
@@ -942,22 +953,34 @@
943954 * @return {Array} decoded json array of message key value pairs
944955 */
945956 function getMsgKeysFromClass( $className ){
 957+
946958 $scriptString = $this->getScriptText( $className );
947959
948 - // Try for AddMessagesIndex
949 - $inx = self::getAddMessagesIndex( $scriptString );
950 - if( $inx ) {
951 - //Get the javascript string
952 - $javaScriptArrayString = substr($scriptString, $inx['s'], ($inx['e']-$inx['s'])) ;
 960+ // Try for includeAllModuleMsgs function call
 961+ if ( preg_match ( self::$includeAllMsgsRegEx, $scriptString ) !== false ) {
 962+ global $wgExtensionJavascriptModules, $wgExtensionMessagesFiles;
 963+ // Get the module $messages keys
953964
954 - // Strip the javascript string of any comments
955 - $javaScriptArrayString = JSMin::minify( $javaScriptArrayString );
 965+ $moduleName = jsClassLoader::getClassModuleName( $className );
 966+ if( $moduleName && $wgExtensionJavascriptModules[ $moduleName ] ) {
956967
957 - // Return the parsed json array of javascript msgs
958 - return FormatJson::decode( '{' . $javaScriptArrayString . '}', true);
 968+ // Get the module localization file:
 969+ $modulePath = $wgExtensionJavascriptModules[ $moduleName ];
 970+
 971+ // Empty out messages in the current scope
 972+ $messages = array();
 973+
 974+ // Get the i18n file from $wgExtensionMessagesFiles path
 975+ require( $wgExtensionMessagesFiles[ $moduleName ] );
 976+
 977+ // Return the English key set ( since base message text is in english )
 978+ return $messages['en'];
 979+ } else {
 980+ // No $moduleName found.
 981+ }
959982 }
960983
961 - // Try for 'AddMessageKey' Index array type
 984+ // Try for mw.addMessageKey() Index array type
962985 $inx = self::getAddMessageKeyIndex( $scriptString );
963986 if( $inx ) {
964987 // Get the javascript array string:
@@ -983,6 +1006,19 @@
9841007
9851008 }
9861009
 1010+ // Try for addMessages() Index json type
 1011+ $inx = self::getAddMessagesIndex( $scriptString );
 1012+ if( $inx ) {
 1013+ //Get the javascript string
 1014+ $javaScriptArrayString = substr($scriptString, $inx['s'], ($inx['e']-$inx['s'])) ;
 1015+
 1016+ // Strip the javascript string of any comments
 1017+ $javaScriptArrayString = JSMin::minify( $javaScriptArrayString );
 1018+
 1019+ // Return the parsed json array of javascript msgs
 1020+ return FormatJson::decode( '{' . $javaScriptArrayString . '}', true);
 1021+ }
 1022+
9871023 // Return an empty array if we are not able to grab any message keys
9881024 return array();
9891025 }
@@ -993,10 +1029,10 @@
9941030 * @param {Array} $jmsg Associative array of message key -> message value pairs
9951031 * @param {String} $langCode Language code override
9961032 */
997 - static public function updateMessageValues(& $messegeArray, $langCode = false){
 1033+ static public function updateMessageValues( & $messegeArray, $langCode = false ){
9981034 global $wgLang;
9991035 // Check the langCode
1000 - if(!$langCode && $wgLang) {
 1036+ if( ! $langCode && $wgLang) {
10011037 $langCode = $wgLang->getCode();
10021038 }
10031039 // Get the msg keys for the a json array
Index: trunk/extensions/JS2Support/JS2Support.php
@@ -23,7 +23,7 @@
2424 $wgExtensionFunctions[] = 'wfSetupJS2';
2525 function wfSetupJS2(){
2626 global $wgOut, $js2Dir, $wgAutoloadClasses, $wgScriptLoaderNamedPaths,
27 - $wgExtensionJavascriptLoader, $wgEnableTestJavascriptModules;
 27+ $wgExtensionJavascriptModules, $wgEnableTestJavascriptModules;
2828
2929 // Remap output page as part of the extension setup
3030 $wgOut = new StubObject( 'wgOut', 'ScriptLoaderOutputPage' );
@@ -34,14 +34,11 @@
3535
3636 // Add the core test module loaders (extensions can add their own test modules referencing this global )
3737 if( $wgEnableTestJavascriptModules ) {
38 - $wgExtensionJavascriptLoader[] = 'extensions/JS2Support/tests/loader.js';
 38+ $wgExtensionJavascriptModules['JS2Tests'] = 'extensions/JS2Support/tests';
3939 }
4040
41 -
4241 // Update all the javascript modules classNames and localization by reading respective loader.js files
43 - // @dependent on all extensions defining $wgExtensionJavascriptLoader paths in config file ( not in setup )
44 - // @NOTE parsing javascript could be delayed or avoided if we require more php extension configuration
45 - // extension would have to configure the path to javascript module localizations and possibly class paths
 42+ // @dependent on all extensions defining $wgExtensionJavascriptModules paths in config file ( not in setup )
4643 //
4744 // @NOTE runtime for loadClassPaths with 8 or so loaders with 100 or so named paths is
4845 // is around .002 seconds on my laptop. Could probably be further optimized and of course it only runs
@@ -75,10 +72,10 @@
7673
7774
7875 /**
79 - * For defining the location of loader.js files of
 76+ * For naming javascript modules in extensions
8077 * for js-modules. ( ie modules hosted inside of extensions )
8178 */
82 -$wgExtensionJavascriptLoader = array();
 79+$wgExtensionJavascriptModules = array();
8380
8481 /**
8582 * The set of script-loader Named Paths, populated via extensions and javascript module loaders
Index: trunk/extensions/JS2Support/maintenance/MergeJavascriptMsg.php
@@ -2,7 +2,7 @@
33 /**
44 * Merges in JavaScript json msgs into respective module i18n.php file
55 *
6 -* If your script uses JSON msg string with the This script helps merge msgs between javascript and php
 6+* If your script uses JSON msg string with the This script helps merge msgs from javascript to php
77 *
88 *
99 * @file
@@ -25,10 +25,9 @@
2626 }
2727
2828 public function execute() {
29 - global $wgExtensionJavascriptLoader, $IP;
30 - foreach ( $wgExtensionJavascriptLoader as $loaderPath ){
 29+ global $wgExtensionJavascriptModules, $IP;
 30+ foreach ( $wgExtensionJavascriptModule as $modulePath ){
3131
32 - $modulePath = dirname( $loaderPath );
3332 $i18nFilePath = false;
3433 $moduleAbsoultePath = $IP ."/". $modulePath;
3534
Index: trunk/extensions/JS2Support/README
@@ -76,9 +76,16 @@
7777 The use of "loaders" enables dynamic packaging of modules with the intent of avoiding multiple requests,
7878 for dynamically loaded interfaces.
7979
80 -JS2 enables the server to deliver static configuration files that drive interface customizations in
81 -javascript rather than costly dynamically html output from php.
82 -
 80+To add a javascript Module to your extension you must supply the relative path to the module in your main
 81+extension .php file:
 82+
 83+$wgExtensionJavascriptModules[ 'myJsModule' ] = 'extensions/myExtension/MyJsModule';
 84+
 85+Your MyJsModule folder should contain:
 86+loader.js ( "module loader" )
 87+{moduleName}.i18n.php ( "mediaWiki localization format localization file" )
 88+{libraryCode.js files} ( "library code" )
 89+
8390 == JS Module Components ==
8491
8592 The three components of a js-module are "module loaders", "module activators" and "library code and assets".
@@ -198,6 +205,8 @@
199206
200207 Putting this function call at the top of your primary library code javascript file will be
201208 replaced with all the msgs in your modules php localization file in the current language.
 209+NOTE you won't be able to pull in msgKeys that are hosted outside of your extension ( to do that
 210+you must list the keys you want at the top of the javascript file with localization option 2 )
202211
203212 2 ) If your code includes many sub-modules and you may want fine grain control over what msgs
204213 are packaged when. You can define the set of msg keys it at the top of any javascript file.
@@ -215,8 +224,9 @@
216225 copy your English fallbacks into the php localization file for the translate wiki scripts to work with.
217226 Running the JS2Support maintenance script "mergeJavascriptMsgs.php" will sync javascript into phpt files.
218227
219 -This is the most complicated setup, if your unsure use the first option:
 228+This is the most complicated setup, if your unsure use the first option and call:
220229 mw.includeAllModuleMsgs();
 230+In your primary library code javascript.
221231
222232 === Accessing Msgs in Javascript ===
223233
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php
@@ -49,10 +49,10 @@
5050
5151
5252 // Add the javascript loader for "EmbedPlayer module"
53 -$wgExtensionJavascriptLoader[] = "extensions/TimedMediaHandler/EmbedPlayer/loader.js";
 53+$wgExtensionJavascriptModules[ 'EmbedPlayer' ] = "extensions/TimedMediaHandler/EmbedPlayer";
5454
5555 // Add the javascript loader for "TimedText module"
56 -$wgExtensionJavascriptLoader[] = "extensions/TimedMediaHandler/TimedText/loader.js";
 56+$wgExtensionJavascriptModules[ 'TimedText' ] = "extensions/TimedMediaHandler/TimedText";
5757
5858 /******************* CONFIGURATION STARTS HERE **********************/
5959
Index: trunk/extensions/TimedMediaHandler/TimedText/mw.TimedTextEdit.js
@@ -426,7 +426,7 @@
427427
428428 // Build cancel button
429429 var cancelButton = {};
430 - var cancelText = gM( 'mwe-timedtext-cancel' );
 430+ var cancelText = gM( 'mwe-cancel' );
431431 cancelButton[ cancelText ] = function() {
432432 _this.onCancelClipEdit();
433433 };
Index: branches/UsabilityInitiativeJS2/loader.js
@@ -13,17 +13,16 @@
1414 "mw.style.wikiEditorToolbar" : "css/wikiEditor.toolbar.css",
1515 "mw.style.vectorJquery-ui" : "css/vector/jquery-ui-1.7.2.css",
1616
17 -
1817 "$j.whileAsync" : "js/plugins/jquery.async.js",
 18+
1919 "$j.fn.autoEllipsis" : "js/plugins/jquery.autoEllipsis.js",
20 - "$j.browserTest" : "js/plugins/jquery.browser.js",
 20+
2121 "$j.fn.collapsibleTabs" : "js/plugins/jquery.collapsibleTabs.js",
2222 "$j.fn.color" : "js/plugins/jquery.color.js",
2323
2424 "$j.fn.delayedBind" : "js/plugins/jquery.delayedBind.js",
25 -
26 - "$j.fn.suggestions" : "js/plugins/jquery.suggestions.js",
2725
 26+
2827 "$j.wikiEditor" : "js/plugins/jquery.wikiEditor.js",
2928
3029 "$j.wikiEditor.modules.dialogs" : "js/plugins/jquery.wikiEditor.dialogs.js",
Index: branches/UsabilityInitiativeJS2/UsabilityInitiative.php
@@ -47,7 +47,7 @@
4848 $wgHooks['BeforePageDisplay'][] = 'UsabilityInitiativeHooks::addResources';
4949 $wgHooks['MakeGlobalVariablesScript'][] = 'UsabilityInitiativeHooks::addJSVars';
5050
51 -// Register the loader.js
52 -$wgExtensionJavascriptLoader[] = 'extensions/UsabilityInitiativeJS2/loader.js';
 51+// Register the UsabilityInitiative javascript module path:
 52+$wgExtensionJavascriptModules[ 'UsabilityInitiative' ] = 'extensions/UsabilityInitiativeJS2';
5353
5454
Index: branches/UsabilityInitiativeJS2/.project
@@ -0,0 +1,22 @@
 2+<?xml version="1.0" encoding="UTF-8"?>
 3+<projectDescription>
 4+ <name>UsabilityInitiativeJS2</name>
 5+ <comment></comment>
 6+ <projects>
 7+ </projects>
 8+ <buildSpec>
 9+ <buildCommand>
 10+ <name>org.eclipse.php.core.PhpIncrementalProjectBuilder</name>
 11+ <arguments>
 12+ </arguments>
 13+ </buildCommand>
 14+ <buildCommand>
 15+ <name>org.eclipse.php.core.ValidationManagerWrapper</name>
 16+ <arguments>
 17+ </arguments>
 18+ </buildCommand>
 19+ </buildSpec>
 20+ <natures>
 21+ <nature>org.eclipse.php.core.PHPNature</nature>
 22+ </natures>
 23+</projectDescription>

Follow-up revisions

RevisionCommit summaryAuthorDate
r66444uploadWizard part of r66443dale21:38, 14 May 2010

Status & tagging log