mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 22:15:26 +00:00
87713008d5
There are lots of calls to $user->isAllowed which could be simplified using available accessors like canEdit(). So simplify those calls and avoid duplication. Note that using canEdit also fixes a bug which affected blocked users: we used to show e.g. the import link, and not to display as disabled several text fields, while blocked users cannot actually edit filters. Depends-On: I22743557e162fd23b3b4e52951a649d8c21109c8 Change-Id: I62779e940949ef49018a9c6d901bb6e10aa81da8
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
class ApiAbuseFilterCheckSyntax extends ApiBase {
|
|
|
|
/**
|
|
* @see ApiBase::execute
|
|
*/
|
|
public function execute() {
|
|
// "Anti-DoS"
|
|
if ( !AbuseFilter::canViewPrivate( $this->getUser() ) ) {
|
|
$this->dieWithError( 'apierror-abusefilter-cantcheck', 'permissiondenied' );
|
|
}
|
|
|
|
$params = $this->extractRequestParams();
|
|
$result = AbuseFilter::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',
|
|
];
|
|
}
|
|
}
|