mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-01 00:56:26 +00:00
f2c1beec44
Since double-equals are evil. I left some of them in place where I wasn't sure, but I may be changed some which were intended to be doubles. It could be a good idea to delay merging this patch until we'll have more code coverage. Change-Id: I1721a3ba532d481e3ecf35f51099c1438b6b73b2
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Auth\AbstractPreAuthenticationProvider;
|
|
use MediaWiki\Auth\AuthenticationRequest;
|
|
|
|
class AbuseFilterPreAuthenticationProvider extends AbstractPreAuthenticationProvider {
|
|
/**
|
|
* @param User $user
|
|
* @param User $creator
|
|
* @param AuthenticationRequest[] $reqs
|
|
* @return StatusValue
|
|
*/
|
|
public function testForAccountCreation( $user, $creator, array $reqs ) {
|
|
return $this->testUser( $user, $creator, false );
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param bool|string $autocreate
|
|
* @param array $options
|
|
* @return StatusValue
|
|
*/
|
|
public function testUserForCreation( $user, $autocreate, array $options = [] ) {
|
|
// if this is not an autocreation, testForAccountCreation already handled it
|
|
if ( $autocreate ) {
|
|
return $this->testUser( $user, $user, true );
|
|
}
|
|
return StatusValue::newGood();
|
|
}
|
|
|
|
/**
|
|
* @param User $user The user being created or autocreated
|
|
* @param User $creator The user who caused $user to be created (or $user itself on autocreation)
|
|
* @param bool $autocreate Is this an autocreation?
|
|
* @return StatusValue
|
|
*/
|
|
protected function testUser( $user, $creator, $autocreate ) {
|
|
if ( $user->getName() === wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text() ) {
|
|
return StatusValue::newFatal( 'abusefilter-accountreserved' );
|
|
}
|
|
|
|
$vars = new AbuseFilterVariableHolder;
|
|
|
|
// generateUserVars records $creator->getName() which would be the IP for unregistered users
|
|
if ( $creator->isLoggedIn() ) {
|
|
$vars->addHolders( AbuseFilter::generateUserVars( $creator ) );
|
|
}
|
|
|
|
$vars->setVar( 'action', $autocreate ? 'autocreateaccount' : 'createaccount' );
|
|
$vars->setVar( 'accountname', $user->getName() );
|
|
|
|
// pass creator in explicitly to prevent recording the current user on autocreation - T135360
|
|
$status = AbuseFilter::filterAction( $vars, SpecialPage::getTitleFor( 'Userlogin' ),
|
|
'default', $creator );
|
|
|
|
return $status->getStatusValue();
|
|
}
|
|
}
|