r16579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16578‎ | r16579 | r16580 >
Date:15:22, 20 September 2006
Author:brion
Status:old (Comments)
Tags:
Comment:
Batch spoof normalized form recorder script
Modified paths:
  • /trunk/extensions/AntiSpoof/SpoofUser.php (modified) (history)
  • /trunk/extensions/AntiSpoof/batchAntiSpoof.php (added) (history)

Diff [purge]

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 @@
7272 * for later comparison of future names...
7373 */
7474 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 ) );
8676 }
 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+ }
87107 }
88108
89109 ?>
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r70810Fix r16579, r69939: proper solution is to make batchRecord() static, not chan...demon12:30, 10 August 2010

Comments

#Comment by Reedy (talk | contribs)   13:12, 26 July 2010

r69939 fixes one call of a method as static that isn't

There's 2 other

SpoofUser::batchRecord( $items );

in batchAntiSpoof.php

#Comment by 😂 (talk | contribs)   12:31, 10 August 2010

Fixed in r70810.

Status & tagging log