Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
CRAP | |
42.86% |
9 / 21 |
TitleBlacklistPreAuthenticationProvider | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
33.58 | |
42.86% |
9 / 21 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
getAuthenticationRequests | |
100.00% |
1 / 1 |
4 | |
100.00% |
6 / 6 |
|||
testForAccountCreation | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
testUserForCreation | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 6 |
<?php | |
namespace MediaWiki\Extension\TitleBlacklist; | |
use MediaWiki\Auth\AbstractPreAuthenticationProvider; | |
use MediaWiki\Auth\AuthenticationRequest; | |
use MediaWiki\Auth\AuthManager; | |
use RequestContext; | |
use StatusValue; | |
use User; | |
class TitleBlacklistPreAuthenticationProvider extends AbstractPreAuthenticationProvider { | |
protected $blockAutoAccountCreation; | |
public function __construct( $params = [] ) { | |
global $wgTitleBlacklistBlockAutoAccountCreation; | |
$params += [ | |
'blockAutoAccountCreation' => $wgTitleBlacklistBlockAutoAccountCreation | |
]; | |
$this->blockAutoAccountCreation = (bool)$params['blockAutoAccountCreation']; | |
} | |
public function getAuthenticationRequests( $action, array $options ) { | |
$needOverrideOption = false; | |
switch ( $action ) { | |
case AuthManager::ACTION_CREATE: | |
$user = User::newFromName( $options['username'] ) ?: new User(); | |
$needOverrideOption = TitleBlacklist::userCanOverride( $user, 'new-account' ); | |
break; | |
} | |
return $needOverrideOption ? [ new TitleBlacklistAuthenticationRequest() ] : []; | |
} | |
public function testForAccountCreation( $user, $creator, array $reqs ) { | |
/** @var TitleBlacklistAuthenticationRequest $req */ | |
$req = AuthenticationRequest::getRequestByClass( $reqs, | |
TitleBlacklistAuthenticationRequest::class ); | |
// For phan check, to ensure that $req is instance of \TitleBlacklistAuthenticationRequest | |
// or null | |
if ( $req instanceof TitleBlacklistAuthenticationRequest ) { | |
$override = $req->ignoreTitleBlacklist; | |
} else { | |
$override = false; | |
} | |
return Hooks::testUserName( $user->getName(), $creator, $override, true ); | |
} | |
public function testUserForCreation( $user, $autocreate, array $options = [] ) { | |
$sv = StatusValue::newGood(); | |
$creator = RequestContext::getMain()->getUser(); | |
if ( !$autocreate && empty( $options['creating'] ) || $this->blockAutoAccountCreation ) { | |
$sv->merge( Hooks::testUserName( | |
$user->getName(), $creator, true, (bool)$autocreate | |
) ); | |
} | |
return $sv; | |
} | |
} |