Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/275716
Change subject: Allow multiple name filter rules
......................................................................
Allow multiple name filter rules
Extend existing logic to multiple sets of keymap, ratio, and score.
Bug: T128928
Change-Id: I438d2ca244df940c90efb778e9f5a0c4c44a207f
---
M DonationInterface.php
M gateway_common/gateway.adapter.php
M tests/Adapter/GatewayAdapterTest.php
3 files changed, 49 insertions(+), 47 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/16/275716/1
diff --git a/DonationInterface.php b/DonationInterface.php
index 69e1ffa..670d17e 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -758,14 +758,12 @@
$wgDonationInterfaceUtmSourceMap = array();
/**
- * $wgDonationInterfaceKeyMapA
- * $wgDonationInterfaceKeyMapB
- * $wgDonationInterfaceNameGibberishWeight
- * $wgDonationInterfaceNameScore
+ * $wgDonationInterfaceNameFilterRules
*
+ * For each entry in the rule array,
* Set KeyMapA and KeyMapB to mutually exclusive arrays of characters.
- * Set NameGibberishWeight to reflect the ratio of characters from one group
that will cause a fail.
- * Set NameScore to the number of points to assign on fail.
+ * Set GibberishWeight to reflect the ratio of characters from one group that
will cause a fail.
+ * Set Score to the number of points to assign on fail.
*
* To enable this filter add this to your LocalSettings.php:
*
@@ -776,20 +774,18 @@
* 'getScoreName' => 100,
* );
*
- * $wgDonationInterfaceKeyMapA = array('a','s','d');
- *
- * $wgDonationInterfaceKeyMapB = array('h','j','k','l');
- *
- * $wgDonationInterfaceNameGibberishWeight = .9;
- *
- * $wgDonationInterfaceNameScore = 10;
+ * $wgDonationInterfaceNameFilterRules = array(
+ * array(
+ * 'KeyMapA' => array('a','s','d'),
+ * 'KeyMapB' => array('h','j','k','l'),
+ * 'GibberishWeight' => .9,
+ * 'Score' => 10,
+ * ),
+ * );
*
*/
-$wgDonationInterfaceKeyMapA = array();
-$wgDonationInterfaceKeyMapB = array();
-$wgDonationInterfaceNameGibberishWeight = 0;
-$wgDonationInterfaceNameScore = 0;
+$wgDonationInterfaceNameFilterRules = array();
$wgDonationInterfaceEnableQueue = false;
$wgDonationInterfaceEnableConversionLog = false; //this is definitely an Extra
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 1d57910..ddb56a0 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -2849,59 +2849,60 @@
return false;
}
- /**
+ /**
* This custom filter function checks the global variable:
- *
- * KeyMapA
- * KeyMapB
+ * wgDonationInterfaceNameFilterRules
+ * Each entry in that array has keys
+ * KeyMapA, KeyMapB: define keyboard zones
+ * GibberishWeight: threshold fraction of name letters in a single
zone
+ * Score: added to the total fraud score when this threshold is
exceeded
*
* How the score is tabulated:
* - If the configurable portion letters in a name come from the same
zone points are added.
* - Returns an integer: 0 <= $score <= 100
*
* @see $wgDonationInterfaceCustomFiltersFunctions
- * @see $wgDonationInterfaceKeyMapA* @see $wgDonationInterfaceKeyMapB
+ * @see $wgDonationInterfaceNameFilterRules
*
* @return integer
*/
- public function getScoreName(){
+ public function getScoreName(){
+ $fName = $this->getData_Unstaged_Escaped( 'fname' );
+ $lName = $this->getData_Unstaged_Escaped( 'lname' );
- $fName = $this->getData_Unstaged_Escaped( 'fname' );
- $lName = $this->getData_Unstaged_Escaped( 'lname' );
+ $nameArray = str_split( strtolower( $fName . $lName ) );
+ $rules = $this->getGlobal( 'NameFilterRules' );
+ $score = 0;
- $nameArray = str_split( strtolower( $fName . $lName ) );
+ foreach( $rules as $rule ) {
+ $keyMapA = $rule['KeyMapA'];
+ $keyMapB = $rule['KeyMapB'];
- $keyMapA = $this->getGlobal( 'KeyMapA' );
+ $gibberishWeight = $rule['GibberishWeight'];
- $keyMapB = $this->getGlobal( 'KeyMapB' );
-
- $gibberishWeight = $this->getGlobal(
'NameGibberishWeight' );
-
- $failScore = $this->getGlobal( 'NameScore' );
+ $failScore = $rule['Score'];
$points = 0;
- $score = 0;
-
- if ( is_array( $nameArray ) && !empty( $nameArray ) ){
- foreach($nameArray as $letter){
+ if ( is_array( $nameArray ) && !empty( $nameArray ) ) {
+ foreach ( $nameArray as $letter ) {
// For each char in zone A add a point,
zone B subtract.
- if( in_array( $letter, $keyMapA ) ){
+ if ( in_array( $letter, $keyMapA ) ) {
$points++;
}
- if( in_array( $letter, $keyMapB ) ){
+ if ( in_array( $letter, $keyMapB ) ) {
$points--;
}
}
- if( abs( $points ) / count( $nameArray ) >=
$gibberishWeight ){
- $score = $failScore;
+ if ( abs( $points ) / count( $nameArray ) >=
$gibberishWeight ) {
+ $score += $failScore;
}
}
-
- return $score;
-
}
+ return $score;
+ }
+
/**
* This custom filter function checks the global variable:
*
diff --git a/tests/Adapter/GatewayAdapterTest.php
b/tests/Adapter/GatewayAdapterTest.php
index 16a5a16..6b86c01 100644
--- a/tests/Adapter/GatewayAdapterTest.php
+++ b/tests/Adapter/GatewayAdapterTest.php
@@ -289,10 +289,15 @@
}
function testGetScoreName() {
- $this->setMwGlobals( array( 'wgDonationInterfaceKeyMapA' =>
array('a','s','d','f','q','w','e','r','t'),
-
'wgDonationInterfaceKeyMapB' => array(),
-
'wgDonationInterfaceNameGibberishWeight' => .9,
-
'wgDonationInterfaceNameScore' => 10) );
+ $rule = array(
+ 'KeyMapA' => array( 'a','s','d','f','q','w','e','r','t'
),
+ 'KeyMapB' => array(),
+ 'GibberishWeight' => .9,
+ 'Score' => 10
+ );
+ $this->setMwGlobals(
+ array( 'wgDonationInterfaceNameFilterRules' => array(
$rule ) )
+ );
$init = $this->getDonorTestData();
$init['fname'] = 'asdf';
$init['lname'] = 'qwert';
--
To view, visit https://gerrit.wikimedia.org/r/275716
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I438d2ca244df940c90efb778e9f5a0c4c44a207f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits