Skip registering RL modules depending on VisualEditor

When VisualEditor is not installed, there is no point in registered
resource loader modules that depends on it.  A use case is trying to run
tests for the MediaWiki tarball. It comes with Cite but without
VisualEditor.

The patch is based on GuidedTour patch by Matthew Flaschen
https://gerrit.wikimedia.org/r/#/c/305691/ for T143297

Change-Id: Idf769e0149f93c099a94b1b7a6cb203273dab881
(cherry picked from commit 5fcecf9e5f)
This commit is contained in:
Antoine Musso 2016-10-14 23:40:54 +02:00 committed by Legoktm
parent dc6c0f2c10
commit 3521136358
2 changed files with 114 additions and 88 deletions

View file

@ -33,6 +33,9 @@
"ResourceLoaderTestModules": [ "ResourceLoaderTestModules": [
"CiteHooks::onResourceLoaderTestModules" "CiteHooks::onResourceLoaderTestModules"
], ],
"ResourceLoaderRegisterModules": [
"CiteHooks::onResourceLoaderRegisterModules"
],
"LinksUpdate": [ "LinksUpdate": [
"CiteHooks::onLinksUpdate" "CiteHooks::onLinksUpdate"
], ],
@ -70,94 +73,6 @@
"desktop", "desktop",
"mobile" "mobile"
] ]
},
"ext.cite.visualEditor.core": {
"scripts": [
"ve-cite/ve.dm.MWReferenceModel.js",
"ve-cite/ve.dm.MWReferencesListNode.js",
"ve-cite/ve.dm.MWReferenceNode.js",
"ve-cite/ve.ce.MWReferencesListNode.js",
"ve-cite/ve.ce.MWReferenceNode.js",
"ve-cite/ve.ui.MWReferencesListCommand.js"
],
"styles": [
"ve-cite/ve.ce.MWReferencesListNode.css",
"ve-cite/ve.ce.MWReferenceNode.css"
],
"dependencies": [
"ext.visualEditor.mwcore"
],
"messages": [
"cite-ve-referenceslist-isempty",
"cite-ve-referenceslist-isempty-default",
"cite-ve-referenceslist-missingref"
],
"targets": [
"desktop",
"mobile"
]
},
"ext.cite.visualEditor.data": {
"class": "CiteDataModule"
},
"ext.cite.visualEditor": {
"scripts": [
"ve-cite/ve.ui.MWReferenceGroupInputWidget.js",
"ve-cite/ve.ui.MWReferenceSearchWidget.js",
"ve-cite/ve.ui.MWReferenceResultWidget.js",
"ve-cite/ve.ui.MWUseExistingReferenceCommand.js",
"ve-cite/ve.ui.MWCitationDialog.js",
"ve-cite/ve.ui.MWReferencesListDialog.js",
"ve-cite/ve.ui.MWReferenceDialog.js",
"ve-cite/ve.ui.MWReferenceDialogTool.js",
"ve-cite/ve.ui.MWCitationDialogTool.js",
"ve-cite/ve.ui.MWReferenceContextItem.js",
"ve-cite/ve.ui.MWReferencesListContextItem.js",
"ve-cite/ve.ui.MWCitationContextItem.js",
"ve-cite/ve.ui.MWCitationAction.js",
"ve-cite/ve.ui.MWReference.init.js"
],
"styles": [
"ve-cite/ve.ui.MWReferenceContextItem.css",
"ve-cite/ve.ui.MWReferenceGroupInputWidget.css",
"ve-cite/ve.ui.MWReferenceIcons.css",
"ve-cite/ve.ui.MWReferenceResultWidget.css",
"ve-cite/ve.ui.MWReferenceSearchWidget.css"
],
"dependencies": [
"ext.cite.visualEditor.core",
"ext.cite.visualEditor.data",
"ext.cite.style",
"ext.visualEditor.mwtransclusion",
"ext.visualEditor.mediawiki"
],
"messages": [
"cite-ve-dialog-reference-editing-reused",
"cite-ve-dialog-reference-options-group-label",
"cite-ve-dialog-reference-options-group-placeholder",
"cite-ve-dialog-reference-options-name-label",
"cite-ve-dialog-reference-options-section",
"cite-ve-dialog-reference-title",
"cite-ve-dialog-reference-useexisting-full-label",
"cite-ve-dialog-reference-useexisting-label",
"cite-ve-dialog-reference-useexisting-tool",
"cite-ve-dialog-referenceslist-contextitem-description-general",
"cite-ve-dialog-referenceslist-contextitem-description-named",
"cite-ve-dialog-referenceslist-title",
"cite-ve-dialogbutton-citation-educationpopup-title",
"cite-ve-dialogbutton-citation-educationpopup-text",
"cite-ve-dialogbutton-reference-full-label",
"cite-ve-dialogbutton-reference-tooltip",
"cite-ve-dialogbutton-reference-title",
"cite-ve-dialogbutton-referenceslist-tooltip",
"cite-ve-reference-input-placeholder",
"cite-ve-toolbar-group-label",
"cite-ve-othergroup-item"
],
"targets": [
"desktop",
"mobile"
]
} }
}, },
"ResourceFileModulePaths": { "ResourceFileModulePaths": {

View file

@ -69,6 +69,117 @@ class CiteHooks {
return true; return true;
} }
/**
* Conditionally register resource loader modules that depends on the
* VisualEditor MediaWiki extension.
*
* @param $resourceLoader
* @return true
*/
public static function onResourceLoaderRegisterModules( &$resourceLoader ) {
if ( ! class_exists( 'VisualEditorHooks' ) ) {
return true;
}
$dir = dirname( __DIR__ ) . DIRECTORY_SEPARATOR;
$resourceLoader->register( "ext.cite.visualEditor.core", [
'localBasePath' => $dir . 'modules',
'remoteExtPath' => 'Cite/modules',
"scripts" => [
"ve-cite/ve.dm.MWReferenceModel.js",
"ve-cite/ve.dm.MWReferencesListNode.js",
"ve-cite/ve.dm.MWReferenceNode.js",
"ve-cite/ve.ce.MWReferencesListNode.js",
"ve-cite/ve.ce.MWReferenceNode.js",
"ve-cite/ve.ui.MWReferencesListCommand.js"
],
"styles" => [
"ve-cite/ve.ce.MWReferencesListNode.css",
"ve-cite/ve.ce.MWReferenceNode.css"
],
"dependencies" => [
"ext.visualEditor.mwcore"
],
"messages" => [
"cite-ve-referenceslist-isempty",
"cite-ve-referenceslist-isempty-default",
"cite-ve-referenceslist-missingref"
],
"targets" => [
"desktop",
"mobile"
]
] );
$resourceLoader->register( "ext.cite.visualEditor.data",
[ "class" => "CiteDataModule" ] );
$resourceLoader->register( "ext.cite.visualEditor", [
'localBasePath' => $dir . 'modules',
'remoteExtPath' => 'Cite/modules',
"scripts" => [
"ve-cite/ve.ui.MWReferenceGroupInputWidget.js",
"ve-cite/ve.ui.MWReferenceSearchWidget.js",
"ve-cite/ve.ui.MWReferenceResultWidget.js",
"ve-cite/ve.ui.MWUseExistingReferenceCommand.js",
"ve-cite/ve.ui.MWCitationDialog.js",
"ve-cite/ve.ui.MWReferencesListDialog.js",
"ve-cite/ve.ui.MWReferenceDialog.js",
"ve-cite/ve.ui.MWReferenceDialogTool.js",
"ve-cite/ve.ui.MWCitationDialogTool.js",
"ve-cite/ve.ui.MWReferenceContextItem.js",
"ve-cite/ve.ui.MWReferencesListContextItem.js",
"ve-cite/ve.ui.MWCitationContextItem.js",
"ve-cite/ve.ui.MWCitationAction.js",
"ve-cite/ve.ui.MWReference.init.js"
],
"styles" => [
"ve-cite/ve.ui.MWReferenceContextItem.css",
"ve-cite/ve.ui.MWReferenceGroupInputWidget.css",
"ve-cite/ve.ui.MWReferenceIcons.css",
"ve-cite/ve.ui.MWReferenceResultWidget.css",
"ve-cite/ve.ui.MWReferenceSearchWidget.css"
],
"dependencies" => [
"ext.cite.visualEditor.core",
"ext.cite.visualEditor.data",
"ext.cite.style",
"ext.visualEditor.mwtransclusion",
"ext.visualEditor.mediawiki"
],
"messages" => [
"cite-ve-dialog-reference-editing-reused",
"cite-ve-dialog-reference-options-group-label",
"cite-ve-dialog-reference-options-group-placeholder",
"cite-ve-dialog-reference-options-name-label",
"cite-ve-dialog-reference-options-section",
"cite-ve-dialog-reference-title",
"cite-ve-dialog-reference-useexisting-full-label",
"cite-ve-dialog-reference-useexisting-label",
"cite-ve-dialog-reference-useexisting-tool",
"cite-ve-dialog-referenceslist-contextitem-description-general",
"cite-ve-dialog-referenceslist-contextitem-description-named",
"cite-ve-dialog-referenceslist-title",
"cite-ve-dialogbutton-citation-educationpopup-title",
"cite-ve-dialogbutton-citation-educationpopup-text",
"cite-ve-dialogbutton-reference-full-label",
"cite-ve-dialogbutton-reference-tooltip",
"cite-ve-dialogbutton-reference-title",
"cite-ve-dialogbutton-referenceslist-tooltip",
"cite-ve-reference-input-placeholder",
"cite-ve-toolbar-group-label",
"cite-ve-othergroup-item"
],
"targets" => [
"desktop",
"mobile"
]
] );
return true;
}
/** /**
* Callback for LinksUpdate hook * Callback for LinksUpdate hook
* Post-output processing of references property, for proper db storage * Post-output processing of references property, for proper db storage