r113554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113553‎ | r113554 | r113555 >
Date:09:26, 10 March 2012
Author:wikinaut
Status:new
Tags:
Comment:
fix enhancement bug35118 . add new user right ajaxpoll-vote
Modified paths:
  • /trunk/extensions/AJAXPoll/AJAXPoll.i18n.php (modified) (history)
  • /trunk/extensions/AJAXPoll/AJAXPoll.php (modified) (history)
  • /trunk/extensions/AJAXPoll/AJAXPoll_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AJAXPoll/AJAXPoll.php
@@ -19,7 +19,7 @@
2020 * @author Jack Phoenix <jack@countervandalism.net>
2121 * @author Thomas Gries
2222 * @maintainer Thomas Gries
23 - * @version 1.61
 23+ * @version 1.62
2424 * @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation
2525 */
2626
@@ -31,7 +31,7 @@
3232 $wgExtensionCredits['parserhook'][] = array(
3333 'path' => __FILE__,
3434 'name' => 'AJAX Poll',
35 - 'version' => '1.61 20120309',
 35+ 'version' => '1.62 20120310',
3636 'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' ),
3737 'descriptionmsg' => 'ajaxpoll-desc',
3838 'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll',
@@ -44,6 +44,14 @@
4545 $wgAjaxExportList[] = 'AJAXPoll::submitVote';
4646 $wgHooks['ParserFirstCallInit'][] = 'AJAXPoll::AJAXPollParserInit';
4747
 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+
4856 // Parameter to enable the automatic tracking category
4957 // for all pages using this parser extension
5058 //
Index: trunk/extensions/AJAXPoll/AJAXPoll_body.php
@@ -217,7 +217,7 @@
218218 }
219219
220220 private static function buildHTML( $ID, $user, $lines = '', $extra_from_ajax = '' ) {
221 - global $wgTitle, $wgLang, $wgUseAjax;
 221+ global $wgTitle, $wgUser, $wgLang, $wgUseAjax;
222222
223223 $dbw = wfGetDB( DB_SLAVE );
224224
@@ -298,7 +298,15 @@
299299 <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>';
300300
301301 // 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+
303311 $ret .= '<div class="ajaxpoll-misc">' . $message . '
304312 </div>';
305313
@@ -319,21 +327,36 @@
320328 // If AJAX is enabled, as it is by default in modern MWs, we can
321329 // just use sajax library function here for that AJAX-y feel.
322330 // 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 - }
328331
 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+
329341 // HTML output has to be on one line thanks to a MediaWiki bug
330342 // @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] ) .
333345 "</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>
334346 </div>
335347 ";
336 - }
337348
 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+
338361 $ret .= '</form>';
339362
340363 // Display information about the poll (creation date, amount of votes)
Index: trunk/extensions/AJAXPoll/AJAXPoll.i18n.php
@@ -10,6 +10,7 @@
1111
1212 /** English
1313 * @author Dariusz Siedlecki
 14+ * @author Thomas Gries
1415 */
1516 $messages['en'] = array(
1617 'ajaxpoll-desc' => 'Allows AJAX-based polls with <tt>&lt;poll&gt;</tt> tag',
@@ -22,6 +23,9 @@
2324 'ajaxpoll-no-vote' => 'Please vote below.', // http://trac.wikia-code.com/changeset/867
2425 'ajaxpoll-info' => 'There {{PLURAL:$1|was one vote|were $1 votes}} since the poll was created on $2.',
2526 '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',
2630 );
2731
2832 /** Message documentation (Message documentation) */
@@ -30,6 +34,9 @@
3135 'ajaxpoll-percent-votes' => '$1 is the percentage number of the votes',
3236 'ajaxpoll-your-vote' => '$1 is the answer name, $2 is the date when the answer was casted',
3337 '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',
3441 );
3542
3643 /** Afrikaans (Afrikaans)

Follow-up revisions

RevisionCommit summaryAuthorDate
r113555follow up r113554 . forgot - and fixed now - the server-side check of the aja...wikinaut11:36, 10 March 2012
r113772follow up r113554 . fixing a regression which was introduced in r113554. Maki...wikinaut22:31, 13 March 2012

Status & tagging log