2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2011-09-29 23:30:42 +00:00
|
|
|
class ApiAbuseFilterEvalExpression extends ApiBase {
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::execute()
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function execute() {
|
2019-11-16 13:22:46 +00:00
|
|
|
// "Anti-DoS"
|
|
|
|
if ( !AbuseFilter::canViewPrivate( $this->getUser() ) ) {
|
|
|
|
$this->dieWithError( 'apierror-abusefilter-canteval', 'permissiondenied' );
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
2018-03-26 18:41:20 +00:00
|
|
|
$status = AbuseFilter::evaluateExpression( $params['expression'] );
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
$this->dieWithError( $status->getErrors()[0] );
|
|
|
|
} else {
|
|
|
|
$res = $status->getValue();
|
|
|
|
$res = $params['prettyprint'] ? AbuseFilter::formatVar( $res ) : $res;
|
|
|
|
$this->getResult()->addValue(
|
|
|
|
null,
|
|
|
|
$this->getModuleName(),
|
|
|
|
ApiResult::addMetadataToResultVars( [ 'result' => $res ] )
|
|
|
|
);
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
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 [
|
|
|
|
'expression' => [
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2018-03-26 18:41:20 +00:00
|
|
|
'prettyprint' => [
|
|
|
|
ApiBase::PARAM_TYPE => 'boolean'
|
|
|
|
]
|
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=abusefilterevalexpression&expression=lcase("FOO")'
|
|
|
|
=> 'apihelp-abusefilterevalexpression-example-1',
|
2018-03-26 18:41:20 +00:00
|
|
|
'action=abusefilterevalexpression&expression=lcase("FOO")&prettyprint=1'
|
|
|
|
=> 'apihelp-abusefilterevalexpression-example-2',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
}
|