Index: trunk/extensions/AntiSpoof/batchAntiSpoof.php |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// Go through all usernames and calculate and record spoof thingies |
| 5 | + |
| 6 | +$base = dirname( dirname( dirname( __FILE__ ) ) ); |
| 7 | +require $base . '/maintenance/commandLine.inc'; |
| 8 | + |
| 9 | +// fixme |
| 10 | +$dbr = new Database( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname ); |
| 11 | +$dbr->bufferResults( false ); |
| 12 | + |
| 13 | +$batchSize = 1000; |
| 14 | + |
| 15 | +$result = $dbr->select( 'user', 'user_name', '1', 'batchAntiSpoof.php' ); |
| 16 | +$n = 0; |
| 17 | +while( $row = $dbr->fetchObject( $result ) ) { |
| 18 | + if( $n++ % $batchSize == 0 ) { |
| 19 | + echo "$wgDBname $n\n"; |
| 20 | + } |
| 21 | + |
| 22 | + $items[] = new SpoofUser( $row->user_name ); |
| 23 | + |
| 24 | + if( $n % $batchSize == 0 ) { |
| 25 | + SpoofUser::batchRecord( $items ); |
| 26 | + $items = array(); |
| 27 | + } |
| 28 | +} |
| 29 | +SpoofUser::batchRecord( $items ); |
| 30 | +echo "$wgDBname $n done.\n"; |
| 31 | +$dbr->freeResult( $result ); |
| 32 | + |
| 33 | + |
| 34 | +?> |
\ No newline at end of file |
Index: trunk/extensions/AntiSpoof/SpoofUser.php |
— | — | @@ -71,18 +71,38 @@ |
72 | 72 | * for later comparison of future names... |
73 | 73 | */ |
74 | 74 | public function record() { |
75 | | - $dbw = wfGetDB( DB_MASTER ); |
76 | | - return $dbw->replace( |
77 | | - 'spoofuser', |
78 | | - array( 'su_name' ), |
79 | | - array( |
80 | | - 'su_name' => $this->mName, |
81 | | - 'su_normalized' => $this->mNormalized, |
82 | | - 'su_legal' => $this->mLegal ? 1 : 0, |
83 | | - 'su_error' => $this->mError, |
84 | | - ), |
85 | | - __METHOD__ ); |
| 75 | + return self::batchRecord( array( $this ) ); |
86 | 76 | } |
| 77 | + |
| 78 | + private function insertFields() { |
| 79 | + return array( |
| 80 | + 'su_name' => $this->mName, |
| 81 | + 'su_normalized' => $this->mNormalized, |
| 82 | + 'su_legal' => $this->mLegal ? 1 : 0, |
| 83 | + 'su_error' => $this->mError, |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Insert a batch of spoof normalization records into the database. |
| 89 | + * @param $items array of SpoofUser |
| 90 | + */ |
| 91 | + public function batchRecord( $items ) { |
| 92 | + if( count( $items ) ) { |
| 93 | + $fields = array(); |
| 94 | + foreach( $items as $item ) { |
| 95 | + $fields[] = $item->insertFields(); |
| 96 | + } |
| 97 | + $dbw = wfGetDB( DB_MASTER ); |
| 98 | + return $dbw->replace( |
| 99 | + 'spoofuser', |
| 100 | + array( 'su_name' ), |
| 101 | + $fields, |
| 102 | + __METHOD__ ); |
| 103 | + } else { |
| 104 | + return false; |
| 105 | + } |
| 106 | + } |
87 | 107 | } |
88 | 108 | |
89 | 109 | ?> |
\ No newline at end of file |