2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
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"
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
|
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
|
|
|
$vars = new AbuseFilterVariableHolder;
|
|
|
|
$pairs = FormatJson::decode( $params['vars'], true );
|
|
|
|
foreach ( $pairs as $name => $value ) {
|
|
|
|
$vars->setVar( $name, $value );
|
|
|
|
}
|
2011-08-26 20:12:34 +00:00
|
|
|
} elseif ( $params['rcid'] ) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-10-12 19:44:48 +00:00
|
|
|
$rcQuery = RecentChange::getQueryInfo();
|
2011-08-26 23:52:46 +00:00
|
|
|
$row = $dbr->selectRow(
|
2017-10-12 19:44:48 +00:00
|
|
|
$rcQuery['tables'],
|
|
|
|
$rcQuery['fields'],
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'rc_id' => $params['rcid'] ],
|
2017-10-12 19:44:48 +00:00
|
|
|
__METHOD__,
|
|
|
|
[],
|
|
|
|
$rcQuery['joins']
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( !$row ) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$result = [
|
2016-10-27 14:10:31 +00:00
|
|
|
ApiResult::META_BC_BOOLS => [ 'result' ],
|
2015-05-18 14:30:02 +00:00
|
|
|
'result' => AbuseFilter::checkConditions( $params['filter'], $vars ),
|
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
|
|
|
}
|
|
|
|
}
|