2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2011-09-29 23:30:42 +00:00
|
|
|
class ApiAbuseFilterUnblockAutopromote extends ApiBase {
|
2011-08-26 20:12:34 +00:00
|
|
|
public function execute() {
|
2016-11-03 19:16:55 +00:00
|
|
|
if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) {
|
|
|
|
$this->checkUserRightsAny( 'abusefilter-modify' );
|
|
|
|
} else {
|
|
|
|
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
|
|
|
|
$this->dieUsage( 'You do not have permissions to unblock autopromotion', 'permissiondenied' );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 23:52:46 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2011-08-26 20:12:34 +00:00
|
|
|
$user = User::newFromName( $params['user'] );
|
|
|
|
|
|
|
|
if ( $user === false ) {
|
2016-11-03 19:16:55 +00:00
|
|
|
$encParamName = $this->encodeParamName( 'user' );
|
|
|
|
if ( is_callable( [ $this, 'dieWithError' ] ) ) {
|
|
|
|
$this->dieWithError(
|
|
|
|
[ 'apierror-baduser', $encParamName, wfEscapeWikiText( $param['user'] ) ],
|
|
|
|
"baduser_{$encParamName}"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->dieUsage(
|
|
|
|
"Invalid value '{$param['user']}' for user parameter $encParamName",
|
|
|
|
"baduser_{$encParamName}"
|
|
|
|
);
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$key = AbuseFilter::autoPromoteBlockKey( $user );
|
2015-05-21 21:54:30 +00:00
|
|
|
$stash = ObjectCache::getMainStashInstance();
|
|
|
|
if ( !$stash->get( $key ) ) {
|
2016-11-03 19:16:55 +00:00
|
|
|
if ( is_callable( [ $this, 'dieWithError' ] ) ) {
|
|
|
|
$this->dieWithError( [ 'abusefilter-reautoconfirm-none', $user->getName() ], 'notsuspended' );
|
|
|
|
} else {
|
|
|
|
$msg = wfMessage( 'abusefilter-reautoconfirm-none', $user->getName() )
|
|
|
|
->inLanguage( 'en' )->useDatabase( false )->text();
|
|
|
|
$this->dieUsage( $msg, 'notsuspended' );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 21:54:30 +00:00
|
|
|
$stash->delete( $key );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
|
|
|
$res = array( 'user' => $params['user'] );
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $res );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mustBePosted() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
|
|
|
return array(
|
|
|
|
'user' => array(
|
2016-11-03 19:16:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'user',
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true
|
|
|
|
),
|
|
|
|
'token' => null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
|
|
|
return array(
|
|
|
|
'action=abusefilterunblockautopromote&user=Example&token=123ABC'
|
|
|
|
=> 'apihelp-abusefilterunblockautopromote-example-1',
|
|
|
|
);
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
}
|