Skip registering RL modules depending on VisualEditor

When VisualEditor is not installed, there is no point in registering
resource loader modules that depends on it.

A use case is trying to run tests for the MediaWiki tarball. It comes
with SyntaxHighlight_GeSHi but without VisualEditor.

The patch is based on GuidedTour patch by Matthew Flaschen
https://gerrit.wikimedia.org/r/#/c/305691/ for T143297
A similar one has been done for Cite:
https://gerrit.wikimedia.org/r/#/c/316010/

Change-Id: Idf769e0149f93c099a94b1b7a6cb203273dab881
This commit is contained in:
Antoine Musso 2017-01-23 10:39:57 +01:00
parent 9debf59c9c
commit fea05d6859
2 changed files with 47 additions and 28 deletions

View file

@ -496,6 +496,50 @@ class SyntaxHighlight_GeSHi {
return true;
}
/**
* Conditionally register resource loader modules that depends on the
* VisualEditor MediaWiki extension.
*
* @param $resourceLoader
* @return true
*/
public static function onResourceLoaderRegisterModules( &$resourceLoader ) {
if ( ExtensionRegistry::getInstance()->isLoaded( 'VisualEditor' ) ) {
return;
}
$resourceLoader->register( 'ext.geshi.visualEditor', [
'class' => 'ResourceLoaderGeSHiVisualEditorModule',
'localBasePath' => __DIR__ . DIRECTORY_SEPARATOR . 'modules',
'remoteExtPath' => 'SyntaxHighlight_GeSHi/modules',
'scripts' => [
've-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js',
've-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.js',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightWindow.js',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightDialogTool.js',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.js',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js',
],
'styles' => [
've-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.css',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.css',
've-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.css',
],
'dependencies' => [
'ext.visualEditor.mwcore',
],
'messages' => [
'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code',
'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language',
'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-none',
'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines',
'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title',
],
'targets' => [ 'desktop', 'mobile' ],
] );
}
/** Backward-compatibility shim for extensions. */
public static function prepare( $text, $lang ) {
wfDeprecated( __METHOD__ );

View file

@ -45,34 +45,6 @@
"pygments.generated.css",
"pygments.wrapper.css"
]
},
"ext.geshi.visualEditor": {
"class": "ResourceLoaderGeSHiVisualEditorModule",
"scripts": [
"ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js",
"ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightWindow.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialogTool.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js"
],
"styles": [
"ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.css",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.css",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.css"
],
"dependencies": [
"ext.visualEditor.mwcore"
],
"messages": [
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-none",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title"
],
"targets": [ "desktop", "mobile" ]
}
},
"Hooks": {
@ -87,6 +59,9 @@
],
"RejectParserCacheValue": [
"SyntaxHighlight_GeSHi::onRejectParserCacheValue"
],
"ResourceLoaderRegisterModules": [
"SyntaxHighlight_GeSHi::onResourceLoaderRegisterModules"
]
},
"SyntaxHighlightModels": {