r51342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51341‎ | r51342 | r51343 >
Date:13:01, 2 June 2009
Author:siebrand
Status:deferred (Comments)
Tags:
Comment:
* delay message loading
* add FIXMEs for hard coded (German) text
* update messages ('poll-delete-cancel' may need another pass)
* update indentation
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)

Diff [purge]

Index: trunk/extensions/Poll/Poll_body.php
@@ -9,23 +9,24 @@
1010
1111
1212 class Poll extends SpecialPage {
13 -
 13+
1414 public function __construct() {
1515 parent::__construct( 'Poll' );
16 - wfLoadExtensionMessages( 'Poll' );
1716 }
1817
1918 public function execute( $par ) {
2019 global $wgRequest, $wgOut;
2120
 21+ wfLoadExtensionMessages( 'Poll' );
 22+
2223 $this->setHeaders();
2324
2425 # Get request data from, e.g.
2526 $action = htmlentities( $wgRequest->getText( 'action' ) );
2627 $id = htmlentities( $wgRequest->getText( 'id' ) );
27 -
 28+
2829 if ( $action == "" OR $action == "list" ) {
29 - $this->make_list();
 30+ $this->make_list();
3031 }
3132
3233 if ( $action == "create" ) {
@@ -35,427 +36,431 @@
3637 if ( $action == "vote" ) {
3738 $this->vote( $id );
3839 }
39 -
 40+
4041 if ( $action == "score" ) {
4142 $this->score( $id );
4243 }
43 -
 44+
4445 if ( $action == "change" ) {
4546 $this->change( $id );
4647 }
47 -
 48+
4849 if ( $action == "delete" ) {
4950 $this->delete( $id );
5051 }
5152
52 - if ( $action == "submit" ) {
53 - $this->submit( $id );
54 - }
 53+ if ( $action == "submit" ) {
 54+ $this->submit( $id );
 55+ }
5556 }
56 -
57 - public function make_list() {
58 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
59 - $wgOut->setPagetitle( wfMsg( 'poll' ) );
60 -
61 - $dbr = wfGetDB( DB_SLAVE );
62 - $query = $dbr->select( 'poll', 'question, dis, id' );
63 -
64 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=create').'">'.wfMsg( 'poll-create-link' ).'</a>' );
65 -
66 - $wgOut->addWikiMsg( 'poll-list-current' );
67 - $wgOut->addHtml( Xml::openElement( 'table' ) );
68 - $wgOut->addHtml( '<tr><th>'.wfMsg( 'poll-question' ).'</th><th>'.wfMsg( 'poll-dis' ).'</th><th>&nbsp;</th></tr>' );
69 -
70 - while( $row = $dbr->fetchObject( $query ) ) {
71 - $wgOut->addHtml( '<tr><td><a href="'.$wgTitle->getFullURL( 'action=vote&id='.$row->id ).'">'.htmlentities( $row->question, ENT_QUOTES, "UTF-8" ).'</a></td>' );
72 - $wgOut->addHtml( '<td>'.$row->dis.'</td>' );
73 - $wgOut->addHtml( '<td><a href="'.$wgTitle->getFullURL( 'action=score&id='.$row->id ).'">'.wfMsg( 'poll-title-score' ).'</a></td></tr>' );
74 - }
75 -
76 - $wgOut->addHtml( Xml::closeElement( 'table' ) );
77 -
78 - }
7957
80 - public function create() {
81 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
82 -
83 - $wgOut->setPagetitle( wfMsg( 'poll-title-create' ) );
84 -
85 - $controll_create_right = $wgUser->isAllowed( 'poll-create' );
86 - $controll_create_blocked = $wgUser->isBlocked();
87 - if ( $controll_create_right != true ) {
88 - $wgOut->addWikiMsg( 'poll-create-right-error' );
89 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
90 - }
91 - elseif ( $controll_create_blocked == true ) {
92 - $wgOut->addWikiMsg( 'poll-create-block-error' );
93 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
94 - }
95 - else {
96 - $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit') ) ) );
97 - $wgOut->addHtml( Xml::openElement( 'table' ) );
98 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-question' ).':</td><td>'.Xml::input('question').'</td></tr>' );
99 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 1:</td><td>'.Xml::input('poll_alternative_1').'</td></tr>' );
100 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 2:</td><td>'.Xml::input('poll_alternative_2').'</td></tr>' );
101 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 3:</td><td>'.Xml::input('poll_alternative_3').'</td></tr>' );
102 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 4:</td><td>'.Xml::input('poll_alternative_4').'</td></tr>' );
103 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5').'</td></tr>' );
104 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6').'</td></tr>' );
105 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-dis' ).':</td><td>'.Xml::textarea('dis', '').'</td></tr>' );
106 - $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'create').'</td></tr>' );
107 - $wgOut->addHtml( Xml::closeElement( 'table' ) );
108 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
109 - }
110 - }
111 -
112 - public function vote( $vid ) {
113 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
114 -
115 - $wgOut->setPagetitle( wfMsg( 'poll-title-vote' ) );
116 -
117 - $controll_vote_right = $wgUser->isAllowed( 'poll-vote' );
118 - $controll_vote_blocked = $wgUser->isBlocked();
119 - if ( $controll_vote_right != true ) {
120 - $wgOut->addWikiMsg( 'poll-vote-right-error' );
121 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
122 - }
123 - elseif ( $controll_vote_blocked == true ) {
124 - $wgOut->addWikiMsg( 'poll-vote-block-error' );
125 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
126 - }
127 - else {
128 - $dbr = wfGetDB( DB_SLAVE );
129 - $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater', array( 'id' => $vid ) );
130 - $poll_admin = $wgUser->isAllowed( 'poll-admin' );
131 - $user = $wgUser->getName();
132 -
133 - while( $row = $dbr->fetchObject( $query ) ) {
134 - $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
135 - $alternative_1 = htmlentities( $row->alternative_1, ENT_QUOTES, 'UTF-8' );
136 - $alternative_2 = htmlentities( $row->alternative_2, ENT_QUOTES, 'UTF-8' );
137 - $alternative_3 = htmlentities( $row->alternative_3, ENT_QUOTES, 'UTF-8' );
138 - $alternative_4 = htmlentities( $row->alternative_4, ENT_QUOTES, 'UTF-8' );
139 - $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' );
140 - $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' );
141 - $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' );
142 - }
143 -
144 - $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$vid) ) ) );
145 - $wgOut->addHtml( Xml::openElement( 'table' ) );
146 - $wgOut->addHtml( '<tr><th>'.$question.'</th></tr>' );
147 - $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '1').' '.$alternative_1.'</td></tr>' );
148 - $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '2').' '.$alternative_2.'</td></tr>' );
149 - if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '3').' '.$alternative_3.'</td></tr>' ); }
150 - if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '4').' '.$alternative_4.'</td></tr>' ); }
151 - if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '5').' '.$alternative_5.'</td></tr>' ); }
152 - if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '6').' '.$alternative_6.'</td></tr>' ); }
153 - $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>' );
154 - $wgOut->addHtml( '<tr><td>' );
155 - $wgOut->addWikiText( '<small>erstellt von [[Benutzer:'.$creater.']]</small>' );
156 - $wgOut->addHtml( '</td></tr>' );
157 - $wgOut->addHtml( Xml::closeElement( 'table' ) );
158 - if( ($poll_admin == true) OR ($creater == $user) ) {
159 - $wgOut->addHtml( 'Administration: <a href="'.$wgTitle->getFullURL('action=change&id='.$vid).'">'.wfMsg('poll-change').'</a> · <a href="'.$wgTitle->getFullURL('action=delete&id='.$vid).'">'.wfMsg('poll-delete').'</a>' );
160 - }
161 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
162 - }
163 - }
164 -
165 - public function score( $sid ) {
166 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
167 -
168 - $wgOut->setPagetitle( wfMsg( 'poll-title-score' ) );
169 -
170 - $dbr = wfGetDB( DB_SLAVE );
171 - $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater', array( 'id' => $sid ) );
172 - $query_1 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '1', 'uid' => $sid ) );
173 - $query_2 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '2', 'uid' => $sid ) );
174 - $query_3 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '3', 'uid' => $sid ) );
175 - $query_4 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '4', 'uid' => $sid ) );
176 - $query_5 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '5', 'uid' => $sid ) );
177 - $query_6 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '6', 'uid' => $sid ) );
178 -
179 - while( $row = $dbr->fetchObject( $query ) ) {
180 - $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
181 - $alternative_1 = htmlentities( $row->alternative_1, ENT_QUOTES, 'UTF-8' );
182 - $alternative_2 = htmlentities( $row->alternative_2, ENT_QUOTES, 'UTF-8' );
183 - $alternative_3 = htmlentities( $row->alternative_3, ENT_QUOTES, 'UTF-8' );
184 - $alternative_4 = htmlentities( $row->alternative_4, ENT_QUOTES, 'UTF-8' );
185 - $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' );
186 - $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' );
187 - $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' );
188 - }
189 -
190 - $query_num_1 = $dbr->numRows( $query_1 );
191 - $query_num_2 = $dbr->numRows( $query_2 );
192 - $query_num_3 = $dbr->numRows( $query_3 );
193 - $query_num_4 = $dbr->numRows( $query_4 );
194 - $query_num_5 = $dbr->numRows( $query_5 );
195 - $query_num_6 = $dbr->numRows( $query_6 );
196 -
197 - $wgOut->addHtml( Xml::openElement( 'table' ) );
198 - $wgOut->addHtml( '<tr><th><center>'.$question.'</center></th></tr>' );
199 - //$wgOut->addHtml( '<tr><td><b>'.wfMsg( 'poll-alternative' ).'</b></td><td><b>'.wfMsg( 'poll-number-poll' ).'</td></tr>' );
200 - $wgOut->addHtml( '<tr><td>'.$alternative_1.'</td><td>'.$query_num_1.'</td></tr>' );
201 - $wgOut->addHtml( '<tr><td>'.$alternative_2.'</td><td>'.$query_num_2.'</td></tr>' );
202 - if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_3.'</td><td>'.$query_num_3.'</td></tr>' ); }
203 - if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_4.'</td><td>'.$query_num_4.'</td></tr>' ); }
204 - if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_5.'</td><td>'.$query_num_5.'</td></tr>' ); }
205 - if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_6.'</td><td>'.$query_num_6.'</td></tr>' ); }
206 - $wgOut->addHtml( '<tr><td>' );
207 - $wgOut->addWikiText( '<small>erstellt von [[Benutzer:'.$creater.']]</small>' );
208 - $wgOut->addHtml( '</td></tr>' );
209 - $wgOut->addHtml( Xml::closeElement( 'table' ) );
210 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 58+ public function make_list() {
 59+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 60+ $wgOut->setPagetitle( wfMsg( 'poll' ) );
 61+
 62+ $dbr = wfGetDB( DB_SLAVE );
 63+ $query = $dbr->select( 'poll', 'question, dis, id' );
 64+
 65+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=create').'">'.wfMsg( 'poll-create-link' ).'</a>' );
 66+
 67+ $wgOut->addWikiMsg( 'poll-list-current' );
 68+ $wgOut->addHtml( Xml::openElement( 'table' ) );
 69+ $wgOut->addHtml( '<tr><th>'.wfMsg( 'poll-question' ).'</th><th>'.wfMsg( 'poll-dis' ).'</th><th>&nbsp;</th></tr>' );
 70+
 71+ while( $row = $dbr->fetchObject( $query ) ) {
 72+ $wgOut->addHtml( '<tr><td><a href="'.$wgTitle->getFullURL( 'action=vote&id='.$row->id ).'">'.htmlentities( $row->question, ENT_QUOTES, "UTF-8" ).'</a></td>' );
 73+ $wgOut->addHtml( '<td>'.$row->dis.'</td>' );
 74+ $wgOut->addHtml( '<td><a href="'.$wgTitle->getFullURL( 'action=score&id='.$row->id ).'">'.wfMsg( 'poll-title-score' ).'</a></td></tr>' );
 75+ }
 76+
 77+ $wgOut->addHtml( Xml::closeElement( 'table' ) );
 78+
21179 }
212 -
213 - public function delete( $did ) {
214 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
215 - $wgOut->setPagetitle( wfMsg( 'poll-title-delete' ) );
216 -
217 - $dbr = wfGetDB( DB_SLAVE );
218 - $query = $dbr->select( 'poll', 'question', array( 'id' => $did ) );
219 -
220 - while( $row = $dbr->fetchObject( $query ) ) {
221 - $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
222 - }
223 -
224 - $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$did) ) ) );
225 - $wgOut->addHtml( Xml::check( 'controll_delete' ).' '.wfMsg('poll-delete-question', $question).'<br />' );
226 - $wgOut->addHtml( Xml::submitButton(wfMsg( 'poll-submit' )).' <a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>'.Xml::hidden('type', 'delete') );
227 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
228 - }
229 -
230 - public function change($cid) {
231 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
232 -
233 - $wgOut->setPagetitle( wfMsg( 'poll-title-change' ) );
234 -
235 - $dbr = wfGetDB( DB_SLAVE );
236 - $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater, dis', array( 'id' => $cid ) );
237 - $user = $wgUser->getName();
238 -
239 - while( $row = $dbr->fetchObject( $query ) ) {
240 - $question = $row->question;
241 - $alternative_1 = $row->alternative_1;
242 - $alternative_2 = $row->alternative_2;
243 - $alternative_3 = $row->alternative_3;
244 - $alternative_4 = $row->alternative_4;
245 - $alternative_5 = $row->alternative_5;
246 - $alternative_6 = $row->alternative_6;
247 - $creater = $row->creater;
248 - $dis = $row->dis;
249 - }
250 -
251 - $controll_create_blocked = $wgUser->isBlocked();
252 - if ( $user != $creater ) {
253 - $wgOut->addWikiMsg( 'poll-change-right-error' );
254 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
255 - }
256 - elseif ( $controll_create_blocked == true ) {
257 - $wgOut->addWikiMsg( 'poll-change-block-error' );
258 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
259 - }
260 - else {
261 - $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$cid) ) ) );
262 - $wgOut->addHtml( Xml::openElement( 'table' ) );
263 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-question' ).':</td><td>'.Xml::input('question', false, $question).'</td></tr>' );
264 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 1:</td><td>'.Xml::input('poll_alternative_1', false, $alternative_1).'</td></tr>' );
265 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 2:</td><td>'.Xml::input('poll_alternative_2', false, $alternative_2).'</td></tr>' );
266 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 3:</td><td>'.Xml::input('poll_alternative_3', false, $alternative_3).'</td></tr>' );
267 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 4:</td><td>'.Xml::input('poll_alternative_4', false, $alternative_4).'</td></tr>' );
268 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5', false, $alternative_5).'</td></tr>' );
269 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6', false, $alternative_6).'</td></tr>' );
270 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-dis' ).':</td><td>'.Xml::textarea('dis', $dis).'</td></tr>' );
271 - $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'change').'</td></tr>' );
272 - $wgOut->addHtml( Xml::closeElement( 'table' ) );
273 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
274 - }
275 - }
276 -
277 - public function submit( $pid ) {
278 - global $wgRequest, $wgOut, $wgUser, $wgTitle;
279 -
280 - $type = $_POST['type'];
281 -
282 - if($type == 'create') {
283 - $controll_create_right = $wgUser->isAllowed( 'poll-create' );
284 - $controll_create_blocked = $wgUser->isBlocked();
285 - if ( $controll_create_right != true ) {
286 - $wgOut->addWikiMsg( 'poll-create-right-error' );
 80+
 81+ public function create() {
 82+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 83+
 84+ $wgOut->setPagetitle( wfMsg( 'poll-title-create' ) );
 85+
 86+ $controll_create_right = $wgUser->isAllowed( 'poll-create' );
 87+ $controll_create_blocked = $wgUser->isBlocked();
 88+ if ( $controll_create_right != true ) {
 89+ $wgOut->addWikiMsg( 'poll-create-right-error' );
28790 $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
288 - }
289 - elseif ( $controll_create_blocked == true ) {
290 - $wgOut->addWikiMsg( 'poll-create-block-error' );
 91+ }
 92+ elseif ( $controll_create_blocked == true ) {
 93+ $wgOut->addWikiMsg( 'poll-create-block-error' );
29194 $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
292 - }
 95+ }
 96+ else {
 97+ $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit') ) ) );
 98+ $wgOut->addHtml( Xml::openElement( 'table' ) );
 99+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-question' ).':</td><td>'.Xml::input('question').'</td></tr>' );
 100+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 1:</td><td>'.Xml::input('poll_alternative_1').'</td></tr>' );
 101+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 2:</td><td>'.Xml::input('poll_alternative_2').'</td></tr>' );
 102+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 3:</td><td>'.Xml::input('poll_alternative_3').'</td></tr>' );
 103+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 4:</td><td>'.Xml::input('poll_alternative_4').'</td></tr>' );
 104+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5').'</td></tr>' );
 105+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6').'</td></tr>' );
 106+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-dis' ).':</td><td>'.Xml::textarea('dis', '').'</td></tr>' );
 107+ $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'create').'</td></tr>' );
 108+ $wgOut->addHtml( Xml::closeElement( 'table' ) );
 109+ $wgOut->addHtml( Xml::closeElement( 'form' ) );
 110+ }
 111+ }
