Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/254897
Change subject: Merge arbcomlist.php back into makeSimpleList.php ...................................................................... Merge arbcomlist.php back into makeSimpleList.php Now that arbcomlist.php's namespace restriction is toggleable via `--mainspace-only` (as of I2a557198d), the functionality it provides is a superset of makeSimpleList.php's. So make it the new makeSimpleList.php. Change-Id: I9be310db1d0d3de7f2fc480a44798fe78ba60af8 --- M cli/makeSimpleList.php D cli/wm-scripts/arbcomlist.php 2 files changed, 46 insertions(+), 106 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SecurePoll refs/changes/97/254897/1 diff --git a/cli/makeSimpleList.php b/cli/makeSimpleList.php index 5f66c26..f63f477 100644 --- a/cli/makeSimpleList.php +++ b/cli/makeSimpleList.php @@ -3,25 +3,45 @@ /** * Generate a list of users with some number of edits before some date. * - * Will eventually be replaced by something called makeList.php, with more features. + * Usage: php makeSimpleList.php [OPTIONS] LIST_NAME + * --replace If list exists, delete it and recreate. + * --ignore-existing Leave existing list items in place. + * --edits=COUNT Edit count required for eligibility. + * --before=DATE Consider edits made before DATE (strtotime format). + * --mainspace-only Consider only NS_MAIN edits. + * --start-from=UID Start from user ID UID. Allows crashed invocations + * to be resumed. */ -$optionsWithArgs = array( 'before', 'edits' ); -require( dirname(__FILE__).'/cli.inc' ); +$optionsWithArgs = array( 'before', 'edits', 'start-from' ); +require( __DIR__ . '/cli.inc' ); $dbr = wfGetDB( DB_SLAVE ); $dbw = wfGetDB( DB_MASTER ); -$fname = 'voterList.php'; -$before = isset( $options['before'] ) ? wfTimestamp( TS_MW, strtotime( $options['before'] ) ) : false; +$fname = 'makeSimpleList.php'; +$before = isset( $options['before'] ) ? $dbr->timestamp( strtotime( $options['before'] ) ) : false; $minEdits = isset( $options['edits'] ) ? intval( $options['edits'] ) : false; if ( !isset( $args[0] ) ) { - echo "Usage: php voterList.php [--replace] [--before=<date>] [--edits=<date>] <name>\n"; + echo <<<EOD +Generate a list of users with some number of edits before some date. + +Usage: php makeSimpleList.php [OPTIONS] LIST_NAME + --replace If list exists, delete it and recreate. + --ignore-existing Leave existing list items in place. + --edits=COUNT Edit count required for eligibility. + --before=DATE Consider edits made before DATE (strtotime format). + --mainspace-only Consider only NS_MAIN edits. + --start-from=UID Start from user ID UID. Allows crashed invocations + to be resumed. + +EOD; exit( 1 ); } $listName = $args[0]; -$startBatch = 0; +$startBatch = isset( $options['start-from'] ) ? $options['start-from'] : 0; $batchSize = 100; +$insertOptions = array(); $listExists = $dbr->selectField( 'securepoll_lists', '1', array( 'li_name' => $listName ), $fname ); @@ -29,19 +49,20 @@ if ( isset( $options['replace'] ) ) { echo "Deleting existing list...\n"; $dbw->delete( 'securepoll_lists', array( 'li_name' => $listName ), $fname ); + } elseif ( isset( $options['ignore-existing'] ) ) { + $insertOptions[] = 'IGNORE'; } else { echo "Error: list exists. Use --replace to replace it.\n"; exit( 1 ); } } -$total = 0; while ( true ) { + echo "user_id > $startBatch\n"; $res = $dbr->select( 'user', 'user_id', array( 'user_id > ' . $dbr->addQuotes( $startBatch ) ), $fname, - array( 'LIMIT' => $batchSize ) - ); + array( 'LIMIT' => $batchSize ) ); if ( !$res->numRows() ) { break; @@ -61,17 +82,25 @@ if ( $before !== false ) { $conds[] = 'rev_timestamp < ' . $dbr->addQuotes( $before ); } - $edits = $dbr->selectField( 'revision', 'COUNT(*)', $conds, $fname ); + if ( isset( $options['mainspace-only'] ) ) { + $conds['page_namespace'] = 0; + } + + $edits = $dbr->selectRowCount( + array( 'revision', 'page' ), + '1', + $conds, + $fname, + array( 'LIMIT' => $minEdits ), + array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ) ) + ); + if ( $edits >= $minEdits ) { $insertBatch[] = $insertRow; } } if ( $insertBatch ) { - $count = count( $insertBatch ); - $total += $count; - echo "$count rows inserted, total $total rows"; - $dbw->insert( 'securepoll_lists', $insertBatch, $fname ); + $dbw->insert( 'securepoll_lists', $insertBatch, $fname, $insertOptions ); + wfWaitForSlaves(); } } - -echo "Done!\n"; diff --git a/cli/wm-scripts/arbcomlist.php b/cli/wm-scripts/arbcomlist.php deleted file mode 100644 index 0597d44..0000000 --- a/cli/wm-scripts/arbcomlist.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php - -/** - * Like makeSimpleList.php except with edits limited to the main namespace - */ - -$optionsWithArgs = array( 'before', 'edits', 'start-from' ); -require( dirname(__FILE__).'/../cli.inc' ); - -$dbr = wfGetDB( DB_SLAVE ); -$dbw = wfGetDB( DB_MASTER ); -$fname = 'arbcomlist.php'; -$before = isset( $options['before'] ) ? $dbr->timestamp( strtotime( $options['before'] ) ) : false; -$minEdits = isset( $options['edits'] ) ? intval( $options['edits'] ) : false; - -if ( !isset( $args[0] ) ) { - echo <<<EOD -Usage: php arbcomlist.php [--ignore-existing|--replace] [--before=<date>] - [--edits=num] [--mainspace-only] - [--start-from=<user_id>] <name> -EOD; - exit( 1 ); -} -$listName = $args[0]; -$startBatch = isset( $options['start-from'] ) ? $options['start-from'] : 0; -$batchSize = 100; -$insertOptions = array(); - -$listExists = $dbr->selectField( 'securepoll_lists', '1', - array( 'li_name' => $listName ), $fname ); -if ( $listExists ) { - if ( isset( $options['replace'] ) ) { - echo "Deleting existing list...\n"; - $dbw->delete( 'securepoll_lists', array( 'li_name' => $listName ), $fname ); - } elseif ( isset( $options['ignore-existing'] ) ) { - $insertOptions[] = 'IGNORE'; - } else { - echo "Error: list exists. Use --replace to replace it.\n"; - exit( 1 ); - } -} - -while ( true ) { - echo "user_id > $startBatch\n"; - $res = $dbr->select( 'user', 'user_id', - array( 'user_id > ' . $dbr->addQuotes( $startBatch ) ), - $fname, - array( 'LIMIT' => $batchSize ) ); - - if ( !$res->numRows() ) { - break; - } - - $insertBatch = array(); - foreach ( $res as $row ) { - $startBatch = $userId = $row->user_id; - $insertRow = array( 'li_name' => $listName, 'li_member' => $userId ); - if ( $minEdits === false ) { - $insertBatch[] = $insertRow; - continue; - } - - # Count edits - $conds = array( 'rev_user' => $userId ); - if ( $before !== false ) { - $conds[] = 'rev_timestamp < ' . $dbr->addQuotes( $before ); - } - if ( isset( $options['mainspace-only'] ) ) { - $conds['page_namespace'] = 0; - } - - $edits = $dbr->selectRowCount( - array( 'revision', 'page' ), - '1', - $conds, - $fname, - array( 'LIMIT' => $minEdits ), - array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ) ) - ); - - if ( $edits >= $minEdits ) { - $insertBatch[] = $insertRow; - } - } - if ( $insertBatch ) { - $dbw->insert( 'securepoll_lists', $insertBatch, $fname, $insertOptions ); - wfWaitForSlaves(); - } -} -- To view, visit https://gerrit.wikimedia.org/r/254897 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9be310db1d0d3de7f2fc480a44798fe78ba60af8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SecurePoll Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits