mediawiki-extensions-TitleB.../TitleBlacklistPreAuthenticationProvider.php
Brad Jorsch 8ab382e535 Add $options parameter for testUserForCreation()
Also use it to only log the title blacklist hit when running for real,
not when testing a username.

Change-Id: Ie9639a15d04b387be0e72754301eb6d91cd8adc2
2016-06-16 17:57:06 -04:00

52 lines
1.7 KiB
PHP

<?php
use MediaWiki\Auth\AbstractPreAuthenticationProvider;
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Auth\AuthManager;
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 );
$override = $req && $req->ignoreTitleBlacklist;
return TitleBlacklistHooks::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( TitleBlacklistHooks::testUserName(
$user->getName(), $creator, true, (bool)$autocreate
) );
}
return $sv;
}
}