2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2011-09-29 23:30:42 +00:00
|
|
|
class ApiAbuseFilterUnblockAutopromote extends ApiBase {
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::execute()
|
|
|
|
*/
|
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();
|
2018-07-16 12:10:36 +00:00
|
|
|
$target = User::newFromName( $params['user'] );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-07-16 12:10:36 +00:00
|
|
|
if ( $target === false ) {
|
2016-11-03 19:16:55 +00:00
|
|
|
$encParamName = $this->encodeParamName( 'user' );
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError(
|
2018-04-29 17:52:45 +00:00
|
|
|
[ 'apierror-baduser', $encParamName, wfEscapeWikiText( $params['user'] ) ],
|
2017-08-07 23:35:21 +00:00
|
|
|
"baduser_{$encParamName}"
|
|
|
|
);
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 18:28:27 +00:00
|
|
|
$block = $this->getUser()->getBlock();
|
|
|
|
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();
|
|
|
|
$res = AbuseFilter::unblockAutopromote( $target, $this->getUser(), $msg );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-07-16 12:10:36 +00:00
|
|
|
if ( $res === false ) {
|
|
|
|
$this->dieWithError( [ 'abusefilter-reautoconfirm-none', $target->getName() ], 'notsuspended' );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2018-07-16 12:10:36 +00:00
|
|
|
$finalResult = [ 'user' => $params['user'] ];
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $finalResult );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::mustBePosted()
|
|
|
|
* @return bool
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::isWriteMode()
|
|
|
|
* @return bool
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getAllowedParams()
|
|
|
|
* @return array
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function getAllowedParams() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
|
|
|
'user' => [
|
2016-11-03 19:16:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'user',
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true
|
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
|
|
|
/**
|
|
|
|
* @see ApiBase::needsToken()
|
|
|
|
* @return string
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2017-10-06 18:52:31 +00:00
|
|
|
* @return array
|
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
|
|
|
}
|
|
|
|
}
|