3 use MediaWiki\Auth\AbstractPreAuthenticationProvider;
4 use MediaWiki\Auth\AuthenticationRequest;
5 use MediaWiki\Auth\AuthManager;
7 class TitleBlacklistPreAuthenticationProvider extends AbstractPreAuthenticationProvider {
8 protected $blockAutoAccountCreation;
10 public function __construct( $params = [] ) {
11 global $wgTitleBlacklistBlockAutoAccountCreation;
14 'blockAutoAccountCreation' => $wgTitleBlacklistBlockAutoAccountCreation
17 $this->blockAutoAccountCreation = (bool)$params['blockAutoAccountCreation'];
20 public function getAuthenticationRequests( $action, array $options ) {
21 $needOverrideOption = false;
23 case AuthManager::ACTION_CREATE:
24 $user = User::newFromName( $options['username'] ) ?: new User();
25 $needOverrideOption = TitleBlacklist::userCanOverride( $user, 'new-account' );
29 return $needOverrideOption ? [ new TitleBlacklistAuthenticationRequest() ] : [];
32 public function testForAccountCreation( $user, $creator, array $reqs ) {
33 /** @var TitleBlacklistAuthenticationRequest $req */
34 $req = AuthenticationRequest::getRequestByClass( $reqs,
35 TitleBlacklistAuthenticationRequest::class );
36 $override = $req && $req->ignoreTitleBlacklist;
37 return TitleBlacklistHooks::testUserName( $user->getName(), $creator, $override, true );
40 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
41 $sv = StatusValue::newGood();
42 $creator = RequestContext::getMain()->getUser();
44 if ( !$autocreate && empty( $options['creating'] ) || $this->blockAutoAccountCreation ) {
45 $sv->merge( TitleBlacklistHooks::testUserName(
46 $user->getName(), $creator, true, (bool)$autocreate