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 |
1 | 8 | + native |
Index: trunk/extensions/Poll/Poll_body.php |
— | — | @@ -103,9 +103,9 @@ |
104 | 104 | $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5').'</td></tr>' ); |
105 | 105 | $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6').'</td></tr>' ); |
106 | 106 | $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>' ); |
109 | 107 | $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') ); |
110 | 110 | $wgOut->addHtml( Xml::closeElement( 'form' ) ); |
111 | 111 | } |
112 | 112 | } |
— | — | @@ -127,7 +127,7 @@ |
128 | 128 | } |
129 | 129 | else { |
130 | 130 | $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 ) ); |
132 | 132 | $poll_admin = $wgUser->isAllowed( 'poll-admin' ); |
133 | 133 | $user = $wgUser->getName(); |
134 | 134 | |
— | — | @@ -140,18 +140,29 @@ |
141 | 141 | $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' ); |
142 | 142 | $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' ); |
143 | 143 | $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' ); |
| 144 | + $multi = $row->multi; |
144 | 145 | } |
145 | 146 | |
146 | 147 | $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$vid) ) ) ); |
147 | 148 | $wgOut->addHtml( Xml::openElement( 'table' ) ); |
148 | 149 | $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>' ); |
156 | 167 | $wgOut->addHtml( '<tr><td>' ); |
157 | 168 | $wgOut->addWikiText( '<small>'.wfMsg( 'poll-score-created', $creater ).'</small>' ); |
158 | 169 | $wgOut->addHtml( '</td></tr>' ); |
— | — | @@ -169,13 +180,7 @@ |
170 | 181 | $wgOut->setPagetitle( wfMsg( 'poll-title-score' ) ); |
171 | 182 | |
172 | 183 | $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 ) ); |
180 | 185 | |
181 | 186 | while( $row = $dbr->fetchObject( $query ) ) { |
182 | 187 | $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' ); |
— | — | @@ -186,14 +191,46 @@ |
187 | 192 | $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' ); |
188 | 193 | $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' ); |
189 | 194 | $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' ); |
| 195 | + $multi = $row->multi; |
190 | 196 | } |
| 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 ) ); |
191 | 205 | |
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 | + } |
198 | 235 | |
199 | 236 | $wgOut->addHtml( Xml::openElement( 'table' ) ); |
200 | 237 | $wgOut->addHtml( '<tr><th><center>'.$question.'</center></th></tr>' );; |
— | — | @@ -301,12 +338,13 @@ |
302 | 339 | $alternative_5 = ($wgRequest->getVal('poll_alternative_5') != "")? $wgRequest->getVal('poll_alternative_5') : ""; |
303 | 340 | $alternative_6 = ($wgRequest->getVal('poll_alternative_6') != "")? $wgRequest->getVal('poll_alternative_6') : ""; |
304 | 341 | $dis = ($wgRequest->getVal('dis') != "")? $wgRequest->getVal( 'dis' ) : wfMsg('poll-no-dis'); |
| 342 | + $multi = ($wgRequest->getVal( 'allow_more' ) == 1)? 1 : 0; |
305 | 343 | $user = $wgUser->getName(); |
306 | 344 | |
307 | 345 | if($question != "" && $alternative_1 != "" && $alternative_2 != "") { |
308 | 346 | $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2, |
309 | 347 | '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 ) ); |
311 | 349 | |
312 | 350 | $log = new LogPage( "poll" ); |
313 | 351 | $title = $wgTitle; |
— | — | @@ -337,17 +375,31 @@ |
338 | 376 | else { |
339 | 377 | $dbw = wfGetDB( DB_MASTER ); |
340 | 378 | $dbr = wfGetDB( DB_SLAVE ); |
341 | | - $vote = $wgRequest->getVal('vote'); |
| 379 | + $multi = $wgRequest->getVal('multi'); |
342 | 380 | $user = $wgUser->getName(); |
343 | 381 | $uid = $wgUser->getId(); |
344 | 382 | |
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"; |
352 | 404 | } |
353 | 405 | |
354 | 406 | if( $num == 0 ) { |
— | — | @@ -436,7 +488,7 @@ |
437 | 489 | } |
438 | 490 | |
439 | 491 | 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 ) { |
441 | 493 | $dbw = wfGetDB( DB_MASTER ); |
442 | 494 | $user = $wgUser->getName(); |
443 | 495 | |
Index: trunk/extensions/Poll/Poll.i18n.php |
— | — | @@ -58,6 +58,7 @@ |
59 | 59 | 'poll-score-created' => 'created from [[User:$1]]', |
60 | 60 | 'poll-administration' => 'Administration:', |
61 | 61 | 'poll-no-dis' => 'No Description!', |
| 62 | + 'poll-create-allow-more' => 'Allow Multi-Vote', |
62 | 63 | ); |
63 | 64 | |
64 | 65 | /** German (Deutsch) |
— | — | @@ -110,4 +111,5 @@ |
111 | 112 | 'poll-score-created' => 'erstellt von [[Benutzer:$1]]', |
112 | 113 | 'poll-administration' => 'Administration:', |
113 | 114 | 'poll-no-dis' => 'Keine Beschreibung vorhanden!', |
| 115 | + 'poll-create-allow-more' => 'Mehfachabstimmung erlaubt', |
114 | 116 | ); |
Index: trunk/extensions/Poll/Poll.php |
— | — | @@ -74,6 +74,7 @@ |
75 | 75 | $wgExtNewFields[] = array( 'poll', 'dis', "$base/archives/patch-dis.sql" ); // Add dis |
76 | 76 | $wgExtNewTables[] = array( 'poll_answer', "$base/archives/Poll-answer.sql" ); // Initial answer tables |
77 | 77 | $wgExtNewFields[] = array( 'poll_answer', 'user', "$base/archives/patch-user.sql" ); // Add user |
| 78 | + $wgExtNewFields[] = array( 'poll', 'multi', "$base/archives/patch-multi.sql" ); // Add user |
78 | 79 | } |
79 | 80 | return true; |
80 | 81 | } |