r89020 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89019‎ | r89020 | r89021 >
Date:07:23, 28 May 2011
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
Add support for detecting number of wikis a user is blocked on, and preventing users from voting if they are blocked on more than a configurable threshold
Modified paths:
  • /trunk/extensions/SecurePoll/SecurePoll.i18n.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/entities/Election.php (modified) (history)
  • /trunk/extensions/SecurePoll/includes/user/Auth.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SecurePoll/SecurePoll.i18n.php
@@ -76,6 +76,7 @@
7777 '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.',
7878 'securepoll-too-new' => 'Sorry, you cannot vote. Your account needs to have been registered before $1 to vote in this election, you registered on $2.',
7979 'securepoll-blocked' => 'Sorry, you cannot vote in this election if you are currently blocked from editing.',
 80+ 'securepoll-blocked-centrally' => 'Sorry, you cannot vote in this election if you are blocked on $1 or more {{PLURAL:$1|wiki|wikis}}.',
8081 'securepoll-bot' => 'Sorry, accounts with the bot flag are not allowed to vote in this election.',
8182 'securepoll-not-in-group' => 'Only members of the "$1" group can vote in this election.',
8283 'securepoll-not-in-list' => 'Sorry, you are not in the predetermined list of users authorised to vote in this election.',
Index: trunk/extensions/SecurePoll/includes/entities/Election.php
@@ -33,6 +33,10 @@
3434 * True if a voter is not allowed to change their vote
3535 * encrypt-type
3636 * The encryption module name
 37+ * not-centrally-blocked
 38+ * True if voters need to not be blocked on more than X projects
 39+ * central-block-threshold
 40+ * Number of blocks across projects that disqualify a user from voting.
3741 *
3842 * See the other module for documentation of the following.
3943 *
@@ -183,6 +187,14 @@
184188 if ( $notBlocked && $isBlocked ) {
185189 $status->fatal( 'securepoll-blocked' );
186190 }
 191+
 192+ # Centrally blocked on more than X projects
 193+ $notCentrallyBlocked = $this->getProperty( 'not-centrally-blocked' );
 194+ $centralBlockCount = isset( $props['central-block-count'] ) ? $props['central-block-count'] : 0;
 195+ $centralBlockThreshold = $this->getProperty( 'central-block-threshold', 1 );
 196+ if ( $centralBlockCount >= $centralBlockThreshold ) {
 197+ $status->fatal( 'securepoll-blocked-centrally', $centralBlockThreshold );
 198+ }
187199
188200 # Bot
189201 $notBot = $this->getProperty( 'not-bot' );
@@ -212,6 +224,7 @@
213225 $status = Status::newFatal( 'securepoll-custom-unqualified', $errorMsg );
214226 }
215227 }
 228+
216229 return $status;
217230 }
218231
Index: trunk/extensions/SecurePoll/includes/user/Auth.php
@@ -209,6 +209,7 @@
210210 'properties' => array(
211211 'wiki' => wfWikiID(),
212212 'blocked' => $user->isBlocked(),
 213+ 'central-block-count' => $this->getCentralBlockCount( $user ),
213214 'edit-count' => $user->getEditCount(),
214215 'bot' => $user->isAllowed( 'bot' ),
215216 'language' => $user->getOption( 'language' ),
@@ -217,6 +218,7 @@
218219 'registration' => $user->getRegistration(),
219220 )
220221 );
 222+
221223 wfRunHooks( 'SecurePoll_GetUserParams', array( $this, $user, &$params ) );
222224 return $params;
223225 }
@@ -240,6 +242,30 @@
241243 }
242244 return $lists;
243245 }
 246+
 247+ /**
 248+ * Checks how many central wikis the user is blocked on
 249+ * @param $user User
 250+ * @return Integer the number of wikis the user is blocked on.
 251+ */
 252+ function getCentralBlockCount( $user ) {
 253+ if ( ! class_exists( 'CentralAuthUser' ) ) {
 254+ return 0;
 255+ }
 256+
 257+ $centralUser = new CentralAuthUser( $user );
 258+
 259+ $attached = $centralUser->queryAttached();
 260+ $blockCount = 0;
 261+
 262+ foreach( $attached as $wiki => $data ) {
 263+ if ( $data['blocked'] ) {
 264+ $blockCount++;
 265+ }
 266+ }
 267+
 268+ return $blockCount;
 269+ }
244270 }
245271
246272 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r89023Merge r89020werdna07:49, 28 May 2011
r89052Followup r89020: Run numbers in this function through $wgLang->formatNum()raymond18:05, 28 May 2011
r104360Follow-up r89020 - the election option to enable checking for blocks on other...happy-melon20:10, 27 November 2011

Comments

#Comment by Happy-melon (talk | contribs)   18:49, 27 November 2011

$notCentrallyBlocked (from the 'not-centrally-blocked' option) is never actually used. This is causing the feature to be enabled by default (and be impossible to turn off cleanly!), which is causing problems for the 2011 enwiki ArbCom election, where this feature should not be in place but actually is.

Status & tagging log