r49310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49309‎ | r49310 | r49311 >
Date:12:02, 8 April 2009
Author:tstarling
Status:deferred
Tags:
Comment:
* Rewrote voterList.php
* Fixed start/finish handling in VotePage
* Added not-bot qualification
* Removed useless securepoll group/right
* Fixed user language transfer from source wiki
Modified paths:
  • /trunk/extensions/SecurePoll/SecurePoll.i18n.php (modified) (history)
  • /trunk/extensions/SecurePoll/SecurePoll.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/Auth.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/Election.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/Page.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/VotePage.php (modified) (history)
  • /trunk/extensions/SecurePoll/voterList.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SecurePoll/SecurePoll.i18n.php
@@ -24,6 +24,7 @@
2525 'securepoll-welcome' => '<strong>Welcome $1!</strong>',
2626 'securepoll-not-started' => 'This election has not yet started.
2727 It is scheduled to start on $2 at $3.',
 28+ 'securepoll-finished' => 'This election has finished, you can no longer vote.',
2829 'securepoll-not-qualified' => 'You are not qualified to vote in this election: $1',
2930 'securepoll-change-disallowed' => 'You have voted in this election before.
3031 Sorry, you may not vote again.',
@@ -71,6 +72,7 @@
7273 'securepoll-not-logged-in' => 'You must log in to vote in this election',
7374 '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.',
7475 '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.',
7577 'securepoll-not-in-group' => 'Only members of the "$1" group can vote in this election.',
7678 'securepoll-not-in-list' => 'Sorry, you are not in the predetermined list of users authorised to vote in this election.',
7779
Index: trunk/extensions/SecurePoll/voterList.php
@@ -1,54 +1,42 @@
22 <?php
33 $IP = getenv( 'MW_INSTALL_PATH' );
4 -if ( !$IP ) {
5 - exit;
 4+if ( strval( $IP ) === '' ) {
 5+ $IP = dirname( __FILE__ ).'/../..';
66 }
7 -require_once( $IP . '/maintenance/commandLine.inc' );
 7+if ( !file_exists( "$IP/includes/WebStart.php" ) ) {
 8+ $IP .= '/phase3';
 9+}
810
 11+$optionsWithArgs = array( 'before', 'edits' );
 12+require( $IP . '/maintenance/commandLine.inc' );
 13+
914 $dbr = wfGetDB( DB_SLAVE );
 15+$dbw = wfGetDB( DB_MASTER );
1016 $fname = 'voterList.php';
1117 $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;
1420
 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+
1527 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+ }
5033
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 );
5338 }
 39+ $edits = $dbr->selectField( 'revision', 'COUNT(*)', $conds, $fname );
 40+ if ( $edits >= $minEdits ) {
 41+ $dbw->insert( 'securepoll_lists', $insertRow, $fname );
 42+ }
5443 }
55 -fclose( $listFile );
Index: trunk/extensions/SecurePoll/SecurePoll.php
@@ -44,11 +44,6 @@
4545 ### END CONFIGURATON ###
4646
4747
48 -
49 -# Vote admins
50 -$wgAvailableRights[] = 'securepoll';
51 -$wgGroupPermissions['securepoll']['securepoll'] = true;
52 -
5348 // Set up the new special page
5449 $dir = dirname( __FILE__ );
5550 $wgExtensionMessagesFiles['SecurePoll'] = "$dir/SecurePoll.i18n.php";
@@ -56,7 +51,6 @@
5752
5853 $wgAutoloadClasses['SecurePollPage'] = "$dir/SecurePoll_body.php";
5954 $wgSpecialPages['SecurePoll'] = 'SecurePollPage';
60 -$wgExtensionFunctions[] = 'wfSetupSecurePoll';
6155
6256 $wgAutoloadClasses = $wgAutoloadClasses + array(
6357 'SecurePoll_Auth' => "$dir/includes/Auth.php",
@@ -87,16 +81,6 @@
8882
8983 $wgAjaxExportList[] = 'wfSecurePollStrike';
9084
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 -
10185 function wfSecurePollStrike( $action, $id, $reason ) {
10286 return SecurePoll_ListPage::ajaxStrike( $action, $id, $reason );
10387 }
Index: trunk/extensions/SecurePoll/includes/Auth.php
@@ -55,7 +55,6 @@
5656 }
5757 if ( isset( $_SESSION['securepoll_voter'][$election->getId()] ) ) {
5858 $voterId = $_SESSION['securepoll_voter'][$election->getId()];
59 - $voter = SecurePoll_Voter::newFromId( $voterId );
6059
6160 # Perform cookie fraud check
6261 $status = $this->autoLogin( $election );
@@ -69,7 +68,8 @@
7069 }
7170
7271 # Sanity check election ID
73 - if ( $voter->getElectionId() != $election->getId() ) {
 72+ $voter = SecurePoll_Voter::newFromId( $voterId );
 73+ if ( !$voter || $voter->getElectionId() != $election->getId() ) {
7474 return false;
7575 } else {
7676 return $voter;
Index: trunk/extensions/SecurePoll/includes/Election.php
@@ -19,6 +19,8 @@
2020 * Minimum number of edits needed to be qualified
2121 * not-blocked
2222 * True if voters need to not be blocked
 23+ * not-bot
 24+ * True if voters need to not have the bot permission
2325 * need-group
2426 * The name of an MW group voters need to be in
2527 * need-list
@@ -158,6 +160,13 @@
159161 $status->fatal( 'securepoll-blocked' );
160162 }
161163
 164+ # Bot
 165+ $notBot = $this->getProperty( 'not-bot' );
 166+ $isBot = !empty( $props['bot'] );
 167+ if ( $notBot && $isBot ) {
 168+ $status->fatal( 'securepoll-bot' );
 169+ }
 170+
162171 # Groups
163172 $needGroup = $this->getProperty( 'need-group' );
164173 $groups = isset( $props['groups'] ) ? $props['groups'] : array();
@@ -288,8 +297,7 @@
289298 * @return SecurePoll_Tallier
290299 */
291300 function getTallier() {
292 - $type = $this->getProperty( 'tally-type' );
293 - $tallier = SecurePoll_Tallier::factory( $type, $this );
 301+ $tallier = SecurePoll_Tallier::factory( $this->tallyType, $this );
294302 if ( !$tallier ) {
295303 throw new MWException( 'Invalid tally type' );
296304 }
Index: trunk/extensions/SecurePoll/includes/VotePage.php
@@ -12,7 +12,7 @@
1313 * @param $params array Array of subpage parameters.
1414 */
1515 function execute( $params ) {
16 - global $wgOut, $wgRequest;
 16+ global $wgOut, $wgRequest, $wgLang;
1717 if ( !count( $params ) ) {
1818 $wgOut->addWikiMsg( 'securepoll-too-few-params' );
1919 return;
@@ -54,6 +54,14 @@
5555 return;
5656 }
5757
 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+
5866 // Show jump form if necessary
5967 if ( $this->election->getProperty( 'jump-url' ) ) {
6068 $this->showJumpForm();
Index: trunk/extensions/SecurePoll/includes/Page.php
@@ -37,5 +37,10 @@
3838 );
3939 $languages = array_unique( $languages );
4040 SecurePoll_Entity::setLanguages( $languages );
 41+
 42+ global $wgLang;
 43+ $topLang = reset( $languages );
 44+ $wgLang = Language::factory( $topLang );
 45+ wfLoadExtensionMessages( 'SecurePoll', $topLang );
4146 }
4247 }

Status & tagging log