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

Revision: 114072
Author:   wikinaut
Date:     2012-03-17 21:13:10 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
best version ever: fully jqueryfied. repaired non-ajax mode for wikis with 
wgUseAjax false

Modified Paths:
--------------
    trunk/extensions/AJAXPoll/AJAXPoll.php
    trunk/extensions/AJAXPoll/AJAXPoll_body.php
    trunk/extensions/AJAXPoll/resources/ajaxpoll.js

Modified: trunk/extensions/AJAXPoll/AJAXPoll.php
===================================================================
--- trunk/extensions/AJAXPoll/AJAXPoll.php      2012-03-17 21:13:01 UTC (rev 
114071)
+++ trunk/extensions/AJAXPoll/AJAXPoll.php      2012-03-17 21:13:10 UTC (rev 
114072)
@@ -19,7 +19,7 @@
  * @author Jack Phoenix <[email protected]>
  * @author Thomas Gries
  * @maintainer Thomas Gries
- * @version 1.741
+ * @version 1.75
  * @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation
  */
 
@@ -31,7 +31,7 @@
 $wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
        'name' => 'AJAX Poll',
-       'version' => '1.741 20120317',
+       'version' => '1.75 20120317',
        'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' 
),
        'descriptionmsg' => 'ajaxpoll-desc',
        'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll',

