Index: trunk/extensions/SecurePoll/cli/makeSimpleList.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Generate a list of users with some number of edits before some date. |
| 6 | + * |
| 7 | + * Will eventually be replaced by something called makeList.php, with more features. |
| 8 | + */ |
| 9 | + |
| 10 | +$optionsWithArgs = array( 'before', 'edits' ); |
| 11 | +require( dirname(__FILE__).'/cli.inc' ); |
| 12 | + |
| 13 | +$dbr = wfGetDB( DB_SLAVE ); |
| 14 | +$dbw = wfGetDB( DB_MASTER ); |
| 15 | +$fname = 'voterList.php'; |
| 16 | +$before = isset( $options['before'] ) ? wfTimestamp( TS_MW, strtotime( $options['before'] ) ) : false; |
| 17 | +$minEdits = isset( $options['edits'] ) ? intval( $options['edits'] ) : false; |
| 18 | + |
| 19 | +if ( !isset( $args[0] ) ) { |
| 20 | + echo "Usage: php voterList.php [--replace] [--before=<date>] [--edits=<date>] <name>\n"; |
| 21 | + exit( 1 ); |
| 22 | +} |
| 23 | +$listName = $args[0]; |
| 24 | +$startBatch = 0; |
| 25 | +$batchSize = 100; |
| 26 | + |
| 27 | +$listExists = $dbr->selectField( 'securepoll_lists', '1', |
| 28 | + array( 'li_name' => $listName ), $fname ); |
| 29 | +if ( $listExists ) { |
| 30 | + if ( isset( $options['replace'] ) ) { |
| 31 | + echo "Deleting existing list...\n"; |
| 32 | + $dbw->delete( 'securepoll_lists', array( 'li_name' => $listName ), $fname ); |
| 33 | + } else { |
| 34 | + echo "Error: list exists. Use --replace to replace it.\n"; |
| 35 | + exit( 1 ); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +while ( true ) { |
| 40 | + $res = $dbr->select( 'user', 'user_id', |
| 41 | + array( 'user_id > ' . $dbr->addQuotes( $startBatch ) ), |
| 42 | + $fname, |
| 43 | + array( 'LIMIT' => $batchSize ) ); |
| 44 | + |
| 45 | + if ( !$res->numRows() ) { |
| 46 | + break; |
| 47 | + } |
| 48 | + |
| 49 | + $insertBatch = array(); |
| 50 | + foreach ( $res as $row ) { |
| 51 | + $startBatch = $userId = $row->user_id; |
| 52 | + $insertRow = array( 'li_name' => $listName, 'li_member' => $userId ); |
| 53 | + if ( $minEdits === false ) { |
| 54 | + $insertBatch[] = $insertRow; |
| 55 | + continue; |
| 56 | + } |
| 57 | + |
| 58 | + # Count edits |
| 59 | + $conds = array( 'rev_user' => $userId ); |
| 60 | + if ( $before !== false ) { |
| 61 | + $conds[] = 'rev_timestamp < ' . $dbr->addQuotes( $before ); |
| 62 | + } |
| 63 | + $edits = $dbr->selectField( 'revision', 'COUNT(*)', $conds, $fname ); |
| 64 | + if ( $edits >= $minEdits ) { |
| 65 | + $insertBatch[] = $insertRow; |
| 66 | + } |
| 67 | + } |
| 68 | + if ( $insertBatch ) { |
| 69 | + $dbw->insert( 'securepoll_lists', $insertBatch, $fname ); |
| 70 | + } |
| 71 | +} |
Property changes on: trunk/extensions/SecurePoll/cli/makeSimpleList.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 72 | + native |