Index: trunk/extensions/SecurePoll/includes/talliers/CommentDumper.php |
— | — | @@ -5,9 +5,17 @@ |
6 | 6 | */ |
7 | 7 | class SecurePoll_CommentDumper extends SecurePoll_ElectionTallier { |
8 | 8 | var $csvHandle; |
| 9 | + var $skipEmptyComments; |
| 10 | + private $countSoFar; |
| 11 | + |
| 12 | + public function __construct( $context, $election, $skipEmptyComments = true ) { |
| 13 | + parent::__construct( $context, $election ); |
| 14 | + $this->skipEmptyComments = $skipEmptyComments; |
| 15 | + } |
9 | 16 | |
10 | 17 | function execute() { |
11 | 18 | $this->csvHandle = fopen( 'php://temp', 'r+' ); |
| 19 | + $this->countSoFar = 0; |
12 | 20 | return parent::execute(); |
13 | 21 | } |
14 | 22 | |
— | — | @@ -21,6 +29,8 @@ |
22 | 30 | * @return Status |
23 | 31 | */ |
24 | 32 | function addRecord( $store, $record ) { |
| 33 | + $this->countSoFar++; |
| 34 | + wfDebug( "Processing vote {$this->countSoFar}\n" ); |
25 | 35 | # Decrypt and unpack |
26 | 36 | if ( $this->crypt ) { |
27 | 37 | $status = $this->crypt->decrypt( $record ); |
— | — | @@ -36,7 +46,9 @@ |
37 | 47 | unset($scores['comment']); |
38 | 48 | |
39 | 49 | // Short circuit if the comments are empty |
40 | | - if ( $comments['native'] == '' && $comments['en'] == '' ) { |
| 50 | + if ( $this->skipEmptyComments && |
| 51 | + $comments['native'] == '' && $comments['en'] == '' ) |
| 52 | + { |
41 | 53 | return Status::newGood(); |
42 | 54 | } |
43 | 55 | |
Index: trunk/extensions/SecurePoll/cli/dumpVoteCsv.php |
— | — | @@ -0,0 +1,69 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Dump all votes from an election from a dump file or local database. |
| 6 | + * |
| 7 | + * For the purposes of the Personal Image Filter referendum, this script |
| 8 | + * dumps the answers to all questions in key order. |
| 9 | + * |
| 10 | + * Can be used to tally very large numbers of votes, when the web interface is |
| 11 | + * not feasible. |
| 12 | + */ |
| 13 | + |
| 14 | +$optionsWithArgs = array( 'name' ); |
| 15 | +require( dirname(__FILE__).'/cli.inc' ); |
| 16 | + |
| 17 | +$wgTitle = Title::newFromText( 'Special:SecurePoll' ); |
| 18 | + |
| 19 | +$usage = <<<EOT |
| 20 | +Usage: |
| 21 | + php dumpVoteCsv.php [--html] --name <election name> |
| 22 | + php dumpVoteCsv.php [--html] <dump file> |
| 23 | +EOT; |
| 24 | + |
| 25 | +if ( !isset( $options['name'] ) && !isset( $args[0] ) ) { |
| 26 | + spFatal( $usage ); |
| 27 | +} |
| 28 | + |
| 29 | +if ( !class_exists( 'SecurePoll_Context' ) ) { |
| 30 | + if ( isset( $options['name'] ) ) { |
| 31 | + spFatal( "Cannot load from database when SecurePoll is not installed" ); |
| 32 | + } |
| 33 | + require( dirname( __FILE__ ) . '/../SecurePoll.php' ); |
| 34 | +} |
| 35 | + |
| 36 | +$context = new SecurePoll_Context; |
| 37 | +if ( !isset( $options['name'] ) ) { |
| 38 | + $context = SecurePoll_Context::newFromXmlFile( $args[0] ); |
| 39 | + if ( !$context ) { |
| 40 | + spFatal( "Unable to parse XML file \"{$args[0]}\"" ); |
| 41 | + } |
| 42 | + $electionIds = $context->getStore()->getAllElectionIds(); |
| 43 | + if ( !count( $electionIds ) ) { |
| 44 | + spFatal( "No elections found in XML file \"{$args[0]}\"" ); |
| 45 | + } |
| 46 | + $election = $context->getElection( reset( $electionIds ) ); |
| 47 | +} else { |
| 48 | + $election = $context->getElectionByTitle( $options['name'] ); |
| 49 | + if ( !$election ) { |
| 50 | + spFatal( "The specified election does not exist." ); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +$tallier = new SecurePoll_CommentDumper( $context, $election, false ); |
| 55 | +$status = $tallier->execute(); |
| 56 | +if ( !$status->isOK() ) { |
| 57 | + spFatal( "Tally error: " . $status->getWikiText() ); |
| 58 | +} |
| 59 | +//$tallier = $status->value; |
| 60 | +if ( isset( $options['html'] ) ) { |
| 61 | + echo $tallier->getHtmlResult(); |
| 62 | +} else { |
| 63 | + echo $tallier->getTextResult(); |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +function spFatal( $message ) { |
| 68 | + fwrite( STDERR, rtrim( $message ) . "\n" ); |
| 69 | + exit( 1 ); |
| 70 | +} |