Jack Phoenix has submitted this change and it was merged. Change subject: Version 3.3.2: Add new 'pollny-vote' user right, required to vote in polls ......................................................................
Version 3.3.2: Add new 'pollny-vote' user right, required to vote in polls For backwards compatibility, the right is granted to all users (*) by default by sysadmins can change this if and when they want to restrict voting. Requested by MediaWiki.org user BradLeeBH: https://www.mediawiki.org/w/index.php?title=Extension_talk:PollNY&oldid=1871214#Request:_Prevent_anonymous_users_from_voting_on_polls.3F Change-Id: I6f79e3893db804aafe32e666b0e86f1f1d84f8d5 --- M ApiPollNY.php M PollNY.php M PollNYHooks.php M PollPage.php M i18n/en.json M i18n/fi.json 6 files changed, 29 insertions(+), 7 deletions(-) Approvals: Jack Phoenix: Looks good to me, approved Objections: Siebrand: There's a problem with this change, please improve diff --git a/ApiPollNY.php b/ApiPollNY.php index 713be6d..ff701c1 100644 --- a/ApiPollNY.php +++ b/ApiPollNY.php @@ -203,7 +203,15 @@ } function vote( $pollID, $choiceID ) { - if ( !$this->poll->userVoted( $this->getUser()->getName(), $pollID ) ) { + $user = $this->getUser(); + if ( !$user->isAllowed( 'pollny-vote' ) ) { + return 'error'; + } + if ( + !$this->poll->userVoted( $user->getName(), $pollID ) && + $user->isAllowed( 'pollny-vote' ) + ) + { $this->poll->addPollVote( $pollID, $choiceID ); } diff --git a/PollNY.php b/PollNY.php index e502629..3e93426 100644 --- a/PollNY.php +++ b/PollNY.php @@ -17,7 +17,7 @@ $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'PollNY', - 'version' => '3.3.1', + 'version' => '3.3.2', 'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ), 'descriptionmsg' => 'poll-desc', 'url' => 'https://www.mediawiki.org/wiki/Extension:PollNY' @@ -37,6 +37,10 @@ $wgCreatePollThresholds = array(); # End configuration values +// New user right for voting in polls +$wgAvailableRights[] = 'pollny-vote'; +$wgGroupPermissions['*']['pollny-vote'] = true; + // New user right for administering polls $wgAvailableRights[] = 'polladmin'; $wgGroupPermissions['sysop']['polladmin'] = true; diff --git a/PollNYHooks.php b/PollNYHooks.php index 8855168..e997d78 100644 --- a/PollNYHooks.php +++ b/PollNYHooks.php @@ -229,9 +229,11 @@ $output .= "\t\t<div class=\"poll-image\">{$poll_image_tag}</div>\n"; } - // If the user hasn't voted for this poll yet and the poll is open - // for votes, display the question and let the user vote - if( + // If the user hasn't voted for this poll yet, they're allowed + // to do so and the poll is open for votes, display the question + // and let the user vote + if ( + $wgUser->isAllowed( 'pollny-vote' ) && !$p->userVoted( $wgUser->getName(), $poll_info['id'] ) && $poll_info['status'] == 1 ) diff --git a/PollPage.php b/PollPage.php index 77cb836..3ecedf8 100644 --- a/PollPage.php +++ b/PollPage.php @@ -189,7 +189,12 @@ } // Display question and let user vote - if( !$p->userVoted( $wgUser->getName(), $poll_info['id'] ) && $poll_info['status'] == 1 ) { + if ( + $wgUser->isAllowed( 'pollny-vote' ) && + !$p->userVoted( $wgUser->getName(), $poll_info['id'] ) && + $poll_info['status'] == 1 + ) + { $output .= '<div id="loading-poll">' . wfMessage( 'poll-js-loading' )->text() . '</div>' . "\n"; $output .= '<div id="poll-display" style="display:none;">' . "\n"; $output .= '<form name="poll"><input type="hidden" id="poll_id" name="poll_id" value="' . $poll_info['id'] . '"/>' . "\n"; @@ -256,7 +261,6 @@ } $output .= '</div>'; } - } else { $show_results = true; // Display message if poll has been closed for voting diff --git a/i18n/en.json b/i18n/en.json index 61fa474..f50bfd1 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -91,6 +91,8 @@ "poll-time-minutes": "{{PLURAL:$1|one minute|$1 minutes}}", "poll-time-seconds": "{{PLURAL:$1|one second|$1 seconds}}", "specialpages-group-poll": "Polls", + "action-pollny-vote": "vote in polls", + "right-pollny-vote": "Vote in polls", "action-polladmin": "administer polls", "right-polladmin": "Administer polls", "apihelp-pollny-description": "PollNY API - includes both user and admin functions.", diff --git a/i18n/fi.json b/i18n/fi.json index 7815306..09c463b 100644 --- a/i18n/fi.json +++ b/i18n/fi.json @@ -88,6 +88,8 @@ "poll-time-minutes": "{{PLURAL:$1|yksi minuutti|$1 minuuttia}}", "poll-time-seconds": "{{PLURAL:$1|yksi sekunti|$1 sekuntia}}", "specialpages-group-poll": "Äänestykset", + "action-pollny-vote": "äänestää äänestyksissä", + "right-pollny-vote": "Äänestää äänestyksissä", "action-polladmin": "hallinnoida äänestyksiä", "right-polladmin": "Hallinnoida äänestyksiä" } -- To view, visit https://gerrit.wikimedia.org/r/235892 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6f79e3893db804aafe32e666b0e86f1f1d84f8d5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PollNY Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <[email protected]> Gerrit-Reviewer: Jack Phoenix <[email protected]> Gerrit-Reviewer: Siebrand <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
