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
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::execute
|
|
|
|
*/
|
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' ) ) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( 'apierror-abusefilter-cantcheck', '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' ] );
|
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$r = [];
|
2011-08-26 20:12:34 +00:00
|
|
|
if ( $result === true ) {
|
|
|
|
// Everything went better than expected :)
|
|
|
|
$r['status'] = 'ok';
|
|
|
|
} else {
|
2017-06-15 14:23:16 +00:00
|
|
|
$r = [
|
2011-08-26 20:12:34 +00:00
|
|
|
'status' => 'error',
|
|
|
|
'message' => $result[0],
|
|
|
|
'character' => $result[1],
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getAllowedParams
|
|
|
|
* @return array
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function getAllowedParams() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
|
|
|
'filter' => [
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:25:22 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2017-10-06 18:52:31 +00:00
|
|
|
* @return array
|
2014-10-28 16:25:22 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
2014-10-28 16:25:22 +00:00
|
|
|
'action=abusefilterchecksyntax&filter="foo"'
|
|
|
|
=> 'apihelp-abusefilterchecksyntax-example-1',
|
|
|
|
'action=abusefilterchecksyntax&filter="bar"%20bad_variable'
|
|
|
|
=> 'apihelp-abusefilterchecksyntax-example-2',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
2012-01-13 21:36:51 +00:00
|
|
|
}
|