Index: trunk/extensions/AddMediaWizard/AddMediaWizard.php |
— | — | @@ -45,10 +45,10 @@ |
46 | 46 | |
47 | 47 | |
48 | 48 | // Add the javascript loader for "AddMedia module" |
49 | | -$wgExtensionJavascriptLoader[] = 'extensions/AddMediaWizard/AddMedia/loader.js'; |
| 49 | +$wgExtensionJavascriptModules['AddMedia'] = 'extensions/AddMediaWizard/AddMedia'; |
50 | 50 | |
51 | 51 | // Add the javascript loader for "ClipEdit module" |
52 | | -$wgExtensionJavascriptLoader[] = 'extensions/AddMediaWizard/ClipEdit/loader.js'; |
| 52 | +$wgExtensionJavascriptModules['ClipEdit'] = 'extensions/AddMediaWizard/ClipEdit'; |
53 | 53 | |
54 | 54 | class AddMediaWizard { |
55 | 55 | public static function addJS( $toolbar) { |
Index: trunk/extensions/AddMediaWizard/AddMedia/mw.FirefoggGUI.js |
— | — | @@ -487,7 +487,7 @@ |
488 | 488 | 'maxlength="' + maxDigits + '" ' + |
489 | 489 | 'size="' + maxDigits + '" ' + |
490 | 490 | '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;" ' + |
492 | 492 | 'value="' + defaultValue + '" >' + |
493 | 493 | '<div class="slider_' + configKey + '"></div>'; |
494 | 494 | break; |
— | — | @@ -574,7 +574,7 @@ |
575 | 575 | $j( this.target_input_file_name ).width( 250 ); |
576 | 576 | |
577 | 577 | // Special preset action |
578 | | - $j( this.selector + ' ._preset_select' ).change( function() { |
| 578 | + $j( this.selector + ' ._preset_select' ).change( function() { |
579 | 579 | _this.updatePresetSelection( $j( this ).val() ); |
580 | 580 | }); |
581 | 581 | |
— | — | @@ -634,7 +634,7 @@ |
635 | 635 | $j( this.selector + ' ._' + configKey) |
636 | 636 | .click( function() { |
637 | 637 | _this.updateLocalValue( _this.getClassId( this ), |
638 | | - $j( this ).is( ":checked" ) ); |
| 638 | + $j( this ).is( ":checked" ) ); |
639 | 639 | _this.updatePresetSelection( 'custom' ); |
640 | 640 | }); |
641 | 641 | break; |
— | — | @@ -643,10 +643,11 @@ |
644 | 644 | case 'int': |
645 | 645 | case 'float': |
646 | 646 | // Check if we have a validate function on the string |
647 | | - $j( this.selector + ' ._' + configKey ).change( function() { |
| 647 | + $j( this.selector + ' ._' + configKey ).change( function() { |
648 | 648 | $j( this ).val( _this.updateLocalValue( |
649 | 649 | _this.getClassId( this ), |
650 | | - $j( this ).val() ) ); |
| 650 | + $j( this ).val() ) |
| 651 | + ); |
651 | 652 | _this.updatePresetSelection( 'custom' ); |
652 | 653 | }) |
653 | 654 | break; |
— | — | @@ -660,8 +661,30 @@ |
661 | 662 | } |
662 | 663 | }); |
663 | 664 | 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 | + |
666 | 689 | $j( this.selector + ' .slider_' + configKey ).slider({ |
667 | 690 | range: "min", |
668 | 691 | animate: true, |
— | — | @@ -670,27 +693,13 @@ |
671 | 694 | min: this.default_encoder_config[ configKey ].range.min, |
672 | 695 | max: this.default_encoder_config[ configKey ].range.max, |
673 | 696 | slide: function( event, ui ) { |
| 697 | + var sliderId = _this.getClassId( this, 'slider_' ); |
674 | 698 | $j( _this.selector + ' ._' + sliderId ).val( ui.value ); |
675 | 699 | |
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 ); |
693 | 701 | }, |
694 | 702 | change: function( event, ui ) { |
| 703 | + var sliderId = _this.getClassId( this, 'slider_' ); |
695 | 704 | _this.updateLocalValue( sliderId, ui.value ); |
696 | 705 | _this.updatePresetSelection( 'custom' ); |
697 | 706 | } |
— | — | @@ -698,15 +707,18 @@ |
699 | 708 | |
700 | 709 | $j( this.selector + ' ._' + configKey ).change( function() { |
701 | 710 | 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 | + ); |
704 | 714 | _this.updatePresetSelection( 'custom' ); |
705 | 715 | // Change it to the validated value |
706 | 716 | $j( this ).val( validValue ); |
707 | 717 | // 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 ); |
711 | 723 | }); |
712 | 724 | break; |
713 | 725 | } |
— | — | @@ -729,7 +741,7 @@ |
730 | 742 | updatePresetSelection: function( presetKey ) { |
731 | 743 | // Update the local configuration |
732 | 744 | this.local_settings['default'] = presetKey; |
733 | | - // mw.log( 'update preset desc: ' + presetKey ); |
| 745 | + mw.log( 'update preset desc: ' + presetKey ); |
734 | 746 | var presetDesc = ''; |
735 | 747 | if ( this.local_settings.presets[presetKey].desc ) { |
736 | 748 | presetDesc = this.local_settings.presets[presetKey].desc; |
— | — | @@ -778,8 +790,8 @@ |
779 | 791 | * range if required. Update the configuration with the validated value and |
780 | 792 | * return it. |
781 | 793 | */ |
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' ) { |
784 | 796 | mw.log( "Error: could not update conf key: " + confKey ) |
785 | 797 | return value; |
786 | 798 | } |
— | — | @@ -824,14 +836,14 @@ |
825 | 837 | * If no prefix is given, "_" is assumed. |
826 | 838 | */ |
827 | 839 | 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(); |
830 | 842 | if ( !prefix ) { |
831 | 843 | prefix = '_'; |
832 | 844 | } |
833 | 845 | if ( eltClass.substr( 0, prefix.length ) == prefix ) { |
834 | 846 | eltClass = eltClass.substr( prefix.length ); |
835 | | - } |
| 847 | + } |
836 | 848 | return eltClass; |
837 | 849 | }, |
838 | 850 | |
— | — | @@ -985,7 +997,7 @@ |
986 | 998 | var pKey = this.local_settings[ 'default' ]; |
987 | 999 | this.updatePresetSelection( pKey ); |
988 | 1000 | |
989 | | - // set the actual HTML & widgets based on any local settings values: |
| 1001 | + // Set the actual HTML & widgets based on any local settings values: |
990 | 1002 | $j.each( _this.local_settings.presets['custom']['conf'], function( inx, val ) { |
991 | 1003 | if ( $j( _this.selector + ' ._' + inx ).length != 0 ) { |
992 | 1004 | $j( _this.selector + ' ._' + inx ).val( val ); |
Index: trunk/extensions/JS2Support/ScriptLoaderOutputPage.php |
— | — | @@ -337,7 +337,7 @@ |
338 | 338 | * @since 1.17 |
339 | 339 | */ |
340 | 340 | public function includeAllPageJS ( ) { |
341 | | - global $wgExtensionJavascriptLoader, $wgEnableScriptLoader, |
| 341 | + global $wgExtensionJavascriptModules, $wgEnableScriptLoader, |
342 | 342 | $wgScriptLoaderNamedPaths, $wgScriptPath; |
343 | 343 | |
344 | 344 | // Set core Classes |
— | — | @@ -362,28 +362,28 @@ |
363 | 363 | $this->mScripts = "\n<!-- Script bucket: allpage --> \n"; |
364 | 364 | $this->mScripts = $this->getLinkedScriptLoaderJs( $coreClasses ); |
365 | 365 | } else { |
366 | | - // No ScriptLoader manually add the classes: |
| 366 | + // No ScriptLoader manually add classes that are normally part of mwEmbed core request. |
367 | 367 | $so = ''; |
368 | 368 | foreach( $coreClasses as $className ){ |
369 | 369 | $this->addScriptClass( $className ); |
370 | 370 | } |
371 | 371 | |
372 | | - // Add the mwEmbed "core-components" ( language, parsing etc ) |
| 372 | + // Add the mwEmbed "core-components" ( language, parsing etc. ) |
373 | 373 | $coreComponets = jsClassLoader::getComponentsList(); |
374 | 374 | foreach( $coreComponets as $className ) { |
375 | 375 | $this->addScriptClass( $className ); |
376 | 376 | } |
377 | 377 | |
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 ){ |
380 | 380 | // Set the loader context for each loader javascript file |
381 | 381 | // ( so that javascript modules can use relative paths ) |
382 | | - $loaderDir = dirname( "$wgScriptPath/$loaderPath" ) . "/"; |
| 382 | + $loaderDir = $modulePath . "/"; |
383 | 383 | $this->addScript( Html::inlineScript( |
384 | 384 | "mw.setConfig( 'loaderContext', '" . xml::escapeJsString( $loaderDir ) . "');" |
385 | 385 | ) ); |
386 | 386 | $this->addScriptFile( |
387 | | - "$wgScriptPath/$loaderPath" |
| 387 | + "$wgScriptPath/$modulePath/loader.js" |
388 | 388 | ); |
389 | 389 | } |
390 | 390 | } |
— | — | @@ -525,7 +525,7 @@ |
526 | 526 | if( $path == false ){ |
527 | 527 | // NOTE:: could throw an error here |
528 | 528 | //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"); |
530 | 530 | return false; // could not find the class |
531 | 531 | } |
532 | 532 | // Valid path add it to script-loader or "link" directly |
Index: trunk/extensions/JS2Support/mwEmbed/includes/jsClassLoader.php |
— | — | @@ -25,11 +25,17 @@ |
26 | 26 | // The current directory context. Used in loading javascript modules outside of the mwEmbed folder |
27 | 27 | private static $directoryContext = ''; |
28 | 28 | |
| 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 | + |
29 | 35 | /** |
30 | 36 | * Get the javascript class paths from javascript files |
31 | 37 | */ |
32 | 38 | public static function loadClassPaths(){ |
33 | | - global $wgMwEmbedDirectory, $wgExtensionJavascriptLoader, |
| 39 | + global $wgMwEmbedDirectory, $wgExtensionJavascriptModules, |
34 | 40 | $wgScriptLoaderNamedPaths, $wgExtensionMessagesFiles, $IP; |
35 | 41 | |
36 | 42 | // Only run once |
— | — | @@ -55,12 +61,10 @@ |
56 | 62 | return false; |
57 | 63 | } |
58 | 64 | |
59 | | - // Read the mwEmbed loader file: |
| 65 | + // Proccess the mwEmbed loader file: |
60 | 66 | $fileContent = file_get_contents( $mwEmbedAbsolutePath . '/loader.js' ); |
61 | | - |
62 | | - // Get class paths from mwEmbed.js |
63 | 67 | self::$directoryContext = $wgMwEmbedDirectory; |
64 | | - self::proccessLoaderContent( $fileContent ); |
| 68 | + self::proccessLoaderContent( $fileContent , 'mwEmbed' ); |
65 | 69 | |
66 | 70 | // Get the list of core component into self::$coreComponentsList |
67 | 71 | preg_replace_callback( |
— | — | @@ -86,14 +90,13 @@ |
87 | 91 | // Get all the classes from the enabled mwEmbed modules folder |
88 | 92 | foreach( self::$moduleList as $na => $moduleName){ |
89 | 93 | $relativeSlash = ( $wgMwEmbedDirectory == '' )? '' : '/'; |
90 | | - self::proccessModulePath( $wgMwEmbedDirectory . $relativeSlash . 'modules/' . $moduleName ); |
| 94 | + $modulePath = $wgMwEmbedDirectory . $relativeSlash . 'modules/' . $moduleName; |
| 95 | + self::proccessModulePath( $moduleName, $modulePath ); |
91 | 96 | } |
92 | 97 | |
93 | 98 | // 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 ); |
98 | 101 | } |
99 | 102 | |
100 | 103 | if( defined( 'DO_MAINTENANCE' ) ) { |
— | — | @@ -105,31 +108,34 @@ |
106 | 109 | /** |
107 | 110 | * Process a loader path, passes off to proccessLoaderContent |
108 | 111 | * |
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 |
110 | 114 | */ |
111 | | - private static function proccessModulePath( $path ){ |
| 115 | + private static function proccessModulePath( $moduleName, $modulePath ){ |
112 | 116 | global $wgExtensionMessagesFiles; |
113 | 117 | |
114 | 118 | // Get the module name |
115 | | - $moduleName = end( explode('/', $path ) ); |
| 119 | + $moduleName = end( explode('/', $modulePath ) ); |
116 | 120 | |
117 | 121 | // Set the directory context for relative js/css paths |
118 | | - self::$directoryContext = $path; |
| 122 | + self::$directoryContext = $modulePath; |
119 | 123 | |
120 | 124 | // Check for the loader.js |
121 | | - if( !is_file( $path . '/loader.js' ) ){ |
| 125 | + if( !is_file( $modulePath . '/loader.js' ) ){ |
122 | 126 | throw new MWException( "Javascript Module $moduleName missing loader.js file\n" ); |
123 | 127 | return false; |
124 | 128 | } |
125 | 129 | |
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 ); |
128 | 132 | |
129 | | - $i18nPath = realpath( $path . '/' . $moduleName . '.i18n.php' ); |
| 133 | + $i18nPath = realpath( $modulePath . '/' . $moduleName . '.i18n.php' ); |
130 | 134 | |
131 | 135 | // Add the module localization file if present: |
132 | 136 | if( is_file( $i18nPath ) ) { |
133 | 137 | $wgExtensionMessagesFiles[ $moduleName ] = $i18nPath; |
| 138 | + } else { |
| 139 | + // Module has no message file |
134 | 140 | } |
135 | 141 | } |
136 | 142 | |
— | — | @@ -140,10 +146,14 @@ |
141 | 147 | * |
142 | 148 | * @param String $fileContent content of loader.js file |
143 | 149 | */ |
144 | | - private static function proccessLoaderContent( & $fileContent ){ |
| 150 | + private static function proccessLoaderContent( & $fileContent , $moduleName){ |
145 | 151 | // Add the mwEmbed loader js to its global collector: |
146 | 152 | self::$combinedLoadersJs .= $fileContent; |
147 | 153 | |
| 154 | + // Is there a way to pass arguments in preg_replace_callback ? |
| 155 | + self::$currentModuleName = $moduleName; |
| 156 | + |
| 157 | + // Run the replace callback: |
148 | 158 | preg_replace_callback( |
149 | 159 | self::$classReplaceExp, |
150 | 160 | 'jsClassLoader::preg_classPathLoader', |
— | — | @@ -276,8 +286,38 @@ |
277 | 287 | // Strip $ from class (as they are stripped on URL request parameter input) |
278 | 288 | $className = str_replace( '$', '', $className ); |
279 | 289 | $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 ) |
280 | 306 | $wgScriptLoaderNamedPaths[ $className ] = $classPath; |
| 307 | + |
| 308 | + // Register the parent module ( javascript module specific ) |
| 309 | + self::$classParentModuleName [ $className ] = self::$currentModuleName ; |
281 | 310 | } |
282 | 311 | } |
| 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 | + } |
283 | 323 | } |
284 | 324 | |
Property changes on: trunk/extensions/JS2Support/mwEmbed/includes/cache |
___________________________________________________________________ |
Name: svn:ignore |
285 | 325 | + 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 @@ |
29 | 29 | // Named paths for the script loader |
30 | 30 | $wgScriptLoaderNamedPaths = array(); |
31 | 31 | |
32 | | -// Added Modules |
33 | | -$wgExtensionJavascriptLoader = array(); |
| 32 | +// Named Module Paths |
| 33 | +$wgExtensionJavascriptModules = array(); |
34 | 34 | |
35 | 35 | // Extension Messages Files |
36 | 36 | $wgExtensionMessagesFiles = array(); |
Index: trunk/extensions/JS2Support/mwEmbed/jsScriptLoader.php |
— | — | @@ -51,6 +51,8 @@ |
52 | 52 | // The raw requested class |
53 | 53 | private static $rawClassList = ''; |
54 | 54 | |
| 55 | + private static $includeAllMsgsRegEx = "/mw\.includeAllModuleMsgs\s*\(\s*\)\;?/"; |
| 56 | + |
55 | 57 | /** |
56 | 58 | * Output the javascript from cache |
57 | 59 | * |
— | — | @@ -782,9 +784,18 @@ |
783 | 785 | |
784 | 786 | // Do language swap by index: |
785 | 787 | if ( $wgEnableScriptLocalization ){ |
786 | | - // Get the mw.addMessage javascript from class name |
| 788 | + // Get the localized mw.addMessage javascript call from class name |
787 | 789 | $translatedJs = "\n" . $this->getInlineMsgFromClass( $className ) . "\n"; |
788 | 790 | |
| 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 | + |
789 | 800 | // Replace mw.addMessages with localized msgs in javascript string |
790 | 801 | $inx = self::getAddMessagesIndex( $scriptText ); |
791 | 802 | if( $inx ){ |
— | — | @@ -799,7 +810,7 @@ |
800 | 811 | return substr($scriptText, 0, $inx['sfull']) . $translatedJs . substr($scriptText, $inx['efull']+1 ); |
801 | 812 | } |
802 | 813 | } |
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 |
804 | 815 | return $scriptText; |
805 | 816 | } |
806 | 817 | |
— | — | @@ -942,22 +953,34 @@ |
943 | 954 | * @return {Array} decoded json array of message key value pairs |
944 | 955 | */ |
945 | 956 | function getMsgKeysFromClass( $className ){ |
| 957 | + |
946 | 958 | $scriptString = $this->getScriptText( $className ); |
947 | 959 | |
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 |
953 | 964 | |
954 | | - // Strip the javascript string of any comments |
955 | | - $javaScriptArrayString = JSMin::minify( $javaScriptArrayString ); |
| 965 | + $moduleName = jsClassLoader::getClassModuleName( $className ); |
| 966 | + if( $moduleName && $wgExtensionJavascriptModules[ $moduleName ] ) { |
956 | 967 | |
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 | + } |
959 | 982 | } |
960 | 983 | |
961 | | - // Try for 'AddMessageKey' Index array type |
| 984 | + // Try for mw.addMessageKey() Index array type |
962 | 985 | $inx = self::getAddMessageKeyIndex( $scriptString ); |
963 | 986 | if( $inx ) { |
964 | 987 | // Get the javascript array string: |
— | — | @@ -983,6 +1006,19 @@ |
984 | 1007 | |
985 | 1008 | } |
986 | 1009 | |
| 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 | + |
987 | 1023 | // Return an empty array if we are not able to grab any message keys |
988 | 1024 | return array(); |
989 | 1025 | } |
— | — | @@ -993,10 +1029,10 @@ |
994 | 1030 | * @param {Array} $jmsg Associative array of message key -> message value pairs |
995 | 1031 | * @param {String} $langCode Language code override |
996 | 1032 | */ |
997 | | - static public function updateMessageValues(& $messegeArray, $langCode = false){ |
| 1033 | + static public function updateMessageValues( & $messegeArray, $langCode = false ){ |
998 | 1034 | global $wgLang; |
999 | 1035 | // Check the langCode |
1000 | | - if(!$langCode && $wgLang) { |
| 1036 | + if( ! $langCode && $wgLang) { |
1001 | 1037 | $langCode = $wgLang->getCode(); |
1002 | 1038 | } |
1003 | 1039 | // Get the msg keys for the a json array |
Index: trunk/extensions/JS2Support/JS2Support.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | $wgExtensionFunctions[] = 'wfSetupJS2'; |
25 | 25 | function wfSetupJS2(){ |
26 | 26 | global $wgOut, $js2Dir, $wgAutoloadClasses, $wgScriptLoaderNamedPaths, |
27 | | - $wgExtensionJavascriptLoader, $wgEnableTestJavascriptModules; |
| 27 | + $wgExtensionJavascriptModules, $wgEnableTestJavascriptModules; |
28 | 28 | |
29 | 29 | // Remap output page as part of the extension setup |
30 | 30 | $wgOut = new StubObject( 'wgOut', 'ScriptLoaderOutputPage' ); |
— | — | @@ -34,14 +34,11 @@ |
35 | 35 | |
36 | 36 | // Add the core test module loaders (extensions can add their own test modules referencing this global ) |
37 | 37 | if( $wgEnableTestJavascriptModules ) { |
38 | | - $wgExtensionJavascriptLoader[] = 'extensions/JS2Support/tests/loader.js'; |
| 38 | + $wgExtensionJavascriptModules['JS2Tests'] = 'extensions/JS2Support/tests'; |
39 | 39 | } |
40 | 40 | |
41 | | - |
42 | 41 | // 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 ) |
46 | 43 | // |
47 | 44 | // @NOTE runtime for loadClassPaths with 8 or so loaders with 100 or so named paths is |
48 | 45 | // is around .002 seconds on my laptop. Could probably be further optimized and of course it only runs |
— | — | @@ -75,10 +72,10 @@ |
76 | 73 | |
77 | 74 | |
78 | 75 | /** |
79 | | - * For defining the location of loader.js files of |
| 76 | + * For naming javascript modules in extensions |
80 | 77 | * for js-modules. ( ie modules hosted inside of extensions ) |
81 | 78 | */ |
82 | | -$wgExtensionJavascriptLoader = array(); |
| 79 | +$wgExtensionJavascriptModules = array(); |
83 | 80 | |
84 | 81 | /** |
85 | 82 | * 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 @@ |
3 | 3 | /** |
4 | 4 | * Merges in JavaScript json msgs into respective module i18n.php file |
5 | 5 | * |
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 |
7 | 7 | * |
8 | 8 | * |
9 | 9 | * @file |
— | — | @@ -25,10 +25,9 @@ |
26 | 26 | } |
27 | 27 | |
28 | 28 | public function execute() { |
29 | | - global $wgExtensionJavascriptLoader, $IP; |
30 | | - foreach ( $wgExtensionJavascriptLoader as $loaderPath ){ |
| 29 | + global $wgExtensionJavascriptModules, $IP; |
| 30 | + foreach ( $wgExtensionJavascriptModule as $modulePath ){ |
31 | 31 | |
32 | | - $modulePath = dirname( $loaderPath ); |
33 | 32 | $i18nFilePath = false; |
34 | 33 | $moduleAbsoultePath = $IP ."/". $modulePath; |
35 | 34 | |
Index: trunk/extensions/JS2Support/README |
— | — | @@ -76,9 +76,16 @@ |
77 | 77 | The use of "loaders" enables dynamic packaging of modules with the intent of avoiding multiple requests, |
78 | 78 | for dynamically loaded interfaces. |
79 | 79 | |
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 | + |
83 | 90 | == JS Module Components == |
84 | 91 | |
85 | 92 | The three components of a js-module are "module loaders", "module activators" and "library code and assets". |
— | — | @@ -198,6 +205,8 @@ |
199 | 206 | |
200 | 207 | Putting this function call at the top of your primary library code javascript file will be |
201 | 208 | 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 ) |
202 | 211 | |
203 | 212 | 2 ) If your code includes many sub-modules and you may want fine grain control over what msgs |
204 | 213 | are packaged when. You can define the set of msg keys it at the top of any javascript file. |
— | — | @@ -215,8 +224,9 @@ |
216 | 225 | copy your English fallbacks into the php localization file for the translate wiki scripts to work with. |
217 | 226 | Running the JS2Support maintenance script "mergeJavascriptMsgs.php" will sync javascript into phpt files. |
218 | 227 | |
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: |
220 | 229 | mw.includeAllModuleMsgs(); |
| 230 | +In your primary library code javascript. |
221 | 231 | |
222 | 232 | === Accessing Msgs in Javascript === |
223 | 233 | |
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php |
— | — | @@ -49,10 +49,10 @@ |
50 | 50 | |
51 | 51 | |
52 | 52 | // Add the javascript loader for "EmbedPlayer module" |
53 | | -$wgExtensionJavascriptLoader[] = "extensions/TimedMediaHandler/EmbedPlayer/loader.js"; |
| 53 | +$wgExtensionJavascriptModules[ 'EmbedPlayer' ] = "extensions/TimedMediaHandler/EmbedPlayer"; |
54 | 54 | |
55 | 55 | // Add the javascript loader for "TimedText module" |
56 | | -$wgExtensionJavascriptLoader[] = "extensions/TimedMediaHandler/TimedText/loader.js"; |
| 56 | +$wgExtensionJavascriptModules[ 'TimedText' ] = "extensions/TimedMediaHandler/TimedText"; |
57 | 57 | |
58 | 58 | /******************* CONFIGURATION STARTS HERE **********************/ |
59 | 59 | |
Index: trunk/extensions/TimedMediaHandler/TimedText/mw.TimedTextEdit.js |
— | — | @@ -426,7 +426,7 @@ |
427 | 427 | |
428 | 428 | // Build cancel button |
429 | 429 | var cancelButton = {}; |
430 | | - var cancelText = gM( 'mwe-timedtext-cancel' ); |
| 430 | + var cancelText = gM( 'mwe-cancel' ); |
431 | 431 | cancelButton[ cancelText ] = function() { |
432 | 432 | _this.onCancelClipEdit(); |
433 | 433 | }; |
Index: branches/UsabilityInitiativeJS2/loader.js |
— | — | @@ -13,17 +13,16 @@ |
14 | 14 | "mw.style.wikiEditorToolbar" : "css/wikiEditor.toolbar.css", |
15 | 15 | "mw.style.vectorJquery-ui" : "css/vector/jquery-ui-1.7.2.css", |
16 | 16 | |
17 | | - |
18 | 17 | "$j.whileAsync" : "js/plugins/jquery.async.js", |
| 18 | + |
19 | 19 | "$j.fn.autoEllipsis" : "js/plugins/jquery.autoEllipsis.js", |
20 | | - "$j.browserTest" : "js/plugins/jquery.browser.js", |
| 20 | + |
21 | 21 | "$j.fn.collapsibleTabs" : "js/plugins/jquery.collapsibleTabs.js", |
22 | 22 | "$j.fn.color" : "js/plugins/jquery.color.js", |
23 | 23 | |
24 | 24 | "$j.fn.delayedBind" : "js/plugins/jquery.delayedBind.js", |
25 | | - |
26 | | - "$j.fn.suggestions" : "js/plugins/jquery.suggestions.js", |
27 | 25 | |
| 26 | + |
28 | 27 | "$j.wikiEditor" : "js/plugins/jquery.wikiEditor.js", |
29 | 28 | |
30 | 29 | "$j.wikiEditor.modules.dialogs" : "js/plugins/jquery.wikiEditor.dialogs.js", |
Index: branches/UsabilityInitiativeJS2/UsabilityInitiative.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | $wgHooks['BeforePageDisplay'][] = 'UsabilityInitiativeHooks::addResources'; |
49 | 49 | $wgHooks['MakeGlobalVariablesScript'][] = 'UsabilityInitiativeHooks::addJSVars'; |
50 | 50 | |
51 | | -// Register the loader.js |
52 | | -$wgExtensionJavascriptLoader[] = 'extensions/UsabilityInitiativeJS2/loader.js'; |
| 51 | +// Register the UsabilityInitiative javascript module path: |
| 52 | +$wgExtensionJavascriptModules[ 'UsabilityInitiative' ] = 'extensions/UsabilityInitiativeJS2'; |
53 | 53 | |
54 | 54 | |
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> |