mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-15 02:03:53 +00:00
ed5cc1b5fc
Repeats I61e4327ef3c7a31b19feef727de7d683f69e260b (which had to be reverted due to a problem with an ancestor patch) without any significant change. Bug: T110448 Bug: T135360 Change-Id: I1688cf9fbcb04bb56d075c9f0876bd0ffeced4f6
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Auth\AbstractPreAuthenticationProvider;
|
|
|
|
class AbuseFilterPreAuthenticationProvider extends AbstractPreAuthenticationProvider {
|
|
public function testForAccountCreation( $user, $creator, array $reqs ) {
|
|
return $this->testUser( $user, $creator, false );
|
|
}
|
|
|
|
public function testUserForCreation( $user, $autocreate ) {
|
|
// 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();
|
|
}
|
|
}
|