Hook: Create HookRunner and interface for own hook

Bug: T348040
Change-Id: I63a7e71a06729dbf607ef9bb275896e42db1b6e0
This commit is contained in:
Ammarpad 2023-10-04 10:31:15 +01:00 committed by Jdlrobson
parent 732069f7fc
commit 3452647071
3 changed files with 47 additions and 4 deletions

View file

@ -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 );
}

View file

@ -0,0 +1,26 @@
<?php
namespace MediaWiki\Skins\Vector\Hooks;
use MediaWiki\HookContainer\HookContainer;
/**
* @internal
*/
class HookRunner implements VectorSearchResourceLoaderConfigHook {
private HookContainer $hookContainer;
public function __construct( HookContainer $hookContainer ) {
$this->hookContainer = $hookContainer;
}
/**
* @inheritDoc
*/
public function onVectorSearchResourceLoaderConfig( array &$vectorSearchConfig ): void {
$this->hookContainer->run(
'VectorSearchResourceLoaderConfig',
[ &$vectorSearchConfig ]
);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace MediaWiki\Skins\Vector\Hooks;
/**
* Use the hook name "VectorSearchResourceLoaderConfig" to register
* handlers implementing this interface to modify Vector's search config.
*
* @stable to implement
* @ingroup Hooks
*/
interface VectorSearchResourceLoaderConfigHook {
/**
* @param array &$vectorSearchConfig
* @return void
*/
public function onVectorSearchResourceLoaderConfig( array &$vectorSearchConfig ): void;
}