2012-10-16 14:03:26 +00:00
|
|
|
<?php
|
2013-02-26 15:06:16 +00:00
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
|
|
|
$IP = __DIR__ . '/../../..';
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
2013-05-31 00:10:43 +00:00
|
|
|
require_once $IP . '/maintenance/Maintenance.php';
|
2012-10-16 14:03:26 +00:00
|
|
|
|
2013-04-30 14:09:18 +00:00
|
|
|
/**
|
|
|
|
* A generator for creating a static HTML loading sequence
|
|
|
|
* for VisualEditor.
|
|
|
|
*
|
|
|
|
* Example usage:
|
|
|
|
*
|
|
|
|
* # Update our static files
|
|
|
|
* $ php maintenance/makeStaticLoader.php --target demo --write-file demos/ve/index.php
|
|
|
|
* $ php maintenance/makeStaticLoader.php --target test --write-file modules/ve/test/index.php
|
|
|
|
*
|
|
|
|
* @author Timo Tijhof, 2013
|
|
|
|
*/
|
2012-10-16 14:03:26 +00:00
|
|
|
class MakeStaticLoader extends Maintenance {
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
2013-05-31 00:10:43 +00:00
|
|
|
$this->addOption(
|
|
|
|
'target',
|
|
|
|
'Which target to use ("demo" or "test"). Default: demo',
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->addOption(
|
|
|
|
'indent',
|
|
|
|
'Indentation prefix to use (number of tabs or a string)',
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->addOption(
|
|
|
|
've-path',
|
|
|
|
'Override path to "VisualEditor/modules" (no trailing slash). Default by --target',
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->addOption(
|
|
|
|
'write-file',
|
|
|
|
'Automatically replace the "Generated by" sections in this file. Default: false',
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$this->addOption(
|
|
|
|
'fixdir',
|
|
|
|
'Embed the absolute path in require() statements. Defaults to relative path. '
|
|
|
|
. '(use this if you evaluate the resulting script in php-STDIN instead of from a file)',
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
);
|
2013-04-30 14:09:18 +00:00
|
|
|
$this->addOption( 'section', 'head, body or both', false, true );
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
global $wgResourceModules, $wgHtml5, $wgWellFormedXml;
|
|
|
|
|
|
|
|
$wgHtml5 = true;
|
|
|
|
$wgWellFormedXml = false;
|
|
|
|
|
2013-02-09 01:33:48 +00:00
|
|
|
$section = $this->getOption( 'section', 'both' );
|
2012-12-04 07:54:49 +00:00
|
|
|
$target = $this->getOption( 'target', 'demo' );
|
|
|
|
$indent = $this->getOption( 'indent', 2 );
|
2013-04-30 14:09:18 +00:00
|
|
|
$writeFile = $this->getOption( 'write-file', false );
|
|
|
|
|
2012-12-04 07:54:49 +00:00
|
|
|
if ( is_numeric( $indent ) ) {
|
|
|
|
$indent = str_repeat( "\t", $indent );
|
|
|
|
}
|
2013-04-30 14:09:18 +00:00
|
|
|
|
2012-12-04 07:54:49 +00:00
|
|
|
// Path to /modules/
|
|
|
|
$vePath = $this->getOption( 've-path',
|
|
|
|
$target === 'demo'
|
|
|
|
// From /demos/ve/index.php
|
2013-04-10 17:18:39 +00:00
|
|
|
? '../../modules'
|
2012-12-04 07:54:49 +00:00
|
|
|
// From /modules/ve/test/index.html
|
2013-04-10 17:18:39 +00:00
|
|
|
: '../..'
|
2012-12-04 07:54:49 +00:00
|
|
|
);
|
|
|
|
|
2012-10-16 14:03:26 +00:00
|
|
|
$wgResourceModules['Dependencies'] = array(
|
|
|
|
'scripts' => array(
|
|
|
|
'jquery/jquery.js',
|
2013-04-29 21:48:27 +00:00
|
|
|
'jquery/jquery.client.js',
|
2013-06-06 01:52:04 +00:00
|
|
|
'oojs/oo.js',
|
2013-05-13 21:44:16 +00:00
|
|
|
'rangy/rangy-core-1.3.js',
|
|
|
|
'rangy/rangy-position-1.3.js',
|
2013-03-18 11:31:14 +00:00
|
|
|
'unicodejs/unicodejs.js',
|
|
|
|
'unicodejs/unicodejs.textstring.js',
|
2013-06-15 12:52:08 +00:00
|
|
|
'unicodejs/unicodejs.graphemebreakproperties.js',
|
|
|
|
'unicodejs/unicodejs.graphemebreak.js',
|
2013-06-07 01:30:44 +00:00
|
|
|
'unicodejs/unicodejs.wordbreakproperties.js',
|
2013-03-18 11:31:14 +00:00
|
|
|
'unicodejs/unicodejs.wordbreak.js',
|
2012-10-16 14:03:26 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2013-04-29 15:24:24 +00:00
|
|
|
// If we're running this script from STDIN,
|
|
|
|
// hardcode the full path
|
|
|
|
$i18nScript = $this->getOption( 'fixdir' ) ?
|
|
|
|
dirname( __DIR__ ) . '/VisualEditor.i18n.php' :
|
|
|
|
$vePath . '/../VisualEditor.i18n.php';
|
|
|
|
|
2013-04-03 03:47:40 +00:00
|
|
|
// Customized version to init standalone instead of mediawiki platform.
|
|
|
|
$wgResourceModules['ext.visualEditor.base#standalone-init'] = array(
|
2012-10-16 14:03:26 +00:00
|
|
|
'styles' => array(
|
|
|
|
've/init/sa/styles/ve.init.sa.css',
|
|
|
|
),
|
2013-04-03 03:47:40 +00:00
|
|
|
'headAdd' => '<script>
|
2013-05-31 00:10:43 +00:00
|
|
|
if (
|
|
|
|
document.createElementNS &&
|
|
|
|
document.createElementNS( \'http://www.w3.org/2000/svg\', \'svg\' ).createSVGRect
|
|
|
|
) {
|
|
|
|
document.write(
|
|
|
|
\'<link rel="stylesheet" \' +
|
|
|
|
\'href="' . $vePath . '/ve/ui/styles/ve.ui.Icons-vector.css">\'
|
|
|
|
);
|
2013-04-03 03:47:40 +00:00
|
|
|
} else {
|
2013-05-31 00:10:43 +00:00
|
|
|
document.write(
|
|
|
|
\'<link rel="stylesheet" \' +
|
|
|
|
\'href="' . $vePath . '/ve/ui/styles/ve.ui.Icons-raster.css">\'
|
|
|
|
);
|
2013-04-03 03:47:40 +00:00
|
|
|
}
|
|
|
|
</script>',
|
2012-12-04 07:54:49 +00:00
|
|
|
'bodyAdd' => '<script>
|
|
|
|
<?php
|
2013-05-31 00:10:43 +00:00
|
|
|
require ' . var_export( $i18nScript, true ) . ';
|
|
|
|
echo \'ve.init.platform.addMessages( \' . json_encode( $messages[\'en\'] ) . " );\n";
|
2012-12-04 07:54:49 +00:00
|
|
|
?>
|
|
|
|
ve.init.platform.setModulesUrl( \'' . $vePath . '\' );
|
|
|
|
</script>'
|
2013-04-03 03:47:40 +00:00
|
|
|
) + $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',
|
|
|
|
) );
|
2012-10-16 14:03:26 +00:00
|
|
|
|
|
|
|
$self = isset( $_SERVER['PHP_SELF'] ) ? $_SERVER['PHP_SELF'] : ( lcfirst( __CLASS__ ) . '.php' );
|
|
|
|
|
2013-04-30 14:09:18 +00:00
|
|
|
$head = $body = '';
|
2012-10-16 14:03:26 +00:00
|
|
|
|
|
|
|
$modules = array(
|
|
|
|
'Dependencies',
|
2013-04-03 03:47:40 +00:00
|
|
|
'ext.visualEditor.base#standalone-init',
|
2012-10-16 14:03:26 +00:00
|
|
|
'ext.visualEditor.core',
|
2013-04-29 21:48:12 +00:00
|
|
|
'ext.visualEditor.experimental',
|
2012-10-16 14:03:26 +00:00
|
|
|
);
|
2013-04-30 14:09:18 +00:00
|
|
|
|
2012-10-16 14:03:26 +00:00
|
|
|
foreach ( $modules as $module ) {
|
|
|
|
if ( !isset( $wgResourceModules[$module] ) ) {
|
2012-12-04 07:54:49 +00:00
|
|
|
echo "\nError: File group $module\n not found!\n";
|
|
|
|
exit( 1 );
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
|
|
|
$registry = $wgResourceModules[$module];
|
2012-12-04 07:54:49 +00:00
|
|
|
|
|
|
|
$headAdd = $bodyAdd = '';
|
|
|
|
|
|
|
|
if ( isset( $registry['styles'] ) && $target !== 'test' ){
|
2013-08-27 23:02:52 +00:00
|
|
|
foreach ( (array)$registry['styles'] as $path ) {
|
2013-07-04 01:58:36 +00:00
|
|
|
if ( strpos( $path, 've-mw/' ) === 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-31 00:10:43 +00:00
|
|
|
$headAdd .= $indent . Html::element( 'link', array(
|
|
|
|
'rel' => 'stylesheet',
|
2013-07-04 01:58:36 +00:00
|
|
|
'href' => "$vePath/$path",
|
2013-05-31 00:10:43 +00:00
|
|
|
) ) . "\n";
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( isset( $registry['scripts'] ) ) {
|
2013-08-27 23:02:52 +00:00
|
|
|
foreach ( (array)$registry['scripts'] as $path ) {
|
2013-07-04 01:58:36 +00:00
|
|
|
if ( strpos( $path, 've-mw/' ) === 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$bodyAdd .= $indent . Html::element( 'script', array( 'src' => "$vePath/$path" ) ) . "\n";
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( isset( $registry['debugScripts'] ) ) {
|
2013-08-27 23:02:52 +00:00
|
|
|
foreach ( (array)$registry['debugScripts'] as $path ) {
|
2013-07-04 01:58:36 +00:00
|
|
|
if ( strpos( $path, 've-mw/' ) === 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$bodyAdd .= $indent . Html::element( 'script', array( 'src' => "$vePath/$path" ) ) . "\n";
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-04 07:54:49 +00:00
|
|
|
if ( isset( $registry['headAdd'] ) ) {
|
|
|
|
$headAdd .= $indent . implode( "\n$indent", explode( "\n", $registry['headAdd'] ) ) . "\n";
|
|
|
|
}
|
|
|
|
if ( isset( $registry['bodyAdd'] ) ) {
|
|
|
|
$bodyAdd .= $indent . implode( "\n$indent", explode( "\n", $registry['bodyAdd'] ) ) . "\n";
|
|
|
|
}
|
|
|
|
|
2012-10-16 14:03:26 +00:00
|
|
|
if ( $headAdd ) {
|
|
|
|
$head .= "$indent<!-- $module -->\n$headAdd";
|
|
|
|
}
|
|
|
|
if ( $bodyAdd ) {
|
|
|
|
$body .= "$indent<!-- $module -->\n$bodyAdd";
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 14:09:18 +00:00
|
|
|
|
|
|
|
$head = rtrim( $head );
|
|
|
|
$body = rtrim( $body );
|
|
|
|
|
|
|
|
// Output
|
|
|
|
|
|
|
|
if ( $writeFile ) {
|
|
|
|
$contents = is_readable( $writeFile ) ? file_get_contents( $writeFile ) : false;
|
|
|
|
if ( !$contents ) {
|
|
|
|
echo "\nError: Write file not readable or empty!\n";
|
|
|
|
exit( 1 );
|
2013-02-09 01:33:48 +00:00
|
|
|
}
|
2013-04-30 14:09:18 +00:00
|
|
|
$lines = explode( "\n", $contents . "\n" );
|
|
|
|
$inHead = $inBody = $inGenerated = false;
|
|
|
|
foreach ( $lines as $i => &$line ) {
|
|
|
|
$text = trim( $line );
|
|
|
|
if ( $text === '<head>' ) {
|
|
|
|
$inHead = true;
|
|
|
|
$inBody = false;
|
|
|
|
$inGenerated = false;
|
|
|
|
} elseif ( $text === '<body>' ) {
|
|
|
|
$inHead = false;
|
|
|
|
$inBody = true;
|
|
|
|
$inGenerated = false;
|
|
|
|
} elseif ( strpos( $text, '<!-- Generated by' ) === 0 ) {
|
|
|
|
// Only set $inGenerated if we're in a generated section
|
|
|
|
// that we want to replace (--section=body, don't replace head).
|
|
|
|
if ( $inHead ) {
|
|
|
|
if ( $section === 'both' || $section === 'head' ) {
|
|
|
|
$inGenerated = true;
|
|
|
|
if ( !$head ) {
|
|
|
|
$line = '';
|
|
|
|
} else {
|
|
|
|
$line = "$indent<!-- Generated by $self -->\n$head";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ( $inBody ) {
|
|
|
|
if ( $section === 'both' || $section === 'body' ) {
|
|
|
|
$inGenerated = true;
|
|
|
|
if ( !$body ) {
|
|
|
|
$line = '';
|
|
|
|
} else {
|
|
|
|
$line = "$indent<!-- Generated by $self -->\n$body";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} elseif ( $text === '' ) {
|
|
|
|
$inGenerated = false;
|
|
|
|
} else {
|
|
|
|
// Strip the lines directly connected to the "<!-- Generated by"
|
|
|
|
if ( $inGenerated ) {
|
|
|
|
unset( $lines[$i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !file_put_contents( $writeFile, trim( implode( "\n", $lines ) ) . "\n" ) ) {
|
|
|
|
echo "\nError: Write to file failed!\n";
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
echo "Done!\n";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ( $head ) {
|
|
|
|
if ( $section === 'both' ) {
|
|
|
|
echo "<head>\n\n$indent<!-- Generated by $self -->\n$head\n\n</head>";
|
|
|
|
} elseif ( $section === 'head' ) {
|
|
|
|
echo $head;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $body ) {
|
|
|
|
if ( $section === 'both' ) {
|
|
|
|
echo "<body>\n\n$indent<!-- Generated by $self -->\n$body\n\n</body>\n";
|
|
|
|
} elseif ( $section === 'body' ) {
|
|
|
|
echo $body;
|
|
|
|
}
|
2013-02-09 01:33:48 +00:00
|
|
|
}
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
2013-04-30 14:09:18 +00:00
|
|
|
|
2012-10-16 14:03:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = 'MakeStaticLoader';
|
2013-05-31 00:10:43 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|