293112
294 - else {
295 - $dbw = wfGetDB( DB_MASTER );
296 - $question = $_POST['question'];
297 - $alternative_1 = $_POST['poll_alternative_1'];
298 - $alternative_2 = $_POST['poll_alternative_2'];
299 - $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
300 - $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
301 - $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
302 - $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
303 - $dis = ($_POST['dis'] != "")? $_POST['dis'] : "Keine Beschreibung vorhanden!";
304 - $user = $wgUser->getName();
305 -
306 - if($question != "" && $alternative_1 != "" && $alternative_2 != "") {
307 - $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
308 - 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
309 - 'alternative_6' => $alternative_6, 'creater' => $user, 'dis' => $dis ) );
310 -
311 - $log = new LogPage( "poll" );
312 - $title = $wgTitle;
313 - $log->addEntry( "poll", $title, wfMsg( 'poll-log-create', "[[Benutzer:".htmlentities( $user, ENT_QUOTES, 'UTF-8' )."]]", htmlentities( $question, ENT_QUOTES, 'UTF-8' ) ) );
314 -
315 - $wgOut->addWikiMsg( 'poll-create-pass' );
 113+ public function vote( $vid ) {
 114+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 115+
 116+ $wgOut->setPagetitle( wfMsg( 'poll-title-vote' ) );
 117+
 118+ $controll_vote_right = $wgUser->isAllowed( 'poll-vote' );
 119+ $controll_vote_blocked = $wgUser->isBlocked();
 120+ if ( $controll_vote_right != true ) {
 121+ $wgOut->addWikiMsg( 'poll-vote-right-error' );
316122 $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
317 - }
318 - else {
319 - $wgOut->addWikiMsg( 'poll-create-fields-error' );
320 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
321 - }
322 - }
323 - }
324 -
325 - if($type == 'vote') {
326 - $controll_vote_right = $wgUser->isAllowed( 'poll-vote' );
327 - $controll_vote_blocked = $wgUser->isBlocked();
328 - if ( $controll_vote_right != true ) {
329 - $wgOut->addWikiMsg( 'poll-vote-right-error' );
 123+ }
 124+ elseif ( $controll_vote_blocked == true ) {
 125+ $wgOut->addWikiMsg( 'poll-vote-block-error' );
330126 $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
331 - }
332 - elseif ( $controll_vote_blocked == true ) {
333 - $wgOut->addWikiMsg( 'poll-vote-block-error' );
334 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
335 - }
 127+ }
 128+ else {
 129+ $dbr = wfGetDB( DB_SLAVE );
 130+ $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater', array( 'id' => $vid ) );
 131+ $poll_admin = $wgUser->isAllowed( 'poll-admin' );
 132+ $user = $wgUser->getName();
336133
337 - else {
338 - $dbw = wfGetDB( DB_MASTER );
339 - $dbr = wfGetDB( DB_SLAVE );
340 - $vote = $_POST['vote'];
341 - $user = $wgUser->getName();
342 - $uid = $wgUser->getId();
343 -
344 - $query = $dbr->select( 'poll_answer', 'uid', array( 'uid' => $uid ));
345 - $num = 0;
346 -
347 - while( $row = $dbr->fetchObject( $query ) ) {
348 - if($row->uid != "") {
349 - $num++;
350 - }
351 - }
352 -
353 - if( $num == 0 ) {
354 - $dbw->insert( 'poll_answer', array( 'pid' => $pid, 'uid' => $uid, 'vote' => $vote, 'user' => $user ) );
355 -
356 - $wgOut->addWikiMsg( 'poll-vote-pass' );
357 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
358 - }
359 - else {
360 - $wgOut->addWikiMsg( 'poll-vote-already-error' );
361 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
362 - }
363 - }
364 - }
365 -
366 - if($type == 'change') {
367 - $dbr = wfGetDB( DB_SLAVE );
368 - $query = $dbr->select( 'poll', 'creater', array( 'id' => $pid ) );
369 - $user = $wgUser->getName();
370 -
 134+ while( $row = $dbr->fetchObject( $query ) ) {
 135+ $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
 136+ $alternative_1 = htmlentities( $row->alternative_1, ENT_QUOTES, 'UTF-8' );
 137+ $alternative_2 = htmlentities( $row->alternative_2, ENT_QUOTES, 'UTF-8' );
 138+ $alternative_3 = htmlentities( $row->alternative_3, ENT_QUOTES, 'UTF-8' );
 139+ $alternative_4 = htmlentities( $row->alternative_4, ENT_QUOTES, 'UTF-8' );
 140+ $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' );
 141+ $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' );
 142+ $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' );
 143+ }
 144+
 145+ $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$vid) ) ) );
 146+ $wgOut->addHtml( Xml::openElement( 'table' ) );
 147+ $wgOut->addHtml( '<tr><th>'.$question.'</th></tr>' );
 148+ $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '1').' '.$alternative_1.'</td></tr>' );
 149+ $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '2').' '.$alternative_2.'</td></tr>' );
 150+ if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '3').' '.$alternative_3.'</td></tr>' ); }
 151+ if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '4').' '.$alternative_4.'</td></tr>' ); }
 152+ if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '5').' '.$alternative_5.'</td></tr>' ); }
 153+ if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.Xml::radio('vote', '6').' '.$alternative_6.'</td></tr>' ); }
 154+ $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>' );
 155+ $wgOut->addHtml( '<tr><td>' );
 156+ // FIXME: hardcoded text (in German)
 157+ $wgOut->addWikiText( '<small>erstellt von [[Benutzer:'.$creater.']]</small>' );
 158+ $wgOut->addHtml( '</td></tr>' );
 159+ $wgOut->addHtml( Xml::closeElement( 'table' ) );
 160+ if( ($poll_admin == true) OR ($creater == $user) ) {
 161+ // FIXME: hardcoded text
 162+ $wgOut->addHtml( 'Administration: <a href="'.$wgTitle->getFullURL('action=change&id='.$vid).'">'.wfMsg('poll-change').'</a> · <a href="'.$wgTitle->getFullURL('action=delete&id='.$vid).'">'.wfMsg('poll-delete').'</a>' );
 163+ }
 164+ $wgOut->addHtml( Xml::closeElement( 'form' ) );
 165+ }
 166+ }
 167+
 168+ public function score( $sid ) {
 169+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 170+
 171+ $wgOut->setPagetitle( wfMsg( 'poll-title-score' ) );
 172+
 173+ $dbr = wfGetDB( DB_SLAVE );
 174+ $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater', array( 'id' => $sid ) );
 175+ $query_1 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '1', 'uid' => $sid ) );
 176+ $query_2 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '2', 'uid' => $sid ) );
 177+ $query_3 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '3', 'uid' => $sid ) );
 178+ $query_4 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '4', 'uid' => $sid ) );
 179+ $query_5 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '5', 'uid' => $sid ) );
 180+ $query_6 = $dbr->select( 'poll_answer', 'uid', array( 'vote' => '6', 'uid' => $sid ) );
 181+
