https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113554

Revision: 113554
Author:   wikinaut
Date:     2012-03-10 09:26:52 +0000 (Sat, 10 Mar 2012)
Log Message:
-----------
fix enhancement bug35118 . add new user right ajaxpoll-vote

Modified Paths:
--------------
    trunk/extensions/AJAXPoll/AJAXPoll.i18n.php
    trunk/extensions/AJAXPoll/AJAXPoll.php
    trunk/extensions/AJAXPoll/AJAXPoll_body.php

Modified: trunk/extensions/AJAXPoll/AJAXPoll.i18n.php
===================================================================
--- trunk/extensions/AJAXPoll/AJAXPoll.i18n.php 2012-03-10 07:34:02 UTC (rev 
113553)
+++ trunk/extensions/AJAXPoll/AJAXPoll.i18n.php 2012-03-10 09:26:52 UTC (rev 
113554)
@@ -10,6 +10,7 @@
 
 /** English
  * @author Dariusz Siedlecki
+ * @author Thomas Gries
  */
 $messages['en'] = array(
        'ajaxpoll-desc' => 'Allows AJAX-based polls with <tt>&lt;poll&gt;</tt> 
tag',
@@ -22,6 +23,9 @@
        'ajaxpoll-no-vote' => 'Please vote below.', // 
http://trac.wikia-code.com/changeset/867
        '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 cannot vote.',
+
+       'right-ajaxpoll-vote' => 'Can vote in AJAX-based polls',
 );
 
 /** Message documentation (Message documentation) */
@@ -30,6 +34,9 @@
        'ajaxpoll-percent-votes' => '$1 is the percentage number of the votes',
        'ajaxpoll-your-vote' => '$1 is the answer name, $2 is the date when the 
answer was casted',
        'ajaxpoll-info' => '$1 is the number of votes, $2 is when the poll was 
started',
+       'ajaxpoll-vote-permission' => 'Text for viewers who do not have the 
right to vote',
+
+       'right-ajaxpoll-vote' => 'Text for the group right allowed to vote',
 );
 
 /** Afrikaans (Afrikaans)

Modified: trunk/extensions/AJAXPoll/AJAXPoll.php
===================================================================
--- trunk/extensions/AJAXPoll/AJAXPoll.php      2012-03-10 07:34:02 UTC (rev 
113553)
+++ trunk/extensions/AJAXPoll/AJAXPoll.php      2012-03-10 09:26:52 UTC (rev 
113554)
@@ -19,7 +19,7 @@
  * @author Jack Phoenix <[email protected]>
  * @author Thomas Gries
  * @maintainer Thomas Gries
- * @version 1.61
+ * @version 1.62
  * @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation
  */
 
@@ -31,7 +31,7 @@
 $wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
        'name' => 'AJAX Poll',
-       'version' => '1.61 20120309',
+       'version' => '1.62 20120310',
        'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' 
),
        'descriptionmsg' => 'ajaxpoll-desc',
        'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll',
@@ -44,6 +44,14 @@
 $wgAjaxExportList[] = 'AJAXPoll::submitVote';
 $wgHooks['ParserFirstCallInit'][] = 'AJAXPoll::AJAXPollParserInit';
 
+# new user rights
+$wgAvailableRights[] = 'ajaxpoll-vote';
+
+# default: everyone can vote
+$wgGroupPermissions['*']['ajaxpoll-vote'] = true;
+# if you want only users to vote use
+# $wgGroupPermissions['user']['ajaxpoll-vote'] = true;
+
 // Parameter to enable the automatic tracking category
 // for all pages using this parser extension
 //

Modified: trunk/extensions/AJAXPoll/AJAXPoll_body.php
===================================================================
--- trunk/extensions/AJAXPoll/AJAXPoll_body.php 2012-03-10 07:34:02 UTC (rev 
113553)
+++ trunk/extensions/AJAXPoll/AJAXPoll_body.php 2012-03-10 09:26:52 UTC (rev 
113554)
@@ -217,7 +217,7 @@
        }
 
        private static function buildHTML( $ID, $user, $lines = '', 
$extra_from_ajax = '' ) {
-               global $wgTitle, $wgLang, $wgUseAjax;
+               global $wgTitle, $wgUser, $wgLang, $wgUseAjax;
 
                $dbw = wfGetDB( DB_SLAVE );
 
@@ -298,7 +298,15 @@
 <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>';
 
                        // Different message depending on if the user has 
already voted or not.
-                       $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : 
wfMsg( 'ajaxpoll-no-vote' );
+
+                       // $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : 
wfMsg( 'ajaxpoll-no-vote' );
+                       
+                       if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
+                               $message = ( isset( $row[0] ) ) ? 
$ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' );
+                       } else {
+                               $message = wfMsg( 'ajaxpoll-vote-permission' );
+                       }
+                       
                        $ret .= '<div class="ajaxpoll-misc">' . $message . '
 </div>';
 
@@ -319,21 +327,36 @@
                                // If AJAX is enabled, as it is by default in 
modern MWs, we can
                                // just use sajax library function here for 
that AJAX-y feel.
                                // If not, we'll have to submit the form 
old-school way...
-                               if ( $wgUseAjax ) {
-                                       $submitJS = 
"sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $ID . "\",\"" . $i . "\"], 
$(\"#ajaxpoll-container-" . $ID . "\")[0]);";
-                               } else {
-                                       $submitJS = "$(\"#ajaxpoll-answer-id-" 
. $ID . "\").submit();";
-                               }
 
+                               if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
+
+                                       if ( $wgUseAjax ) {
+                                               $submitJS = 
"sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $ID . "\",\"" . $i . "\"], 
$(\"#ajaxpoll-container-" . $ID . "\")[0]);";
+                                       } else {
+                                               $submitJS = 
"$(\"#ajaxpoll-answer-id-" . $ID . "\").submit();";
+                                       }
+
+
                                // HTML output has to be on one line thanks to 
a MediaWiki bug
                                // @see 
https://bugzilla.wikimedia.org/show_bug.cgi?id=1319
-                               $ret .= "
-<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] ) .
+                                       $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] ) .
 "</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 . "' 
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] ) .
+"</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>
+";
+
+                               }
+
+                       }
+
                        $ret .= '</form>';
 
                        // Display information about the poll (creation date, 
amount of votes)


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to