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.61 |
| 23 | + * @version 1.62 |
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.61 20120309', |
| 35 | + 'version' => '1.62 20120310', |
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', |
— | — | @@ -44,6 +44,14 @@ |
45 | 45 | $wgAjaxExportList[] = 'AJAXPoll::submitVote'; |
46 | 46 | $wgHooks['ParserFirstCallInit'][] = 'AJAXPoll::AJAXPollParserInit'; |
47 | 47 | |
| 48 | +# new user rights |
| 49 | +$wgAvailableRights[] = 'ajaxpoll-vote'; |
| 50 | + |
| 51 | +# default: everyone can vote |
| 52 | +$wgGroupPermissions['*']['ajaxpoll-vote'] = true; |
| 53 | +# if you want only users to vote use |
| 54 | +# $wgGroupPermissions['user']['ajaxpoll-vote'] = true; |
| 55 | + |
48 | 56 | // Parameter to enable the automatic tracking category |
49 | 57 | // for all pages using this parser extension |
50 | 58 | // |
Index: trunk/extensions/AJAXPoll/AJAXPoll_body.php |
— | — | @@ -217,7 +217,7 @@ |
218 | 218 | } |
219 | 219 | |
220 | 220 | private static function buildHTML( $ID, $user, $lines = '', $extra_from_ajax = '' ) { |
221 | | - global $wgTitle, $wgLang, $wgUseAjax; |
| 221 | + global $wgTitle, $wgUser, $wgLang, $wgUseAjax; |
222 | 222 | |
223 | 223 | $dbw = wfGetDB( DB_SLAVE ); |
224 | 224 | |
— | — | @@ -298,7 +298,15 @@ |
299 | 299 | <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>'; |
300 | 300 | |
301 | 301 | // Different message depending on if the user has already voted or not. |
302 | | - $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' ); |
| 302 | + |
| 303 | + // $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' ); |
| 304 | + |
| 305 | + if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) { |
| 306 | + $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' ); |
| 307 | + } else { |
| 308 | + $message = wfMsg( 'ajaxpoll-vote-permission' ); |
| 309 | + } |
| 310 | + |
303 | 311 | $ret .= '<div class="ajaxpoll-misc">' . $message . ' |
304 | 312 | </div>'; |
305 | 313 | |
— | — | @@ -319,21 +327,36 @@ |
320 | 328 | // If AJAX is enabled, as it is by default in modern MWs, we can |
321 | 329 | // just use sajax library function here for that AJAX-y feel. |
322 | 330 | // If not, we'll have to submit the form old-school way... |
323 | | - if ( $wgUseAjax ) { |
324 | | - $submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $ID . "\",\"" . $i . "\"], $(\"#ajaxpoll-container-" . $ID . "\")[0]);"; |
325 | | - } else { |
326 | | - $submitJS = "$(\"#ajaxpoll-answer-id-" . $ID . "\").submit();"; |
327 | | - } |
328 | 331 | |
| 332 | + if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) { |
| 333 | + |
| 334 | + if ( $wgUseAjax ) { |
| 335 | + $submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $ID . "\",\"" . $i . "\"], $(\"#ajaxpoll-container-" . $ID . "\")[0]);"; |
| 336 | + } else { |
| 337 | + $submitJS = "$(\"#ajaxpoll-answer-id-" . $ID . "\").submit();"; |
| 338 | + } |
| 339 | + |
| 340 | + |
329 | 341 | // HTML output has to be on one line thanks to a MediaWiki bug |
330 | 342 | // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319 |
331 | | - $ret .= " |
332 | | -<div id='ajaxpoll-answer-" . $ans_no . "' class='ajaxpoll-answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-answer-radio-" . $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' value='" . $i . "'" . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) . |
| 343 | + $ret .= " |
| 344 | +<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] ) . |
333 | 345 | "</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> |
334 | 346 | </div> |
335 | 347 | "; |
336 | | - } |
337 | 348 | |
| 349 | + } else { |
| 350 | + |
| 351 | + $ret .= " |
| 352 | +<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-vote-permission' ) . "\");$(\"#ajaxpoll-ajax-" . $ID . "\").css(\"display\",\"block\");'><input disabled='disabled' type='radio' id='ajaxpoll-post-answer-" . $ans_no . "' name='ajaxpoll-post-answer-" . $ans_no . "' value='" . $i . "'" . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) . |
| 353 | +"</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> |
| 354 | +</div> |
| 355 | +"; |
| 356 | + |
| 357 | + } |
| 358 | + |
| 359 | + } |
| 360 | + |
338 | 361 | $ret .= '</form>'; |
339 | 362 | |
340 | 363 | // Display information about the poll (creation date, amount of votes) |
Index: trunk/extensions/AJAXPoll/AJAXPoll.i18n.php |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | |
12 | 12 | /** English |
13 | 13 | * @author Dariusz Siedlecki |
| 14 | + * @author Thomas Gries |
14 | 15 | */ |
15 | 16 | $messages['en'] = array( |
16 | 17 | 'ajaxpoll-desc' => 'Allows AJAX-based polls with <tt><poll></tt> tag', |
— | — | @@ -22,6 +23,9 @@ |
23 | 24 | 'ajaxpoll-no-vote' => 'Please vote below.', // http://trac.wikia-code.com/changeset/867 |
24 | 25 | 'ajaxpoll-info' => 'There {{PLURAL:$1|was one vote|were $1 votes}} since the poll was created on $2.', |
25 | 26 | 'ajaxpoll-submitting' => 'Please wait, submitting your vote.', |
| 27 | + 'ajaxpoll-vote-permission' => 'You cannot vote.', |
| 28 | + |
| 29 | + 'right-ajaxpoll-vote' => 'Can vote in AJAX-based polls', |
26 | 30 | ); |
27 | 31 | |
28 | 32 | /** Message documentation (Message documentation) */ |
— | — | @@ -30,6 +34,9 @@ |
31 | 35 | 'ajaxpoll-percent-votes' => '$1 is the percentage number of the votes', |
32 | 36 | 'ajaxpoll-your-vote' => '$1 is the answer name, $2 is the date when the answer was casted', |
33 | 37 | 'ajaxpoll-info' => '$1 is the number of votes, $2 is when the poll was started', |
| 38 | + 'ajaxpoll-vote-permission' => 'Text for viewers who do not have the right to vote', |
| 39 | + |
| 40 | + 'right-ajaxpoll-vote' => 'Text for the group right allowed to vote', |
34 | 41 | ); |
35 | 42 | |
36 | 43 | /** Afrikaans (Afrikaans) |