mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-03 18:16:15 +00:00
1445d5962a
This service is responsible for the blockautopromote feature: (un)block autopromotion and check status. The patch mostly moves code from static methods to the new class and relaxes type hints (e.g. from User to UserIdentity). Change-Id: I79a72377881cf06717931cd09af12f3b8e5f3e3f
89 lines
2 KiB
PHP
89 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
|
|
|
class ApiAbuseFilterUnblockAutopromote extends ApiBase {
|
|
/**
|
|
* @see ApiBase::execute()
|
|
*/
|
|
public function execute() {
|
|
$this->checkUserRightsAny( 'abusefilter-modify' );
|
|
|
|
$params = $this->extractRequestParams();
|
|
$target = User::newFromName( $params['user'] );
|
|
|
|
if ( $target === false ) {
|
|
$encParamName = $this->encodeParamName( 'user' );
|
|
$this->dieWithError(
|
|
[ 'apierror-baduser', $encParamName, wfEscapeWikiText( $params['user'] ) ],
|
|
"baduser_{$encParamName}"
|
|
);
|
|
}
|
|
|
|
$block = $this->getUser()->getBlock();
|
|
if ( $block && $block->isSitewide() ) {
|
|
$this->dieBlocked( $block );
|
|
}
|
|
|
|
$msg = $this->msg( 'abusefilter-tools-restoreautopromote' )->inContentLanguage()->text();
|
|
$blockAutopromoteStore = AbuseFilterServices::getBlockAutopromoteStore();
|
|
$res = $blockAutopromoteStore->unblockAutopromote( $target, $this->getUser(), $msg );
|
|
|
|
if ( $res === false ) {
|
|
$this->dieWithError( [ 'abusefilter-reautoconfirm-none', $target->getName() ], 'notsuspended' );
|
|
}
|
|
|
|
$finalResult = [ 'user' => $params['user'] ];
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $finalResult );
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::mustBePosted()
|
|
* @return bool
|
|
*/
|
|
public function mustBePosted() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::isWriteMode()
|
|
* @return bool
|
|
*/
|
|
public function isWriteMode() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::getAllowedParams()
|
|
* @return array
|
|
*/
|
|
public function getAllowedParams() {
|
|
return [
|
|
'user' => [
|
|
ApiBase::PARAM_TYPE => 'user',
|
|
ApiBase::PARAM_REQUIRED => true
|
|
],
|
|
'token' => null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::needsToken()
|
|
* @return string
|
|
*/
|
|
public function needsToken() {
|
|
return 'csrf';
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::getExamplesMessages()
|
|
* @return array
|
|
*/
|
|
protected function getExamplesMessages() {
|
|
return [
|
|
'action=abusefilterunblockautopromote&user=Example&token=123ABC'
|
|
=> 'apihelp-abusefilterunblockautopromote-example-1',
|
|
];
|
|
}
|
|
}
|