Index: trunk/extensions/AJAXPoll/AJAXPoll.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @author Jack Phoenix <jack@countervandalism.net> |
21 | 21 | * @author Thomas Gries |
22 | 22 | * @maintainer Thomas Gries |
23 | | - * @version 1.67 |
| 23 | + * @version 1.68 |
24 | 24 | * @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation |
25 | 25 | */ |
26 | 26 | |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | $wgExtensionCredits['parserhook'][] = array( |
33 | 33 | 'path' => __FILE__, |
34 | 34 | 'name' => 'AJAX Poll', |
35 | | - 'version' => '1.67 20120312', |
| 35 | + 'version' => '1.68 20120313', |
36 | 36 | 'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' ), |
37 | 37 | 'descriptionmsg' => 'ajaxpoll-desc', |
38 | 38 | 'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll', |
Index: trunk/extensions/AJAXPoll/AJAXPoll.css |
— | — | @@ -23,6 +23,14 @@ |
24 | 24 | font-size: 0.9em; |
25 | 25 | } |
26 | 26 | |
| 27 | +.ajaxpoll .ajaxpoll-hover-vote { |
| 28 | + background: cyan; |
| 29 | +} |
| 30 | + |
| 31 | +.ajaxpoll .ajaxpoll-hover-revoke { |
| 32 | + background: gold; |
| 33 | +} |
| 34 | + |
27 | 35 | .ajaxpoll .ajaxpoll-answer-vote { |
28 | 36 | border: 1px solid #CCC; |
29 | 37 | width: 100%; |
Index: trunk/extensions/AJAXPoll/AJAXPoll_body.php |
— | — | @@ -165,51 +165,68 @@ |
166 | 166 | return AJAXPoll::buildHTML( $id, $user ); |
167 | 167 | } |
168 | 168 | |
169 | | - $answer = ++$answer; |
| 169 | + if ( $answer != 0 ) { |
170 | 170 | |
171 | | - $q = $dbw->select( |
172 | | - 'poll_vote', |
173 | | - 'COUNT(*) AS c', |
174 | | - array( |
175 | | - 'poll_id' => $id, |
176 | | - 'poll_user' => $user |
177 | | - ), |
178 | | - __METHOD__ |
179 | | - ); |
180 | | - $row = $dbw->fetchRow( $q ); |
| 171 | + $answer = ++$answer; |
181 | 172 | |
182 | | - if ( $row['c'] > 0 ) { |
183 | | - |
184 | | - $updateQuery = $dbw->update( |
| 173 | + $q = $dbw->select( |
185 | 174 | 'poll_vote', |
| 175 | + 'COUNT(*) AS count', |
186 | 176 | array( |
187 | | - 'poll_answer' => $answer, |
188 | | - 'poll_date' => wfTimestampNow() |
189 | | - ), |
190 | | - array( |
191 | 177 | 'poll_id' => $id, |
192 | 178 | 'poll_user' => $user |
193 | 179 | ), |
194 | 180 | __METHOD__ |
195 | 181 | ); |
196 | | - $dbw->commit(); |
197 | | - $pollContainerText = ( $updateQuery ) ? 'ajaxpoll-vote-update' : 'ajaxpoll-vote-error'; |
| 182 | + $row = $dbw->fetchRow( $q ); |
198 | 183 | |
199 | | - } else { |
| 184 | + if ( $row['count'] > 0 ) { |
200 | 185 | |
201 | | - $insertQuery = $dbw->insert( |
| 186 | + $updateQuery = $dbw->update( |
| 187 | + 'poll_vote', |
| 188 | + array( |
| 189 | + 'poll_answer' => $answer, |
| 190 | + 'poll_date' => wfTimestampNow() |
| 191 | + ), |
| 192 | + array( |
| 193 | + 'poll_id' => $id, |
| 194 | + 'poll_user' => $user, |
| 195 | + ), |
| 196 | + __METHOD__ |
| 197 | + ); |
| 198 | + $dbw->commit(); |
| 199 | + $pollContainerText = ( $updateQuery ) ? 'ajaxpoll-vote-update' : 'ajaxpoll-vote-error'; |
| 200 | + |
| 201 | + } else { |
| 202 | + |
| 203 | + $insertQuery = $dbw->insert( |
| 204 | + 'poll_vote', |
| 205 | + array( |
| 206 | + 'poll_id' => $id, |
| 207 | + 'poll_user' => $user, |
| 208 | + 'poll_ip' => wfGetIP(), |
| 209 | + 'poll_answer' => $answer, |
| 210 | + 'poll_date' => wfTimestampNow() |
| 211 | + ), |
| 212 | + __METHOD__ |
| 213 | + ); |
| 214 | + $dbw->commit(); |
| 215 | + $pollContainerText = ( $insertQuery ) ? 'ajaxpoll-vote-add' : 'ajaxpoll-vote-error'; |
| 216 | + |
| 217 | + } |
| 218 | + |
| 219 | + } else { // revoking a vote |
| 220 | + |
| 221 | + $deleteQuery = $dbw->delete( |
202 | 222 | 'poll_vote', |
203 | 223 | array( |
204 | 224 | 'poll_id' => $id, |
205 | 225 | 'poll_user' => $user, |
206 | | - 'poll_ip' => wfGetIP(), |
207 | | - 'poll_answer' => $answer, |
208 | | - 'poll_date' => wfTimestampNow() |
209 | 226 | ), |
210 | 227 | __METHOD__ |
211 | 228 | ); |
212 | 229 | $dbw->commit(); |
213 | | - $pollContainerText = ( $insertQuery ) ? 'ajaxpoll-vote-add' : 'ajaxpoll-vote-error'; |
| 230 | + $pollContainerText = ( $deleteQuery ) ? 'ajaxpoll-vote-revoked' : 'ajaxpoll-vote-error'; |
214 | 231 | |
215 | 232 | } |
216 | 233 | |
— | — | @@ -301,7 +318,12 @@ |
302 | 319 | // Different message depending on if the user has already voted or not, or is entitled to vote |
303 | 320 | |
304 | 321 | if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) { |
305 | | - $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' ); |
| 322 | + if ( isset( $row[0] ) ) { |
| 323 | + $message = $ourLastVoteDate; |
| 324 | + $lines[] = wfMsg( 'ajaxpoll-revoke-vote' ); |
| 325 | + } else { |
| 326 | + $message = wfMsg( 'ajaxpoll-no-vote' ); |
| 327 | + } |
306 | 328 | } else { |
307 | 329 | $message = wfMsg( 'ajaxpoll-vote-permission' ); |
308 | 330 | } |
— | — | @@ -313,6 +335,9 @@ |
314 | 336 | '" id="ajaxpoll-answer-id-' . $id . '"><input type="hidden" name="ajaxpoll-post-id" value="' . $id . '" />'; |
315 | 337 | |
316 | 338 | for ( $i = 1; $i < count( $lines ); $i++ ) { |
| 339 | + |
| 340 | + $vote = ( $i != count( $lines ) - 1 ); |
| 341 | + $voteValue = ( $vote ) ? $i : 0; |
317 | 342 | $ans_no = $i - 1; |
318 | 343 | |
319 | 344 | if ( $amountOfVotes == 0 ) { |
— | — | @@ -330,19 +355,28 @@ |
331 | 356 | if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) { |
332 | 357 | |
333 | 358 | if ( $wgUseAjax ) { |
334 | | - $submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $i . "\"], $(\"#ajaxpoll-container-" . $id . "\")[0]);"; |
| 359 | + $submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $voteValue . "\"], $(\"#ajaxpoll-container-" . $id . "\")[0]);"; |
335 | 360 | } else { |
336 | 361 | $submitJS = "$(\"#ajaxpoll-answer-id-" . $id . "\").submit();"; |
337 | 362 | } |
338 | 363 | |
339 | 364 | |
340 | | - // HTML output has to be on one line thanks to a MediaWiki bug |
341 | | - // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319 |
342 | | - $ret .= " |
343 | | -<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] ) . |
| 365 | + // HTML output has to be on one line thanks to a MediaWiki bug |
| 366 | + // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319 |
| 367 | + |
| 368 | + if ( $vote ) { |
| 369 | + $ret .= " |
| 370 | +<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] ) . |
344 | 371 | "</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> |
345 | 372 | </div> |
346 | 373 | "; |
| 374 | + } else { |
| 375 | + $ret .= " |
| 376 | +<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] ) . |
| 377 | +"</label></div> |
| 378 | +</div> |
| 379 | +"; |
| 380 | + } |
347 | 381 | |
348 | 382 | } else { |
349 | 383 | |
— | — | @@ -351,7 +385,6 @@ |
352 | 386 | "</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> |
353 | 387 | </div> |
354 | 388 | "; |
355 | | - |
356 | 389 | } |
357 | 390 | |
358 | 391 | } |
Index: trunk/extensions/AJAXPoll/AJAXPoll.i18n.php |
— | — | @@ -24,6 +24,8 @@ |
25 | 25 | 'ajaxpoll-info' => 'There {{PLURAL:$1|was one vote|were $1 votes}} since the poll was created on $2.', |
26 | 26 | 'ajaxpoll-submitting' => 'Please wait, submitting your vote.', |
27 | 27 | 'ajaxpoll-vote-permission' => 'You are not entitled to vote.', |
| 28 | + 'ajaxpoll-revoke-vote' => 'I want to revoke my vote', |
| 29 | + 'ajaxpoll-vote-revoked' => 'You succesfully revoked your vote.', |
28 | 30 | |
29 | 31 | 'right-ajaxpoll-vote' => 'Can vote in AJAX-based polls', |
30 | 32 | ); |