From 3521136358cc1aa61f0e0a7a0f8e13610b50de98 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 14 Oct 2016 23:40:54 +0200 Subject: [PATCH] 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 5fcecf9e5f18a355327a883ecd745b9255f21173) --- extension.json | 91 ++------------------------------- includes/CiteHooks.php | 111 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 88 deletions(-) diff --git a/extension.json b/extension.json index b3aa8af51..35d451cad 100644 --- a/extension.json +++ b/extension.json @@ -33,6 +33,9 @@ "ResourceLoaderTestModules": [ "CiteHooks::onResourceLoaderTestModules" ], + "ResourceLoaderRegisterModules": [ + "CiteHooks::onResourceLoaderRegisterModules" + ], "LinksUpdate": [ "CiteHooks::onLinksUpdate" ], @@ -70,94 +73,6 @@ "desktop", "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": { diff --git a/includes/CiteHooks.php b/includes/CiteHooks.php index efa7c5e72..7e3c5bffe 100644 --- a/includes/CiteHooks.php +++ b/includes/CiteHooks.php @@ -69,6 +69,117 @@ class CiteHooks { 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 * Post-output processing of references property, for proper db storage