Modified: trunk/extensions/AJAXPoll/AJAXPoll_body.php
===================================================================
--- trunk/extensions/AJAXPoll/AJAXPoll_body.php 2012-03-17 21:13:01 UTC (rev 
114071)
+++ trunk/extensions/AJAXPoll/AJAXPoll_body.php 2012-03-17 21:13:10 UTC (rev 
114072)
@@ -30,7 +30,7 @@
 
        # The callback function for converting the input text to HTML output
        static function AJAXPollRender( $input, $params = array(), Parser 
$parser ) {
-               global $wgUser, $wgOut, $wgTitle, $wgScriptPath,
+               global $wgUser, $wgOut, $wgTitle, $wgScriptPath, $wgUseAjax,
                        $wgAJAXPollTrackingCategory;
 
                $parser->disableCache();
@@ -55,6 +55,16 @@
                $input = trim( strip_tags( $input->getText() ) );
                $lines = explode( "\n", trim( $input ) );
 
+               // compatibility for non-ajax requests - just in case
+               if ( !$wgUseAjax ) {
+                       $responseId = "ajaxpoll-post-id";
+                       $responseAnswer = "ajaxpoll-post-answer-$id";
+               
+                       if ( isset( $_POST[$responseId] ) && isset( 
$_POST[$responseAnswer] ) && $_POST[$responseId] == $id ) {
+                               AJAXPoll::submitVote( $id, intval( 
$_POST[$responseAnswer] ) );
+                       }
+               }
+               
                $dbw = wfGetDB( DB_MASTER );
                $dbw->begin( __METHOD__ );
 
@@ -146,6 +156,7 @@
 
        public static function submitVote( $id, $answer ) {
                global $wgUser,$wgOut;
+               // echo "id: $id ans $answer<br/>";
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -292,7 +303,8 @@
                        }
                        // 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-id-' . $id . '" 
class="ajaxpoll">
+                       $ret = '<script>var useAjax='. ( !empty($wgUseAjax) ? 
"true" : "false" ) . ';</script>
+<div id="ajaxpoll-id-' . $id . '" class="ajaxpoll">
 <div id="ajaxpoll-ajax-' . $id . '" class="ajaxpoll-ajax"' . $attributes . '>' 
. $ajaxMessage . '</div>
 <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>';
 
@@ -343,25 +355,18 @@
 
                                if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
 
-                                       if ( $wgUseAjax ) {
-                                               $submitJS = 
"sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $answer . 
"\"],$(\"#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
 
                                        if ( $vote ) {
                                                $ret .= "
-<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer'><div 
class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-$xid' 
onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 
'ajaxpoll-submitting' ) . 
"\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true);"
 . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-$xid' 
name='ajaxpoll-post-answer-$xid' value='" . $answer . "' " . ( $our ? 
'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
+<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer' poll='$id' 
answer='$answer'><div class='ajaxpoll-answer-name'><label 
for='ajaxpoll-post-answer-$xid'><input type='radio' 
id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$id' value='" . 
$answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( 
$lines[$i] ) .
 "</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' 
ajaxpoll-our-vote' : '' ) ."'><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-$xid' class='ajaxpoll-answer'><div 
class='ajaxpoll-answer-name ajaxpoll-answer-name-revoke'><label 
for='ajaxpoll-post-answer-$xid' onclick='$(\"#ajaxpoll-ajax-" . $xid . 
"\").html(\"" . wfMsg( 'ajaxpoll-submitting' ) . 
"\").css(\"display\",\"block\");$(this).addClass(\"ajaxpoll-checkevent\").prop(\"checked\",true);"
 . $submitJS . "'><input type='radio' id='ajaxpoll-post-answer-$xid' 
name='ajaxpoll-post-answer-$xid' value='" . $answer . "' " . ( $our ? 
'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
+<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer' poll='$id' 
answer='$answer'><div class='ajaxpoll-answer-name 
ajaxpoll-answer-name-revoke'><label for='ajaxpoll-post-answer-$xid'><input 
type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$id' 
value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . 
strip_tags( $lines[$i] ) .
 "</label></div>
 </div>
 ";
@@ -370,7 +375,7 @@
                                } else {
 
                                        $ret .= "
-<div id='ajaxpoll-answer-" . $xid . "' class='ajaxpoll-answer'><div 
class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $xid . "' 
onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 
'ajaxpoll-vote-permission' ) . "\").css(\"display\",\"block\");'><input 
disabled='disabled' type='radio' id='ajaxpoll-post-answer-" . $xid . "' 
name='ajaxpoll-post-answer-" . $xid . "' value='" . $answer . "'/>" . 
strip_tags( $lines[$i] ) .
+<div id='ajaxpoll-answer-" . $xid . "' class='ajaxpoll-answer' poll='$id' 
answer='$answer'><div class='ajaxpoll-answer-name'><label 
for='ajaxpoll-post-answer-" . $xid . "' onclick='$(\"#ajaxpoll-ajax-" . $xid . 
"\").html(\"" . wfMsg( 'ajaxpoll-vote-permission' ) . 
"\").css(\"display\",\"block\");'><input disabled='disabled' type='radio' 
id='ajaxpoll-post-answer-" . $xid . "' name='ajaxpoll-post-answer-" . $id . "' 
value='" . $answer . "'/>" . strip_tags( $lines[$i] ) .
 "</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' 
ajaxpoll-our-vote' : '' ) ."'><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>
 ";

Modified: trunk/extensions/AJAXPoll/resources/ajaxpoll.js
===================================================================
--- trunk/extensions/AJAXPoll/resources/ajaxpoll.js     2012-03-17 21:13:01 UTC 
(rev 114071)
+++ trunk/extensions/AJAXPoll/resources/ajaxpoll.js     2012-03-17 21:13:10 UTC 
(rev 114072)
@@ -1,22 +1,48 @@
-var ajaxpolltmp;
+var ajaxpollTmp;
 
 $(".ajaxpoll-answer-vote").live("mouseover",
        function(){
-       var sp=$(this).find("span");
-       ajaxpolltmp=sp.html();
-       sp.text(sp.attr("title"));
-       sp.attr("title","");
+               var sp=$(this).find("span");
+               ajaxpollTmp=sp.html();
+               sp.text(sp.attr("title"));
+               sp.attr("title","");
        }
 );
 
 $(".ajaxpoll-answer-vote").live("mouseout",
        function(){
-       var sp=$(this).find("span");
-       sp.attr("title",sp.text());
-       sp.text(ajaxpolltmp);
+               var sp=$(this).find("span");
+               sp.attr("title",sp.text());
+               sp.text(ajaxpollTmp);
        }
 );
 
+/* attach click handler */
+$(".ajaxpoll-answer")
+       .live("click",
+               function(event){
+                       event.preventDefault();
+                       event.stopPropagation();
+                       $this = $(this);
+                       var poll = $this.attr( "poll" );
+                       var answer = $this.attr("answer");
+                       $this
+                               .addClass("ajaxpoll-checkevent")
+                               .find("input").prop("checked",true);
+                       $( "#ajaxpoll-ajax-"+poll )
+                               .html("Please wait, submitting your vote.")
+                               .css("display","block");
+                       if (useAjax){
+                               sajax_do_call(
+                                       "AJAXPoll::submitVote",
+                                       [poll,answer],
+                                       $("#ajaxpoll-container-"+poll)[0]
+                               )
+                       } else {
+                               $("#ajaxpoll-answer-id-"+poll).submit();
+                       }
+               }
+       )
 
 $(".ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) 
label").live("mouseover",
        function(){


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

Reply via email to