Index: trunk/extensions/SecurePoll/SecurePoll.i18n.php |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | 'securepoll-welcome' => '<strong>Welcome $1!</strong>', |
26 | 26 | 'securepoll-not-started' => 'This election has not yet started. |
27 | 27 | It is scheduled to start on $2 at $3.', |
| 28 | + 'securepoll-finished' => 'This election has finished, you can no longer vote.', |
28 | 29 | 'securepoll-not-qualified' => 'You are not qualified to vote in this election: $1', |
29 | 30 | 'securepoll-change-disallowed' => 'You have voted in this election before. |
30 | 31 | Sorry, you may not vote again.', |
— | — | @@ -71,6 +72,7 @@ |
72 | 73 | 'securepoll-not-logged-in' => 'You must log in to vote in this election', |
73 | 74 | 'securepoll-too-few-edits' => 'Sorry, you cannot vote. You need to have made at least $1 {{PLURAL:$1|edit|edits}} to vote in this election, you have made $2.', |
74 | 75 | 'securepoll-blocked' => 'Sorry, you cannot vote in this election if you are currently blocked from editing.', |
| 76 | + 'securepoll-bot' => 'Sorry, accounts with the bot flag are not allowed to vote in this election.', |
75 | 77 | 'securepoll-not-in-group' => 'Only members of the "$1" group can vote in this election.', |
76 | 78 | 'securepoll-not-in-list' => 'Sorry, you are not in the predetermined list of users authorised to vote in this election.', |
77 | 79 | |
Index: trunk/extensions/SecurePoll/voterList.php |
— | — | @@ -1,54 +1,42 @@ |
2 | 2 | <?php |
3 | 3 | $IP = getenv( 'MW_INSTALL_PATH' ); |
4 | | -if ( !$IP ) { |
5 | | - exit; |
| 4 | +if ( strval( $IP ) === '' ) { |
| 5 | + $IP = dirname( __FILE__ ).'/../..'; |
6 | 6 | } |
7 | | -require_once( $IP . '/maintenance/commandLine.inc' ); |
| 7 | +if ( !file_exists( "$IP/includes/WebStart.php" ) ) { |
| 8 | + $IP .= '/phase3'; |
| 9 | +} |
8 | 10 | |
| 11 | +$optionsWithArgs = array( 'before', 'edits' ); |
| 12 | +require( $IP . '/maintenance/commandLine.inc' ); |
| 13 | + |
9 | 14 | $dbr = wfGetDB( DB_SLAVE ); |
| 15 | +$dbw = wfGetDB( DB_MASTER ); |
10 | 16 | $fname = 'voterList.php'; |
11 | 17 | $maxUser = $dbr->selectField( 'user', 'MAX(user_id)', false ); |
12 | | -$server = str_replace( 'http://', '', $wgServer ); |
13 | | -$listFile = fopen( "voter-list", "a" ); |
| 18 | +$before = isset( $options['before'] ) ? wfTimestamp( TS_MW, strtotime( $options['before'] ) ) : false; |
| 19 | +$minEdits = isset( $options['edits'] ) ? intval( $options['edits'] ) : false; |
14 | 20 | |
| 21 | +if ( !isset( $args[0] ) ) { |
| 22 | + echo "Usage: php voterList.php [--before=<date>] [--edits=<date>] <name>\n"; |
| 23 | + exit( 1 ); |
| 24 | +} |
| 25 | +$name = $args[0]; |
| 26 | + |
15 | 27 | for ( $user = 1; $user <= $maxUser; $user++ ) { |
16 | | - $oldEdits = $dbr->selectField( |
17 | | - 'revision', |
18 | | - 'COUNT(*)', |
19 | | - array( |
20 | | - 'rev_user' => $user, |
21 | | - "rev_timestamp < '200803010000'" |
22 | | - ), |
23 | | - $fname |
24 | | - ); |
25 | | - $newEdits = $dbr->selectField( |
26 | | - 'revision', |
27 | | - 'COUNT(*)', |
28 | | - array( |
29 | | - 'rev_user' => $user, |
30 | | - "rev_timestamp BETWEEN '200801010000' AND '200805285959'" |
31 | | - ), |
32 | | - $fname |
33 | | - ); |
34 | | - if ( $oldEdits >= 600 && $newEdits >= 50 ) { |
35 | | - $userObj = User::newFromId( $user ); |
36 | | - $props = array(); |
37 | | - if ( $userObj->isAllowed( 'bot' ) ) { |
38 | | - $props[] = 'bot'; |
39 | | - } |
40 | | - $isBlocked = $userObj->isBlocked(); |
41 | | - if ( $userObj->isBlocked() |
42 | | - && $userObj->mBlock->mExpiry == 'infinity' ) |
43 | | - { |
44 | | - $props[] = 'indefblocked'; |
45 | | - } |
46 | | - $props = implode( ',', $props ); |
47 | | - $email = $userObj->getEmail(); |
48 | | - $editCount = $userObj->getEditCount(); |
49 | | - $name = $userObj->getName(); |
| 28 | + $insertRow = array( 'li_name' => $name, 'li_member' => $user ); |
| 29 | + if ( $minEdits === false ) { |
| 30 | + $dbw->insert( 'securepoll_lists', $insertRow, $fname ); |
| 31 | + continue; |
| 32 | + } |
50 | 33 | |
51 | | - fwrite( $listFile, "$wgDBname\t$server\t$name\t" . |
52 | | - "$email\t$editCount\t$props\n" ); |
| 34 | + # Count edits |
| 35 | + $conds = array( 'rev_user' => $user ); |
| 36 | + if ( $before !== false ) { |
| 37 | + $conds[] = 'rev_timestamp < ' . $dbr->addQuotes( $before ); |
53 | 38 | } |
| 39 | + $edits = $dbr->selectField( 'revision', 'COUNT(*)', $conds, $fname ); |
| 40 | + if ( $edits >= $minEdits ) { |
| 41 | + $dbw->insert( 'securepoll_lists', $insertRow, $fname ); |
| 42 | + } |
54 | 43 | } |
55 | | -fclose( $listFile ); |
Index: trunk/extensions/SecurePoll/SecurePoll.php |
— | — | @@ -44,11 +44,6 @@ |
45 | 45 | ### END CONFIGURATON ### |
46 | 46 | |
47 | 47 | |
48 | | - |
49 | | -# Vote admins |
50 | | -$wgAvailableRights[] = 'securepoll'; |
51 | | -$wgGroupPermissions['securepoll']['securepoll'] = true; |
52 | | - |
53 | 48 | // Set up the new special page |
54 | 49 | $dir = dirname( __FILE__ ); |
55 | 50 | $wgExtensionMessagesFiles['SecurePoll'] = "$dir/SecurePoll.i18n.php"; |
— | — | @@ -56,7 +51,6 @@ |
57 | 52 | |
58 | 53 | $wgAutoloadClasses['SecurePollPage'] = "$dir/SecurePoll_body.php"; |
59 | 54 | $wgSpecialPages['SecurePoll'] = 'SecurePollPage'; |
60 | | -$wgExtensionFunctions[] = 'wfSetupSecurePoll'; |
61 | 55 | |
62 | 56 | $wgAutoloadClasses = $wgAutoloadClasses + array( |
63 | 57 | 'SecurePoll_Auth' => "$dir/includes/Auth.php", |
— | — | @@ -87,16 +81,6 @@ |
88 | 82 | |
89 | 83 | $wgAjaxExportList[] = 'wfSecurePollStrike'; |
90 | 84 | |
91 | | -function wfSetupSecurePoll() { |
92 | | - wfSetupSession(); |
93 | | - if ( isset( $_SESSION['bvLang'] ) && !isset( $_REQUEST['uselang'] ) ) { |
94 | | - wfDebug( __METHOD__ . ": Setting user language to {$_SESSION['bvLang']}\n" ); |
95 | | - $_REQUEST['uselang'] = $_SESSION['bvLang']; |
96 | | - global $wgLang; |
97 | | - $wgLang = Language::factory( $_SESSION['bvLang'] ); |
98 | | - } |
99 | | -} |
100 | | - |
101 | 85 | function wfSecurePollStrike( $action, $id, $reason ) { |
102 | 86 | return SecurePoll_ListPage::ajaxStrike( $action, $id, $reason ); |
103 | 87 | } |
Index: trunk/extensions/SecurePoll/includes/Auth.php |
— | — | @@ -55,7 +55,6 @@ |
56 | 56 | } |
57 | 57 | if ( isset( $_SESSION['securepoll_voter'][$election->getId()] ) ) { |
58 | 58 | $voterId = $_SESSION['securepoll_voter'][$election->getId()]; |
59 | | - $voter = SecurePoll_Voter::newFromId( $voterId ); |
60 | 59 | |
61 | 60 | # Perform cookie fraud check |
62 | 61 | $status = $this->autoLogin( $election ); |
— | — | @@ -69,7 +68,8 @@ |
70 | 69 | } |
71 | 70 | |
72 | 71 | # Sanity check election ID |
73 | | - if ( $voter->getElectionId() != $election->getId() ) { |
| 72 | + $voter = SecurePoll_Voter::newFromId( $voterId ); |
| 73 | + if ( !$voter || $voter->getElectionId() != $election->getId() ) { |
74 | 74 | return false; |
75 | 75 | } else { |
76 | 76 | return $voter; |
Index: trunk/extensions/SecurePoll/includes/Election.php |
— | — | @@ -19,6 +19,8 @@ |
20 | 20 | * Minimum number of edits needed to be qualified |
21 | 21 | * not-blocked |
22 | 22 | * True if voters need to not be blocked |
| 23 | + * not-bot |
| 24 | + * True if voters need to not have the bot permission |
23 | 25 | * need-group |
24 | 26 | * The name of an MW group voters need to be in |
25 | 27 | * need-list |
— | — | @@ -158,6 +160,13 @@ |
159 | 161 | $status->fatal( 'securepoll-blocked' ); |
160 | 162 | } |
161 | 163 | |
| 164 | + # Bot |
| 165 | + $notBot = $this->getProperty( 'not-bot' ); |
| 166 | + $isBot = !empty( $props['bot'] ); |
| 167 | + if ( $notBot && $isBot ) { |
| 168 | + $status->fatal( 'securepoll-bot' ); |
| 169 | + } |
| 170 | + |
162 | 171 | # Groups |
163 | 172 | $needGroup = $this->getProperty( 'need-group' ); |
164 | 173 | $groups = isset( $props['groups'] ) ? $props['groups'] : array(); |
— | — | @@ -288,8 +297,7 @@ |
289 | 298 | * @return SecurePoll_Tallier |
290 | 299 | */ |
291 | 300 | function getTallier() { |
292 | | - $type = $this->getProperty( 'tally-type' ); |
293 | | - $tallier = SecurePoll_Tallier::factory( $type, $this ); |
| 301 | + $tallier = SecurePoll_Tallier::factory( $this->tallyType, $this ); |
294 | 302 | if ( !$tallier ) { |
295 | 303 | throw new MWException( 'Invalid tally type' ); |
296 | 304 | } |
Index: trunk/extensions/SecurePoll/includes/VotePage.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | * @param $params array Array of subpage parameters. |
14 | 14 | */ |
15 | 15 | function execute( $params ) { |
16 | | - global $wgOut, $wgRequest; |
| 16 | + global $wgOut, $wgRequest, $wgLang; |
17 | 17 | if ( !count( $params ) ) { |
18 | 18 | $wgOut->addWikiMsg( 'securepoll-too-few-params' ); |
19 | 19 | return; |
— | — | @@ -54,6 +54,14 @@ |
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
| 58 | + if ( $this->election->isFinished() ) { |
| 59 | + $wgOut->addWikiMsg( 'securepoll-finished', |
| 60 | + $wgLang->timeanddate( $this->election->getEndDate() ) , |
| 61 | + $wgLang->date( $this->election->getEndDate() ) , |
| 62 | + $wgLang->time( $this->election->getEndDate() ) ); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
58 | 66 | // Show jump form if necessary |
59 | 67 | if ( $this->election->getProperty( 'jump-url' ) ) { |
60 | 68 | $this->showJumpForm(); |
Index: trunk/extensions/SecurePoll/includes/Page.php |
— | — | @@ -37,5 +37,10 @@ |
38 | 38 | ); |
39 | 39 | $languages = array_unique( $languages ); |
40 | 40 | SecurePoll_Entity::setLanguages( $languages ); |
| 41 | + |
| 42 | + global $wgLang; |
| 43 | + $topLang = reset( $languages ); |
| 44 | + $wgLang = Language::factory( $topLang ); |
| 45 | + wfLoadExtensionMessages( 'SecurePoll', $topLang ); |
41 | 46 | } |
42 | 47 | } |