Create HookRunner class and the hook handler interface

Bug: T315823
Change-Id: I09c45ed939e103e6edb3a76623687574dcf0206f
This commit is contained in:
Umherirrender 2023-06-04 20:38:52 +02:00
parent 2bb554f1ea
commit 903034de23
3 changed files with 55 additions and 1 deletions

View file

@ -29,6 +29,7 @@ use MediaWiki\Hook\FetchChangesListHook;
use MediaWiki\Hook\OutputPageBodyAttributesHook; use MediaWiki\Hook\OutputPageBodyAttributesHook;
use MediaWiki\Hook\UserLogoutCompleteHook; use MediaWiki\Hook\UserLogoutCompleteHook;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Minerva\Hooks\HookRunner;
use MediaWiki\Minerva\Skins\SkinMinerva; use MediaWiki\Minerva\Skins\SkinMinerva;
use MediaWiki\Minerva\Skins\SkinUserPageHelper; use MediaWiki\Minerva\Skins\SkinUserPageHelper;
use MediaWiki\ResourceLoader\Context; use MediaWiki\ResourceLoader\Context;
@ -320,7 +321,7 @@ class Hooks implements
), ),
SkinOptions::TABS_ON_SPECIALS => true, SkinOptions::TABS_ON_SPECIALS => true,
] ); ] );
$services->getHookContainer()->run( 'SkinMinervaOptionsInit', [ $skin, $skinOptions ] ); ( new HookRunner( $services->getHookContainer() ) )->onSkinMinervaOptionsInit( $skin, $skinOptions );
} }
} }

View file

@ -0,0 +1,31 @@
<?php
namespace MediaWiki\Minerva\Hooks;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Minerva\SkinOptions;
use Skin;
/**
* This is a hook runner class, see docs/Hooks.md in core.
* @internal
*/
class HookRunner implements
SkinMinervaOptionsInitHook
{
private HookContainer $hookContainer;
public function __construct( HookContainer $hookContainer ) {
$this->hookContainer = $hookContainer;
}
/**
* @inheritDoc
*/
public function onSkinMinervaOptionsInit( Skin $skin, SkinOptions $skinOptions ) {
return $this->hookContainer->run(
'SkinMinervaOptionsInit',
[ $skin, $skinOptions ]
);
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace MediaWiki\Minerva\Hooks;
use MediaWiki\Minerva\SkinOptions;
use Skin;
/**
* This is a hook handler interface, see docs/Hooks.md in core.
* Use the hook name "SkinMinervaOptionsInit" to register handlers implementing this interface.
*
* @stable to implement
* @ingroup Hooks
*/
interface SkinMinervaOptionsInitHook {
/**
* @param Skin $skin
* @param SkinOptions $skinOptions
* @return bool|void True or no return value to continue or false to abort
*/
public function onSkinMinervaOptionsInit( Skin $skin, SkinOptions $skinOptions );
}