mediawiki-extensions-AbuseF.../api/ApiAbuseFilterCheckSyntax.php
Brad Jorsch 4cbea0bcf7 Update for API error i18n
See Iae0e2ce3.

Change-Id: I09c564413f91e410bf9ba8336f65cb14d7105a07
2016-11-15 11:15:58 -05: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 = array();
if ( $result === true ) {
// Everything went better than expected :)
$r['status'] = 'ok';
} else {
$r = array(
'status' => 'error',
'message' => $result[0],
'character' => $result[1],
);
}
$this->getResult()->addValue( null, $this->getModuleName(), $r );
}
public function getAllowedParams() {
return array(
'filter' => array(
ApiBase::PARAM_REQUIRED => true,
),
);
}
/**
* @see ApiBase::getExamplesMessages()
*/
protected function getExamplesMessages() {
return array(
'action=abusefilterchecksyntax&filter="foo"'
=> 'apihelp-abusefilterchecksyntax-example-1',
'action=abusefilterchecksyntax&filter="bar"%20bad_variable'
=> 'apihelp-abusefilterchecksyntax-example-2',
);
}
}