Index: branches/js2-work/phase3/includes/OutputPage.php |
— | — | @@ -131,11 +131,13 @@ |
132 | 132 | $path = "{$wgStylePath}/common/{$file}"; |
133 | 133 | } |
134 | 134 | |
135 | | - // If the class can be determined, use the addScriptClass method |
136 | | - $js_class = $this->getJsClassFromPath( $path ); |
137 | | - if( $js_class ) { |
138 | | - $this->addScriptClass( $js_class ); |
139 | | - return true; |
| 135 | + // If script-loader enabled check if we can add the script via script-loader |
| 136 | + if( $wgEnableScriptLoader ) { |
| 137 | + $js_class = $this->getJsClassFromPath( $path ); |
| 138 | + if( $js_class ) { |
| 139 | + $this->addScriptClass( $js_class ); |
| 140 | + return true; |
| 141 | + } |
140 | 142 | } |
141 | 143 | |
142 | 144 | // Do checks for wiki-titles |
— | — | @@ -199,7 +201,7 @@ |
200 | 202 | $this->addScriptClass( $js_class ); |
201 | 203 | } |
202 | 204 | } |
203 | | - //now re-append any scripts that got added prior to the addCoreScripts2Top call |
| 205 | + //Now re-append any scripts that got added prior to the addCoreScripts2Top call |
204 | 206 | $this->mScripts = $this->mScripts . $postScripts; |
205 | 207 | } |
206 | 208 | |
— | — | @@ -211,15 +213,6 @@ |
212 | 214 | global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses, $IP, |
213 | 215 | $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgStylePath, $wgEnableJS2system; |
214 | 216 | |
215 | | - // Load the javascript script class paths |
216 | | - if( ! $this->mLoadedJavascriptClasses ){ |
217 | | - require_once("$IP/js/mwEmbed/includes/jsAutoloadLocalClasses.php"); |
218 | | - // Issue the load request: |
219 | | - wfLoadMwEmbedClassPaths(); |
220 | | - // Set the flag to true |
221 | | - $this->mLoadedJavascriptClasses = true; |
222 | | - } |
223 | | - |
224 | 217 | $path = jsScriptLoader::getJsPathFromClass( $js_class ); |
225 | 218 | if( $path !== false ){ |
226 | 219 | if( $wgEnableScriptLoader ) { |
— | — | @@ -357,6 +350,8 @@ |
358 | 351 | */ |
359 | 352 | function getJsClassFromPath( $path ) { |
360 | 353 | global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgScriptPath; |
| 354 | + //Make sure we have the scriptClasses loaded: |
| 355 | + $this->loadJsClassPaths(); |
361 | 356 | |
362 | 357 | $scriptLoaderPaths = array_merge( $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses ); |
363 | 358 | foreach( $scriptLoaderPaths as $js_class => $js_path ) { |
— | — | @@ -366,6 +361,18 @@ |
367 | 362 | } |
368 | 363 | return false; |
369 | 364 | } |
| 365 | + /** |
| 366 | + * Loads the javascript class paths into the AutoLoad class var |
| 367 | + */ |
| 368 | + function loadJsClassPaths(){ |
| 369 | + // Load the javascript script class paths |
| 370 | + if( ! $this->mLoadedJavascriptClasses ){ |
| 371 | + // Issue the load request: |
| 372 | + jsClassLoader::loadClassPaths(); |
| 373 | + // Set the flag to true |
| 374 | + $this->mLoadedJavascriptClasses = true; |
| 375 | + } |
| 376 | + } |
370 | 377 | |
371 | 378 | /** |
372 | 379 | * Add a self-contained script tag with the given contents |
Index: branches/js2-work/phase3/includes/AutoLoader.php |
— | — | @@ -134,6 +134,7 @@ |
135 | 135 | 'JSMin' => 'js/mwEmbed/includes/library/JSMin.php', |
136 | 136 | 'JSMinException' => 'js/mwEmbed/includes/minify/JSMin.php', |
137 | 137 | 'jsScriptLoader' => 'js/mwEmbed/jsScriptLoader.php', |
| 138 | + 'jsClassLoader' => 'js/mwEmbed/includes/jsClassLoader.php', |
138 | 139 | 'Job' => 'includes/JobQueue.php', |
139 | 140 | 'LCStore_DB' => 'includes/LocalisationCache.php', |
140 | 141 | 'LCStore_CDB' => 'includes/LocalisationCache.php', |
Index: branches/js2-work/phase3/includes/DefaultSettings.php |
— | — | @@ -2862,6 +2862,12 @@ |
2863 | 2863 | */ |
2864 | 2864 | $wgJSAutoloadClasses = array(); |
2865 | 2865 | |
| 2866 | +/** |
| 2867 | + * For defining the location of loader.js files of |
| 2868 | + * external mwEmbed modules. ( ie modules hosted inside of extensions ) |
| 2869 | + */ |
| 2870 | +$wgJSModuleLoaderPaths = array(); |
| 2871 | + |
2866 | 2872 | /* |
2867 | 2873 | * boolean; if the script loader should be used to group all javascript requests. |
2868 | 2874 | * more about the script loader: http://www.mediawiki.org/wiki/ScriptLoader |
— | — | @@ -3146,9 +3152,9 @@ |
3147 | 3153 | /** |
3148 | 3154 | * Fake out the timezone that the server thinks it's in. This will be used for |
3149 | 3155 | * date display and not for what's stored in the DB. Leave to null to retain |
3150 | | - * your server's OS-based timezone value. |
| 3156 | + * your server's OS-based timezone value. |
3151 | 3157 | * |
3152 | | - * This variable is currently used only for signature formatting and for local |
| 3158 | + * This variable is currently used only for signature formatting and for local |
3153 | 3159 | * time/date parser variables ({{LOCALTIME}} etc.) |
3154 | 3160 | * |
3155 | 3161 | * Timezones can be translated by editing MediaWiki messages of type |
Index: branches/js2-work/phase3/js/mwEmbed/tests/Add_Media_Wizard.html |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | } |
14 | 14 | </style> |
15 | 15 | <script type="text/javascript" src="../mwEmbed.js?debug=true"></script> |
16 | | - <!-- <script type="text/javascript" src="../jsScriptLoader.php?class=window.jQuery,mwEmbed,remoteSearchDriver,$j.ui,$j.ui.resizable,$j.ui.draggable,$j.ui.dialog,$j.ui.tabs,$j.ui.sortable,$j.cookie,baseRemoteSearch&urid=1257728132531&debug=true&uselang=en"></script> --> |
| 16 | + <script type="text/javascript" src="../jsScriptLoader.php?class=window.jQuery,mwEmbed,mw.RemoteSearchDriver,$j.ui,$j.ui.resizable,$j.ui.draggable,$j.ui.dialog,$j.ui.tabs,$j.ui.sortable,$j.cookie,baseRemoteSearch&urid=1257728132531&debug=true&uselang=en"></script> |
17 | 17 | <script type="text/javascript"> |
18 | 18 | mw.ready(function(){ |
19 | 19 | mw.load( 'AddMedia.addMediaWizard', function(){ |
Index: branches/js2-work/phase3/js/mwEmbed/includes/jsAutoloadLocalClasses.php |
— | — | @@ -1,86 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -if ( !defined( 'MEDIAWIKI' ) ) die( 1 ); |
5 | | - |
6 | | -global $wgJSAutoloadLocalClasses, $wgMwEmbedDirectory; |
7 | | -global $wgJSModuleList; |
8 | | - |
9 | | -// NOTE this is growing in complexity and globals sloppiness |
10 | | -// we should refactor as a class with some static methods |
11 | | - |
12 | | -//Initialize $wgJSModuleList |
13 | | -$wgJSModuleList = array(); |
14 | | - |
15 | | -//Initialize $wgLoaderJs |
16 | | -$wgMwEmbedLoaderJs = ''; |
17 | | - |
18 | | -/** |
19 | | - * Loads javascript class name paths from mwEmbed.js |
20 | | - */ |
21 | | -function wfLoadMwEmbedClassPaths ( ) { |
22 | | - global $wgMwEmbedDirectory, $wgJSModuleList, $wgMwEmbedLoaderJs; |
23 | | - //Set up the replace key: |
24 | | - $ClassReplaceKey = '/mw\.addClassFilePaths\s*\(\s*{(.*)}\s*\)\s*\;/siU'; |
25 | | - // Load classes from mwEmbed.js |
26 | | - if ( is_file( $wgMwEmbedDirectory . 'mwEmbed.js' ) ) { |
27 | | - // Read the file: |
28 | | - $file_content = file_get_contents( $wgMwEmbedDirectory . 'mwEmbed.js' ); |
29 | | - // Call jsClassPathLoader() for each lcPaths() call in the JS source |
30 | | - $replace_test = preg_replace_callback( |
31 | | - $ClassReplaceKey, |
32 | | - 'wfClassPathLoader', |
33 | | - $file_content |
34 | | - ); |
35 | | - |
36 | | - // Get the list of enabled modules into $wgJSModuleList |
37 | | - $replace_test = preg_replace_callback( |
38 | | - '/mwEnabledModuleList\s*\=\s*\[(.*)\]/siU', |
39 | | - 'wfBuildModuleList', |
40 | | - $file_content |
41 | | - ); |
42 | | - |
43 | | - // Get all the classes from the loader files: |
44 | | - foreach( $wgJSModuleList as $na => $moduleName){ |
45 | | - $file_content = file_get_contents( |
46 | | - $wgMwEmbedDirectory . 'modules/' . $moduleName . '/loader.js' |
47 | | - ); |
48 | | - // Add the mwEmbed loader js to its global collector: |
49 | | - $wgMwEmbedLoaderJs .= $file_content; |
50 | | - |
51 | | - $replace_test.= preg_replace_callback( |
52 | | - $ClassReplaceKey, |
53 | | - 'wfClassPathLoader', |
54 | | - $file_content |
55 | | - ); |
56 | | - } |
57 | | - } |
58 | | -} |
59 | | -function wfBuildModuleList( $jsvar ){ |
60 | | - global $wgMwEmbedDirectory, $wgJSModuleList; |
61 | | - if(! isset( $jsvar[1] )){ |
62 | | - return false; |
63 | | - } |
64 | | - $moduleSet = explode(',', $jsvar[1] ); |
65 | | - |
66 | | - foreach( $moduleSet as $na => $module ){ |
67 | | - $moduleName = str_replace( array( '../', '\'', '"'), '', trim( $module )); |
68 | | - // Check if there is there are module loader files |
69 | | - if( is_file( $wgMwEmbedDirectory . 'modules/' . $moduleName . '/loader.js' )){ |
70 | | - array_push( $wgJSModuleList, $moduleName ); |
71 | | - } |
72 | | - } |
73 | | - return ''; |
74 | | -} |
75 | | -function wfClassPathLoader( $jvar ) { |
76 | | - global $wgJSAutoloadLocalClasses, $wgMwEmbedDirectory; |
77 | | - if ( !isset( $jvar[1] ) ) |
78 | | - return false; |
79 | | - |
80 | | - $jClassSet = FormatJson::decode( '{' . $jvar[1] . '}', true ); |
81 | | - foreach ( $jClassSet as $jClass => $jPath ) { |
82 | | - // Strip $ from jClass (as they are stripped on URL request parameter input) |
83 | | - $jClass = str_replace( '$', '', $jClass ); |
84 | | - $wgJSAutoloadLocalClasses[ $jClass ] = $wgMwEmbedDirectory . $jPath; |
85 | | - } |
86 | | - |
87 | | -} |
Index: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php |
— | — | @@ -0,0 +1,112 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( !defined( 'MEDIAWIKI' ) ) die( 1 ); |
| 5 | + |
| 6 | +global $wgJSAutoloadLocalClasses, $wgMwEmbedDirectory; |
| 7 | +// NOTE this is growing in complexity and globals sloppiness |
| 8 | + |
| 9 | + |
| 10 | +class jsClassLoader { |
| 11 | + private static $moduleList = array(); |
| 12 | + private static $combinedLoadersJs = ''; |
| 13 | + private static $classReplaceExp = '/mw\.addClassFilePaths\s*\(\s*{(.*)}\s*\)\s*\;/siU'; |
| 14 | + |
| 15 | + private static $loadClassFlag = false; |
| 16 | + /** |
| 17 | + * Get the javascript class paths |
| 18 | + */ |
| 19 | + public static function loadClassPaths(){ |
| 20 | + global $wgMwEmbedDirectory, $wgJSModuleLoaderPaths; |
| 21 | + |
| 22 | + // Only run "once" |
| 23 | + if( self::$loadClassFlag ) |
| 24 | + return false; |
| 25 | + self::$loadClassFlag = true; |
| 26 | + |
| 27 | + // Load classes from mwEmbed.js |
| 28 | + if ( !is_file( $wgMwEmbedDirectory . 'mwEmbed.js' ) ) { |
| 29 | + // throw error no mwEmbed found |
| 30 | + throw new MWException( "mwEmbed.js missing check \$wgMwEmbedDirectory path\n" ); |
| 31 | + return false; |
| 32 | + } |
| 33 | + // Read the file: |
| 34 | + $file_content = file_get_contents( $wgMwEmbedDirectory . 'mwEmbed.js' ); |
| 35 | + // Get class paths from mwEmbed.js |
| 36 | + $replace_test = preg_replace_callback( |
| 37 | + self::$classReplaceExp, |
| 38 | + 'jsClassLoader::preg_classPathLoader', |
| 39 | + $file_content |
| 40 | + ); |
| 41 | + |
| 42 | + // Get the list of enabled modules into $wgJSModuleList |
| 43 | + $replace_test = preg_replace_callback( |
| 44 | + '/mwEnabledModuleList\s*\=\s*\[(.*)\]/siU', |
| 45 | + 'jsClassLoader::preg_buildModuleList', |
| 46 | + $file_content |
| 47 | + ); |
| 48 | + |
| 49 | + // Get all the classes from the loader files: |
| 50 | + foreach( self::$moduleList as $na => $moduleName){ |
| 51 | + $file_content = file_get_contents( |
| 52 | + $wgMwEmbedDirectory . 'modules/' . $moduleName . '/loader.js' |
| 53 | + ); |
| 54 | + // Add the mwEmbed loader js to its global collector: |
| 55 | + self::$combinedLoadersJs .= $file_content; |
| 56 | + |
| 57 | + $replace_test.= preg_replace_callback( |
| 58 | + self::$classReplaceExp, |
| 59 | + 'jsClassLoader::preg_classPathLoader', |
| 60 | + $file_content |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + // Get all the classes from extensions registered mwEmbed modules |
| 65 | + |
| 66 | + } |
| 67 | + /** |
| 68 | + * Get the combined loader javascript |
| 69 | + * |
| 70 | + * @return the combined loader jss |
| 71 | + */ |
| 72 | + public static function getCombinedLoaderJs(){ |
| 73 | + self::loadClassPaths(); |
| 74 | + return self::$combinedLoadersJs; |
| 75 | + } |
| 76 | + private static function preg_buildModuleList( $jsvar ){ |
| 77 | + global $wgMwEmbedDirectory; |
| 78 | + if(! isset( $jsvar[1] )){ |
| 79 | + return false; |
| 80 | + } |
| 81 | + $moduleSet = explode(',', $jsvar[1] ); |
| 82 | + |
| 83 | + foreach( $moduleSet as $na => $module ){ |
| 84 | + $moduleName = str_replace( array( '../', '\'', '"'), '', trim( $module )); |
| 85 | + // Check if there is there are module loader files |
| 86 | + if( is_file( $wgMwEmbedDirectory . 'modules/' . $moduleName . '/loader.js' )){ |
| 87 | + array_push( self::$moduleList, $moduleName ); |
| 88 | + } |
| 89 | + } |
| 90 | + return ''; |
| 91 | + } |
| 92 | + /** |
| 93 | + * Adds javascript autoloader class names and paths |
| 94 | + * to $wgJSAutoloadLocalClasses global |
| 95 | + * |
| 96 | + * Use $wgJSAutoloadLocalClasses to support manual adding of class name / paths |
| 97 | + * |
| 98 | + * @param string $jvar Json string with class name list |
| 99 | + */ |
| 100 | + private static function preg_classPathLoader( $jsvar ) { |
| 101 | + global $wgJSAutoloadLocalClasses, $wgMwEmbedDirectory; |
| 102 | + if ( !isset( $jsvar[1] ) ) |
| 103 | + return false; |
| 104 | + |
| 105 | + $jClassSet = FormatJson::decode( '{' . $jsvar[1] . '}', true ); |
| 106 | + foreach ( $jClassSet as $jClass => $jPath ) { |
| 107 | + // Strip $ from jClass (as they are stripped on URL request parameter input) |
| 108 | + $jClass = str_replace( '$', '', $jClass ); |
| 109 | + $wgJSAutoloadLocalClasses[ $jClass ] = $wgMwEmbedDirectory . $jPath; |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
Property changes on: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php |
___________________________________________________________________ |
Name: svn:mergeinfo |
1 | 114 | + /branches/REL1_15/phase3/js2/mwEmbed/php/jsAutoloadLocalClasses.php:51646 |
/branches/sqlite/js2/mwEmbed/php/jsAutoloadLocalClasses.php:58211-58321 |
Name: svn:eol-style |
2 | 115 | + native |
Index: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php |
— | — | @@ -24,6 +24,8 @@ |
25 | 25 | $wgJSAutoloadClasses = array(); |
26 | 26 | $wgJSAutoloadLocalClasses = array(); |
27 | 27 | |
| 28 | +$wgJSModuleLoaderPaths = array(); |
| 29 | + |
28 | 30 | /*Localization:*/ |
29 | 31 | $wgEnableScriptLocalization = true; |
30 | 32 | |
— | — | @@ -46,9 +48,9 @@ |
47 | 49 | $wgJsMimeType = 'text/javascript'; |
48 | 50 | |
49 | 51 | // Get the autoload classes |
50 | | -require_once( realpath( dirname( __FILE__ ) ) . '/jsAutoloadLocalClasses.php' ); |
| 52 | +require_once( realpath( dirname( __FILE__ ) ) . '/jsClassLoader.php' ); |
51 | 53 | // Load the javascript Classes |
52 | | -wfLoadMwEmbedClassPaths(); |
| 54 | +jsClassLoader::loadClassPaths(); |
53 | 55 | |
54 | 56 | // Get the JSmin class: |
55 | 57 | require_once( realpath( dirname( __FILE__ ) ) . '/library/JSMin.php' ); |
— | — | @@ -104,3 +106,6 @@ |
105 | 107 | return json_decode( $value, $assoc ); |
106 | 108 | } |
107 | 109 | } |
| 110 | +// MWException extends Exception (for noWiki we don't do anything fancy ) |
| 111 | +class MWException extends Exception { |
| 112 | +} |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | 'play_head': { |
52 | 52 | 'w':0, // special case (takes up remaining space) |
53 | 53 | 'o':function( ctrlObj ) { |
54 | | - return '<div class="play_head" style="width: ' + ( ctrlObj.available_width - 35 ) + 'px;"></div>'; |
| 54 | + return '<div class="play_head" style="width: ' + ( ctrlObj.available_width - 10 ) + 'px;"></div>'; |
55 | 55 | } |
56 | 56 | }, |
57 | 57 | 'options_menu': { |
Index: branches/js2-work/phase3/js/mwEmbed/skins/kskin/playerSkin.css |
— | — | @@ -97,7 +97,9 @@ |
98 | 98 | cursor: pointer; |
99 | 99 | -moz-border-radius:5px 5px 5px 5px; |
100 | 100 | } |
101 | | - |
| 101 | +.k-player .ui-corner-all { |
| 102 | + -moz-border-radius:5px 5px 5px 5px; |
| 103 | +} |
102 | 104 | .k-player .time-disp { |
103 | 105 | border: medium none; |
104 | 106 | display: inline; |
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js |
— | — | @@ -137,6 +137,9 @@ |
138 | 138 | // Local scope configuration var: |
139 | 139 | var mwConfig = { }; |
140 | 140 | |
| 141 | + // Stores global callbacks |
| 142 | + var mwLoadDoneCB = { }; |
| 143 | + |
141 | 144 | //Local scope mwUserConfig var. Stores user configuration |
142 | 145 | var mwUserConfig = { }; |
143 | 146 | |
— | — | @@ -899,7 +902,7 @@ |
900 | 903 | * |
901 | 904 | * {String} Name of a module to be loaded |
902 | 905 | * Modules are added via addModuleLoader and can define custom |
903 | | - * code needed to load the module dependencies |
| 906 | + * code needed to check config and load the module dependencies |
904 | 907 | * |
905 | 908 | * {String} Name of a class to loaded. |
906 | 909 | * Classes are added via addClassFilePaths function |
— | — | @@ -957,11 +960,11 @@ |
958 | 961 | return ; |
959 | 962 | } |
960 | 963 | |
961 | | - // Try loading as a "file"? |
| 964 | + // Try loading as a "file" or via ScriptLoader |
962 | 965 | if( loadRequest ) { |
963 | 966 | if( loadRequest.indexOf( '.js' ) == -1 && !mw.getScriptLoaderPath() ){ |
964 | 967 | mw.log( 'Error: are you sure ' + loadRequest + ' is a file ( is it missing a class path? ) ' ); |
965 | | - } |
| 968 | + } |
966 | 969 | mw.getScript( loadRequest, callback ); |
967 | 970 | return ; |
968 | 971 | } |
— | — | @@ -969,8 +972,7 @@ |
970 | 973 | //possible error? |
971 | 974 | mw.log( "Error could not handle load request: " + loadRequest ); |
972 | 975 | }, |
973 | | - |
974 | | - |
| 976 | + |
975 | 977 | /** |
976 | 978 | * Load a set of scripts. |
977 | 979 | * Will issue many load requests or package the request for the script-loader |
— | — | @@ -990,7 +992,7 @@ |
991 | 993 | mw.log( 'loadMany:all classes already loaded'); |
992 | 994 | callback(); |
993 | 995 | return ; |
994 | | - } |
| 996 | + } |
995 | 997 | }else{ |
996 | 998 | // Check if its a dependency set ( nested objects ) |
997 | 999 | if( typeof loadSet [ 0 ] == 'object' ){ |
— | — | @@ -1043,12 +1045,13 @@ |
1044 | 1046 | */ |
1045 | 1047 | getGroupLoadState: function( loadSet ){ |
1046 | 1048 | var groupedLoadSet = []; |
1047 | | - var loadStates = { }; |
| 1049 | + var loadStates = { }; |
1048 | 1050 | // Merge load set into new groupedLoadSet |
1049 | 1051 | if( typeof loadSet[0] == 'object' ){ |
1050 | 1052 | for( var i = 0; i < loadSet.length ; i++ ){ |
1051 | 1053 | for( var j = 0; j < loadSet[i].length ; j++ ){ |
1052 | | - groupedLoadSet.push( loadSet[i][j] ); |
| 1054 | + // Make sure we have not already included it: |
| 1055 | + groupedLoadSet.push( loadSet[i][j] ); |
1053 | 1056 | } |
1054 | 1057 | } |
1055 | 1058 | }else{ |
— | — | @@ -1142,6 +1145,7 @@ |
1143 | 1146 | |
1144 | 1147 | // If the scriptloader is enabled use the className as the scriptRequest: |
1145 | 1148 | if( mw.getScriptLoaderPath() ){ |
| 1149 | + // replace $j with j since php strips the $ from the request class |
1146 | 1150 | scriptRequest = className; |
1147 | 1151 | }else{ |
1148 | 1152 | // Get the class url: |
— | — | @@ -1180,16 +1184,23 @@ |
1181 | 1185 | } ); |
1182 | 1186 | //mw.log( 'done with running getScript request ' ); |
1183 | 1187 | |
1184 | | - // Check if the class is ready: ( not all browsers support onLoad script attribute ) |
1185 | | - // In the case of a "class" we can pull the javascript state until its ready |
1186 | | - setTimeout( function(){ |
1187 | | - mw.waitForObject( className, function( className ){ |
1188 | | - if( callback ){ |
1189 | | - callback( className ); |
1190 | | - callback = null; |
1191 | | - } |
1192 | | - } ); |
1193 | | - }, 25 ); |
| 1188 | + /* |
| 1189 | + * If scriptLoader is not enabled |
| 1190 | + * |
| 1191 | + * Check if the class is ready: |
| 1192 | + * ( not all browsers support onLoad script attribute ) |
| 1193 | + * In the case of a "class" we can pull the javascript state until its ready |
| 1194 | + */ |
| 1195 | + if( !mw.getScriptLoaderPath() ){ |
| 1196 | + setTimeout( function(){ |
| 1197 | + mw.waitForObject( className, function( className ){ |
| 1198 | + if( callback ){ |
| 1199 | + callback( className ); |
| 1200 | + callback = null; |
| 1201 | + } |
| 1202 | + } ); |
| 1203 | + }, 25 ); |
| 1204 | + } |
1194 | 1205 | }, |
1195 | 1206 | |
1196 | 1207 | /** |
— | — | @@ -1247,6 +1258,17 @@ |
1248 | 1259 | } |
1249 | 1260 | |
1250 | 1261 | /** |
| 1262 | + * Load done callback for script loader |
| 1263 | + * this way webkit browsers don't have to check if variables are "ready" |
| 1264 | + */ |
| 1265 | + mw.loadDone = function( requestName ) { |
| 1266 | + mw.log( "LoadDone: " + requestName ); |
| 1267 | + if( mwLoadDoneCB[ requestName ] ){ |
| 1268 | + mwLoadDoneCB[ requestName ]( requestName ); |
| 1269 | + } |
| 1270 | + }, |
| 1271 | + |
| 1272 | + /** |
1251 | 1273 | * Add module entry point: Adds a module to the mwLoader object |
1252 | 1274 | */ |
1253 | 1275 | mw.addModuleLoader = function ( name, loaderFunction ){ |
— | — | @@ -1698,6 +1720,8 @@ |
1699 | 1721 | var isRelativePath = ( scriptRequest.indexOf('://') == -1 && scriptRequest.indexOf('/') !== 0 )? true : false; |
1700 | 1722 | if( slpath && isRelativePath ) { |
1701 | 1723 | url = slpath + '?class=' + scriptRequest; |
| 1724 | + //Add a class callback hook ( for script-loader onDone callback ) |
| 1725 | + mwLoadDoneCB[ scriptRequest ] = callback; |
1702 | 1726 | }else{ |
1703 | 1727 | // Add the mwEmbed path if a relative path request |
1704 | 1728 | url = ( isRelativePath )? mw.getMwEmbedPath() : ''; |
— | — | @@ -1710,7 +1734,8 @@ |
1711 | 1735 | |
1712 | 1736 | |
1713 | 1737 | mw.log( 'mw.getScript: ' + url ); |
1714 | | - // If jQuery is available and debug is off get the scirpt j |
| 1738 | + // If jQuery is available and debug is off load the scirpt via jQuery |
| 1739 | + //( will use XHR if on same domain ) |
1715 | 1740 | if( mw.isset( 'window.jQuery' ) && mw.getConfig( 'debug' ) === false ) { |
1716 | 1741 | $j.getScript( url, function(){ |
1717 | 1742 | if( callback ) |
— | — | @@ -1721,20 +1746,22 @@ |
1722 | 1747 | /** |
1723 | 1748 | * No jQuery |
1724 | 1749 | * OR |
1725 | | - * In debug mode inject the script instead of doing an ajax request and eval |
| 1750 | + * In debug mode inject the script instead of doing an XHR eval |
1726 | 1751 | */ |
1727 | 1752 | // Load and bind manually: ( copied from jQuery ajax function ) |
1728 | 1753 | var head = document.getElementsByTagName("head")[0]; |
1729 | 1754 | var script = document.createElement("script"); |
1730 | 1755 | script.setAttribute( 'src', url ); |
1731 | 1756 | |
1732 | | - // Attach handlers for all browsers ( might not work in safari < version 2.0 ) |
1733 | | - script.onload = script.onreadystatechange = function(){ |
1734 | | - if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") { |
1735 | | - if( callback ) |
1736 | | - callback( scriptRequest ); |
1737 | | - } |
1738 | | - }; |
| 1757 | + // Attach handlers ( if not using script loader that issues onDone callback ) |
| 1758 | + if( !mw.getScriptLoaderPath() ){ |
| 1759 | + script.onload = script.onreadystatechange = function(){ |
| 1760 | + if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") { |
| 1761 | + if( callback ) |
| 1762 | + callback( scriptRequest ); |
| 1763 | + } |
| 1764 | + }; |
| 1765 | + } |
1739 | 1766 | // Append the script to the DOM: |
1740 | 1767 | head.appendChild( script ); |
1741 | 1768 | } |
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php |
— | — | @@ -32,6 +32,8 @@ |
33 | 33 | var $jsvarurl = false; |
34 | 34 | var $doProcReqFlag = true; |
35 | 35 | |
| 36 | + private static $rawClassList = ''; |
| 37 | + |
36 | 38 | /** |
37 | 39 | * Output the javascript from cache |
38 | 40 | * |
— | — | @@ -68,8 +70,8 @@ |
69 | 71 | $wgExtensionMessagesFiles[ 'mwEmbed' ] = realpath( dirname( __FILE__ ) ) . '/includes/languages/mwEmbed.i18n.php'; |
70 | 72 | |
71 | 73 | //Load the javascript class paths: |
72 | | - require_once( realpath( dirname( __FILE__ ) ) . "/includes/jsAutoloadLocalClasses.php"); |
73 | | - wfLoadMwEmbedClassPaths(); |
| 74 | + require_once( realpath( dirname( __FILE__ ) ) . "/includes/jsClassLoader.php"); |
| 75 | + jsClassLoader::loadClassPaths(); |
74 | 76 | |
75 | 77 | // Reset the requestKey: |
76 | 78 | $this->requestKey = ''; |
— | — | @@ -82,8 +84,8 @@ |
83 | 85 | $this->jsout .= 'var mwScriptLoaderDate = "' . date( 'c' ) . '";' . "\n"; |
84 | 86 | $this->jsout .= 'var mwScriptLoaderRequestKey = "' . htmlspecialchars( $this->requestKey ) . '";' . "\n"; |
85 | 87 | $this->jsout .= 'var mwLang = "' . htmlspecialchars( $this->langCode ) . '";' . "\n"; |
| 88 | + |
86 | 89 | // Build the output |
87 | | - |
88 | 90 | // Swap in the appropriate language per js_file |
89 | 91 | foreach ( $this->jsFileList as $classKey => $file_name ) { |
90 | 92 | // Get the script content |
— | — | @@ -91,14 +93,16 @@ |
92 | 94 | if( $jstxt ){ |
93 | 95 | $this->jsout .= $this->doProcessJs( $jstxt ); |
94 | 96 | } |
95 | | - |
96 | | - // If the special mwEmbed class entry point (include loader js |
| 97 | + // If the core mwEmbed class entry point include loader js |
97 | 98 | if( $classKey == 'mwEmbed' ){ |
98 | | - global $wgMwEmbedLoaderJs; |
99 | | - $this->jsout .= $wgMwEmbedLoaderJs; |
| 99 | + $this->jsout .= jsClassLoader::getCombinedLoaderJs(); |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
| 103 | + // Add a mw.loadDone callback so webkit browsers don't have to check if variables are "ready" |
| 104 | + $this->jsout .= self::getOnDoneCallback( ); |
| 105 | + |
| 106 | + |
103 | 107 | // Check if we should minify the whole thing: |
104 | 108 | if ( !$this->debug ) { |
105 | 109 | $this->jsout = self::getMinifiedJs( $this->jsout , $this->requestKey ); |
— | — | @@ -120,52 +124,74 @@ |
121 | 125 | $this->outputJsWithHeaders(); |
122 | 126 | } |
123 | 127 | } |
124 | | - |
125 | 128 | /** |
| 129 | + * Get the onDone javascript callback for a given class list |
| 130 | + * |
| 131 | + * @return unknown |
| 132 | + */ |
| 133 | + static private function getOnDoneCallback( ){ |
| 134 | + return 'if(mw && mw.loadDone){mw.loadDone(\'' . |
| 135 | + htmlspecialchars( self::$rawClassList ) . '\');};'; |
| 136 | + } |
| 137 | + /** |
126 | 138 | * Get Minified js |
127 | 139 | * |
128 | 140 | * Takes the $js_string input |
129 | 141 | * and |
130 | | - * returns minified or "compiled" javascript value |
| 142 | + * @return minified javascript value |
131 | 143 | */ |
132 | 144 | static function getMinifiedJs( & $js_string, $requestKey='' ){ |
133 | 145 | global $wgJavaPath, $wgClosureCompilerPath, $wgClosureCompilerLevel; |
134 | | - // Check if we support the google closure compiler: |
| 146 | + |
| 147 | + |
| 148 | + // Check if google closure compiler is enabled and we can get its output |
135 | 149 | if( $wgJavaPath && $wgClosureCompilerPath && wfShellExecEnabled() ){ |
136 | | - if( is_file( $wgJavaPath ) && is_file( $wgClosureCompilerPath ) ){ |
137 | | - // Update the requestKey with a random value if no provided: |
138 | | - if( $requestKey == '') |
139 | | - $requestKey = rand() + microtime(); |
| 150 | + $jsMinVal = self::getClosureMinifiedJs( $js_string, $requestKey ); |
| 151 | + if( $jsMinVal ){ |
| 152 | + return $jsMinVal; |
| 153 | + }else{ |
| 154 | + wfDebug( 'Closure compiler failed to produce code for:' . $requestKey); |
| 155 | + } |
| 156 | + } |
| 157 | + // Do the minification using php JSMin |
| 158 | + return JSMin::minify( $js_string ); |
| 159 | + } |
| 160 | + static function getClosureMinifiedJs( & $js_string, $requestKey=''){ |
| 161 | + if( !is_file( $wgJavaPath ) || ! is_file( $wgClosureCompilerPath ) ){ |
| 162 | + return false; |
| 163 | + } |
| 164 | + // Update the requestKey with a random value if no provided |
| 165 | + // requestKey is used for the temporary file |
| 166 | + // ( There are problems with using standard output and Closure compile ) |
| 167 | + if( $requestKey == '') |
| 168 | + $requestKey = rand() + microtime(); |
140 | 169 | |
141 | | - // Write the grouped javascript to a temporary file: |
142 | | - // ( closure compiler does not support reading from standard in ) |
143 | | - $td = wfTempDir(); |
144 | | - $jsFileName = $td . '/' . $requestKey . '.tmp.js'; |
145 | | - file_put_contents( $jsFileName, $js_string ); |
146 | | - $retval = ''; |
147 | | - $cmd = $wgJavaPath . ' -jar ' . $wgClosureCompilerPath; |
148 | | - $cmd.= ' --js ' . $jsFileName; |
| 170 | + // Write the grouped javascript to a temporary file: |
| 171 | + // ( closure compiler does not support reading from standard in ) |
| 172 | + $td = wfTempDir(); |
| 173 | + $jsFileName = $td . '/' . $requestKey . '.tmp.js'; |
| 174 | + file_put_contents( $jsFileName, $js_string ); |
| 175 | + $retval = ''; |
| 176 | + $cmd = $wgJavaPath . ' -jar ' . $wgClosureCompilerPath; |
| 177 | + $cmd.= ' --js ' . $jsFileName; |
149 | 178 | |
150 | | - if( $wgClosureCompilerLevel ) |
151 | | - $cmd.= ' --compilation_level ' . wfEscapeShellArg( $wgClosureCompilerLevel ); |
| 179 | + if( $wgClosureCompilerLevel ) |
| 180 | + $cmd.= ' --compilation_level ' . wfEscapeShellArg( $wgClosureCompilerLevel ); |
152 | 181 | |
153 | | - // only output js ( no warnings ) |
154 | | - $cmd.= ' --warning_level QUIET'; |
155 | | - //print "run: $cmd"; |
156 | | - // Run the command: |
157 | | - $jsMinVal = wfShellExec($cmd , $retval); |
| 182 | + // only output js ( no warnings ) |
| 183 | + $cmd.= ' --warning_level QUIET'; |
| 184 | + //print "run: $cmd"; |
| 185 | + // Run the command: |
| 186 | + $jsMinVal = wfShellExec($cmd , $retval); |
158 | 187 | |
159 | | - // Clean up ( remove temporary file ) |
160 | | - //unlink( $jsFileName ); |
| 188 | + // Clean up ( remove temporary file ) |
| 189 | + unlink( $jsFileName ); |
161 | 190 | |
162 | | - if( strlen( $jsMinVal ) != 0 && $retval === 0){ |
163 | | - //die( "used closure" ); |
164 | | - return $jsMinVal; |
165 | | - } |
166 | | - } |
| 191 | + if( strlen( $jsMinVal ) != 0 && $retval === 0){ |
| 192 | + //die( "used closure" ); |
| 193 | + return $jsMinVal; |
167 | 194 | } |
168 | | - // Do the minification and output |
169 | | - return JSMin::minify( $js_string ); |
| 195 | + return false; |
170 | 196 | } |
171 | 197 | /** |
172 | 198 | * Gets Script Text |
— | — | @@ -341,6 +367,7 @@ |
342 | 368 | $reqClassList = false; |
343 | 369 | if ( isset( $_GET['class'] ) && $_GET['class'] != '' ) { |
344 | 370 | $reqClassList = explode( ',', $_GET['class'] ); |
| 371 | + self::$rawClassList= $_GET['class']; |
345 | 372 | } |
346 | 373 | |
347 | 374 | // Check for the requested classes |