2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2020-01-11 17:05:30 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\VariableGenerator\RCVariableGenerator;
|
|
|
|
|
2011-09-29 23:30:42 +00:00
|
|
|
class ApiAbuseFilterCheckMatch extends ApiBase {
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::execute
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function execute() {
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
$this->requireOnlyOneParameter( $params, 'vars', 'rcid', 'logid' );
|
|
|
|
|
|
|
|
// "Anti-DoS"
|
2019-08-27 10:08:17 +00:00
|
|
|
if ( !AbuseFilter::canViewPrivate( $this->getUser() ) ) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( 'apierror-abusefilter-canttest', 'permissiondenied' );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 12:28:39 +00:00
|
|
|
$vars = null;
|
2011-08-26 20:12:34 +00:00
|
|
|
if ( $params['vars'] ) {
|
2014-07-30 00:50:30 +00:00
|
|
|
$pairs = FormatJson::decode( $params['vars'], true );
|
2019-02-24 14:55:19 +00:00
|
|
|
$vars = AbuseFilterVariableHolder::newFromArray( $pairs );
|
2011-08-26 20:12:34 +00:00
|
|
|
} elseif ( $params['rcid'] ) {
|
2020-05-28 18:09:17 +00:00
|
|
|
$rc = RecentChange::newFromId( $params['rcid'] );
|
2011-08-26 20:12:34 +00:00
|
|
|
|
2020-05-28 18:09:17 +00:00
|
|
|
if ( !$rc ) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 16:39:57 +00:00
|
|
|
$vars = new AbuseFilterVariableHolder();
|
2020-05-28 18:09:17 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable T240141
|
2020-09-20 22:07:57 +00:00
|
|
|
$varGenerator = new RCVariableGenerator( $vars, $rc, $this->getUser() );
|
2019-06-25 16:39:57 +00:00
|
|
|
$vars = $varGenerator->getVars();
|
2011-08-26 20:12:34 +00:00
|
|
|
} elseif ( $params['logid'] ) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2011-08-26 23:52:46 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'abuse_filter_log',
|
2018-02-05 10:48:58 +00:00
|
|
|
'afl_var_dump',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'afl_id' => $params['logid'] ],
|
2011-08-26 23:52:46 +00:00
|
|
|
__METHOD__
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( !$row ) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( [ 'apierror-abusefilter-nosuchlogid', $params['logid'] ], 'nosuchlogid' );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( AbuseFilter::checkSyntax( $params[ 'filter' ] ) !== true ) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( 'apierror-abusefilter-badsyntax', 'badsyntax' );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 10:04:10 +00:00
|
|
|
$parser = AbuseFilter::getDefaultParser( $vars );
|
2017-06-15 14:23:16 +00:00
|
|
|
$result = [
|
2016-10-27 14:10:31 +00:00
|
|
|
ApiResult::META_BC_BOOLS => [ 'result' ],
|
2019-01-24 10:33:01 +00:00
|
|
|
'result' => AbuseFilter::checkConditions( $params['filter'], $parser ),
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2015-05-18 14:30:02 +00:00
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
$this->getResult()->addValue(
|
|
|
|
null,
|
|
|
|
$this->getModuleName(),
|
2015-05-18 14:30:02 +00:00
|
|
|
$result
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getAllowedParams
|
|
|
|
* @return array
|
|
|
|
*/
|
2011-08-26 20:12:34 +00:00
|
|
|
public function getAllowedParams() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
|
|
|
'filter' => [
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2011-08-26 20:12:34 +00:00
|
|
|
'vars' => null,
|
2017-06-15 14:23:16 +00:00
|
|
|
'rcid' => [
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'logid' => [
|
2011-08-26 20:12:34 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:25:22 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2017-10-06 18:52:31 +00:00
|
|
|
* @return array
|
2014-10-28 16:25:22 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
2014-10-28 16:25:22 +00:00
|
|
|
'action=abusefiltercheckmatch&filter=!("autoconfirmed"%20in%20user_groups)&rcid=15'
|
|
|
|
=> 'apihelp-abusefiltercheckmatch-example-1',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
}
|