r111817 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111816‎ | r111817 | r111818 >
Date:08:46, 18 February 2012
Author:wikinaut
Status:deferred
Tags:
Comment:
code cosmetics and first step towards solution of my still to-do: fix the usage of , , and inside of a parser function.
Modified paths:
  • /trunk/extensions/AJAXPoll/AJAXPoll.css (modified) (history)
  • /trunk/extensions/AJAXPoll/AJAXPoll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AJAXPoll/AJAXPoll.php
@@ -31,7 +31,7 @@
3232 $wgExtensionCredits['parserhook'][] = array(
3333 'path' => __FILE__,
3434 'name' => 'AJAX Poll',
35 - 'version' => '1.600 20120216',
 35+ 'version' => '1.601 20120218',
3636 'author' => array( 'Dariusz Siedlecki', 'Jack Phoenix', 'Thomas Gries' ),
3737 'descriptionmsg' => 'ajaxpoll-desc',
3838 'url' => 'https://www.mediawiki.org/wiki/Extension:AJAX_Poll',
@@ -113,9 +113,8 @@
114114 $retVal = buildStats( $ID, $user );
115115 break;
116116 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>';
120119 break;
121120 }
122121 return $retVal;
@@ -171,7 +170,7 @@
172171 }
173172
174173 function submitVote( $ID, $answer ) {
175 - global $wgUser;
 174+ global $wgUser,$wgOut;
176175
177176 $dbw = wfGetDB( DB_MASTER );
178177
@@ -196,9 +195,10 @@
197196 ),
198197 __METHOD__
199198 );
200 - $r = $dbw->fetchRow( $q );
 199+ $row = $dbw->fetchRow( $q );
201200
202 - if ( $r['c'] > 0 ) {
 201+ if ( $row['c'] > 0 ) {
 202+
203203 $updateQuery = $dbw->update(
204204 'poll_vote',
205205 array(
@@ -212,12 +212,10 @@
213213 __METHOD__
214214 );
215215 $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+
221218 } else {
 219+
222220 $insertQuery = $dbw->insert(
223221 'poll_vote',
224222 array(
@@ -230,12 +228,12 @@
231229 __METHOD__
232230 );
233231 $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+
239234 }
 235+
 236+ return buildHTML( $ID, $user, '', $pollContainerText );
 237+
240238 }
241239
242240 function buildHTML( $ID, $user, $lines = '', $extra_from_ajax = '' ) {
@@ -249,13 +247,13 @@
250248 array( 'poll_id' => $ID ),
251249 __METHOD__
252250 );
253 - $r = $dbw->fetchRow( $q );
 251+ $row = $dbw->fetchRow( $q );
254252
255253 if ( empty( $lines ) ) {
256 - $lines = explode( "\n", trim( $r['poll_txt'] ) );
 254+ $lines = explode( "\n", trim( $row['poll_txt'] ) );
257255 }
258256
259 - $start_date = $r['poll_date'];
 257+ $start_date = $row['poll_date'];
260258
261259 $q = $dbw->select(
262260 'poll_vote',
@@ -267,8 +265,8 @@
268266
269267 $poll_result = array();
270268
271 - while ( $r = $q->fetchRow() ) {
272 - $poll_result[$r[0]] = $r[1];
 269+ while ( $row = $q->fetchRow() ) {
 270+ $poll_result[$row[0]] = $row[1];
273271 }
274272
275273 $amountOfVotes = array_sum( $poll_result );
@@ -284,29 +282,27 @@
285283 __METHOD__
286284 );
287285
288 - if ( $r = $dbw->fetchRow( $q ) ) {
289 - $tmp_date = wfMsg(
 286+ if ( $row = $dbw->fetchRow( $q ) ) {
 287+ $ourLastVoteDate = wfMsg(
290288 '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? */ )
293291 );
294292 }
295293
296294 if ( is_object( $wgTitle ) ) {
297295 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 );
300298 } else {
301 - $additionalAttributes = '';
302 - $message = '';
 299+ $attributes = '';
 300+ $ajaxMessage = '';
303301 }
304302 // HTML output has to be on one line thanks to a MediaWiki bug
305303 // @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;
311307 function mover(x){
312308 var sp=$(x).find("span");
313309 tmp=sp.html();
@@ -322,11 +318,9 @@
323319 <div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>';
324320
325321 // 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>';
331325
332326 $ret .= '<form method="post" action="' . $wgTitle->getLocalURL() .
333327 '" id="ajaxpoll-answer-id-' . $ID . '"><input type="hidden" name="ajaxpoll-post-id" value="' . $ID . '" />';
@@ -340,7 +334,7 @@
341335 $percent = $wgLang->formatNum( round( ( isset( $poll_result[$i + 1] ) ? $poll_result[$i + 1] : 0 ) * 100 / $amountOfVotes, 2 ) );
342336 }
343337
344 - $our = ( isset( $r[0] ) && ( $r[0] - 1 == $i ) );
 338+ $our = ( isset( $row[0] ) && ( $row[0] - 1 == $i ) );
345339
346340 // If AJAX is enabled, as it is by default in modern MWs, we can
347341 // just use sajax library function here for that AJAX-y feel.
@@ -363,14 +357,14 @@
364358 $ret .= '</form>';
365359
366360 // Display information about the poll (creation date, amount of votes)
367 - $tmp_date = wfMsgExt(
 361+ $pollSummary = wfMsgExt(
368362 'ajaxpoll-info',
369363 'parsemag', // parse PLURAL
370364 $amountOfVotes, // amount of votes
371365 $wgLang->timeanddate( wfTimestamp( TS_MW, $start_date ), true /* adjust? */ )
372366 );
373367
374 - $ret .= '<div id="ajaxpoll-info">' . $tmp_date . '</div>';
 368+ $ret .= '<div id="ajaxpoll-info-' . $ID . '" class="ajaxpoll-info">' . $pollSummary . '</div>';
375369
376370 $ret .= '</div>';
377371 } else {
Index: trunk/extensions/AJAXPoll/AJAXPoll.css
@@ -17,15 +17,6 @@
1818 font-weight: bold;
1919 }
2020
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 -
3021 .ajaxpoll .ajaxpoll-answer-name {
3122 margin-top: 5px;
3223 padding-left: 0px;
@@ -81,12 +72,20 @@
8273 background: cyan;
8374 }
8475
85 -.ajaxpoll #ajaxpoll-info {
86 - margin-top: 20px;
 76+.ajaxpoll .ajaxpoll-misc {
 77+ margin-bottom: 10px;
8778 color: grey;
8879 }
8980
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;
9291 color: grey;
9392 }

Status & tagging log