Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/289809

Change subject: Fire IP velocity filter early
......................................................................

Fire IP velocity filter early

Run the first time we see them, let them get one attempt on that
credit, and then fire again on every subsequent attempt.

Change-Id: Ibccebdccf4f6758dc7c9f07d467eaeb74a619edd
---
M DonationInterface.php
M extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
2 files changed, 34 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/09/289809/1

diff --git a/DonationInterface.php b/DonationInterface.php
index 40426b7..d256e91 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -896,6 +896,7 @@
 $wgHooks['GatewayValidate'][] = array( 
'Gateway_Extras_CustomFilters::onValidate' );
 
 $wgHooks['GatewayInitialFilter'][] = array( 
'Gateway_Extras_CustomFilters_Functions::onFilter' );
+$wgHooks['GatewayInitialFilter'][] = array( 
'Gateway_Extras_CustomFilters_IP_Velocity::onInitialFilter' );
 
 $wgHooks['GatewayCustomFilter'][] = array( 
'Gateway_Extras_CustomFilters_Referrer::onFilter' );
 $wgHooks['GatewayCustomFilter'][] = array( 
'Gateway_Extras_CustomFilters_Source::onFilter' );
diff --git a/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php 
b/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
index 9188ede..fc05da2 100644
--- a/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
+++ b/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
@@ -154,16 +154,47 @@
                $new_velocity_records[] = $nowstamp;
                return $new_velocity_records;
        }
-       
 
+
+       /**
+        * This is called when we're actually talking to the processor.
+        * We don't call on the first attempt in this session, since
+        * onInitialFilter already struck once.
+        * @param GatewayType $gateway_adapter
+        * @param Gateway_Extras_CustomFilters $custom_filter_object
+        * @return bool
+        */
        static function onFilter( $gateway_adapter, $custom_filter_object ) {
                if ( !$gateway_adapter->getGlobal( 'EnableIPVelocityFilter' ) ){
+                       return true;
+               }
+               if ( !$gateway_adapter->getRequest()->getSessionData( 
'numAttempt' ) ) {
+                       // We're on the first attempt, already counted in 
onInitialFilter
                        return true;
                }
                $gateway_adapter->debugarray[] = 'IP Velocity onFilter hook!';
                return self::singleton( $gateway_adapter, $custom_filter_object 
)->filter();
        }
-       
+
+       /**
+        * Run the filter if we haven't for this session, and set a flag
+        * @param GatewayType $gateway_adapter
+        * @param Gateway_Extras_CustomFilters $custom_filter_object
+        * @return bool
+        */
+       static function onInitialFilter( $gateway_adapter, 
$custom_filter_object ) {
+               if ( !$gateway_adapter->getGlobal( 'EnableIPVelocityFilter' ) ){
+                       return true;
+               }
+               if ( $gateway_adapter->getRequest()->getSessionData( 
'initialIPVelocity' ) ) {
+                       return true;
+               }
+
+               $gateway_adapter->getRequest()->setSessionData( 
'initialIPVelocity', true );
+               $gateway_adapter->debugarray[] = 'IP Velocity onFilter hook!';
+               return self::singleton( $gateway_adapter, $custom_filter_object 
)->filter();
+       }
+
        static function onPostProcess( GatewayType $gateway_adapter ) {
                if ( !$gateway_adapter->getGlobal( 'EnableIPVelocityFilter' ) ){
                        return true;

-- 
To view, visit https://gerrit.wikimedia.org/r/289809
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibccebdccf4f6758dc7c9f07d467eaeb74a619edd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to