Use HookHandlers for core hooks

The use of "HookHandlers" attribute in extension.json makes it possible
to inject services into hook handler classes in a future patch.

Bug: T271032
Change-Id: I612c09264b830fe5588aafdad80a9eebaa66d71b
This commit is contained in:
Umherirrender 2023-08-14 19:49:09 +02:00
parent 87dc3cb2db
commit ce0bcb5c82
2 changed files with 9 additions and 5 deletions

View file

@ -34,9 +34,12 @@
"TextExtracts\\": "includes/"
},
"Hooks": {
"ApiOpenSearchSuggest": [
"TextExtracts\\Hooks::onApiOpenSearchSuggest"
]
"ApiOpenSearchSuggest": "main"
},
"HookHandlers": {
"main": {
"class": "TextExtracts\\Hooks"
}
},
"config": {
"ExtractsRemoveClasses": {

View file

@ -5,19 +5,20 @@ namespace TextExtracts;
use ApiBase;
use ApiMain;
use ApiResult;
use MediaWiki\Api\Hook\ApiOpenSearchSuggestHook;
use MediaWiki\MediaWikiServices;
use MediaWiki\Request\FauxRequest;
/**
* @license GPL-2.0-or-later
*/
class Hooks {
class Hooks implements ApiOpenSearchSuggestHook {
/**
* ApiOpenSearchSuggest hook handler
* @param array &$results Array of search results
*/
public static function onApiOpenSearchSuggest( &$results ) {
public function onApiOpenSearchSuggest( &$results ) {
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || $results === [] ) {
return;