371182 while( $row = $dbr->fetchObject( $query ) ) {
372 - $creater = htmlentities( $row->creater );
373 - }
374 -
375 - $controll_change_right = $wgUser->isAllowed( 'poll-admin' );
376 - $controll_change_blocked = $wgUser->isBlocked();
377 -
378 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
379 -
380 - if ( ( $creater != $user ) AND ( $controll_change_right == false ) ) {
381 - $wgOut->addWikiMsg( 'poll-change-right-error' );
382 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 183+ $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
 184+ $alternative_1 = htmlentities( $row->alternative_1, ENT_QUOTES, 'UTF-8' );
 185+ $alternative_2 = htmlentities( $row->alternative_2, ENT_QUOTES, 'UTF-8' );
 186+ $alternative_3 = htmlentities( $row->alternative_3, ENT_QUOTES, 'UTF-8' );
 187+ $alternative_4 = htmlentities( $row->alternative_4, ENT_QUOTES, 'UTF-8' );
 188+ $alternative_5 = htmlentities( $row->alternative_5, ENT_QUOTES, 'UTF-8' );
 189+ $alternative_6 = htmlentities( $row->alternative_6, ENT_QUOTES, 'UTF-8' );
 190+ $creater = htmlentities( $row->creater, ENT_QUOTES, 'UTF-8' );
383191 }
384 -
385 - if ( isset($controll_delete_blocked) AND ( $controll_change_blocked == true ) ) {
386 - $wgOut->addWikiMsg( 'poll-change-block-error' );
387 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
388 - }
389 -
390 - if ( ( ( $creater == $user ) OR ( $controll_change_right == true ) ) AND ( $controll_change_blocked != true ) ) {
391 - $dbw = wfGetDB( DB_MASTER );
392 - $question = $_POST['question'];
393 - $alternative_1 = $_POST['poll_alternative_1'];
394 - $alternative_2 = $_POST['poll_alternative_2'];
395 - $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
396 - $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
397 - $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
398 - $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
399 - $dis = ($_POST['dis'] != "")? $_POST['dis'] : "Keine Beschreibung vorhanden!";
400 - $user = $wgUser->getName();
401 -
402 - $dbw->update( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
403 - 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
404 - 'alternative_6' => $alternative_6, 'creater' => $user, 'dis' => $dis ), array( 'id' => $pid ) );
405 -
406 - $log = new LogPage( "poll" );
407 - $title = $wgTitle;
408 - $log->addEntry( "poll", $title, wfMsg( 'poll-log-change', "[[Benutzer:".htmlentities( $user, ENT_QUOTES, 'UTF-8' )."]]", htmlentities( $question, ENT_QUOTES, 'UTF-8' ) ) );
409 -
410 - $wgOut->addWikiMsg( 'poll-change-pass' );
411 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
412 - }
413 - }
414 -
415 - if($type == 'delete') {
416 - $dbr = wfGetDB( DB_SLAVE );
417 - $query = $dbr->select( 'poll', 'creater, question', array( 'id' => $pid ) );
418 - $user = $wgUser->getName();
419 -
420 - while( $row = $dbr->fetchObject( $query ) ) {
421 - $creater = htmlentities( $row->creater );
 192+
 193+ $query_num_1 = $dbr->numRows( $query_1 );
 194+ $query_num_2 = $dbr->numRows( $query_2 );
 195+ $query_num_3 = $dbr->numRows( $query_3 );
 196+ $query_num_4 = $dbr->numRows( $query_4 );
 197+ $query_num_5 = $dbr->numRows( $query_5 );
 198+ $query_num_6 = $dbr->numRows( $query_6 );
 199+
 200+ $wgOut->addHtml( Xml::openElement( 'table' ) );
 201+ $wgOut->addHtml( '<tr><th><center>'.$question.'</center></th></tr>' );
 202+ //$wgOut->addHtml( '<tr><td><b>'.wfMsg( 'poll-alternative' ).'</b></td><td><b>'.wfMsg( 'poll-number-poll' ).'</td></tr>' );
 203+ $wgOut->addHtml( '<tr><td>'.$alternative_1.'</td><td>'.$query_num_1.'</td></tr>' );
 204+ $wgOut->addHtml( '<tr><td>'.$alternative_2.'</td><td>'.$query_num_2.'</td></tr>' );
 205+ if($alternative_3 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_3.'</td><td>'.$query_num_3.'</td></tr>' ); }
 206+ if($alternative_4 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_4.'</td><td>'.$query_num_4.'</td></tr>' ); }
 207+ if($alternative_5 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_5.'</td><td>'.$query_num_5.'</td></tr>' ); }
 208+ if($alternative_6 != "") { $wgOut->addHtml( '<tr><td>'.$alternative_6.'</td><td>'.$query_num_6.'</td></tr>' ); }
 209+ $wgOut->addHtml( '<tr><td>' );
 210+ // FIXME: hardcoded text (in German)
 211+ $wgOut->addWikiText( '<small>erstellt von [[Benutzer:'.$creater.']]</small>' );
 212+ $wgOut->addHtml( '</td></tr>' );
 213+ $wgOut->addHtml( Xml::closeElement( 'table' ) );
 214+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 215+ }
 216+
 217+ public function delete( $did ) {
 218+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 219+ $wgOut->setPagetitle( wfMsg( 'poll-title-delete' ) );
 220+
 221+ $dbr = wfGetDB( DB_SLAVE );
 222+ $query = $dbr->select( 'poll', 'question', array( 'id' => $did ) );
 223+
 224+ while( $row = $dbr->fetchObject( $query ) ) {
 225+ $question = htmlentities( $row->question, ENT_QUOTES, 'UTF-8' );
 226+ }
 227+
 228+ $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$did) ) ) );
 229+ $wgOut->addHtml( Xml::check( 'controll_delete' ).' '.wfMsg('poll-delete-question', $question).'<br />' );
 230+ $wgOut->addHtml( Xml::submitButton(wfMsg( 'poll-submit' )).' <a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>'.Xml::hidden('type', 'delete') );
 231+ $wgOut->addHtml( Xml::closeElement( 'form' ) );
 232+ }
 233+
 234+ public function change($cid) {
 235+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 236+
 237+ $wgOut->setPagetitle( wfMsg( 'poll-title-change' ) );
 238+
 239+ $dbr = wfGetDB( DB_SLAVE );
 240+ $query = $dbr->select( 'poll', 'question, alternative_1, alternative_2, alternative_3, alternative_4, alternative_5, alternative_6, creater, dis', array( 'id' => $cid ) );
 241+ $user = $wgUser->getName();
 242+
 243+ while( $row = $dbr->fetchObject( $query ) ) {
422244 $question = $row->question;
423 - }
424 -
425 - $controll_delete_right = $wgUser->isAllowed( 'poll-admin' );
426 - $controll_delete_blocked = $wgUser->isBlocked();
427 -
428 - if ( ( $creater != $user ) AND ( $controll_delete_right == false ) ) {
429 - $wgOut->addWikiMsg( 'poll-delete-right-error' );
430 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 245+ $alternative_1 = $row->alternative_1;
 246+ $alternative_2 = $row->alternative_2;
 247+ $alternative_3 = $row->alternative_3;
 248+ $alternative_4 = $row->alternative_4;
 249+ $alternative_5 = $row->alternative_5;
 250+ $alternative_6 = $row->alternative_6;
 251+ $creater = $row->creater;
 252+ $dis = $row->dis;
431253 }
432 -
433 - if ( isset($controll_delete_blocked) AND ( $controll_delete_blocked == true ) ) {
434 - $wgOut->addWikiMsg( 'poll-delete-block-error' );
435 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
436 - }
437 -
438 - if ( ( ( $creater == $user ) OR ( $controll_delete_right == true ) ) AND ( $controll_delete_blocked != true ) ) {
439 - if( isset($_POST['controll_delete']) AND $_POST['controll_delete'] == 1 ) {
440 - $dbw = wfGetDB( DB_MASTER );
441 - $user = $wgUser->getName();
442 -
443 - $dbw->delete( 'poll', array( 'id' => $pid ) );
444 - $dbw->delete( 'poll_answer', array( 'uid' => $pid ) );
445 -
446 - $log = new LogPage( "poll" );
447 - //$title = "Delete Poll";
448 - $title = $wgTitle;
449 - $log->addEntry( "poll", $title, wfMsg( 'poll-log-delete', "[[Benutzer:".htmlentities( $user, ENT_QUOTES, 'UTF-8' )."]]", htmlentities( $question, ENT_QUOTES, 'UTF-8' ) ) );
450 -
451 - $wgOut->addWikiMsg( 'poll-delete-pass' );
452 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
453 - }
454 - else {
455 - $wgOut->addWikiMsg( 'poll-delete-cancel' );
456 - $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
457 - }
458 - }
459 - }
460 -
461 - }
 254+
 255+ $controll_create_blocked = $wgUser->isBlocked();
 256+ if ( $user != $creater ) {
 257+ $wgOut->addWikiMsg( 'poll-change-right-error' );
 258+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 259+ }
 260+ elseif ( $controll_create_blocked == true ) {
 261+ $wgOut->addWikiMsg( 'poll-change-block-error' );
 262+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 263+ }
 264+ else {
 265+ $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => $wgTitle->getFullURL('action=submit&id='.$cid) ) ) );
 266+ $wgOut->addHtml( Xml::openElement( 'table' ) );
 267+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-question' ).':</td><td>'.Xml::input('question', false, $question).'</td></tr>' );
 268+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 1:</td><td>'.Xml::input('poll_alternative_1', false, $alternative_1).'</td></tr>' );
 269+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 2:</td><td>'.Xml::input('poll_alternative_2', false, $alternative_2).'</td></tr>' );
 270+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 3:</td><td>'.Xml::input('poll_alternative_3', false, $alternative_3).'</td></tr>' );
 271+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 4:</td><td>'.Xml::input('poll_alternative_4', false, $alternative_4).'</td></tr>' );
 272+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5', false, $alternative_5).'</td></tr>' );
 273+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6', false, $alternative_6).'</td></tr>' );
 274+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-dis' ).':</td><td>'.Xml::textarea('dis', $dis).'</td></tr>' );
 275+ $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('type', 'change').'</td></tr>' );
 276+ $wgOut->addHtml( Xml::closeElement( 'table' ) );
 277+ $wgOut->addHtml( Xml::closeElement( 'form' ) );
 278+ }
 279+ }
 280+
 281+ public function submit( $pid ) {
 282+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 283+
 284+ $type = $_POST['type'];
 285+
 286+ if($type == 'create') {
 287+ $controll_create_right = $wgUser->isAllowed( 'poll-create' );
 288+ $controll_create_blocked = $wgUser->isBlocked();
 289+ if ( $controll_create_right != true ) {
 290+ $wgOut->addWikiMsg( 'poll-create-right-error' );
 291+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 292+ }
 293+ elseif ( $controll_create_blocked == true ) {
 294+ $wgOut->addWikiMsg( 'poll-create-block-error' );
 295+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 296+ }
 297+
 298+ else {
 299+ $dbw = wfGetDB( DB_MASTER );
 300+ $question = $_POST['question'];
 301+ $alternative_1 = $_POST['poll_alternative_1'];
 302+ $alternative_2 = $_POST['poll_alternative_2'];
 303+ $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
 304+ $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
 305+ $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
 306+ $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
 307+ // FIXME: hardcoded text (in German)
 308+ $dis = ($_POST['dis'] != "")? $_POST['dis'] : "Keine Beschreibung vorhanden!";
 309+ $user = $wgUser->getName();
 310+
 311+ if($question != "" && $alternative_1 != "" && $alternative_2 != "") {
 312+ $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
 313+ 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
 314+ 'alternative_6' => $alternative_6, 'creater' => $user, 'dis' => $dis ) );
 315+
 316+ $log = new LogPage( "poll" );
 317+ $title = $wgTitle;
 318+ $log->addEntry( "poll", $title, wfMsg( 'poll-log-create', "[[User:".htmlentities( $user, ENT_QUOTES, 'UTF-8' )."]]", htmlentities( $question, ENT_QUOTES, 'UTF-8' ) ) );
 319+
 320+ $wgOut->addWikiMsg( 'poll-create-pass' );
 321+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 322+ }
 323+ else {
 324+ $wgOut->addWikiMsg( 'poll-create-fields-error' );
 325+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 326+ }
 327+ }
 328+ }
 329+
 330+ if($type == 'vote') {
 331+ $controll_vote_right = $wgUser->isAllowed( 'poll-vote' );
 332+ $controll_vote_blocked = $wgUser->isBlocked();
 333+ if ( $controll_vote_right != true ) {
 334+ $wgOut->addWikiMsg( 'poll-vote-right-error' );
 335+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 336+ }
 337+ elseif ( $controll_vote_blocked == true ) {
 338+ $wgOut->addWikiMsg( 'poll-vote-block-error' );
 339+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 340+ }
 341+
 342+ else {
 343+ $dbw = wfGetDB( DB_MASTER );
 344+ $dbr = wfGetDB( DB_SLAVE );
 345+ $vote = $_POST['vote'];
 346+ $user = $wgUser->getName();
 347+ $uid = $wgUser->getId();
 348+
 349+ $query = $dbr->select( 'poll_answer', 'uid', array( 'uid' => $uid ));
 350+ $num = 0;
 351+
 352+ while( $row = $dbr->fetchObject( $query ) ) {
 353+ if($row->uid != "") {
 354+ $num++;
 355+ }
 356+ }
 357+
 358+ if( $num == 0 ) {
 359+ $dbw->insert( 'poll_answer', array( 'pid' => $pid, 'uid' => $uid, 'vote' => $vote, 'user' => $user ) );
 360+
 361+ $wgOut->addWikiMsg( 'poll-vote-pass' );
 362+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 363+ }
 364+ else {
 365+ $wgOut->addWikiMsg( 'poll-vote-already-error' );
 366+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 367+ }
 368+ }
 369+ }
 370+
 371+ if($type == 'change') {
 372+ $dbr = wfGetDB( DB_SLAVE );
 373+ $query = $dbr->select( 'poll', 'creater', array( 'id' => $pid ) );
 374+ $user = $wgUser->getName();
 375+
 376+ while( $row = $dbr->fetchObject( $query ) ) {
 377+ $creater = htmlentities( $row->creater );
 378+ }
 379+
 380+ $controll_change_right = $wgUser->isAllowed( 'poll-admin' );
 381+ $controll_change_blocked = $wgUser->isBlocked();
 382+
 383+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 384+
 385+ if ( ( $creater != $user ) AND ( $controll_change_right == false ) ) {
 386+ $wgOut->addWikiMsg( 'poll-change-right-error' );
 387+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 388+ }
 389+
 390+ if ( isset($controll_delete_blocked) AND ( $controll_change_blocked == true ) ) {
 391+ $wgOut->addWikiMsg( 'poll-change-block-error' );
 392+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 393+ }
 394+
 395+ if ( ( ( $creater == $user ) OR ( $controll_change_right == true ) ) AND ( $controll_change_blocked != true ) ) {
 396+ $dbw = wfGetDB( DB_MASTER );
 397+ $question = $_POST['question'];
 398+ $alternative_1 = $_POST['poll_alternative_1'];
 399+ $alternative_2 = $_POST['poll_alternative_2'];
 400+ $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
 401+ $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
 402+ $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
 403+ $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
 404+ // FIXME: hardcoded text (in German)
 405+ $dis = ($_POST['dis'] != "")? $_POST['dis'] : "Keine Beschreibung vorhanden!";
 406+ $user = $wgUser->getName();
 407+
 408+ $dbw->update( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
 409+ 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
 410+ 'alternative_6' => $alternative_6, 'creater' => $user, 'dis' => $dis ), array( 'id' => $pid ) );
 411+
 412+ $log = new LogPage( "poll" );
 413+ $title = $wgTitle;
 414+ $log->addEntry( "poll", $title, wfMsg( 'poll-log-change', "[[User:".htmlentities( $user, ENT_QUOTES, 'UTF-8' )."]]", htmlentities( $question, ENT_QUOTES, 'UTF-8' ) ) );
 415+
 416+ $wgOut->addWikiMsg( 'poll-change-pass' );
 417+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 418+ }
 419+ }
 420+
 421+ if($type == 'delete') {
 422+ $dbr = wfGetDB( DB_SLAVE );
 423+ $query = $dbr->select( 'poll', 'creater, question', array( 'id' => $pid ) );
 424+ $user = $wgUser->getName();
 425+
 426+ while( $row = $dbr->fetchObject( $query ) ) {
 427+ $creater = htmlentities( $row->creater );
 428+ $question = $row->question;
 429+ }
 430+
 431+ $controll_delete_right = $wgUser->isAllowed( 'poll-admin' );
 432+ $controll_delete_blocked = $wgUser->isBlocked();
 433+
 434+ if ( ( $creater != $user ) AND ( $controll_delete_right == false ) ) {
 435+ $wgOut->addWikiMsg( 'poll-delete-right-error' );
 436+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 437+ }
 438+
 439+ if ( isset($controll_delete_blocked) AND ( $controll_delete_blocked == true ) ) {
 440+ $wgOut->addWikiMsg( 'poll-delete-block-error' );
 441+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 442+ }
 443+
 444+ if ( ( ( $creater == $user ) OR ( $controll_delete_right == true ) ) AND ( $controll_delete_blocked != true ) ) {
 445+ if( isset($_POST['controll_delete']) AND $_POST['controll_delete'] == 1 ) {
 446+ $dbw = wfGetDB( DB_MASTER );
 447+ $user = $wgUser->getName();
 448+
 449+ $dbw->delete( 'poll', array( 'id' => $pid ) );
 450+ $dbw->delete( 'poll_answer', array( 'uid' => $pid ) );
 451+
 452+ $log = new LogPage( "poll" );
 453+ //$title = "Delete Poll";
 454+ $title = $wgTitle;
 455+ $log->addEntry( "poll", $title, wfMsg( 'poll-log-delete', "[[User:".htmlentities( $user, ENT_QUOTES, 'UTF-8' )."]]", htmlentities( $question, ENT_QUOTES, 'UTF-8' ) ) );
 456+
 457+ $wgOut->addWikiMsg( 'poll-delete-pass' );
 458+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 459+ }
 460+ else {
 461+ $wgOut->addWikiMsg( 'poll-delete-cancel' );
 462+ $wgOut->addHtml( '<a href="'.$wgTitle->getFullURL('action=list').'">'.wfMsg('poll-back').'</a>' );
 463+ }
 464+ }
 465+ }
 466+ }
462467 }
Index: trunk/extensions/Poll/Poll.i18n.php
@@ -48,12 +48,12 @@
4949 'poll-delete-right-error' => 'You must be the creater of the Poll or have the "poll-admin" right to delete this Poll',
5050 'poll-delete-block-error' => 'You are not allowed to delete a poll because you use a blocked user',
5151 'poll-delete-pass' => 'Deleted!',
52 - 'poll-delete-cancel' => 'Poll don\'t delete(Checkbox don\'t set)!',
53 - 'poll-logpage' => 'Poll-Log',
54 - 'poll-logpagetext' => 'This is a log of changes to Polls.',
55 - 'poll-log-create' => '$1 created "$2"!',
56 - 'poll-log-change' => '$1 changed "$2"!',
57 - 'poll-log-delete' => '$1 deleted "$2"!',
 52+ 'poll-delete-cancel' => 'Do not delete the poll (checkbox not set)',
 53+ 'poll-logpage' => 'Poll log',
 54+ 'poll-logpagetext' => 'This is a log of changes to polls.',
 55+ 'poll-log-create' => '$1 created poll "$2"',
 56+ 'poll-log-change' => '$1 changed poll "$2"',
 57+ 'poll-log-delete' => '$1 deleted poll "$2"',
5858 'poll-logentry' => 'Polls changed',
5959 );
6060
Index: trunk/extensions/Poll/Poll.php
@@ -62,7 +62,6 @@
6363 $wgLogHeaders['poll'] = 'poll-logpagetext';
6464 $wgLogActions['poll/poll'] = 'poll-logentry';
6565
66 -
6766 # Schema changes
6867 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efPollSchemaUpdates';
6968
@@ -75,6 +74,6 @@
7675 $wgExtNewFields[] = array( 'poll', 'dis', "$base/archives/patch-dis.sql" ); // Add dis
7776 $wgExtNewTables[] = array( 'poll_answer', "$base/archives/Poll-answer.sql" ); // Initial answer tables
7877 $wgExtNewFields[] = array( 'poll_answer', 'user', "$base/archives/patch-user.sql" ); // Add user
79 - }
 78+ }
8079 return true;
8180 }

Comments

#Comment by Jan Luca (talk | contribs)   15:51, 2 June 2009

Resolved in r51368

Status & tagging log