mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 09:43:30 +00:00
Create HookRunner class and the hook handler interface
Bug: T273303 Change-Id: I6d00848f07fc7d17f3dc7f44b7b6b61553219558
This commit is contained in:
parent
6295079d77
commit
378769a974
23
includes/Hooks/DiscussionToolsTermsOfUseMessagesHook.php
Normal file
23
includes/Hooks/DiscussionToolsTermsOfUseMessagesHook.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
||||
|
||||
use Config;
|
||||
use MessageLocalizer;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md in core.
|
||||
* Use the hook name "DiscussionToolsTermsOfUseMessages" to register handlers implementing this interface.
|
||||
*
|
||||
* @stable to implement
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface DiscussionToolsTermsOfUseMessagesHook {
|
||||
/**
|
||||
* @param array &$messages
|
||||
* @param MessageLocalizer $context
|
||||
* @param Config $config
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onDiscussionToolsTermsOfUseMessages( array &$messages, MessageLocalizer $context, Config $config );
|
||||
}
|
31
includes/Hooks/HookRunner.php
Normal file
31
includes/Hooks/HookRunner.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DiscussionTools\Hooks;
|
||||
|
||||
use Config;
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
use MessageLocalizer;
|
||||
|
||||
/**
|
||||
* This is a hook runner class, see docs/Hooks.md in core.
|
||||
* @internal
|
||||
*/
|
||||
class HookRunner implements
|
||||
DiscussionToolsTermsOfUseMessagesHook
|
||||
{
|
||||
private HookContainer $hookContainer;
|
||||
|
||||
public function __construct( HookContainer $hookContainer ) {
|
||||
$this->hookContainer = $hookContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function onDiscussionToolsTermsOfUseMessages( array &$messages, MessageLocalizer $context, Config $config ) {
|
||||
return $this->hookContainer->run(
|
||||
'DiscussionToolsTermsOfUseMessages',
|
||||
[ &$messages, $context, $config ]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace MediaWiki\Extension\DiscussionTools;
|
|||
|
||||
use Config;
|
||||
use ExtensionRegistry;
|
||||
use MediaWiki\Extension\DiscussionTools\Hooks\HookRunner;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\ResourceLoader as RL;
|
||||
use MessageLocalizer;
|
||||
|
@ -84,8 +85,8 @@ class ResourceLoaderData {
|
|||
$context->msg( 'discussiontools-replywidget-newtopic' )->text() ],
|
||||
];
|
||||
|
||||
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
|
||||
$hookContainer->run( 'DiscussionToolsTermsOfUseMessages', [ &$messages, $context, $config ] );
|
||||
$hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
|
||||
$hookRunner->onDiscussionToolsTermsOfUseMessages( $messages, $context, $config );
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
|
16
tests/phpunit/unit/HookRunnerTest.php
Normal file
16
tests/phpunit/unit/HookRunnerTest.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\DiscussionTools\Tests\Unit;
|
||||
|
||||
use MediaWiki\Extension\DiscussionTools\Hooks\HookRunner;
|
||||
use MediaWiki\Tests\HookContainer\HookRunnerTestBase;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\DiscussionTools\Hooks\HookRunner
|
||||
*/
|
||||
class HookRunnerTest extends HookRunnerTestBase {
|
||||
|
||||
public static function provideHookRunners() {
|
||||
yield HookRunner::class => [ HookRunner::class ];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue