2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2020-12-03 22:05:42 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Api;
|
|
|
|
|
|
|
|
use ApiBase;
|
2021-04-04 18:57:49 +00:00
|
|
|
use ApiMain;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore;
|
2022-07-02 12:45:19 +00:00
|
|
|
use MediaWiki\ParamValidator\TypeDef\UserDef;
|
2022-04-03 23:23:52 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2020-10-21 14:18:08 +00:00
|
|
|
|
2020-12-03 22:05:42 +00:00
|
|
|
class UnblockAutopromote extends ApiBase {
|
2021-04-04 18:57:49 +00:00
|
|
|
|
|
|
|
/** @var BlockAutopromoteStore */
|
|
|
|
private $afBlockAutopromoteStore;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ApiMain $main
|
|
|
|
* @param string $action
|
|
|
|
* @param BlockAutopromoteStore $afBlockAutopromoteStore
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ApiMain $main,
|
|
|
|
$action,
|
|
|
|
BlockAutopromoteStore $afBlockAutopromoteStore
|
|
|
|
) {
|
|
|
|
parent::__construct( $main, $action );
|
|
|
|
$this->afBlockAutopromoteStore = $afBlockAutopromoteStore;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2020-12-03 08:49:56 +00:00
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function execute() {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->checkUserRightsAny( 'abusefilter-modify' );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2011-08-26 23:52:46 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2022-07-02 12:45:19 +00:00
|
|
|
$target = $params['user'];
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2023-07-17 17:58:42 +00:00
|
|
|
$block = $this->getAuthority()->getBlock();
|
2019-09-13 18:28:27 +00:00
|
|
|
if ( $block && $block->isSitewide() ) {
|
2019-09-14 08:18:01 +00:00
|
|
|
$this->dieBlocked( $block );
|
2019-09-13 18:28:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 12:10:36 +00:00
|
|
|
$msg = $this->msg( 'abusefilter-tools-restoreautopromote' )->inContentLanguage()->text();
|
2022-07-02 12:45:19 +00:00
|
|
|
$res = $this->afBlockAutopromoteStore->unblockAutopromote( $target, $this->getUser(), $msg );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2021-09-04 02:30:36 +00:00
|
|
|
if ( !$res ) {
|
2018-07-16 12:10:36 +00:00
|
|
|
$this->dieWithError( [ 'abusefilter-reautoconfirm-none', $target->getName() ], 'notsuspended' );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2022-07-02 12:45:19 +00:00
|
|
|
$finalResult = [ 'user' => $target->getName() ];
|
2018-07-16 12:10:36 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $finalResult );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function getAllowedParams() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
|
|
|
'user' => [
|
2022-04-03 23:23:52 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'user',
|
2022-07-02 12:45:19 +00:00
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
|
|
UserDef::PARAM_RETURN_OBJECT => true,
|
|
|
|
UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name' ],
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2011-08-26 20:12:34 +00:00
|
|
|
'token' => null,
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function needsToken() {
|
2014-08-09 12:56:14 +00:00
|
|
|
return 'csrf';
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:25:22 +00:00
|
|
|
/**
|
2021-01-17 11:54:43 +00:00
|
|
|
* @codeCoverageIgnore Merely declarative
|
|
|
|
* @inheritDoc
|
2014-10-28 16:25:22 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
2014-10-28 16:25:22 +00:00
|
|
|
'action=abusefilterunblockautopromote&user=Example&token=123ABC'
|
|
|
|
=> 'apihelp-abusefilterunblockautopromote-example-1',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
}
|