mediawiki-extensions-AbuseF.../includes/api/ApiAbuseFilterCheckSyntax.php
Thiemo Kreuz 7047dba1f1 Update a few unspecific PHPDoc comments
Change-Id: I363d7f854c550654c5d4345f381e3731de6f2d3c
2020-12-03 09:50:09 +01:00

60 lines
1.3 KiB
PHP

<?php
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
class ApiAbuseFilterCheckSyntax extends ApiBase {
/**
* @inheritDoc
*/
public function execute() {
$afPermManager = AbuseFilterServices::getPermissionManager();
// "Anti-DoS"
if ( !$afPermManager->canViewPrivateFilters( $this->getUser() ) ) {
$this->dieWithError( 'apierror-abusefilter-cantcheck', 'permissiondenied' );
}
$params = $this->extractRequestParams();
$result = AbuseFilterServices::getParserFactory()->newParser()->checkSyntax( $params[ 'filter' ] );
$r = [];
if ( $result === true ) {
// Everything went better than expected :)
$r['status'] = 'ok';
} else {
$r = [
'status' => 'error',
'message' => $result[0],
'character' => $result[1],
];
}
$this->getResult()->addValue( null, $this->getModuleName(), $r );
}
/**
* @see ApiBase::getAllowedParams
* @return array
*/
public function getAllowedParams() {
return [
'filter' => [
ApiBase::PARAM_REQUIRED => true,
],
];
}
/**
* @see ApiBase::getExamplesMessages()
* @return array
*/
protected function getExamplesMessages() {
return [
'action=abusefilterchecksyntax&filter="foo"'
=> 'apihelp-abusefilterchecksyntax-example-1',
'action=abusefilterchecksyntax&filter="bar"%20bad_variable'
=> 'apihelp-abusefilterchecksyntax-example-2',
];
}
}