mediawiki-extensions-AbuseF.../includes/api/ApiAbuseFilterCheckSyntax.php
Daimona Eaytoy 2026e3ac3a Add an AbuseFilterPermissionManager service
This service should act as a mediator between the AF code and the
permission manager, and it should know what are the permissions required
by each action.

Change-Id: Ieb177d9992147b11fa7b8f05929da6c182cc2286
2020-10-10 14:03:29 +02:00

60 lines
1.3 KiB
PHP

<?php
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
class ApiAbuseFilterCheckSyntax extends ApiBase {
/**
* @see ApiBase::execute
*/
public function execute() {
$afPermManager = AbuseFilterServices::getPermissionManager();
// "Anti-DoS"
if ( !$afPermManager->canViewPrivateFilters( $this->getUser() ) ) {
$this->dieWithError( 'apierror-abusefilter-cantcheck', 'permissiondenied' );
}
$params = $this->extractRequestParams();
$result = AbuseFilter::getDefaultParser()->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',
];
}
}