r50495 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50494‎ | r50495 | r50496 >
Date:19:04, 11 May 2009
Author:demon
Status:deferred
Tags:
Comment:
* Style fixes: whitespace, indentation, etc
* Remove some un-needed variables and globals
* TODO/FIXME: If $action == 'submit', in the submit() method, $action could never possibly be 'create' as well, so those checks can't happen. Also, don't use $_POST directly, that's what $wgRequest is for.
Modified paths:
  • /trunk/extensions/Poll/Poll.php (modified) (history)
  • /trunk/extensions/Poll/Poll_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Poll/Poll_body.php
@@ -1,12 +1,12 @@
22 <?php
33
44 class Poll extends SpecialPage {
5 - function __construct() {
 5+
 6+ public function __construct() {
67 parent::__construct( 'Poll' );
7 - wfLoadExtensionMessages( 'Poll' );
88 }
99
10 - function execute( $par ) {
 10+ public function execute( $par ) {
1111 global $wgRequest, $wgOut;
1212
1313 $this->setHeaders();
@@ -22,91 +22,82 @@
2323 if ( $action == "vote" ) {
2424 $this->vote();
2525 }
26 -
27 - if ( $action == "submit" ) {
28 - $this->submit();
29 - }
 26+
 27+ if ( $action == "submit" ) {
 28+ $this->submit();
 29+ }
3030 }
31 -
32 - public function create() {
33 - global $wgRequest, $wgOut, $wgUser;
34 -
35 - $wgOut->setPagetitle( wfMsg( 'poll-title-create' ) );
36 -
37 - $controll_create_right = $wgUser->isAllowed( 'poll-create' );
38 - $controll_create_blocked = $wgUser->isBlocked();
39 - if ( $controll_create_right != true ) {
40 - $wgOut->addWikiMsg( 'poll-create-right-error' );
41 - }
42 - elseif ( $controll_create_blocked == true ) {
43 - $wgOut->addWikiMsg( 'poll-create-block-error' );
44 - }
45 - else {
46 - $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => 'index.php?title=Special:Poll&action=submit' ) ) );
47 - $wgOut->addHtml( Xml::openElement( 'table' ) );
48 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-question' ).':</td><td>'.Xml::input('question').'</td></tr>' );
49 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 1:</td><td>'.Xml::input('poll_alternative_1').'</td></tr>' );
50 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 2:</td><td>'.Xml::input('poll_alternative_2').'</td></tr>' );
51 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 3:</td><td>'.Xml::input('poll_alternative_3').'</td></tr>' );
52 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 4:</td><td>'.Xml::input('poll_alternative_4').'</td></tr>' );
53 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5').'</td></tr>' );
54 - $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6').'</td></tr>' );
55 - $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('action', 'create').'</td></tr>' );
56 - $wgOut->addHtml( Xml::closeElement( 'table' ) );
57 - $wgOut->addHtml( Xml::closeElement( 'form' ) );
58 - }
59 - }
60 -
61 - public function vote() {
62 - global $wgRequest, $wgOut, $wgUser;
63 -
64 - $wgOut->setPagetitle( wfMsg( 'poll-title-vote' ) );
65 -
66 - $controll_create_right = $wgUser->isAllowed( 'poll-vote' );
67 - $controll_create_blocked = $wgUser->isBlocked();
68 - if ( $controll_create_right != true ) {
69 - $wgOut->addWikiMsg( 'poll-vote-right-error' );
70 - }
71 - elseif ( $controll_create_blocked == true ) {
72 - $wgOut->addWikiMsg( 'poll-vote-block-error' );
73 - }
74 - else {
75 -
76 - }
77 - }
78 -
79 - public function submit() {
80 - global $wgRequest, $wgOut, $wgUser;
81 -
82 - $type = htmlenttitles($_POST['action']);
83 -
84 - if($type == 'create') {
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 - }
90 - elseif ( $controll_create_blocked == true ) {
91 - $wgOut->addWikiMsg( 'poll-create-block-error' );
92 - }
 31+ public function create() {
 32+ global $wgRequest, $wgOut, $wgUser;
 33+
 34+ $wgOut->setPagetitle( wfMsg( 'poll-title-create' ) );
 35+
 36+ if ( !$wgUser->isAllowed( 'poll-create' ) ) {
 37+ $wgOut->addWikiMsg( 'poll-create-right-error' );
 38+ }
 39+ elseif ( $wgUser->isBlocked() ) {
 40+ $wgOut->addWikiMsg( 'poll-create-block-error' );
 41+ }
9342 else {
94 - $dbw = wfGetDB( DB_MASTER );
95 - $question = $_POST['question'];
96 - $alternative_1 = $_POST['poll_alternative_1'];
97 - $alternative_2 = $_POST['poll_alternative_2'];
98 - $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
99 - $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
100 - $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
101 - $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
102 -
103 - if($question != "" && $alternative_1 != "" && $alternative_2 != "") {
104 - $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
105 - 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
106 - 'alternative_6' => $alternative_6 ) );
107 - }
108 - else {
109 - $wgOut->addWikiMsg( 'poll-create-fields-error' );
110 - }
111 - }
112 - }
 43+ $wgOut->addHtml( Xml::openElement( 'form', array('method'=> 'post', 'action' => 'index.php?title=Special:Poll&action=submit' ) ) );
 44+ $wgOut->addHtml( Xml::openElement( 'table' ) );
 45+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-question' ).':</td><td>'.Xml::input('question').'</td></tr>' );
 46+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 1:</td><td>'.Xml::input('poll_alternative_1').'</td></tr>' );
 47+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 2:</td><td>'.Xml::input('poll_alternative_2').'</td></tr>' );
 48+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 3:</td><td>'.Xml::input('poll_alternative_3').'</td></tr>' );
 49+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 4:</td><td>'.Xml::input('poll_alternative_4').'</td></tr>' );
 50+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 5:</td><td>'.Xml::input('poll_alternative_5').'</td></tr>' );
 51+ $wgOut->addHtml( '<tr><td>'.wfMsg( 'poll-alternative' ).' 6:</td><td>'.Xml::input('poll_alternative_6').'</td></tr>' );
 52+ $wgOut->addHtml( '<tr><td>'.Xml::submitButton(wfMsg( 'poll-submit' )).''.Xml::hidden('action', 'create').'</td></tr>' );
 53+ $wgOut->addHtml( Xml::closeElement( 'table' ) );
 54+ $wgOut->addHtml( Xml::closeElement( 'form' ) );
 55+ }
 56+ }
 57+
 58+ public function vote() {
 59+ global $wgOut, $wgUser;
 60+
 61+ $wgOut->setPagetitle( wfMsg( 'poll-title-vote' ) );
 62+
 63+ if ( !$wgUser->isAllowed( 'poll-vote' ); ) {
 64+ $wgOut->addWikiMsg( 'poll-vote-right-error' );
 65+ }
 66+ elseif ( $wgUser-isBlocked() ) {
 67+ $wgOut->addWikiMsg( 'poll-vote-block-error' );
 68+ }
 69+ else {
 70+ }
 71+ }
 72+
 73+ public function submit() {
 74+ global $wgRequest, $wgOut, $wgUser;
 75+
 76+ $type = htmlenttitles($_POST['action']);
 77+
 78+ if ( $type == 'create' && !$wgUser->isAllowed( 'poll-create' ) ) {
 79+ $wgOut->addWikiMsg( 'poll-create-right-error' );
 80+ }
 81+ elseif ( $type == 'create' && $wgUser->isBlocked() ) {
 82+ $wgOut->addWikiMsg( 'poll-create-block-error' );
 83+ }
 84+ else {
 85+ $dbw = wfGetDB( DB_MASTER );
 86+ $question = $_POST['question'];
 87+ $alternative_1 = $_POST['poll_alternative_1'];
 88+ $alternative_2 = $_POST['poll_alternative_2'];
 89+ $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
 90+ $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
 91+ $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
 92+ $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
 93+
 94+ if($question != "" && $alternative_1 != "" && $alternative_2 != "") {
 95+ $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
 96+ 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
 97+ 'alternative_6' => $alternative_6 ) );
 98+ }
 99+ else {
 100+ $wgOut->addWikiMsg( 'poll-create-fields-error' );
 101+ }
 102+ }
 103+ }
113104 }
Index: trunk/extensions/Poll/Poll.php
@@ -54,4 +54,4 @@
5555 $wgExtensionMessagesFiles['Poll'] = $dir . 'Poll.i18n.php';
5656 $wgExtensionAliasesFiles['Poll'] = $dir . 'Poll.alias.php';
5757 $wgSpecialPages['Poll'] = 'Poll'; # Let MediaWiki know about your new special page.
58 -$wgSpecialPageGroups['Poll'] = 'other';
\ No newline at end of file
 58+$wgSpecialPageGroups['Poll'] = 'other';

Status & tagging log