mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/LoginNotify
synced 2024-09-23 10:20:21 +00:00
Create HookRunner class
Only core hooks are run, but own HookRunner is recommended Bug: T263353 Change-Id: I2506f4af21ef955a7feeb145d5173f46ca11b334
This commit is contained in:
parent
122d47d87d
commit
222b7475fb
31
includes/Hooks/HookRunner.php
Normal file
31
includes/Hooks/HookRunner.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace LoginNotify\Hooks;
|
||||
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
|
||||
/**
|
||||
* This is a hook runner class, see docs/Hooks.md in core.
|
||||
* @internal
|
||||
*/
|
||||
class HookRunner implements
|
||||
\MediaWiki\Auth\Hook\AuthManagerLoginAuthenticateAuditHook
|
||||
{
|
||||
private HookContainer $hookContainer;
|
||||
|
||||
public function __construct( HookContainer $hookContainer ) {
|
||||
$this->hookContainer = $hookContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function onAuthManagerLoginAuthenticateAudit( $response, $user,
|
||||
$username, $extraData
|
||||
) {
|
||||
return $this->hookContainer->run(
|
||||
'AuthManagerLoginAuthenticateAudit',
|
||||
[ $response, $user, $username, $extraData ]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace LoginNotify\Maintenance;
|
||||
|
||||
use LoginNotify\Hooks\HookRunner;
|
||||
use Maintenance;
|
||||
use MediaWiki\Auth\AuthenticationResponse;
|
||||
use MediaWiki\Language\RawMessage;
|
||||
|
@ -64,15 +65,15 @@ class LoginAttempt extends Maintenance {
|
|||
return;
|
||||
}
|
||||
|
||||
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
|
||||
$hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
|
||||
for ( $i = 0; $i < $reps; $i++ ) {
|
||||
if ( $success ) {
|
||||
$res = AuthenticationResponse::newPass( $username );
|
||||
$hookContainer->run( 'AuthManagerLoginAuthenticateAudit', [ $res, $user, $username, [] ] );
|
||||
$hookRunner->onAuthManagerLoginAuthenticateAudit( $res, $user, $username, [] );
|
||||
$this->output( "A successful login attempt was registered!\n" );
|
||||
} else {
|
||||
$res = AuthenticationResponse::newFail( new RawMessage( 'Well, it failed' ) );
|
||||
$hookContainer->run( 'AuthManagerLoginAuthenticateAudit', [ $res, null, $username, [] ] );
|
||||
$hookRunner->onAuthManagerLoginAuthenticateAudit( $res, null, $username, [] );
|
||||
$this->output( "A failed login attempt was registered!\n" );
|
||||
}
|
||||
}
|
||||
|
|
16
tests/phpunit/unit/HookRunnerTest.php
Normal file
16
tests/phpunit/unit/HookRunnerTest.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace LoginNotify\Tests\Unit;
|
||||
|
||||
use LoginNotify\Hooks\HookRunner;
|
||||
use MediaWiki\Tests\HookContainer\HookRunnerTestBase;
|
||||
|
||||
/**
|
||||
* @covers \LoginNotify\Hooks\HookRunner
|
||||
*/
|
||||
class HookRunnerTest extends HookRunnerTestBase {
|
||||
|
||||
public static function provideHookRunners() {
|
||||
yield HookRunner::class => [ HookRunner::class ];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue