r61122 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61121‎ | r61122 | r61123 >
Date:10:02, 16 January 2010
Author:dale
Status:deferred
Tags:
Comment:
* minor script-loader refactor
** added ondone callback to scriptloader ( no wait for variable for webkit browsers when using script-loader )
** added jsClassLoader class abstraction
* some kskin player skin updates
Modified paths:
  • /branches/js2-work/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/js2-work/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/js2-work/phase3/includes/OutputPage.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/jsAutoloadLocalClasses.php (deleted) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php (added) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/skins/kskin/kskinConfig.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/skins/kskin/playerSkin.css (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/Add_Media_Wizard.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/includes/OutputPage.php
@@ -131,11 +131,13 @@
132132 $path = "{$wgStylePath}/common/{$file}";
133133 }
134134
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+ }
140142 }
141143
142144 // Do checks for wiki-titles
@@ -199,7 +201,7 @@
200202 $this->addScriptClass( $js_class );
201203 }
202204 }
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
204206 $this->mScripts = $this->mScripts . $postScripts;
205207 }
206208
@@ -211,15 +213,6 @@
212214 global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses, $IP,
213215 $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgStylePath, $wgEnableJS2system;
214216
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 -
224217 $path = jsScriptLoader::getJsPathFromClass( $js_class );
225218 if( $path !== false ){
226219 if( $wgEnableScriptLoader ) {
@@ -357,6 +350,8 @@
358351 */
359352 function getJsClassFromPath( $path ) {
360353 global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgScriptPath;
 354+ //Make sure we have the scriptClasses loaded:
 355+ $this->loadJsClassPaths();
361356
362357 $scriptLoaderPaths = array_merge( $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses );
363358 foreach( $scriptLoaderPaths as $js_class => $js_path ) {
@@ -366,6 +361,18 @@
367362 }
368363 return false;
369364 }
 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+ }
370377
371378 /**
372379 * Add a self-contained script tag with the given contents
Index: branches/js2-work/phase3/includes/AutoLoader.php
@@ -134,6 +134,7 @@
135135 'JSMin' => 'js/mwEmbed/includes/library/JSMin.php',
136136 'JSMinException' => 'js/mwEmbed/includes/minify/JSMin.php',
137137 'jsScriptLoader' => 'js/mwEmbed/jsScriptLoader.php',
 138+ 'jsClassLoader' => 'js/mwEmbed/includes/jsClassLoader.php',
138139 'Job' => 'includes/JobQueue.php',
139140 'LCStore_DB' => 'includes/LocalisationCache.php',
140141 'LCStore_CDB' => 'includes/LocalisationCache.php',
Index: branches/js2-work/phase3/includes/DefaultSettings.php
@@ -2862,6 +2862,12 @@
28632863 */
28642864 $wgJSAutoloadClasses = array();
28652865
 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+
28662872 /*
28672873 * boolean; if the script loader should be used to group all javascript requests.
28682874 * more about the script loader: http://www.mediawiki.org/wiki/ScriptLoader
@@ -3146,9 +3152,9 @@
31473153 /**
31483154 * Fake out the timezone that the server thinks it's in. This will be used for
31493155 * 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.
31513157 *
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
31533159 * time/date parser variables ({{LOCALTIME}} etc.)
31543160 *
31553161 * 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 @@
1313 }
1414 </style>
1515 <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>
1717 <script type="text/javascript">
1818 mw.ready(function(){
1919 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
1114 + /branches/REL1_15/phase3/js2/mwEmbed/php/jsAutoloadLocalClasses.php:51646
/branches/sqlite/js2/mwEmbed/php/jsAutoloadLocalClasses.php:58211-58321
Name: svn:eol-style
2115 + native
Index: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
@@ -24,6 +24,8 @@
2525 $wgJSAutoloadClasses = array();
2626 $wgJSAutoloadLocalClasses = array();
2727
 28+$wgJSModuleLoaderPaths = array();
 29+
2830 /*Localization:*/
2931 $wgEnableScriptLocalization = true;
3032
@@ -46,9 +48,9 @@
4749 $wgJsMimeType = 'text/javascript';
4850
4951 // Get the autoload classes
50 -require_once( realpath( dirname( __FILE__ ) ) . '/jsAutoloadLocalClasses.php' );
 52+require_once( realpath( dirname( __FILE__ ) ) . '/jsClassLoader.php' );
5153 // Load the javascript Classes
52 -wfLoadMwEmbedClassPaths();
 54+jsClassLoader::loadClassPaths();
5355
5456 // Get the JSmin class:
5557 require_once( realpath( dirname( __FILE__ ) ) . '/library/JSMin.php' );
@@ -104,3 +106,6 @@
105107 return json_decode( $value, $assoc );
106108 }
107109 }
 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 @@
5151 'play_head': {
5252 'w':0, // special case (takes up remaining space)
5353 '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>';
5555 }
5656 },
5757 'options_menu': {
Index: branches/js2-work/phase3/js/mwEmbed/skins/kskin/playerSkin.css
@@ -97,7 +97,9 @@
9898 cursor: pointer;
9999 -moz-border-radius:5px 5px 5px 5px;
100100 }
101 -
 101+.k-player .ui-corner-all {
 102+ -moz-border-radius:5px 5px 5px 5px;
 103+}
102104 .k-player .time-disp {
103105 border: medium none;
104106 display: inline;
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -137,6 +137,9 @@
138138 // Local scope configuration var:
139139 var mwConfig = { };
140140
 141+ // Stores global callbacks
 142+ var mwLoadDoneCB = { };
 143+
141144 //Local scope mwUserConfig var. Stores user configuration
142145 var mwUserConfig = { };
143146
@@ -899,7 +902,7 @@
900903 *
901904 * {String} Name of a module to be loaded
902905 * 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
904907 *
905908 * {String} Name of a class to loaded.
906909 * Classes are added via addClassFilePaths function
@@ -957,11 +960,11 @@
958961 return ;
959962 }
960963
961 - // Try loading as a "file"?
 964+ // Try loading as a "file" or via ScriptLoader
962965 if( loadRequest ) {
963966 if( loadRequest.indexOf( '.js' ) == -1 && !mw.getScriptLoaderPath() ){
964967 mw.log( 'Error: are you sure ' + loadRequest + ' is a file ( is it missing a class path? ) ' );
965 - }
 968+ }
966969 mw.getScript( loadRequest, callback );
967970 return ;
968971 }
@@ -969,8 +972,7 @@
970973 //possible error?
971974 mw.log( "Error could not handle load request: " + loadRequest );
972975 },
973 -
974 -
 976+
975977 /**
976978 * Load a set of scripts.
977979 * Will issue many load requests or package the request for the script-loader
@@ -990,7 +992,7 @@
991993 mw.log( 'loadMany:all classes already loaded');
992994 callback();
993995 return ;
994 - }
 996+ }
995997 }else{
996998 // Check if its a dependency set ( nested objects )
997999 if( typeof loadSet [ 0 ] == 'object' ){
@@ -1043,12 +1045,13 @@
10441046 */
10451047 getGroupLoadState: function( loadSet ){
10461048 var groupedLoadSet = [];
1047 - var loadStates = { };
 1049+ var loadStates = { };
10481050 // Merge load set into new groupedLoadSet
10491051 if( typeof loadSet[0] == 'object' ){
10501052 for( var i = 0; i < loadSet.length ; i++ ){
10511053 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] );
10531056 }
10541057 }
10551058 }else{
@@ -1142,6 +1145,7 @@
11431146
11441147 // If the scriptloader is enabled use the className as the scriptRequest:
11451148 if( mw.getScriptLoaderPath() ){
 1149+ // replace $j with j since php strips the $ from the request class
11461150 scriptRequest = className;
11471151 }else{
11481152 // Get the class url:
@@ -1180,16 +1184,23 @@
11811185 } );
11821186 //mw.log( 'done with running getScript request ' );
11831187
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+ }
11941205 },
11951206
11961207 /**
@@ -1247,6 +1258,17 @@
12481259 }
12491260
12501261 /**
 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+ /**
12511273 * Add module entry point: Adds a module to the mwLoader object
12521274 */
12531275 mw.addModuleLoader = function ( name, loaderFunction ){
@@ -1698,6 +1720,8 @@
16991721 var isRelativePath = ( scriptRequest.indexOf('://') == -1 && scriptRequest.indexOf('/') !== 0 )? true : false;
17001722 if( slpath && isRelativePath ) {
17011723 url = slpath + '?class=' + scriptRequest;
 1724+ //Add a class callback hook ( for script-loader onDone callback )
 1725+ mwLoadDoneCB[ scriptRequest ] = callback;
17021726 }else{
17031727 // Add the mwEmbed path if a relative path request
17041728 url = ( isRelativePath )? mw.getMwEmbedPath() : '';
@@ -1710,7 +1734,8 @@
17111735
17121736
17131737 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 )
17151740 if( mw.isset( 'window.jQuery' ) && mw.getConfig( 'debug' ) === false ) {
17161741 $j.getScript( url, function(){
17171742 if( callback )
@@ -1721,20 +1746,22 @@
17221747 /**
17231748 * No jQuery
17241749 * 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
17261751 */
17271752 // Load and bind manually: ( copied from jQuery ajax function )
17281753 var head = document.getElementsByTagName("head")[0];
17291754 var script = document.createElement("script");
17301755 script.setAttribute( 'src', url );
17311756
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+ }
17391766 // Append the script to the DOM:
17401767 head.appendChild( script );
17411768 }
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -32,6 +32,8 @@
3333 var $jsvarurl = false;
3434 var $doProcReqFlag = true;
3535
 36+ private static $rawClassList = '';
 37+
3638 /**
3739 * Output the javascript from cache
3840 *
@@ -68,8 +70,8 @@
6971 $wgExtensionMessagesFiles[ 'mwEmbed' ] = realpath( dirname( __FILE__ ) ) . '/includes/languages/mwEmbed.i18n.php';
7072
7173 //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();
7476
7577 // Reset the requestKey:
7678 $this->requestKey = '';
@@ -82,8 +84,8 @@
8385 $this->jsout .= 'var mwScriptLoaderDate = "' . date( 'c' ) . '";' . "\n";
8486 $this->jsout .= 'var mwScriptLoaderRequestKey = "' . htmlspecialchars( $this->requestKey ) . '";' . "\n";
8587 $this->jsout .= 'var mwLang = "' . htmlspecialchars( $this->langCode ) . '";' . "\n";
 88+
8689 // Build the output
87 -
8890 // Swap in the appropriate language per js_file
8991 foreach ( $this->jsFileList as $classKey => $file_name ) {
9092 // Get the script content
@@ -91,14 +93,16 @@
9294 if( $jstxt ){
9395 $this->jsout .= $this->doProcessJs( $jstxt );
9496 }
95 -
96 - // If the special mwEmbed class entry point (include loader js
 97+ // If the core mwEmbed class entry point include loader js
9798 if( $classKey == 'mwEmbed' ){
98 - global $wgMwEmbedLoaderJs;
99 - $this->jsout .= $wgMwEmbedLoaderJs;
 99+ $this->jsout .= jsClassLoader::getCombinedLoaderJs();
100100 }
101101 }
102102
 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+
103107 // Check if we should minify the whole thing:
104108 if ( !$this->debug ) {
105109 $this->jsout = self::getMinifiedJs( $this->jsout , $this->requestKey );
@@ -120,52 +124,74 @@
121125 $this->outputJsWithHeaders();
122126 }
123127 }
124 -
125128 /**
 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+ /**
126138 * Get Minified js
127139 *
128140 * Takes the $js_string input
129141 * and
130 - * returns minified or "compiled" javascript value
 142+ * @return minified javascript value
131143 */
132144 static function getMinifiedJs( & $js_string, $requestKey='' ){
133145 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
135149 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();
140169
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;
149178
150 - if( $wgClosureCompilerLevel )
151 - $cmd.= ' --compilation_level ' . wfEscapeShellArg( $wgClosureCompilerLevel );
 179+ if( $wgClosureCompilerLevel )
 180+ $cmd.= ' --compilation_level ' . wfEscapeShellArg( $wgClosureCompilerLevel );
152181
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);
158187
159 - // Clean up ( remove temporary file )
160 - //unlink( $jsFileName );
 188+ // Clean up ( remove temporary file )
 189+ unlink( $jsFileName );
161190
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;
167194 }
168 - // Do the minification and output
169 - return JSMin::minify( $js_string );
 195+ return false;
170196 }
171197 /**
172198 * Gets Script Text
@@ -341,6 +367,7 @@
342368 $reqClassList = false;
343369 if ( isset( $_GET['class'] ) && $_GET['class'] != '' ) {
344370 $reqClassList = explode( ',', $_GET['class'] );
 371+ self::$rawClassList= $_GET['class'];
345372 }
346373
347374 // Check for the requested classes

Status & tagging log