added method for votersto revoke their vote.

This commit is contained in:
Thomas Gries 2012-03-12 23:56:59 +00:00
parent 3efd345740
commit 632fd5befc
Notes: Thomas Gries 2012-03-12 23:56:59 +00:00
4 changed files with 78 additions and 35 deletions

View file

@ -23,6 +23,14 @@
font-size: 0.9em;
}
.ajaxpoll .ajaxpoll-hover-vote {
background: cyan;
}
.ajaxpoll .ajaxpoll-hover-revoke {
background: gold;
}
.ajaxpoll .ajaxpoll-answer-vote {
border: 1px solid #CCC;
width: 100%;

View file

@ -24,6 +24,8 @@ $messages['en'] = array(
'ajaxpoll-info' => 'There {{PLURAL:$1|was one vote|were $1 votes}} since the poll was created on $2.',
'ajaxpoll-submitting' => 'Please wait, submitting your vote.',
'ajaxpoll-vote-permission' => 'You are not entitled to vote.',
'ajaxpoll-revoke-vote' => 'I want to revoke my vote',
'ajaxpoll-vote-revoked' => 'You succesfully revoked your vote.',
'right-ajaxpoll-vote' => 'Can vote in AJAX-based polls',
);

View file

@ -19,7 +19,7 @@
* @author Jack Phoenix <jack@countervandalism.net>
* @author Thomas Gries
* @maintainer Thomas Gries
* @version 1.67
* @version 1.68
* @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation
*/
@ -31,7 +31,7 @@ if( !defined( 'MEDIAWIKI' ) ) {
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'AJAX Poll',
'version' => '1.67 20120312',
'version' => '1.68 20120313',
'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' ),
'descriptionmsg' => 'ajaxpoll-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll',

View file

@ -165,11 +165,13 @@ class AJAXPoll {
return AJAXPoll::buildHTML( $id, $user );
}
if ( $answer != 0 ) {
$answer = ++$answer;
$q = $dbw->select(
'poll_vote',
'COUNT(*) AS c',
'COUNT(*) AS count',
array(
'poll_id' => $id,
'poll_user' => $user
@ -178,7 +180,7 @@ class AJAXPoll {
);
$row = $dbw->fetchRow( $q );
if ( $row['c'] > 0 ) {
if ( $row['count'] > 0 ) {
$updateQuery = $dbw->update(
'poll_vote',
@ -188,7 +190,7 @@ class AJAXPoll {
),
array(
'poll_id' => $id,
'poll_user' => $user
'poll_user' => $user,
),
__METHOD__
);
@ -213,6 +215,21 @@ class AJAXPoll {
}
} else { // revoking a vote
$deleteQuery = $dbw->delete(
'poll_vote',
array(
'poll_id' => $id,
'poll_user' => $user,
),
__METHOD__
);
$dbw->commit();
$pollContainerText = ( $deleteQuery ) ? 'ajaxpoll-vote-revoked' : 'ajaxpoll-vote-error';
}
return AJAXPoll::buildHTML( $id, $user, '', $pollContainerText );
}
@ -301,7 +318,12 @@ function mout(x){
// Different message depending on if the user has already voted or not, or is entitled to vote
if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
$message = ( isset( $row[0] ) ) ? $ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' );
if ( isset( $row[0] ) ) {
$message = $ourLastVoteDate;
$lines[] = wfMsg( 'ajaxpoll-revoke-vote' );
} else {
$message = wfMsg( 'ajaxpoll-no-vote' );
}
} else {
$message = wfMsg( 'ajaxpoll-vote-permission' );
}
@ -313,6 +335,9 @@ function mout(x){
'" id="ajaxpoll-answer-id-' . $id . '"><input type="hidden" name="ajaxpoll-post-id" value="' . $id . '" />';
for ( $i = 1; $i < count( $lines ); $i++ ) {
$vote = ( $i != count( $lines ) - 1 );
$voteValue = ( $vote ) ? $i : 0;
$ans_no = $i - 1;
if ( $amountOfVotes == 0 ) {
@ -330,7 +355,7 @@ function mout(x){
if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
if ( $wgUseAjax ) {
$submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $i . "\"], $(\"#ajaxpoll-container-" . $id . "\")[0]);";
$submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $voteValue . "\"], $(\"#ajaxpoll-container-" . $id . "\")[0]);";
} else {
$submitJS = "$(\"#ajaxpoll-answer-id-" . $id . "\").submit();";
}
@ -338,11 +363,20 @@ function mout(x){
// HTML output has to be on one line thanks to a MediaWiki bug
// @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319
if ( $vote ) {
$ret .= "
<div id='ajaxpoll-answer-" . $ans_no . "' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $ans_no . "' onclick='$(\"#ajaxpoll-ajax-" . $id . "\").html(\"" . wfMsg( 'ajaxpoll-submitting' ) . "\");$(\"#ajaxpoll-ajax-" . $id . "\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true); " . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-" . $ans_no . "' name='ajaxpoll-post-answer-" . $ans_no . "' value='" . $i . "'" . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
<div id='ajaxpoll-answer-" . $ans_no . "' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $ans_no . "' onmouseover='$(this).addClass(\"ajaxpoll-hover-vote\");' onmouseout='$(this).removeClass(\"ajaxpoll-hover-vote\");' onclick='$(\"#ajaxpoll-ajax-" . $id . "\").html(\"" . wfMsg( 'ajaxpoll-submitting' ) . "\");$(\"#ajaxpoll-ajax-" . $id . "\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true); " . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-" . $ans_no . "' name='ajaxpoll-post-answer-" . $ans_no . "' value='" . $voteValue . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
"</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' ajaxpoll-our-vote' : '' ) ."' onmouseover='mover(this)' onmouseout='mout(this);'><span title='" . wfMsg( 'ajaxpoll-percent-votes', sprintf( $percent ) ) . "'>" . ( ( isset( $poll_result ) && !empty( $poll_result[$i + 1] ) ) ? $poll_result[$i + 1] : 0 ) . "</span><div style='width: " . $percent . "%;" . ( $percent == 0 ? ' border:0;' : '' ) . "'></div></div>
</div>
";
} else {
$ret .= "
<div id='ajaxpoll-answer-" . $ans_no . "' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $ans_no . "' onmouseover='$(this).addClass(\"ajaxpoll-hover-revoke\");' onmouseout='$(this).removeClass(\"ajaxpoll-hover-revoke\");' onclick='$(\"#ajaxpoll-ajax-" . $id . "\").html(\"" . wfMsg( 'ajaxpoll-submitting' ) . "\");$(\"#ajaxpoll-ajax-" . $id . "\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true); " . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-" . $ans_no . "' name='ajaxpoll-post-answer-" . $ans_no . "' value='" . $voteValue . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
"</label></div>
</div>
";
}
} else {
@ -351,7 +385,6 @@ function mout(x){
"</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' ajaxpoll-our-vote' : '' ) ."' onmouseover='mover(this)' onmouseout='mout(this);'><span title='" . wfMsg( 'ajaxpoll-percent-votes', sprintf( $percent ) ) . "'>" . ( ( isset( $poll_result ) && !empty( $poll_result[$i + 1] ) ) ? $poll_result[$i + 1] : 0 ) . "</span><div style='width: " . $percent . "%;" . ( $percent == 0 ? ' border:0;' : '' ) . "'></div></div>
</div>
";
}
}