2011-08-26 20:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
2011-09-29 23:30:42 +00:00
|
|
|
class ApiAbuseFilterCheckMatch extends ApiBase {
|
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' ) ) {
|
2013-10-27 16:33:39 +00:00
|
|
|
$this->dieUsage( 'You don\'t have permission to test abuse filters', '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'] ) {
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2011-08-26 23:52:46 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'recentchanges',
|
|
|
|
'*',
|
|
|
|
array( 'rc_id' => $params['rcid'] ),
|
|
|
|
__METHOD__
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( !$row ) {
|
|
|
|
$this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
|
|
} elseif ( $params['logid'] ) {
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2011-08-26 23:52:46 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'abuse_filter_log',
|
|
|
|
'*',
|
|
|
|
array( 'afl_id' => $params['logid'] ),
|
|
|
|
__METHOD__
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( !$row ) {
|
|
|
|
$this->dieUsage(
|
|
|
|
"There is no abuselog entry with the id ``{$params['logid']}''",
|
|
|
|
'nosuchlogid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( AbuseFilter::checkSyntax( $params[ 'filter' ] ) !== true ) {
|
|
|
|
$this->dieUsage( 'The filter has invalid syntax', 'badsyntax' );
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:30:02 +00:00
|
|
|
$result = array(
|
2016-09-20 18:39:11 +00:00
|
|
|
ApiResult::META_BC_BOOLS => 'result',
|
2015-05-18 14:30:02 +00:00
|
|
|
'result' => AbuseFilter::checkConditions( $params['filter'], $vars ),
|
|
|
|
);
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
|
|
|
return array(
|
|
|
|
'filter' => array(
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
),
|
|
|
|
'vars' => null,
|
|
|
|
'rcid' => array(
|
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
|
|
),
|
|
|
|
'logid' => array(
|
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-10-28 16:25:22 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
|
|
|
return array(
|
|
|
|
'action=abusefiltercheckmatch&filter=!("autoconfirmed"%20in%20user_groups)&rcid=15'
|
|
|
|
=> 'apihelp-abusefiltercheckmatch-example-1',
|
|
|
|
);
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
}
|