mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-29 00:10:26 +00:00
382751a707
Instead of relying on static methods and members in the AbuseFilter class, move everything related to conditions inside the Parser, as the amount of used conditions is something pertaining a single AbuseFilter(Caching)Parser instance. This change requires changing some signatures and adding parameters, but will make introducing the new AbuseFilterRunner class easier (and that will clean signatures, too). Depends-On: I5b29ff556eca45fe59d15e2e3df4d06f1f6b3934 Change-Id: I7c1ea17adf7f42cf9260d416906bfbf3b8a20688
105 lines
2.5 KiB
PHP
105 lines
2.5 KiB
PHP
<?php
|
|
|
|
class ApiAbuseFilterCheckMatch extends ApiBase {
|
|
/**
|
|
* @see ApiBase::execute
|
|
*/
|
|
public function execute() {
|
|
$params = $this->extractRequestParams();
|
|
$this->requireOnlyOneParameter( $params, 'vars', 'rcid', 'logid' );
|
|
|
|
// "Anti-DoS"
|
|
if ( !$this->getUser()->isAllowedAny( 'abusefilter-modify', 'abusefilter-view-private' ) ) {
|
|
$this->dieWithError( 'apierror-abusefilter-canttest', 'permissiondenied' );
|
|
}
|
|
|
|
$vars = null;
|
|
if ( $params['vars'] ) {
|
|
$vars = new AbuseFilterVariableHolder;
|
|
$pairs = FormatJson::decode( $params['vars'], true );
|
|
foreach ( $pairs as $name => $value ) {
|
|
$vars->setVar( $name, $value );
|
|
}
|
|
} elseif ( $params['rcid'] ) {
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
$rcQuery = RecentChange::getQueryInfo();
|
|
$row = $dbr->selectRow(
|
|
$rcQuery['tables'],
|
|
$rcQuery['fields'],
|
|
[ 'rc_id' => $params['rcid'] ],
|
|
__METHOD__,
|
|
[],
|
|
$rcQuery['joins']
|
|
);
|
|
|
|
if ( !$row ) {
|
|
$this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
|
|
}
|
|
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
} elseif ( $params['logid'] ) {
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
$row = $dbr->selectRow(
|
|
'abuse_filter_log',
|
|
'afl_var_dump',
|
|
[ 'afl_id' => $params['logid'] ],
|
|
__METHOD__
|
|
);
|
|
|
|
if ( !$row ) {
|
|
$this->dieWithError( [ 'apierror-abusefilter-nosuchlogid', $params['logid'] ], 'nosuchlogid' );
|
|
}
|
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
|
}
|
|
|
|
if ( AbuseFilter::checkSyntax( $params[ 'filter' ] ) !== true ) {
|
|
$this->dieWithError( 'apierror-abusefilter-badsyntax', 'badsyntax' );
|
|
}
|
|
|
|
$parserClass = $this->getConfig()->get( 'AbuseFilterParserClass' );
|
|
/** @var AbuseFilterParser $parser */
|
|
$parser = new $parserClass( $vars );
|
|
$result = [
|
|
ApiResult::META_BC_BOOLS => [ 'result' ],
|
|
'result' => AbuseFilter::checkConditions( $params['filter'], $parser ),
|
|
];
|
|
|
|
$this->getResult()->addValue(
|
|
null,
|
|
$this->getModuleName(),
|
|
$result
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::getAllowedParams
|
|
* @return array
|
|
*/
|
|
public function getAllowedParams() {
|
|
return [
|
|
'filter' => [
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
],
|
|
'vars' => null,
|
|
'rcid' => [
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
],
|
|
'logid' => [
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @see ApiBase::getExamplesMessages()
|
|
* @return array
|
|
*/
|
|
protected function getExamplesMessages() {
|
|
return [
|
|
'action=abusefiltercheckmatch&filter=!("autoconfirmed"%20in%20user_groups)&rcid=15'
|
|
=> 'apihelp-abusefiltercheckmatch-example-1',
|
|
];
|
|
}
|
|
}
|