mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-28 16:00:28 +00:00
3f83e57ad7
This is another step needed to reduce the size of the gigantic AbuseFilter and AbuseFilterHooks classes. It also makes many methods non-static, for more testability. Note, this layout is still not final. We should somehow merge the functionality of VariableGenerator and AFComputedVariable, for which I already have plans. Change-Id: I366d598b69ad866496b7cb0059e0835c02e54041
60 lines
2 KiB
PHP
60 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Auth\AbstractPreAuthenticationProvider;
|
|
use MediaWiki\Auth\AuthenticationRequest;
|
|
use MediaWiki\Extension\AbuseFilter\VariableGenerator\RunVariableGenerator;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
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 ) {
|
|
$startTime = microtime( true );
|
|
if ( $user->getName() === wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text() ) {
|
|
return StatusValue::newFatal( 'abusefilter-accountreserved' );
|
|
}
|
|
|
|
$title = SpecialPage::getTitleFor( 'Userlogin' );
|
|
$vars = new AbuseFilterVariableHolder();
|
|
$builder = new RunVariableGenerator( $vars, $creator, $title );
|
|
$vars = $builder->getAccountCreationVars( $user, $autocreate );
|
|
|
|
// pass creator in explicitly to prevent recording the current user on autocreation - T135360
|
|
$runner = new AbuseFilterRunner( $creator, $title, $vars, 'default' );
|
|
$status = $runner->run();
|
|
|
|
MediaWikiServices::getInstance()->getStatsdDataFactory()
|
|
->timing( 'timing.createaccountAbuseFilter', microtime( true ) - $startTime );
|
|
|
|
return $status->getStatusValue();
|
|
}
|
|
}
|