Index: trunk/extensions/AJAXPoll/AJAXPoll.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | $wgExtensionCredits['parserhook'][] = array( |
33 | 33 | 'path' => __FILE__, |
34 | 34 | 'name' => 'AJAX Poll', |
35 | | - 'version' => '1.600 20120216', |
| 35 | + 'version' => '1.601 20120218', |
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', |
— | — | @@ -113,9 +113,8 @@ |
114 | 114 | $retVal = buildStats( $ID, $user ); |
115 | 115 | break; |
116 | 116 | default: |
117 | | - $retVal = '<div id="ajaxpoll-container-' . $ID . '">' . |
118 | | - buildHTML( $ID, $user, $lines ) . |
119 | | - '</div>'; |
| 117 | + $retVal = ' |
| 118 | +<div id="ajaxpoll-container-' . $ID . '">' . buildHTML( $ID, $user, $lines ) . '</div>'; |
120 | 119 | break; |
121 | 120 | } |
122 | 121 | return $retVal; |
— | — | @@ -171,7 +170,7 @@ |
172 | 171 | } |
173 | 172 | |
174 | 173 | function submitVote( $ID, $answer ) { |
175 | | - global $wgUser; |
| 174 | + global $wgUser,$wgOut; |
176 | 175 | |
177 | 176 | $dbw = wfGetDB( DB_MASTER ); |
178 | 177 | |
— | — | @@ -196,9 +195,10 @@ |
197 | 196 | ), |
198 | 197 | __METHOD__ |
199 | 198 | ); |
200 | | - $r = $dbw->fetchRow( $q ); |
| 199 | + $row = $dbw->fetchRow( $q ); |
201 | 200 | |
202 | | - if ( $r['c'] > 0 ) { |
| 201 | + if ( $row['c'] > 0 ) { |
| 202 | + |
203 | 203 | $updateQuery = $dbw->update( |
204 | 204 | 'poll_vote', |
205 | 205 | array( |
— | — | @@ -212,12 +212,10 @@ |
213 | 213 | __METHOD__ |
214 | 214 | ); |
215 | 215 | $dbw->commit(); |
216 | | - if ( $updateQuery ) { |
217 | | - return buildHTML( $ID, $user, '', 'ajaxpoll-vote-update' ); |
218 | | - } else { |
219 | | - return buildHTML( $ID, $user, '', 'ajaxpoll-vote-error' ); |
220 | | - } |
| 216 | + $pollContainerText = ( $updateQuery ) ? 'ajaxpoll-vote-update' : 'ajaxpoll-vote-error'; |
| 217 | + |
221 | 218 | } else { |
| 219 | + |
222 | 220 | $insertQuery = $dbw->insert( |
223 | 221 | 'poll_vote', |
224 | 222 | array( |
— | — | @@ -230,12 +228,12 @@ |
231 | 229 | __METHOD__ |
232 | 230 | ); |
233 | 231 | $dbw->commit(); |
234 | | - if ( $insertQuery ) { |
235 | | - return buildHTML( $ID, $user, '', 'ajaxpoll-vote-add' ); |
236 | | - } else { |
237 | | - return buildHTML( $ID, $user, '', 'ajaxpoll-vote-error' ); |
238 | | - } |
| 232 | + $pollContainerText = ( $insertQuery ) ? 'ajaxpoll-vote-add' : 'ajaxpoll-vote-error'; |
| 233 | + |
239 | 234 | } |
| 235 | + |
| 236 | + return buildHTML( $ID, $user, '', $pollContainerText ); |
| 237 | + |
240 | 238 | } |
241 | 239 | |
242 | 240 | function buildHTML( $ID, $user, $lines = '', $extra_from_ajax = '' ) { |
— | — | @@ -249,13 +247,13 @@ |
250 | 248 | array( 'poll_id' => $ID ), |
251 | 249 | __METHOD__ |
252 | 250 | ); |
253 | | - $r = $dbw->fetchRow( $q ); |
| 251 | + $row = $dbw->fetchRow( $q ); |
254 | 252 | |
255 | 253 | if ( empty( $lines ) ) { |
256 | | - $lines = explode( "\n", trim( $r['poll_txt'] ) ); |
| 254 | + $lines = explode( "\n", trim( $row['poll_txt'] ) ); |
257 | 255 | } |
258 | 256 | |
259 | | - $start_date = $r['poll_date']; |
| 257 | + $start_date = $row['poll_date']; |
260 | 258 | |
261 | 259 | $q = $dbw->select( |
262 | 260 | 'poll_vote', |
— | — | @@ -267,8 +265,8 @@ |
268 | 266 | |
269 | 267 | $poll_result = array(); |
270 | 268 | |
271 | | - while ( $r = $q->fetchRow() ) { |
272 | | - $poll_result[$r[0]] = $r[1]; |
| 269 | + while ( $row = $q->fetchRow() ) { |
| 270 | + $poll_result[$row[0]] = $row[1]; |
273 | 271 | } |
274 | 272 | |
275 | 273 | $amountOfVotes = array_sum( $poll_result ); |
— | — | @@ -284,29 +282,27 @@ |
285 | 283 | __METHOD__ |
286 | 284 | ); |
287 | 285 | |
288 | | - if ( $r = $dbw->fetchRow( $q ) ) { |
289 | | - $tmp_date = wfMsg( |
| 286 | + if ( $row = $dbw->fetchRow( $q ) ) { |
| 287 | + $ourLastVoteDate = wfMsg( |
290 | 288 | 'ajaxpoll-your-vote', |
291 | | - $lines[$r[0] - 1], |
292 | | - $wgLang->timeanddate( wfTimestamp( TS_MW, $r[1] ), true /* adjust? */ ) |
| 289 | + $lines[$row[0] - 1], |
| 290 | + $wgLang->timeanddate( wfTimestamp( TS_MW, $row[1] ), true /* adjust? */ ) |
293 | 291 | ); |
294 | 292 | } |
295 | 293 | |
296 | 294 | if ( is_object( $wgTitle ) ) { |
297 | 295 | if( !empty( $extra_from_ajax ) ) { |
298 | | - $additionalAttributes = ' style="display: block;"'; |
299 | | - $message = wfMsg( $extra_from_ajax ); |
| 296 | + $attributes = ' style="display: block;"'; |
| 297 | + $ajaxMessage = wfMsg( $extra_from_ajax ); |
300 | 298 | } else { |
301 | | - $additionalAttributes = ''; |
302 | | - $message = ''; |
| 299 | + $attributes = ''; |
| 300 | + $ajaxMessage = ''; |
303 | 301 | } |
304 | 302 | // HTML output has to be on one line thanks to a MediaWiki bug |
305 | 303 | // @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319 |
306 | | - $ret = '<div id="ajaxpoll-id-' . $ID . '" class="ajaxpoll"><div id="ajaxpoll-ajax-' . $ID . '" class="ajaxpoll-ajax"' . |
307 | | - $additionalAttributes . '>' . $message . |
308 | | - '</div> |
309 | | -<script> |
310 | | -var tmp; |
| 304 | + $ret = '<div id="ajaxpoll-id-' . $ID . '" class="ajaxpoll"> |
| 305 | +<div id="ajaxpoll-ajax-' . $ID . '" class="ajaxpoll-ajax"' . $attributes . '>' . $ajaxMessage . '</div> |
| 306 | +<script>var tmp; |
311 | 307 | function mover(x){ |
312 | 308 | var sp=$(x).find("span"); |
313 | 309 | tmp=sp.html(); |
— | — | @@ -322,11 +318,9 @@ |
323 | 319 | <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>'; |
324 | 320 | |
325 | 321 | // Different message depending on if the user has already voted or not. |
326 | | - if ( isset( $r[0] ) ) { |
327 | | - $ret .= '<div class="ajaxpoll-misc">' . $tmp_date . '</div>'; |
328 | | - } else { |
329 | | - $ret .= '<div class="ajaxpoll-misc">' . wfMsg( 'ajaxpoll-no-vote' ) . '</div>'; |
330 | | - } |
| 322 | + $message = ( isset( $row[0] ) ) ? $ourLastVoteDate : wfMsg( 'ajaxpoll-no-vote' ); |
| 323 | + $ret .= '<div class="ajaxpoll-misc">' . $message . ' |
| 324 | +</div>'; |
331 | 325 | |
332 | 326 | $ret .= '<form method="post" action="' . $wgTitle->getLocalURL() . |
333 | 327 | '" id="ajaxpoll-answer-id-' . $ID . '"><input type="hidden" name="ajaxpoll-post-id" value="' . $ID . '" />'; |
— | — | @@ -340,7 +334,7 @@ |
341 | 335 | $percent = $wgLang->formatNum( round( ( isset( $poll_result[$i + 1] ) ? $poll_result[$i + 1] : 0 ) * 100 / $amountOfVotes, 2 ) ); |
342 | 336 | } |
343 | 337 | |
344 | | - $our = ( isset( $r[0] ) && ( $r[0] - 1 == $i ) ); |
| 338 | + $our = ( isset( $row[0] ) && ( $row[0] - 1 == $i ) ); |
345 | 339 | |
346 | 340 | // If AJAX is enabled, as it is by default in modern MWs, we can |
347 | 341 | // just use sajax library function here for that AJAX-y feel. |
— | — | @@ -363,14 +357,14 @@ |
364 | 358 | $ret .= '</form>'; |
365 | 359 | |
366 | 360 | // Display information about the poll (creation date, amount of votes) |
367 | | - $tmp_date = wfMsgExt( |
| 361 | + $pollSummary = wfMsgExt( |
368 | 362 | 'ajaxpoll-info', |
369 | 363 | 'parsemag', // parse PLURAL |
370 | 364 | $amountOfVotes, // amount of votes |
371 | 365 | $wgLang->timeanddate( wfTimestamp( TS_MW, $start_date ), true /* adjust? */ ) |
372 | 366 | ); |
373 | 367 | |
374 | | - $ret .= '<div id="ajaxpoll-info">' . $tmp_date . '</div>'; |
| 368 | + $ret .= '<div id="ajaxpoll-info-' . $ID . '" class="ajaxpoll-info">' . $pollSummary . '</div>'; |
375 | 369 | |
376 | 370 | $ret .= '</div>'; |
377 | 371 | } else { |
Index: trunk/extensions/AJAXPoll/AJAXPoll.css |
— | — | @@ -17,15 +17,6 @@ |
18 | 18 | font-weight: bold; |
19 | 19 | } |
20 | 20 | |
21 | | -.ajaxpoll .ajaxpoll-ajax { |
22 | | - background: #FFFFCF; |
23 | | - padding: 1px 4px; |
24 | | - width: 200px; |
25 | | - border-radius: 0.5em; |
26 | | - -moz-border-radius: 0.5em; |
27 | | - display: none; |
28 | | -} |
29 | | - |
30 | 21 | .ajaxpoll .ajaxpoll-answer-name { |
31 | 22 | margin-top: 5px; |
32 | 23 | padding-left: 0px; |
— | — | @@ -81,12 +72,20 @@ |
82 | 73 | background: cyan; |
83 | 74 | } |
84 | 75 | |
85 | | -.ajaxpoll #ajaxpoll-info { |
86 | | - margin-top: 20px; |
| 76 | +.ajaxpoll .ajaxpoll-misc { |
| 77 | + margin-bottom: 10px; |
87 | 78 | color: grey; |
88 | 79 | } |
89 | 80 | |
90 | | -.ajaxpoll .ajaxpoll-misc { |
91 | | - margin-bottom: 20px; |
| 81 | +.ajaxpoll .ajaxpoll-ajax { |
| 82 | + background: #FFFFCF; |
| 83 | + padding: 1px 4px; |
| 84 | + width: 200px; |
| 85 | + border-radius: 0.5em; |
| 86 | + -moz-border-radius: 0.5em; |
| 87 | +} |
| 88 | + |
| 89 | +.ajaxpoll .ajaxpoll-info { |
| 90 | + margin-top: 20px; |
92 | 91 | color: grey; |
93 | 92 | } |