Jump to content

User:Legoktm/StopForumSpam effectiveness

From mediawiki.org

It's been proposed to deploy StopForumSpam blacklists to Wikimedia sites. I've done a few checks to see how effective it would be. I'm using the 7 day IPv4 + IPv6 list from 2017-09-08, and the 2017-09-02 globalblocking database dump.

  • Records in globalblocking database: 9,062
    • 7,147 are for individual IPs
    • 1,915 are for range blocks
  • IPs in SFS list: 17,806
    • 68 are IPv6
  • SFS IPs that are already blocked on Wikimedia: 4,223 (23.7% of the SFS list is already blocked)
    • 3,937 were covered by a globalblock range block
    • 286 were covered by a globalblock IP block

Code

[edit]
diff --git a/includes/BlacklistUpdate.php b/includes/BlacklistUpdate.php
index 19ad9ed..5e57a30 100644
--- a/includes/BlacklistUpdate.php
+++ b/includes/BlacklistUpdate.php
@@ -26,6 +26,8 @@ use IP;
 class BlacklistUpdate implements DeferrableUpdate {
        private $lineNo, $usedKeys, $data, $skipLines, $finished = false;
 
+       public $checked = 0, $blocked = 0, $rangeMatch = 0, $exactMatch = 0;
+
        public function doUpdate() {
                global $wgSFSIPListLocation, $wgSFSIPThreshold, $wgSFSValidateIPList,
                           $wgSFSBlacklistCacheDuration, $wgMemc;
@@ -65,6 +67,18 @@ class BlacklistUpdate implements DeferrableUpdate {
                while ( !feof( $fh ) ) {
                        $ip = fgetcsv( $fh, 4096, ',', '"' );
                        $this->lineNo++;
+                       //throw new Exception(var_export($ip,true));
+                       if ( $ip !== [ null ] && IP::isValid( $ip[0] ) ) {
+                               $this->checked++;
+                               if ( $block = GlobalBlocking::getGlobalBlockingBlock( $ip[0], false ) ) {
+                                       $this->blocked++;
+                                       if ( $block->gb_address === $ip[0] ) {
+                                               $this->exactMatch++;
+                                       } else {
+                                               $this->rangeMatch++;
+                                       }
+                               }
+                       }
                        if ( $this->lineNo < $this->skipLines ) {
                                continue;
                        } elseif (
diff --git a/updateBlacklist.php b/updateBlacklist.php
index 3b743b3..dd37df2 100644
--- a/updateBlacklist.php
+++ b/updateBlacklist.php
@@ -47,6 +47,10 @@ class SFSBlacklistUpdate extends Maintenance {
 
                $this->output( "Done!\n" );
                $this->output( "Took {$diff} seconds\n" );
+               $this->output( "Checked: {$update->checked}\n" );
+               $this->output( "Blocked: {$update->blocked}\n" );
+               $this->output( "Range match: {$update->rangeMatch}\n" );
+               $this->output( "Exact match: {$update->exactMatch}\n" );
        }
 
 }