Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
40.91% |
9 / 22 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
TitleBlacklistPreAuthenticationProvider | |
40.91% |
9 / 22 |
|
50.00% |
2 / 4 |
35.97 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getAuthenticationRequests | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
testForAccountCreation | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
testUserForCreation | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\TitleBlacklist; |
4 | |
5 | use MediaWiki\Auth\AbstractPreAuthenticationProvider; |
6 | use MediaWiki\Auth\AuthenticationRequest; |
7 | use MediaWiki\Auth\AuthManager; |
8 | use MediaWiki\User\User; |
9 | use RequestContext; |
10 | use StatusValue; |
11 | |
12 | class TitleBlacklistPreAuthenticationProvider extends AbstractPreAuthenticationProvider { |
13 | |
14 | /** @var bool */ |
15 | protected $blockAutoAccountCreation; |
16 | |
17 | public function __construct( $params = [] ) { |
18 | global $wgTitleBlacklistBlockAutoAccountCreation; |
19 | |
20 | $params += [ |
21 | 'blockAutoAccountCreation' => $wgTitleBlacklistBlockAutoAccountCreation |
22 | ]; |
23 | |
24 | $this->blockAutoAccountCreation = (bool)$params['blockAutoAccountCreation']; |
25 | } |
26 | |
27 | public function getAuthenticationRequests( $action, array $options ) { |
28 | $needOverrideOption = false; |
29 | switch ( $action ) { |
30 | case AuthManager::ACTION_CREATE: |
31 | $user = User::newFromName( $options['username'] ) ?: new User(); |
32 | $needOverrideOption = TitleBlacklist::userCanOverride( $user, 'new-account' ); |
33 | break; |
34 | } |
35 | |
36 | return $needOverrideOption ? [ new TitleBlacklistAuthenticationRequest() ] : []; |
37 | } |
38 | |
39 | public function testForAccountCreation( $user, $creator, array $reqs ) { |
40 | /** @var TitleBlacklistAuthenticationRequest $req */ |
41 | $req = AuthenticationRequest::getRequestByClass( $reqs, |
42 | TitleBlacklistAuthenticationRequest::class ); |
43 | // For phan check, to ensure that $req is instance of \TitleBlacklistAuthenticationRequest |
44 | // or null |
45 | if ( $req instanceof TitleBlacklistAuthenticationRequest ) { |
46 | $override = $req->ignoreTitleBlacklist; |
47 | } else { |
48 | $override = false; |
49 | } |
50 | |
51 | return Hooks::testUserName( $user->getName(), $creator, $override, true ); |
52 | } |
53 | |
54 | public function testUserForCreation( $user, $autocreate, array $options = [] ) { |
55 | $sv = StatusValue::newGood(); |
56 | $creator = RequestContext::getMain()->getUser(); |
57 | |
58 | if ( ( !$autocreate && empty( $options['creating'] ) ) || $this->blockAutoAccountCreation ) { |
59 | $sv->merge( Hooks::testUserName( |
60 | $user->getName(), $creator, true, (bool)$autocreate |
61 | ) ); |
62 | } |
63 | return $sv; |
64 | } |
65 | } |