makeStaticLoader: Update fake standalone init module

* Don't add ext.visualEditor.base to it, and strip of ve-mw stuff
** .base doesn't contain ve-mw stuff any more, so no stripping needed
** Instead of appending .base, just load .base and create a
   separate fake module for Standalone init.

* Don't manually register .sa files
** Instead use ext.visualEditor.standalone, it's right there.
** Add missing CSS file to .standalone.

* Documented the purpose of 'Dependencies' and removed scripts
  from that fake module that don't fall under that rationale and
  instead add them as regular modules (rangy, unicodejs).

* Removed weird 'jquery' dependency in 'ext.visualEditor.core'
  module. This is strongly recommended against, and might
  actually cause jQuery to be reloaded due to outstanding bugs
  in core with the state machine in the startup queue (jquery, mediawiki).

* Unlist unused 'jquery.client' dependency in makeStaticLoader.
  As per the module definitions in VisualEditor.php, this is
  only used by the .mediawiki module. Grepped modules/ve/ and
  found 0 uses.

* Update dependency order to roughly match the dependency tree
  as it is specified in ResourceLoader (e.g. rangy is for .core,
  not .base).

* Keep fake modules out of ResourceLoader.

Change-Id: I2a31543e5ad2fc39f5980fea855172108eda4428
This commit is contained in:
Roan Kattouw 2013-12-09 15:25:23 -08:00 committed by Timo Tijhof
parent 1d9c82d7f5
commit 4c98f753a0
4 changed files with 120 additions and 63 deletions

View file

@ -261,6 +261,9 @@ $wgResourceModules += array(
've/init/sa/ve.init.sa.Platform.js', 've/init/sa/ve.init.sa.Platform.js',
've/init/sa/ve.init.sa.Target.js', 've/init/sa/ve.init.sa.Target.js',
), ),
'styles' => array(
've/init/sa/styles/ve.init.sa.css'
),
'dependencies' => array( 'dependencies' => array(
'ext.visualEditor.base', 'ext.visualEditor.base',
), ),
@ -532,7 +535,6 @@ $wgResourceModules += array(
've-mw/ui/styles/ve.ui.MWDialog.css', 've-mw/ui/styles/ve.ui.MWDialog.css',
), ),
'dependencies' => array( 'dependencies' => array(
'jquery',
'rangy', 'rangy',
'unicodejs.wordbreak', 'unicodejs.wordbreak',
'ext.visualEditor.base', 'ext.visualEditor.base',

View file

@ -27,8 +27,9 @@ $html = file_get_contents( $page );
<!-- Generated by maintenance/makeStaticLoader.php --> <!-- Generated by maintenance/makeStaticLoader.php -->
<!-- oojs-ui --> <!-- oojs-ui -->
<link rel=stylesheet href="../../modules/oojs-ui/oojs-ui.svg.css"> <link rel=stylesheet href="../../modules/oojs-ui/oojs-ui.svg.css">
<!-- ext.visualEditor.base#standalone-init --> <!-- ext.visualEditor.standalone -->
<link rel=stylesheet href="../../modules/ve/init/sa/styles/ve.init.sa.css"> <link rel=stylesheet href="../../modules/ve/init/sa/styles/ve.init.sa.css">
<!-- Standalone init -->
<script> <script>
if ( if (
document.createElementNS && document.createElementNS &&
@ -80,30 +81,31 @@ $html = file_get_contents( $page );
<div class="ve-demo-editor"></div> <div class="ve-demo-editor"></div>
<!-- Generated by maintenance/makeStaticLoader.php --> <!-- Generated by maintenance/makeStaticLoader.php -->
<!-- Dependencies --> <!-- jquery -->
<script src="../../modules/jquery/jquery.js"></script> <script src="../../modules/jquery/jquery.js"></script>
<script src="../../modules/jquery/jquery.client.js"></script> <!-- oojs -->
<script src="../../modules/oojs/oojs.js"></script> <script src="../../modules/oojs/oojs.js"></script>
<script src="../../modules/rangy/rangy-core-1.3.js"></script> <!-- oojs-ui -->
<script src="../../modules/rangy/rangy-position-1.3.js"></script> <script src="../../modules/oojs-ui/oojs-ui.js"></script>
<!-- unicodejs.wordbreak -->
<script src="../../modules/unicodejs/unicodejs.js"></script> <script src="../../modules/unicodejs/unicodejs.js"></script>
<script src="../../modules/unicodejs/unicodejs.textstring.js"></script> <script src="../../modules/unicodejs/unicodejs.textstring.js"></script>
<script src="../../modules/unicodejs/unicodejs.graphemebreakproperties.js"></script> <script src="../../modules/unicodejs/unicodejs.graphemebreakproperties.js"></script>
<script src="../../modules/unicodejs/unicodejs.graphemebreak.js"></script> <script src="../../modules/unicodejs/unicodejs.graphemebreak.js"></script>
<script src="../../modules/unicodejs/unicodejs.wordbreakproperties.js"></script> <script src="../../modules/unicodejs/unicodejs.wordbreakproperties.js"></script>
<script src="../../modules/unicodejs/unicodejs.wordbreak.js"></script> <script src="../../modules/unicodejs/unicodejs.wordbreak.js"></script>
<!-- oojs-ui --> <!-- ext.visualEditor.base -->
<script src="../../modules/oojs-ui/oojs-ui.js"></script>
<!-- ext.visualEditor.base#standalone-init -->
<script src="../../modules/ve/ve.js"></script> <script src="../../modules/ve/ve.js"></script>
<script src="../../modules/ve/ve.track.js"></script> <script src="../../modules/ve/ve.track.js"></script>
<script src="../../modules/ve/init/ve.init.js"></script> <script src="../../modules/ve/init/ve.init.js"></script>
<script src="../../modules/ve/init/ve.init.Platform.js"></script> <script src="../../modules/ve/init/ve.init.Platform.js"></script>
<script src="../../modules/ve/init/ve.init.Target.js"></script> <script src="../../modules/ve/init/ve.init.Target.js"></script>
<script src="../../modules/ve/ve.debug.js"></script>
<!-- ext.visualEditor.standalone -->
<script src="../../modules/ve/init/sa/ve.init.sa.js"></script> <script src="../../modules/ve/init/sa/ve.init.sa.js"></script>
<script src="../../modules/ve/init/sa/ve.init.sa.Platform.js"></script> <script src="../../modules/ve/init/sa/ve.init.sa.Platform.js"></script>
<script src="../../modules/ve/init/sa/ve.init.sa.Target.js"></script> <script src="../../modules/ve/init/sa/ve.init.sa.Target.js"></script>
<script src="../../modules/ve/ve.debug.js"></script> <!-- Standalone init -->
<script> <script>
<?php <?php
require '../../modules/../VisualEditor.i18n.php'; require '../../modules/../VisualEditor.i18n.php';
@ -111,6 +113,10 @@ $html = file_get_contents( $page );
?> ?>
ve.init.platform.setModulesUrl( '../../modules' ); ve.init.platform.setModulesUrl( '../../modules' );
</script> </script>
<!-- rangy -->
<script src="../../modules/rangy/rangy-core-1.3.js"></script>
<script src="../../modules/rangy/rangy-position-1.3.js"></script>
<script src="../../modules/rangy/rangy-export.js"></script>
<!-- ext.visualEditor.core --> <!-- ext.visualEditor.core -->
<script src="../../modules/ve/ve.Range.js"></script> <script src="../../modules/ve/ve.Range.js"></script>
<script src="../../modules/ve/ve.Node.js"></script> <script src="../../modules/ve/ve.Node.js"></script>

View file

@ -80,34 +80,68 @@ class MakeStaticLoader extends Maintenance {
'../..' '../..'
); );
$wgResourceModules['Dependencies'] = array(
'scripts' => array(
'jquery/jquery.js',
'jquery/jquery.client.js',
'oojs/oojs.js',
'rangy/rangy-core-1.3.js',
'rangy/rangy-position-1.3.js',
'unicodejs/unicodejs.js',
'unicodejs/unicodejs.textstring.js',
'unicodejs/unicodejs.graphemebreakproperties.js',
'unicodejs/unicodejs.graphemebreak.js',
'unicodejs/unicodejs.wordbreakproperties.js',
'unicodejs/unicodejs.wordbreak.js',
),
);
// If we're running this script from STDIN, // If we're running this script from STDIN,
// hardcode the full path // hardcode the full path
$i18nScript = $this->getOption( 'fixdir' ) ? $i18nScript = $this->getOption( 'fixdir' ) ?
dirname( __DIR__ ) . '/VisualEditor.i18n.php' : dirname( __DIR__ ) . '/VisualEditor.i18n.php' :
$vePath . '/../VisualEditor.i18n.php'; $vePath . '/../VisualEditor.i18n.php';
// Customized version to init standalone instead of mediawiki platform. $self = isset( $_SERVER['PHP_SELF'] ) ? $_SERVER['PHP_SELF'] : ( lcfirst( __CLASS__ ) . '.php' );
$wgResourceModules['ext.visualEditor.base#standalone-init'] = array(
'styles' => array( $fakeModules = array(
've/init/sa/styles/ve.init.sa.css', // These are dependencies that exist in MediaWiki core (such as jquery.js), but we
// can't reference those modules as there is no reliable url to access them from
// standalone. This must also include dependencies like oojs and jquery.uls which
// are only registered by VisualEditor if they aren't registered by MediaWiki).
'jquery' => array(
'scripts' => array(
'jquery/jquery.js',
),
), ),
'headAdd' => '<script> 'jquery.client' => array(
'scripts' => array(
'jquery/jquery.client.js',
),
),
'oojs' => array(
'scripts' => array(
'oojs/oojs.js',
),
),
'oojs-ui' => array(
'scripts' => array(
'oojs-ui/oojs-ui.js',
),
'styles' => array(
'oojs-ui/oojs-ui.svg.css',
),
),
'jquery.uls.grid' => array(
'styles' => 'jquery.uls/css/jquery.uls.grid.css',
),
'jquery.uls.data' => array(
'scripts' => array(
'jquery.uls/src/jquery.uls.data.js',
'jquery.uls/src/jquery.uls.data.utils.js',
)
),
'jquery.uls.compact' => array(
'styles' => 'jquery.uls/css/jquery.uls.compact.css',
),
'jquery.uls' => array(
'scripts' => array(
'jquery.uls/src/jquery.uls.core.js',
'jquery.uls/src/jquery.uls.lcd.js',
'jquery.uls/src/jquery.uls.languagefilter.js',
'jquery.uls/src/jquery.uls.regionfilter.js',
),
'styles' => array(
'jquery.uls/css/jquery.uls.css',
'jquery.uls/css/jquery.uls.lcd.css',
),
),
'Standalone init' => array(
'headAdd' => '<script>
if ( if (
document.createElementNS && document.createElementNS &&
document.createElementNS( \'http://www.w3.org/2000/svg\', \'svg\' ).createSVGRect document.createElementNS( \'http://www.w3.org/2000/svg\', \'svg\' ).createSVGRect
@ -123,32 +157,29 @@ class MakeStaticLoader extends Maintenance {
); );
} }
</script>', </script>',
'bodyAdd' => '<script> 'bodyAdd' => '<script>
<?php <?php
require ' . var_export( $i18nScript, true ) . '; require ' . var_export( $i18nScript, true ) . ';
echo \'ve.init.platform.addMessages( \' . json_encode( $messages[\'en\'] ) . " );\n"; echo \'ve.init.platform.addMessages( \' . json_encode( $messages[\'en\'] ) . " );\n";
?> ?>
ve.init.platform.setModulesUrl( \'' . $vePath . '\' ); ve.init.platform.setModulesUrl( \'' . $vePath . '\' );
</script>' </script>'
) + $wgResourceModules['ext.visualEditor.base']; ),
$baseScripts = &$wgResourceModules['ext.visualEditor.base#standalone-init']['scripts']; );
$baseScripts = array_filter( $baseScripts, function ( $script ) {
return strpos( $script, 've/init/mw/ve.init.mw' ) === false;
} );
$baseScripts = array_merge( $baseScripts, array(
've/init/sa/ve.init.sa.js',
've/init/sa/ve.init.sa.Platform.js',
've/init/sa/ve.init.sa.Target.js',
) );
$self = isset( $_SERVER['PHP_SELF'] ) ? $_SERVER['PHP_SELF'] : ( lcfirst( __CLASS__ ) . '.php' );
$head = $body = '';
$modules = array( $modules = array(
'Dependencies', // Dependencies for ext.visualEditor.base:
'jquery',
'oojs',
'oojs-ui', 'oojs-ui',
'ext.visualEditor.base#standalone-init', 'unicodejs.wordbreak',
// Dependencies for ext.visualEditor.standalone:
'ext.visualEditor.base',
'ext.visualEditor.standalone',
'Standalone init',
// Dependencies for ext.visualEditor.core:
'rangy',
// Dependencies for ext.visualEditor.language
'ext.visualEditor.core', 'ext.visualEditor.core',
'jquery.uls.grid', 'jquery.uls.grid',
'jquery.uls.data', 'jquery.uls.data',
@ -157,15 +188,23 @@ class MakeStaticLoader extends Maintenance {
'ext.visualEditor.language', 'ext.visualEditor.language',
); );
$head = $body = '';
$resourceLoader = new ResourceLoader(); $resourceLoader = new ResourceLoader();
foreach ( $modules as $module ) { foreach ( $modules as $module ) {
$moduleObj = $resourceLoader->getModule( $module ); if ( isset( $fakeModules[ $module ] ) ) {
if ( !$moduleObj ) { $registry = $fakeModules[ $module ];
echo "\nError: Module $module\n not found!\n"; } else {
exit( 1 ); $moduleObj = $resourceLoader->getModule( $module );
if ( !$moduleObj ) {
echo "\nError: Module $module\n not found!\n";
exit( 1 );
}
$registry = isset( $wgResourceModules[$module] ) ?
$wgResourceModules[$module] :
$moduleObj->getDefinitionSummary( ResourceLoaderContext::newDummyContext() );
} }
$registry = isset( $wgResourceModules[$module] ) ? $wgResourceModules[$module] :
$moduleObj->getDefinitionSummary( ResourceLoaderContext::newDummyContext() );
$headAdd = $bodyAdd = ''; $headAdd = $bodyAdd = '';
@ -180,6 +219,7 @@ class MakeStaticLoader extends Maintenance {
) ) . "\n"; ) ) . "\n";
} }
} }
if ( isset( $registry['scripts'] ) ) { if ( isset( $registry['scripts'] ) ) {
foreach ( (array)$registry['scripts'] as $path ) { foreach ( (array)$registry['scripts'] as $path ) {
if ( strpos( $path, 've-mw/' ) === 0 ) { if ( strpos( $path, 've-mw/' ) === 0 ) {
@ -188,6 +228,7 @@ class MakeStaticLoader extends Maintenance {
$bodyAdd .= $indent . Html::element( 'script', array( 'src' => "$vePath/$path" ) ) . "\n"; $bodyAdd .= $indent . Html::element( 'script', array( 'src' => "$vePath/$path" ) ) . "\n";
} }
} }
if ( isset( $registry['debugScripts'] ) ) { if ( isset( $registry['debugScripts'] ) ) {
foreach ( (array)$registry['debugScripts'] as $path ) { foreach ( (array)$registry['debugScripts'] as $path ) {
if ( strpos( $path, 've-mw/' ) === 0 ) { if ( strpos( $path, 've-mw/' ) === 0 ) {
@ -196,9 +237,11 @@ class MakeStaticLoader extends Maintenance {
$bodyAdd .= $indent . Html::element( 'script', array( 'src' => "$vePath/$path" ) ) . "\n"; $bodyAdd .= $indent . Html::element( 'script', array( 'src' => "$vePath/$path" ) ) . "\n";
} }
} }
if ( isset( $registry['headAdd'] ) ) { if ( isset( $registry['headAdd'] ) ) {
$headAdd .= $indent . implode( "\n$indent", explode( "\n", $registry['headAdd'] ) ) . "\n"; $headAdd .= $indent . implode( "\n$indent", explode( "\n", $registry['headAdd'] ) ) . "\n";
} }
if ( isset( $registry['bodyAdd'] ) ) { if ( isset( $registry['bodyAdd'] ) ) {
$bodyAdd .= $indent . implode( "\n$indent", explode( "\n", $registry['bodyAdd'] ) ) . "\n"; $bodyAdd .= $indent . implode( "\n$indent", explode( "\n", $registry['bodyAdd'] ) ) . "\n";
} }
@ -206,6 +249,7 @@ class MakeStaticLoader extends Maintenance {
if ( $headAdd ) { if ( $headAdd ) {
$head .= "$indent<!-- $module -->\n$headAdd"; $head .= "$indent<!-- $module -->\n$headAdd";
} }
if ( $bodyAdd ) { if ( $bodyAdd ) {
$body .= "$indent<!-- $module -->\n$bodyAdd"; $body .= "$indent<!-- $module -->\n$bodyAdd";
} }

View file

@ -12,7 +12,7 @@
<script src="../../qunit/qunit.js"></script> <script src="../../qunit/qunit.js"></script>
<!-- Generated by maintenance/makeStaticLoader.php --> <!-- Generated by maintenance/makeStaticLoader.php -->
<!-- ext.visualEditor.base#standalone-init --> <!-- Standalone init -->
<script> <script>
if ( if (
document.createElementNS && document.createElementNS &&
@ -33,30 +33,31 @@
</head> </head>
<body> <body>
<!-- Generated by maintenance/makeStaticLoader.php --> <!-- Generated by maintenance/makeStaticLoader.php -->
<!-- Dependencies --> <!-- jquery -->
<script src="../../jquery/jquery.js"></script> <script src="../../jquery/jquery.js"></script>
<script src="../../jquery/jquery.client.js"></script> <!-- oojs -->
<script src="../../oojs/oojs.js"></script> <script src="../../oojs/oojs.js"></script>
<script src="../../rangy/rangy-core-1.3.js"></script> <!-- oojs-ui -->
<script src="../../rangy/rangy-position-1.3.js"></script> <script src="../../oojs-ui/oojs-ui.js"></script>
<!-- unicodejs.wordbreak -->
<script src="../../unicodejs/unicodejs.js"></script> <script src="../../unicodejs/unicodejs.js"></script>
<script src="../../unicodejs/unicodejs.textstring.js"></script> <script src="../../unicodejs/unicodejs.textstring.js"></script>
<script src="../../unicodejs/unicodejs.graphemebreakproperties.js"></script> <script src="../../unicodejs/unicodejs.graphemebreakproperties.js"></script>
<script src="../../unicodejs/unicodejs.graphemebreak.js"></script> <script src="../../unicodejs/unicodejs.graphemebreak.js"></script>
<script src="../../unicodejs/unicodejs.wordbreakproperties.js"></script> <script src="../../unicodejs/unicodejs.wordbreakproperties.js"></script>
<script src="../../unicodejs/unicodejs.wordbreak.js"></script> <script src="../../unicodejs/unicodejs.wordbreak.js"></script>
<!-- oojs-ui --> <!-- ext.visualEditor.base -->
<script src="../../oojs-ui/oojs-ui.js"></script>
<!-- ext.visualEditor.base#standalone-init -->
<script src="../../ve/ve.js"></script> <script src="../../ve/ve.js"></script>
<script src="../../ve/ve.track.js"></script> <script src="../../ve/ve.track.js"></script>
<script src="../../ve/init/ve.init.js"></script> <script src="../../ve/init/ve.init.js"></script>
<script src="../../ve/init/ve.init.Platform.js"></script> <script src="../../ve/init/ve.init.Platform.js"></script>
<script src="../../ve/init/ve.init.Target.js"></script> <script src="../../ve/init/ve.init.Target.js"></script>
<script src="../../ve/ve.debug.js"></script>
<!-- ext.visualEditor.standalone -->
<script src="../../ve/init/sa/ve.init.sa.js"></script> <script src="../../ve/init/sa/ve.init.sa.js"></script>
<script src="../../ve/init/sa/ve.init.sa.Platform.js"></script> <script src="../../ve/init/sa/ve.init.sa.Platform.js"></script>
<script src="../../ve/init/sa/ve.init.sa.Target.js"></script> <script src="../../ve/init/sa/ve.init.sa.Target.js"></script>
<script src="../../ve/ve.debug.js"></script> <!-- Standalone init -->
<script> <script>
<?php <?php
require '../../../VisualEditor.i18n.php'; require '../../../VisualEditor.i18n.php';
@ -64,6 +65,10 @@
?> ?>
ve.init.platform.setModulesUrl( '../..' ); ve.init.platform.setModulesUrl( '../..' );
</script> </script>
<!-- rangy -->
<script src="../../rangy/rangy-core-1.3.js"></script>
<script src="../../rangy/rangy-position-1.3.js"></script>
<script src="../../rangy/rangy-export.js"></script>
<!-- ext.visualEditor.core --> <!-- ext.visualEditor.core -->
<script src="../../ve/ve.Range.js"></script> <script src="../../ve/ve.Range.js"></script>
<script src="../../ve/ve.Node.js"></script> <script src="../../ve/ve.Node.js"></script>