2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2011-09-29 23:30:42 +00:00
|
|
|
class ApiAbuseFilterCheckSyntax extends ApiBase {
|
2011-08-26 20:12:34 +00:00
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
// "Anti-DoS"
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
|
2013-10-27 16:33:39 +00:00
|
|
|
$this->dieUsage( 'You don\'t have permission to check syntax of abuse filters', '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
|
|
|
$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(
|
2013-10-27 16:33:39 +00:00
|
|
|
array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to check syntax of abuse filters' ),
|
2011-08-26 20:12:34 +00:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExamples() {
|
|
|
|
return array(
|
2012-01-13 21:36:51 +00:00
|
|
|
'api.php?action=abusefilterchecksyntax&filter="foo"',
|
|
|
|
'api.php?action=abusefilterchecksyntax&filter="bar"%20bad_variable',
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
}
|
2012-01-13 21:36:51 +00:00
|
|
|
}
|