Skip to content

Instantly share code, notes, and snippets.

@Jarry1250
Created March 25, 2014 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jarry1250/9760320 to your computer and use it in GitHub Desktop.
Save Jarry1250/9760320 to your computer and use it in GitHub Desktop.
Maintenance script for mirror the WMF global block list
<?php
/*
WMUK block copier © 2011 and 2013 Harry Burt <jarry1250@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
require_once( '/data/project/jarry-common/public_html/peachy/Init.php' );
$wiki = Peachy::newWiki( 'wmuk' );
$http = new HTTP();
$meta = Peachy::newWiki( 'livingbotmeta' );
$query = array(
'_code' => 'bg',
'_limit' => 10000,
'action' => 'query',
'list' => 'globalblocks',
'bgprop' => 'address|expiry|timestamp',
'bgstart' => '2014-03-20T01:00:02Z',
'bgdir' => 'newer'
);
$blocks = $meta->listHandler( $query );
$ipNumbers = array();
foreach( $blocks as $block ){
$params = array( 'nocreate' );
$isRangeBlock = ( strpos( $block['address'], '/' ) !== false );
if( $isRangeBlock ) {
list( $address, $bits ) = explode( '/', $block['address'] );
if( strpos( $address, ':' ) !== false ) continue; // IPv6
$ipNumbers[] = pow( 2, ( 32 - intval( $bits ) ) );
continue;
}
if( isset( $block['anononly'] ) ) $params[] = 'anononly';
if( strtotime( $block['expiry'] ) < time() ) continue;
$user = initUser( $block['address'] );
if( $user->block( 'Mirror WMF [[:meta:Global_blocks|global block]] of this IP address. ([[User:Global block importer bot|what does that mean?]], [[User:Global block importer bot|appeals]])', $block['expiry'], $params ) ) {
echo $block['address'] . " blocked.\n";
}
}
echo "Found " . array_sum( $ipNumbers ) . " blocked IPs across " . count( $ipNumbers ) . " ranges.\n";
echo "Distribution: " . print_r( array_count_values( $ipNumbers ), true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment