r51645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51644‎ | r51645 | r51646 >
Date:15:52, 9 June 2009
Author:jan
Status:deferred
Tags:
Comment:
Add multi-voting(function, DB and messages)
Modified paths:
  • /trunk/extensions/Poll/Poll.i18n.php (modified) (history)
  • /trunk/extensions/Poll/Poll.php (modified) (history)
  • /trunk/extensions/Poll/Poll_body.php (modified) (history)
  • /trunk/extensions/Poll/archives/patch-multi.sql (added) (history)

Diff [purge]

Index: trunk/extensions/Poll/archives/patch-multi.sql
@@ -0,0 +1,6 @@
 2+-- (c) Jan Luca, 2009, CC by-sa 3.0 or later
 3+-- Table structure for table `Poll`
 4+-- Replace /*$wgDBprefix*/ with the proper prefix
 5+
 6+ALTER TABLE /*$wgDBprefix*/poll
 7+ADD `multi` INT( 1 ) NOT NULL ;
\ No newline at end of file
Property changes on: trunk/extensions/Poll/archives/patch-multi.sql
___________________________________________________________________
Name: svn:eol-style
18 + native
Index: trunk/extensions/Poll/Poll_body.php
@@ -103,9 +103,9 @@
104104 $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5').'</td></tr>' );
105105 $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6').'</td></tr>' );
106106 $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-dis' ).':</td><td>'.Xml::textarea('dis', '').'</td></tr>' );
107 - $wgOut->addHtml( '<tr><td>'.Xml::check('allow_more').' 6:</td><td>'.wfMsg( 'poll-create-allow-more' ).'</td></tr>' );
108 - $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'create').'</td></tr>' );
109107 $wgOut->addHtml( Xml::closeElement( 'table' ) );
 108+ $wgOut->addHtml( Xml::check('allow_more').' '.wfMsg( 'poll-create-allow-more' ).'<br />' );
 109+ $wgOut->addHtml( Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'create') );
110110 $wgOut->addHtml( Xml::closeElement( 'form' ) );
111111 }
112112 }
@@ -127,7 +127,7 @@
128128 }
129129 else {
130130 $dbr = wfGetDB( DB_SLAVE );
131 - $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater', array( 'id' => $vid ) );
 131+ $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater, multi', array( 'id' => $vid ) );
132132 $poll_admin = $wgUser->isAllowed( 'poll-admin' );
133133 $user = $wgUser->getName();
134134
@@ -140,18 +140,29 @@
141141 $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' );
142142 $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' );
143143 $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' );
 144+ $multi = $row->multi;
144145 }
145146
146147 $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$vid) ) ) );
147148 $wgOut->addHtml( Xml::openElement( 'table' ) );
148149 $wgOut->addHtml( '<tr><th>'.$question.'</th></tr>' );
149 - $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '1').' '.$alternative_1.'</td></tr>' );
150 - $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '2').' '.$alternative_2.'</td></tr>' );
151 - if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '3').' '.$alternative_3.'</td></tr>' ); }
152 - if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '4').' '.$alternative_4.'</td></tr>' ); }
153 - if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '5').' '.$alternative_5.'</td></tr>' ); }
154 - if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '6').' '.$alternative_6.'</td></tr>' ); }
155 - $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'vote').'</td><td><a href="'.$wgTitle->getFullURL( 'action=score&id='.$vid ).'">'.wfMsg( 'poll-title-score' ).'</a></td></tr>' );
 150+ if( $multi != 1 ) {
 151+ $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '1').' '.$alternative_1.'</td></tr>' );
 152+ $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '2').' '.$alternative_2.'</td></tr>' );
 153+ if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '3').' '.$alternative_3.'</td></tr>' ); }
 154+ if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '4').' '.$alternative_4.'</td></tr>' ); }
 155+ if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '5').' '.$alternative_5.'</td></tr>' ); }
 156+ if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '6').' '.$alternative_6.'</td></tr>' ); }
 157+ }
 158+ if( $multi == 1 ) {
 159+ $wgOut->addHtml( '<tr><td>'.Xml::check('vote_1').' '.$alternative_1.'</td></tr>' );
 160+ $wgOut->addHtml( '<tr><td>'.Xml::check('vote_2').' '.$alternative_2.'</td></tr>' );
 161+ if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.Xml::check('vote_3').' '.$alternative_3.'</td></tr>' ); }
 162+ if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.Xml::check('vote_4').' '.$alternative_4.'</td></tr>' ); }
 163+ if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.Xml::check('vote_5').' '.$alternative_5.'</td></tr>' ); }
 164+ if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.Xml::check('vote_6').' '.$alternative_6.'</td></tr>' ); }
 165+ }
 166+ $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'vote').''.Xml::hidden('multi', $multi).'</td><td><a href="'.$wgTitle->getFullURL( 'action=score&id='.$vid ).'">'.wfMsg( 'poll-title-score' ).'</a></td></tr>' );
156167 $wgOut->addHtml( '<tr><td>' );
157168 $wgOut->addWikiText( '<small>'.wfMsg( 'poll-score-created', $creater ).'</small>' );
158169 $wgOut->addHtml( '</td></tr>' );
@@ -169,13 +180,7 @@
170181 $wgOut->setPagetitle( wfMsg( 'poll-title-score' ) );
171182
172183 $dbr = wfGetDB( DB_SLAVE );
173 - $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater', array( 'id' => $sid ) );
174 - $query_1 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '1', 'uid' => $sid ) );
175 - $query_2 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '2', 'uid' => $sid ) );
176 - $query_3 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '3', 'uid' => $sid ) );
177 - $query_4 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '4', 'uid' => $sid ) );
178 - $query_5 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '5', 'uid' => $sid ) );
179 - $query_6 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '6', 'uid' => $sid ) );
 184+ $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater, multi', array( 'id' => $sid ) );
180185
181186 while( $row = $dbr->fetchObject( $query ) ) {
182187 $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
@@ -186,14 +191,46 @@
187192 $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' );
188193 $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' );
189194 $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' );
 195+ $multi = $row->multi;
190196 }
 197+
 198+ if($multi != 1) {
 199+ $query_1 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '1', 'pid' => $sid ) );
 200+ $query_2 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '2', 'pid' => $sid ) );
 201+ $query_3 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '3', 'pid' => $sid ) );
 202+ $query_4 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '4', 'pid' => $sid ) );
 203+ $query_5 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '5', 'pid' => $sid ) );
 204+ $query_6 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '6', 'pid' => $sid ) );
191205
192 - $query_num_1 = $dbr->numRows( $query_1 );
193 - $query_num_2 = $dbr->numRows( $query_2 );
194 - $query_num_3 = $dbr->numRows( $query_3 );
195 - $query_num_4 = $dbr->numRows( $query_4 );
196 - $query_num_5 = $dbr->numRows( $query_5 );
197 - $query_num_6 = $dbr->numRows( $query_6 );
 206+ $query_num_1 = $dbr->numRows( $query_1 );
 207+ $query_num_2 = $dbr->numRows( $query_2 );
 208+ $query_num_3 = $dbr->numRows( $query_3 );
 209+ $query_num_4 = $dbr->numRows( $query_4 );
 210+ $query_num_5 = $dbr->numRows( $query_5 );
 211+ $query_num_6 = $dbr->numRows( $query_6 );
 212+ }
 213+
 214+ if($multi == 1) {
 215+ $query_num_1 = 0;
 216+ $query_num_2 = 0;
 217+ $query_num_3 = 0;
 218+ $query_num_4 = 0;
 219+ $query_num_5 = 0;
 220+ $query_num_6 = 0;
 221+
 222+ $query_multi = $dbr->select( 'poll_answer', 'vote', array( 'pid' => $sid ) );
 223+ while( $row = $dbr->fetchObject( $query_multi ) ) {
 224+ $vote = $row->vote;
 225+ $vote = explode("|", $vote);
 226+
 227+ if($vote[0] == "1") { $query_num_1++; }
 228+ if($vote[1] == "1") { $query_num_2++; }
 229+ if($vote[2] == "1") { $query_num_3++; }
 230+ if($vote[3] == "1") { $query_num_4++; }
 231+ if($vote[4] == "1") { $query_num_5++; }
 232+ if($vote[5] == "1") { $query_num_6++; }
 233+ }
 234+ }
198235
199236 $wgOut->addHtml( Xml::openElement( 'table' ) );
200237 $wgOut->addHtml( '<tr><th><center>'.$question.'</center></th></tr>' );;
@@ -301,12 +338,13 @@
302339 $alternative_5 = ($wgRequest->getVal('poll_alternative_5') != "")? $wgRequest->getVal('poll_alternative_5') : "";
303340 $alternative_6 = ($wgRequest->getVal('poll_alternative_6') != "")? $wgRequest->getVal('poll_alternative_6') : "";
304341 $dis = ($wgRequest->getVal('dis') != "")? $wgRequest->getVal( 'dis' ) : wfMsg('poll-no-dis');
 342+ $multi = ($wgRequest->getVal( 'allow_more' ) == 1)? 1 : 0;
305343 $user = $wgUser->getName();
306344
307345 if($question != "" && $alternative_1 != "" && $alternative_2 != "") {
308346 $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
309347 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
310 - 'alternative_6' => $alternative_6, 'creater' => $user, 'dis' => $dis ) );
 348+ 'alternative_6' => $alternative_6, 'creater' => $user, 'dis' => $dis, 'multi' => $multi ) );
311349
312350 $log = new LogPage( "poll" );
313351 $title = $wgTitle;
@@ -337,17 +375,31 @@
338376 else {
339377 $dbw = wfGetDB( DB_MASTER );
340378 $dbr = wfGetDB( DB_SLAVE );
341 - $vote = $wgRequest->getVal('vote');
 379+ $multi = $wgRequest->getVal('multi');
342380 $user = $wgUser->getName();
343381 $uid = $wgUser->getId();
344382
345 - $query = $dbr->select( 'poll_answer', 'uid', array( 'uid' => $uid ));
346 - $num = 0;
347 -
348 - while( $row = $dbr->fetchObject( $query ) ) {
349 - if($row->uid != "") {
350 - $num++;
351 - }
 383+ $query = $dbr->select( 'poll_answer', 'uid', array( 'uid' => $uid, 'pid' => $pid ));
 384+ $num = $dbr->numRows( $query );;
 385+
 386+ if($multi != 1) {
 387+ $vote = $wgRequest->getVal('vote');
 388+ }
 389+ if($multi == 1) {
 390+ $vote_1 = $wgRequest->getVal('vote_1');
 391+ $vote_2 = $wgRequest->getVal('vote_2');
 392+ $vote_3 = $wgRequest->getVal('vote_3');
 393+ $vote_4 = $wgRequest->getVal('vote_4');
 394+ $vote_5 = $wgRequest->getVal('vote_5');
 395+ $vote_6 = $wgRequest->getVal('vote_6');
 396+
 397+ $vote = "";
 398+ $vote .= ($vote_1 == 1)? "1|" : "0|";
 399+ $vote .= ($vote_2 == 1)? "1|" : "0|";
 400+ $vote .= ($vote_3 == 1)? "1|" : "0|";
 401+ $vote .= ($vote_4 == 1)? "1|" : "0|";
 402+ $vote .= ($vote_5 == 1)? "1|" : "0|";
 403+ $vote .= ($vote_6 == 1)? "1" : "0";
352404 }
353405
354406 if( $num == 0 ) {
@@ -436,7 +488,7 @@
437489 }
438490
439491 if ( ( ( $creater == $user ) OR ( $controll_delete_right == true ) ) AND ( $controll_delete_blocked != true ) ) {
440 - if( $wgRequest->getCheck('controll_delete') AND $wgRequest->getVal('controll_delete') === 1 ) {
 492+ if( $wgRequest->getCheck('controll_delete') AND $wgRequest->getVal('controll_delete') == 1 ) {
441493 $dbw = wfGetDB( DB_MASTER );
442494 $user = $wgUser->getName();
443495
Index: trunk/extensions/Poll/Poll.i18n.php
@@ -58,6 +58,7 @@
5959 'poll-score-created' => 'created from [[User:$1]]',
6060 'poll-administration' => 'Administration:',
6161 'poll-no-dis' => 'No Description!',
 62+ 'poll-create-allow-more' => 'Allow Multi-Vote',
6263 );
6364
6465 /** German (Deutsch)
@@ -110,4 +111,5 @@
111112 'poll-score-created' => 'erstellt von [[Benutzer:$1]]',
112113 'poll-administration' => 'Administration:',
113114 'poll-no-dis' => 'Keine Beschreibung vorhanden!',
 115+ 'poll-create-allow-more' => 'Mehfachabstimmung erlaubt',
114116 );
Index: trunk/extensions/Poll/Poll.php
@@ -74,6 +74,7 @@
7575 $wgExtNewFields[] = array( 'poll', 'dis', "$base/archives/patch-dis.sql" ); // Add dis
7676 $wgExtNewTables[] = array( 'poll_answer', "$base/archives/Poll-answer.sql" ); // Initial answer tables
7777 $wgExtNewFields[] = array( 'poll_answer', 'user', "$base/archives/patch-user.sql" ); // Add user
 78+ $wgExtNewFields[] = array( 'poll', 'multi', "$base/archives/patch-multi.sql" ); // Add user
7879 }
7980 return true;
8081 }

Status & tagging log