From 3452647071ba8a077e8c58cd59f12993b373e226 Mon Sep 17 00:00:00 2001 From: Ammarpad Date: Wed, 4 Oct 2023 10:31:15 +0100 Subject: [PATCH] Hook: Create HookRunner and interface for own hook Bug: T348040 Change-Id: I63a7e71a06729dbf607ef9bb275896e42db1b6e0 --- includes/Hooks.php | 7 +++-- includes/Hooks/HookRunner.php | 26 +++++++++++++++++++ .../VectorSearchResourceLoaderConfigHook.php | 18 +++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 includes/Hooks/HookRunner.php create mode 100644 includes/Hooks/VectorSearchResourceLoaderConfigHook.php diff --git a/includes/Hooks.php b/includes/Hooks.php index 7b685f16f..743932d40 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -11,6 +11,7 @@ use MediaWiki\ResourceLoader as RL; use MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteModulePagesHook; use MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteStylesModulePagesHook; use MediaWiki\Skins\Hook\SkinPageReadyConfigHook; +use MediaWiki\Skins\Vector\Hooks\HookRunner; use OutputPage; use RuntimeException; use SkinTemplate; @@ -101,10 +102,8 @@ class Hooks implements VectorServices::getLanguageService()->canWordsBeSplitSafely( $context->getLanguage() ) ]; - MediaWikiServices::getInstance()->getHookContainer()->run( - 'VectorSearchResourceLoaderConfig', - [ &$vectorSearchConfig ] - ); + $hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ); + $hookRunner->onVectorSearchResourceLoaderConfig( $vectorSearchConfig ); return array_merge( $config->get( 'VectorWvuiSearchOptions' ), $vectorSearchConfig ); } diff --git a/includes/Hooks/HookRunner.php b/includes/Hooks/HookRunner.php new file mode 100644 index 000000000..d9d14beea --- /dev/null +++ b/includes/Hooks/HookRunner.php @@ -0,0 +1,26 @@ +hookContainer = $hookContainer; + } + + /** + * @inheritDoc + */ + public function onVectorSearchResourceLoaderConfig( array &$vectorSearchConfig ): void { + $this->hookContainer->run( + 'VectorSearchResourceLoaderConfig', + [ &$vectorSearchConfig ] + ); + } +} diff --git a/includes/Hooks/VectorSearchResourceLoaderConfigHook.php b/includes/Hooks/VectorSearchResourceLoaderConfigHook.php new file mode 100644 index 000000000..152d9cb8a --- /dev/null +++ b/includes/Hooks/VectorSearchResourceLoaderConfigHook.php @@ -0,0 +1,18 @@ +