mediawiki-extensions-AbuseF.../api/ApiAbuseFilterCheckSyntax.php
umherirrender b3456b1e17 API: Add text for Unknown error: "permissiondenied"
The api does not known a generic "permissiondenied" message.

Change-Id: I65822c9f58ce323352db759d46bf11d4ddab14bd
2013-10-27 17:33:39 +01:00

66 lines
1.5 KiB
PHP

<?php
class ApiAbuseFilterCheckSyntax extends ApiBase {
public function execute() {
// "Anti-DoS"
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
$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,
),
);
}
public function getParamDescription() {
return array(
'filter' => 'The full filter text to check syntax on',
);
}
public function getDescription() {
return array(
'Check syntax of an AbuseFilter filter'
);
}
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to check syntax of abuse filters' ),
) );
}
public function getExamples() {
return array(
'api.php?action=abusefilterchecksyntax&filter="foo"',
'api.php?action=abusefilterchecksyntax&filter="bar"%20bad_variable',
);
}
public function getVersion() {
return __CLASS__ . ': $Id$';
}
}