mediawiki-extensions-AbuseF.../api/ApiAbuseFilterCheckSyntax.php
Umherirrender 24e4e85603 Use short array syntax - Views / api
Done by phpcbf over composer fix

Change-Id: I83ab556c8400354ecd09f33e1eb28caa17aa803d
2017-06-15 14:40:55 +00:00

56 lines
1.3 KiB
PHP

<?php
class ApiAbuseFilterCheckSyntax extends ApiBase {
public function execute() {
// "Anti-DoS"
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
if ( is_callable( [ $this, 'dieWithError' ] ) ) {
$this->dieWithError( 'apierror-abusefilter-cantcheck', 'permissiondenied' );
} else {
$this->dieUsage(
'You don\'t have permission to check syntax of abuse filters',
'permissiondenied'
);
}
}
$params = $this->extractRequestParams();
$result = AbuseFilter::checkSyntax( $params[ 'filter' ] );
$r = [];
if ( $result === true ) {
// Everything went better than expected :)
$r['status'] = 'ok';
} else {
$r = [
'status' => 'error',
'message' => $result[0],
'character' => $result[1],
];
}
$this->getResult()->addValue( null, $this->getModuleName(), $r );
}
public function getAllowedParams() {
return [
'filter' => [
ApiBase::PARAM_REQUIRED => true,
],
];
}
/**
* @see ApiBase::getExamplesMessages()
*/
protected function getExamplesMessages() {
return [
'action=abusefilterchecksyntax&filter="foo"'
=> 'apihelp-abusefilterchecksyntax-example-1',
'action=abusefilterchecksyntax&filter="bar"%20bad_variable'
=> 'apihelp-abusefilterchecksyntax-example-2',
];
}
}