http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89020
Revision: 89020
Author: werdna
Date: 2011-05-28 07:23:40 +0000 (Sat, 28 May 2011)
Log Message:
-----------
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
trunk/extensions/SecurePoll/includes/entities/Election.php
trunk/extensions/SecurePoll/includes/user/Auth.php
Modified: trunk/extensions/SecurePoll/SecurePoll.i18n.php
===================================================================
--- trunk/extensions/SecurePoll/SecurePoll.i18n.php 2011-05-28 04:14:01 UTC
(rev 89019)
+++ trunk/extensions/SecurePoll/SecurePoll.i18n.php 2011-05-28 07:23:40 UTC
(rev 89020)
@@ -76,6 +76,7 @@
'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.',
'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.',
'securepoll-blocked' => 'Sorry, you cannot vote in this election if you
are currently blocked from editing.',
+ 'securepoll-blocked-centrally' => 'Sorry, you cannot vote in this
election if you are blocked on $1 or more {{PLURAL:$1|wiki|wikis}}.',
'securepoll-bot' => 'Sorry, accounts with the bot flag are not allowed
to vote in this election.',
'securepoll-not-in-group' => 'Only members of the "$1" group can vote
in this election.',
'securepoll-not-in-list' => 'Sorry, you are not in the predetermined
list of users authorised to vote in this election.',
Modified: trunk/extensions/SecurePoll/includes/entities/Election.php
===================================================================
--- trunk/extensions/SecurePoll/includes/entities/Election.php 2011-05-28
04:14:01 UTC (rev 89019)
+++ trunk/extensions/SecurePoll/includes/entities/Election.php 2011-05-28
07:23:40 UTC (rev 89020)
@@ -33,6 +33,10 @@
* True if a voter is not allowed to change their vote
* encrypt-type
* The encryption module name
+ * not-centrally-blocked
+ * True if voters need to not be blocked on more than X projects
+ * central-block-threshold
+ * Number of blocks across projects that disqualify a user from
voting.
*
* See the other module for documentation of the following.
*
@@ -183,6 +187,14 @@
if ( $notBlocked && $isBlocked ) {
$status->fatal( 'securepoll-blocked' );
}
+
+ # Centrally blocked on more than X projects
+ $notCentrallyBlocked = $this->getProperty(
'not-centrally-blocked' );
+ $centralBlockCount = isset( $props['central-block-count'] ) ?
$props['central-block-count'] : 0;
+ $centralBlockThreshold = $this->getProperty(
'central-block-threshold', 1 );
+ if ( $centralBlockCount >= $centralBlockThreshold ) {
+ $status->fatal( 'securepoll-blocked-centrally',
$centralBlockThreshold );
+ }
# Bot
$notBot = $this->getProperty( 'not-bot' );
@@ -212,6 +224,7 @@
$status = Status::newFatal(
'securepoll-custom-unqualified', $errorMsg );
}
}
+
return $status;
}
Modified: trunk/extensions/SecurePoll/includes/user/Auth.php
===================================================================
--- trunk/extensions/SecurePoll/includes/user/Auth.php 2011-05-28 04:14:01 UTC
(rev 89019)
+++ trunk/extensions/SecurePoll/includes/user/Auth.php 2011-05-28 07:23:40 UTC
(rev 89020)
@@ -209,6 +209,7 @@
'properties' => array(
'wiki' => wfWikiID(),
'blocked' => $user->isBlocked(),
+ 'central-block-count' =>
$this->getCentralBlockCount( $user ),
'edit-count' => $user->getEditCount(),
'bot' => $user->isAllowed( 'bot' ),
'language' => $user->getOption( 'language' ),
@@ -217,6 +218,7 @@
'registration' => $user->getRegistration(),
)
);
+
wfRunHooks( 'SecurePoll_GetUserParams', array( $this, $user,
&$params ) );
return $params;
}
@@ -240,6 +242,30 @@
}
return $lists;
}
+
+ /**
+ * Checks how many central wikis the user is blocked on
+ * @param $user User
+ * @return Integer the number of wikis the user is blocked on.
+ */
+ function getCentralBlockCount( $user ) {
+ if ( ! class_exists( 'CentralAuthUser' ) ) {
+ return 0;
+ }
+
+ $centralUser = new CentralAuthUser( $user );
+
+ $attached = $centralUser->queryAttached();
+ $blockCount = 0;
+
+ foreach( $attached as $wiki => $data ) {
+ if ( $data['blocked'] ) {
+ $blockCount++;
+ }
+ }
+
+ return $blockCount;
+ }
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs