r104212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104211‎ | r104212 | r104213 >
Date:00:56, 25 November 2011
Author:tstarling
Status:ok
Tags:
Comment:
MFT r104211: makeArbcomList.php
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/SecurePoll/cli/wm-scripts/makeArbcomList.php (added) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/SecurePoll/cli/wm-scripts/makeArbcomList.php
@@ -0,0 +1,70 @@
 2+<?php
 3+
 4+/**
 5+ * Like makeSimpleList.php except with edits limited to the main namespace
 6+ */
 7+
 8+$optionsWithArgs = array( 'before', 'edits' );
 9+require( dirname(__FILE__).'/cli.inc' );
 10+
 11+$dbr = wfGetDB( DB_SLAVE );
 12+$dbw = wfGetDB( DB_MASTER );
 13+$fname = 'voterList.php';
 14+$before = isset( $options['before'] ) ? wfTimestamp( TS_MW, strtotime( $options['before'] ) ) : false;
 15+$minEdits = isset( $options['edits'] ) ? intval( $options['edits'] ) : false;
 16+
 17+if ( !isset( $args[0] ) ) {
 18+ echo "Usage: php voterList.php [--replace] [--before=<date>] [--edits=<date>] <name>\n";
 19+ exit( 1 );
 20+}
 21+$listName = $args[0];
 22+$startBatch = 0;
 23+$batchSize = 100;
 24+
 25+$listExists = $dbr->selectField( 'securepoll_lists', '1',
 26+ array( 'li_name' => $listName ), $fname );
 27+if ( $listExists ) {
 28+ if ( isset( $options['replace'] ) ) {
 29+ echo "Deleting existing list...\n";
 30+ $dbw->delete( 'securepoll_lists', array( 'li_name' => $listName ), $fname );
 31+ } else {
 32+ echo "Error: list exists. Use --replace to replace it.\n";
 33+ exit( 1 );
 34+ }
 35+}
 36+
 37+while ( true ) {
 38+ $res = $dbr->select( 'user', 'user_id',
 39+ array( 'user_id > ' . $dbr->addQuotes( $startBatch ) ),
 40+ $fname,
 41+ array( 'LIMIT' => $batchSize ) );
 42+
 43+ if ( !$res->numRows() ) {
 44+ break;
 45+ }
 46+
 47+ $insertBatch = array();
 48+ foreach ( $res as $row ) {
 49+ $startBatch = $userId = $row->user_id;
 50+ $insertRow = array( 'li_name' => $listName, 'li_member' => $userId );
 51+ if ( $minEdits === false ) {
 52+ $insertBatch[] = $insertRow;
 53+ continue;
 54+ }
 55+
 56+ # Count edits
 57+ $conds = array( 'rev_user' => $userId );
 58+ if ( $before !== false ) {
 59+ $conds[] = 'rev_timestamp < ' . $dbr->addQuotes( $before );
 60+ }
 61+ $conds[] = 'page_id=rev_page';
 62+ $conds['page_namespace'] = 0;
 63+ $edits = $dbr->selectField( array( 'page', '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: branches/wmf/1.18wmf1/extensions/SecurePoll/cli/wm-scripts/makeArbcomList.php
___________________________________________________________________
Added: svn:eol-style
172 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r104211Add list script for arbcom voteststarling00:55, 25 November 2011

Status & tagging log