r111669 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111668‎ | r111669 | r111670 >
Date:19:53, 16 February 2012
Author:reedy
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1/extensions (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/AntiSpoof/maintenance/BatchAntiSpoofClass.php (added) (history)
  • /branches/wmf/1.19wmf1/extensions/AntiSpoof/maintenance/batchAntiSpoof.php (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/CentralAuth/AntiSpoof/batchCAAntiSpoof.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/extensions/AntiSpoof/maintenance/BatchAntiSpoofClass.php
@@ -0,0 +1,74 @@
 2+<?php
 3+
 4+$IP = getenv( 'MW_INSTALL_PATH' );
 5+if ( $IP === false ) {
 6+ $IP = dirname( __FILE__ ) . '/../../..';
 7+}
 8+require_once( "$IP/maintenance/Maintenance.php" );
 9+
 10+/**
 11+ * Go through all usernames and calculate and record spoof thingies
 12+ */
 13+class BatchAntiSpoof extends Maintenance {
 14+
 15+ /**
 16+ * @param $items array
 17+ */
 18+ protected function batchRecord( $items ) {
 19+ SpoofUser::batchRecord( $items );
 20+ }
 21+
 22+ /**
 23+ * @return string
 24+ */
 25+ protected function getTableName() {
 26+ return 'user';
 27+ }
 28+
 29+ /**
 30+ * @return string
 31+ */
 32+ protected function getUserColumn() {
 33+ return 'user_name';
 34+ }
 35+
 36+ /**
 37+ * @param $name string
 38+ * @return SpoofUser
 39+ */
 40+ protected function makeSpoofUser( $name ) {
 41+ return new SpoofUser( $name );
 42+ }
 43+
 44+ /**
 45+ * Do the actual work. All child classes will need to implement this
 46+ */
 47+ public function execute() {
 48+ $dbw = $this->getDB( DB_MASTER );
 49+
 50+ $batchSize = 1000;
 51+
 52+ $this->output( "Creating username spoofs...\n" );
 53+ $userCol = $this->getUserColumn();
 54+ $result = $dbw->select( $this->getTableName(), $userCol, null, __FUNCTION__ );
 55+ $n = 0;
 56+ $items = array();
 57+ foreach( $result as $row ) {
 58+ if ( $n++ % $batchSize == 0 ) {
 59+ $this->output( "...$n\n" );
 60+ }
 61+
 62+ $items[] = $this->makeSpoofUser( $row->$userCol );
 63+
 64+ if ( $n % $batchSize == 0 ) {
 65+ $this->batchRecord( $items );
 66+ $items = array();
 67+ wfWaitForSlaves();
 68+ }
 69+ }
 70+
 71+ $this->batchRecord( $items );
 72+ $this->output( "$n user(s) done.\n" );
 73+ }
 74+}
 75+
Property changes on: branches/wmf/1.19wmf1/extensions/AntiSpoof/maintenance/BatchAntiSpoofClass.php
___________________________________________________________________
Added: svn:eol-style
176 + native
Index: branches/wmf/1.19wmf1/extensions/AntiSpoof/maintenance/batchAntiSpoof.php
@@ -1,75 +1,5 @@
22 <?php
3 -// Go through all usernames and calculate and record spoof thingies
 3+require_once( "BatchAntiSpoofClass.php" );
44
5 -$IP = getenv( 'MW_INSTALL_PATH' );
6 -if ( $IP === false ) {
7 - $IP = dirname( __FILE__ ) . '/../../..';
8 -}
9 -require_once( "$IP/maintenance/Maintenance.php" );
10 -
11 -class BatchAntiSpoof extends Maintenance {
12 -
13 - /**
14 - * @param $items array
15 - */
16 - protected function batchRecord( $items ) {
17 - SpoofUser::batchRecord( $items );
18 - }
19 -
20 - /**
21 - * @return string
22 - */
23 - protected function getTableName() {
24 - return 'user';
25 - }
26 -
27 - /**
28 - * @return string
29 - */
30 - protected function getUserColumn() {
31 - return 'user_name';
32 - }
33 -
34 - /**
35 - * @param $name string
36 - * @return SpoofUser
37 - */
38 - protected function makeSpoofUser( $name ) {
39 - return new SpoofUser( $name );
40 - }
41 -
42 - /**
43 - * Do the actual work. All child classes will need to implement this
44 - */
45 - public function execute() {
46 - $dbw = $this->getDB( DB_MASTER );
47 -
48 - // $dbw->bufferResults( false );
49 -
50 - $batchSize = 1000;
51 -
52 - $this->output( "Creating username spoofs...\n" );
53 - $userCol = $this->getUserColumn();
54 - $result = $dbw->select( $this->getTableName(), $userCol, null, __FUNCTION__ );
55 - $n = 0;
56 - $items = array();
57 - foreach( $result as $row ) {
58 - if ( $n++ % $batchSize == 0 ) {
59 - $this->output( "...$n\n" );
60 - }
61 -
62 - $items[] = $this->makeSpoofUser( $row->$userCol );
63 -
64 - if ( $n % $batchSize == 0 ) {
65 - $this->batchRecord( $items );
66 - $items = array();
67 - }
68 - }
69 -
70 - $this->batchRecord( $items );
71 - $this->output( "$n user(s) done.\n" );
72 - }
73 -}
74 -
755 $maintClass = "BatchAntiSpoof";
766 require_once( DO_MAINTENANCE );
Index: branches/wmf/1.19wmf1/extensions/CentralAuth/AntiSpoof/batchCAAntiSpoof.php
@@ -5,7 +5,7 @@
66 if ( $IP === false ) {
77 $IP = dirname( __FILE__ ) . '/../../..';
88 }
9 -require_once( "$IP/extensions/AntiSpoof/maintenance/batchAntiSpoof.php" );
 9+require_once( "$IP/extensions/AntiSpoof/maintenance/BatcbAntiSpoofClass.php" );
1010
1111 class BatchCAAntiSpoof extends BatchAntiSpoof {
1212
Property changes on: branches/wmf/1.19wmf1/extensions
___________________________________________________________________
Modified: svn:mergeinfo
1313 Merged /trunk/extensions:r111668

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111668Seeing as just including a maintenance script to be subclassed means the orig...reedy19:51, 16 February 2012

Status & tagging log