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'] ) {
|
2011-09-30 00:48:00 +00:00
|
|
|
$vars = FormatJson::decode( $params['vars'], true );
|
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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = AbuseFilter::checkConditions( $params['filter'], $vars );
|
|
|
|
$this->getResult()->addValue(
|
|
|
|
null,
|
|
|
|
$this->getModuleName(),
|
|
|
|
array( 'result' => $result )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
|
|
|
return array(
|
|
|
|
'filter' => 'The full filter text to check for a match',
|
|
|
|
'vars' => 'JSON encoded array of variables to test against',
|
|
|
|
'rcid' => 'Recent change ID to check against',
|
|
|
|
'logid' => 'Abuse filter log ID to check against',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
|
|
|
return array(
|
|
|
|
'Check to see if an AbuseFilter matches a set of variables, edit'
|
|
|
|
. 'or logged AbuseFilter event.',
|
|
|
|
'vars, rcid or logid is required however only one may be used',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPossibleErrors() {
|
|
|
|
return array_merge( parent::getPossibleErrors(),
|
2011-08-26 23:52:46 +00:00
|
|
|
$this->getRequireOnlyOneParameterErrorMessages( array( 'vars', 'rcid', 'logid' ) ),
|
|
|
|
array(
|
2013-10-27 16:33:39 +00:00
|
|
|
array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to test abuse filters' ),
|
2011-08-26 23:52:46 +00:00
|
|
|
array( 'nosuchrcid' ),
|
|
|
|
array( 'code' => 'nosuchlogid', 'info' => 'There is no abuselog entry with the id given' ),
|
|
|
|
array( 'code' => 'badsyntax', 'info' => 'The filter has invalid syntax' ),
|
|
|
|
)
|
|
|
|
);
|
2011-08-26 20:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getExamples() {
|
|
|
|
return array(
|
2012-01-13 21:36:51 +00:00
|
|
|
'api.php?action=abusefiltercheckmatch&filter=!("autoconfirmed"%20in%20user_groups)&rcid=15'
|
2011-08-26 20:12:34 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
}
|
|
|
|
}
|