Merge "Add new method: AbuseFilterVariableHolder::newFromArray"

This commit is contained in:
jenkins-bot 2019-07-24 18:59:03 +00:00 committed by Gerrit Code Review
commit 1281cce4c9
3 changed files with 17 additions and 18 deletions

View file

@ -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;

View file

@ -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

View file

@ -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();