r114072 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114071‎ | r114072 | r114073 >
Date:21:13, 17 March 2012
Author:wikinaut
Status:new
Tags:
Comment:
best version ever: fully jqueryfied. repaired non-ajax mode for wikis with wgUseAjax false
Modified paths:
  • /trunk/extensions/AJAXPoll/AJAXPoll.php (modified) (history)
  • /trunk/extensions/AJAXPoll/AJAXPoll_body.php (modified) (history)
  • /trunk/extensions/AJAXPoll/resources/ajaxpoll.js (modified) (history)

Diff [purge]

Index: trunk/extensions/AJAXPoll/resources/ajaxpoll.js
@@ -1,22 +1,48 @@
2 -var ajaxpolltmp;
 2+var ajaxpollTmp;
33
44 $(".ajaxpoll-answer-vote").live("mouseover",
55 function(){
6 - var sp=$(this).find("span");
7 - ajaxpolltmp=sp.html();
8 - sp.text(sp.attr("title"));
9 - sp.attr("title","");
 6+ var sp=$(this).find("span");
 7+ ajaxpollTmp=sp.html();
 8+ sp.text(sp.attr("title"));
 9+ sp.attr("title","");
1010 }
1111 );
1212
1313 $(".ajaxpoll-answer-vote").live("mouseout",
1414 function(){
15 - var sp=$(this).find("span");
16 - sp.attr("title",sp.text());
17 - sp.text(ajaxpolltmp);
 15+ var sp=$(this).find("span");
 16+ sp.attr("title",sp.text());
 17+ sp.text(ajaxpollTmp);
1818 }
1919 );
2020
 21+/* attach click handler */
 22+$(".ajaxpoll-answer")
 23+ .live("click",
 24+ function(event){
 25+ event.preventDefault();
 26+ event.stopPropagation();
 27+ $this = $(this);
 28+ var poll = $this.attr( "poll" );
 29+ var answer = $this.attr("answer");
 30+ $this
 31+ .addClass("ajaxpoll-checkevent")
 32+ .find("input").prop("checked",true);
 33+ $( "#ajaxpoll-ajax-"+poll )
 34+ .html("Please wait, submitting your vote.")
 35+ .css("display","block");
 36+ if (useAjax){
 37+ sajax_do_call(
 38+ "AJAXPoll::submitVote",
 39+ [poll,answer],
 40+ $("#ajaxpoll-container-"+poll)[0]
 41+ )
 42+ } else {
 43+ $("#ajaxpoll-answer-id-"+poll).submit();
 44+ }
 45+ }
 46+ )
2147
2248 $(".ajaxpoll-answer-name:not(.ajaxpoll-answer-name-revoke) label").live("mouseover",
2349 function(){
Index: trunk/extensions/AJAXPoll/AJAXPoll_body.php
@@ -30,7 +30,7 @@
3131
3232 # The callback function for converting the input text to HTML output
3333 static function AJAXPollRender( $input, $params = array(), Parser $parser ) {
34 - global $wgUser, $wgOut, $wgTitle, $wgScriptPath,
 34+ global $wgUser, $wgOut, $wgTitle, $wgScriptPath, $wgUseAjax,
3535 $wgAJAXPollTrackingCategory;
3636
3737 $parser->disableCache();
@@ -55,6 +55,16 @@
5656 $input = trim( strip_tags( $input->getText() ) );
5757 $lines = explode( "\n", trim( $input ) );
5858
 59+ // compatibility for non-ajax requests - just in case
 60+ if ( !$wgUseAjax ) {
 61+ $responseId = "ajaxpoll-post-id";
 62+ $responseAnswer = "ajaxpoll-post-answer-$id";
 63+
 64+ if ( isset( $_POST[$responseId] ) && isset( $_POST[$responseAnswer] ) && $_POST[$responseId] == $id ) {
 65+ AJAXPoll::submitVote( $id, intval( $_POST[$responseAnswer] ) );
 66+ }
 67+ }
 68+
5969 $dbw = wfGetDB( DB_MASTER );
6070 $dbw->begin( __METHOD__ );
6171
@@ -146,6 +156,7 @@
147157
148158 public static function submitVote( $id, $answer ) {
149159 global $wgUser,$wgOut;
 160+ // echo "id: $id ans $answer<br/>";
150161
151162 $dbw = wfGetDB( DB_MASTER );
152163
@@ -292,7 +303,8 @@
293304 }
294305 // HTML output has to be on one line thanks to a MediaWiki bug
295306 // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319
296 - $ret = '<div id="ajaxpoll-id-' . $id . '" class="ajaxpoll">
 307+ $ret = '<script>var useAjax='. ( !empty($wgUseAjax) ? "true" : "false" ) . ';</script>
 308+<div id="ajaxpoll-id-' . $id . '" class="ajaxpoll">
297309 <div id="ajaxpoll-ajax-' . $id . '" class="ajaxpoll-ajax"' . $attributes . '>' . $ajaxMessage . '</div>
298310 <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>';
299311
@@ -343,25 +355,18 @@
344356
345357 if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
346358
347 - if ( $wgUseAjax ) {
348 - $submitJS = "sajax_do_call(\"AJAXPoll::submitVote\",[\"" . $id . "\",\"" . $answer . "\"],$(\"#ajaxpoll-container-" . $id . "\")[0]);";
349 - } else {
350 - $submitJS = "$(\"#ajaxpoll-answer-id-" . $id . "\").submit();";
351 - }
352 -
353 -
354359 // HTML output has to be on one line thanks to a MediaWiki bug
355360 // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319
356361
357362 if ( $vote ) {
358363 $ret .= "
359 -<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] ) .
 364+<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] ) .
360365 "</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>
361366 </div>
362367 ";
363368 } else {
364369 $ret .= "
365 -<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] ) .
 370+<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] ) .
366371 "</label></div>
367372 </div>
368373 ";
@@ -370,7 +375,7 @@
371376 } else {
372377
373378 $ret .= "
374 -<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] ) .
 379+<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] ) .
375380 "</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>
376381 </div>
377382 ";
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.741
 23+ * @version 1.75
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.741 20120317',
 35+ 'version' => '1.75 20120317',
3636 'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' ),
3737 'descriptionmsg' => 'ajaxpoll-desc',
3838 'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll',

Status & tagging log