mediawiki-extensions-AbuseF.../includes/api/ApiAbuseFilterEvalExpression.php
Daimona Eaytoy 4c98aecf4d Improve var dumping in /details, /examine and /tools
Using var_export for better visual effect, especially for arrays.
The result from /tools is much clearer and the 'wrong syntax' message is
a bit more explicative than before.

Bug: T190653
Bug: T239972
Change-Id: I79a17305c7f19f7900f896f895e9365bb5f2fd58
2020-03-28 17:35:43 +01:00

57 lines
1.3 KiB
PHP

<?php
class ApiAbuseFilterEvalExpression extends ApiBase {
/**
* @see ApiBase::execute()
*/
public function execute() {
// "Anti-DoS"
if ( !AbuseFilter::canViewPrivate( $this->getUser() ) ) {
$this->dieWithError( 'apierror-abusefilter-canteval', 'permissiondenied' );
}
$params = $this->extractRequestParams();
$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 ] )
);
}
}
/**
* @see ApiBase::getAllowedParams()
* @return array
*/
public function getAllowedParams() {
return [
'expression' => [
ApiBase::PARAM_REQUIRED => true,
],
'prettyprint' => [
ApiBase::PARAM_TYPE => 'boolean'
]
];
}
/**
* @see ApiBase::getExamplesMessages()
* @return array
*/
protected function getExamplesMessages() {
return [
'action=abusefilterevalexpression&expression=lcase("FOO")'
=> 'apihelp-abusefilterevalexpression-example-1',
'action=abusefilterevalexpression&expression=lcase("FOO")&prettyprint=1'
=> 'apihelp-abusefilterevalexpression-example-2',
];
}
}