From 4c9eaed7a360e96cf67cb0e8ead40bde2dcbdbd5 Mon Sep 17 00:00:00 2001 From: Reedy Date: Sun, 7 Apr 2024 21:15:52 +0100 Subject: [PATCH] Conditionally register popup RestRoute using ExtensionFunctions Bug: T362027 Change-Id: Id1329c72b81372468a98da3b47b101302c07b40d (cherry picked from commit 4c2401961feba10f3a1d01a405226676413ca543) --- extension.json | 16 +++------------- popupRestRoutes.json | 13 +++++++++++++ src/Hooks.php | 7 +++++++ 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 popupRestRoutes.json diff --git a/extension.json b/extension.json index 6cff01db6..016663dea 100644 --- a/extension.json +++ b/extension.json @@ -34,6 +34,9 @@ "MathAlias": "Math.alias.php", "MathAliasNoTranslate": "Math.alias.noTranslate.php" }, + "ExtensionFunctions": [ + "MediaWiki\\Extension\\Math\\Hooks::onExtensionFunctions" + ], "HookHandlers": { "ParserHooksHandler": { "class": "MediaWiki\\Extension\\Math\\HookHandlers\\ParserHooksHandler", @@ -388,18 +391,5 @@ "ServiceWiringFiles": [ "ServiceWiring.php" ], - "RestRoutes": [ - { - "path": "/math/v0/popup/html/{qid}", - "method": "GET", - "class": "MediaWiki\\Extension\\Math\\Rest\\Popup", - "services": [ - "Math.WikibaseConnector", - "LanguageFactory", - "LanguageNameUtils", - "TitleFactory" - ] - } - ], "manifest_version": 2 } diff --git a/popupRestRoutes.json b/popupRestRoutes.json new file mode 100644 index 000000000..6ab53088c --- /dev/null +++ b/popupRestRoutes.json @@ -0,0 +1,13 @@ +[ + { + "path": "/math/v0/popup/html/{qid}", + "method": "GET", + "class": "MediaWiki\\Extension\\Math\\Rest\\Popup", + "services": [ + "Math.WikibaseConnector", + "LanguageFactory", + "LanguageNameUtils", + "TitleFactory" + ] + } +] diff --git a/src/Hooks.php b/src/Hooks.php index 924382634..fc6d3fc48 100644 --- a/src/Hooks.php +++ b/src/Hooks.php @@ -17,6 +17,13 @@ use RequestContext; class Hooks { + public static function onExtensionFunctions() { + if ( ExtensionRegistry::getInstance()->isLoaded( 'WikibaseClient' ) ) { + global $wgRestAPIAdditionalRouteFiles; + $wgRestAPIAdditionalRouteFiles[] = dirname( __DIR__ ) . '/popupRestRoutes.json'; + } + } + /** * MaintenanceRefreshLinksInit handler; optimize settings for refreshLinks batch job. *