Index: trunk/extensions/AntiSpoof/AntiSpoof.php |
— | — | @@ -36,6 +36,7 @@ |
37 | 37 | $wgAutoloadClasses['AntiSpoof'] = "$dir/AntiSpoof_body.php"; |
38 | 38 | $wgAutoloadClasses['AntiSpoofHooks'] = "$dir/AntiSpoofHooks.php"; |
39 | 39 | $wgAutoloadClasses['SpoofUser'] = "$dir/SpoofUser.php"; |
| 40 | +$wgAutoloadClasses['BatchAntiSpoof'] = "$dir/batchAntiSpoof.php"; |
40 | 41 | |
41 | 42 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'AntiSpoofHooks::asUpdateSchema'; |
42 | 43 | $wgHooks['AbortNewAccount'][] = 'AntiSpoofHooks::asAbortNewAccountHook'; |
Index: trunk/extensions/AntiSpoof/batchAntiSpoof.php |
— | — | @@ -1,31 +1,51 @@ |
2 | 2 | <?php |
3 | 3 | // Go through all usernames and calculate and record spoof thingies |
4 | 4 | |
5 | | -require_once ( getenv( 'MW_INSTALL_PATH' ) !== false |
6 | | - ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" |
7 | | - : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' ); |
| 5 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 6 | +if ( $IP === false ) { |
| 7 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 8 | +} |
| 9 | +require( "$IP/maintenance/Maintenance.php" ); |
8 | 10 | |
9 | | -$dbw = wfGetDB( DB_MASTER ); |
| 11 | +class BatchAntiSpoof extends Maintenance { |
10 | 12 | |
11 | | -$dbw->bufferResults( false ); |
| 13 | + /** |
| 14 | + * @param $items array |
| 15 | + */ |
| 16 | + private function batchRecord( $items ) { |
| 17 | + SpoofUser::batchRecord( $items ); |
| 18 | + } |
12 | 19 | |
13 | | -$batchSize = 1000; |
| 20 | + /** |
| 21 | + * Do the actual work. All child classes will need to implement this |
| 22 | + */ |
| 23 | + public function execute() { |
| 24 | + $dbw = $this->getDB( DB_MASTER ); |
14 | 25 | |
15 | | -$result = $dbw->select( 'user', 'user_name', null, 'batchAntiSpoof.php' ); |
16 | | -$n = 0; |
17 | | -foreach( $result as $row ) { |
18 | | - if ( $n++ % $batchSize == 0 ) { |
19 | | - echo "$wgDBname $n\n"; |
20 | | - } |
| 26 | + $dbw->bufferResults( false ); |
21 | 27 | |
22 | | - $items[] = new SpoofUser( $row->user_name ); |
| 28 | + $batchSize = 1000; |
23 | 29 | |
24 | | - if ( $n % $batchSize == 0 ) { |
25 | | - SpoofUser::batchRecord( $items ); |
| 30 | + $result = $dbw->select( 'user', 'user_name', null, __FUNCTION__ ); |
| 31 | + $n = 0; |
26 | 32 | $items = array(); |
| 33 | + foreach( $result as $row ) { |
| 34 | + if ( $n++ % $batchSize == 0 ) { |
| 35 | + $this->output( "...$n\n" ); |
| 36 | + } |
| 37 | + |
| 38 | + $items[] = new SpoofUser( $row->user_name ); |
| 39 | + |
| 40 | + if ( $n % $batchSize == 0 ) { |
| 41 | + $this->batchRecord( $items ); |
| 42 | + $items = array(); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + $this->batchRecord( $items ); |
| 47 | + $this->output( "$n user(s) done.\n" ); |
27 | 48 | } |
28 | 49 | } |
29 | 50 | |
30 | | -SpoofUser::batchRecord( $items ); |
31 | | -echo "$wgDBname $n done.\n"; |
32 | | -$dbw->freeResult( $result ); |
| 51 | +$maintClass = "BatchAntiSpoof"; |
| 52 | +require_once( DO_MAINTENANCE ); |