mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Merge "Add new method: AbuseFilterVariableHolder::newFromArray"
This commit is contained in:
commit
1281cce4c9
|
@ -870,16 +870,7 @@ class AbuseFilter {
|
|||
// Backward compatibility
|
||||
if ( substr( $stored_dump, 0, strlen( 'stored-text:' ) ) !== 'stored-text:' ) {
|
||||
$data = unserialize( $stored_dump );
|
||||
if ( is_array( $data ) ) {
|
||||
$vh = new AbuseFilterVariableHolder;
|
||||
foreach ( $data as $name => $value ) {
|
||||
$vh->setVar( $name, $value );
|
||||
}
|
||||
|
||||
return $vh;
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
return is_array( $data ) ? AbuseFilterVariableHolder::newFromArray( $data ) : $data;
|
||||
}
|
||||
|
||||
$text_id = substr( $stored_dump, strlen( 'stored-text:' ) );
|
||||
|
@ -912,10 +903,7 @@ class AbuseFilter {
|
|||
|
||||
if ( in_array( 'nativeDataArray', $flags ) ) {
|
||||
$vars = $obj;
|
||||
$obj = new AbuseFilterVariableHolder();
|
||||
foreach ( $vars as $key => $value ) {
|
||||
$obj->setVar( $key, $value );
|
||||
}
|
||||
$obj = AbuseFilterVariableHolder::newFromArray( $vars );
|
||||
// If old variable names are used, make sure to keep them
|
||||
if ( count( array_intersect_key( self::getDeprecatedVariables(), $obj->getVars() ) ) !== 0 ) {
|
||||
$obj->mVarsVersion = 1;
|
||||
|
|
|
@ -13,6 +13,20 @@ class AbuseFilterVariableHolder {
|
|||
*/
|
||||
public $mVarsVersion = 2;
|
||||
|
||||
/**
|
||||
* Utility function to translate an array with shape [ varname => value ] into a self instance
|
||||
*
|
||||
* @param array $vars
|
||||
* @return AbuseFilterVariableHolder
|
||||
*/
|
||||
public static function newFromArray( array $vars ) : AbuseFilterVariableHolder {
|
||||
$ret = new self;
|
||||
foreach ( $vars as $var => $value ) {
|
||||
$ret->setVar( $var, $value );
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $variable
|
||||
* @param mixed $datum
|
||||
|
|
|
@ -15,11 +15,8 @@ class ApiAbuseFilterCheckMatch extends ApiBase {
|
|||
|
||||
$vars = null;
|
||||
if ( $params['vars'] ) {
|
||||
$vars = new AbuseFilterVariableHolder;
|
||||
$pairs = FormatJson::decode( $params['vars'], true );
|
||||
foreach ( $pairs as $name => $value ) {
|
||||
$vars->setVar( $name, $value );
|
||||
}
|
||||
$vars = AbuseFilterVariableHolder::newFromArray( $pairs );
|
||||
} elseif ( $params['rcid'] ) {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$rcQuery = RecentChange::getQueryInfo();
|
||||
|
|
Loading…
Reference in a new issue