r50523 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50522‎ | r50523 | r50524 >
Date:17:33, 12 May 2009
Author:jan
Status:deferred
Tags:
Comment:
* Add SQL-File for update.php
* Resolve bugs
Modified paths:
  • /trunk/extensions/Poll/Poll.php (modified) (history)
  • /trunk/extensions/Poll/Poll.sql (added) (history)
  • /trunk/extensions/Poll/Poll_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Poll/Poll.sql
@@ -0,0 +1,15 @@
 2+-- (c) Aaron Schulz, 2007-2009, GPL
 3+-- Table structure for table `Flagged Revisions`
 4+-- Replace /*$wgDBprefix*/ with the proper prefix
 5+-- Replace /*$wgDBTableOptions*/ with the correct options
 6+
 7+CREATE TABLE /*$wgDBprefix*/poll (
 8+`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
 9+`question` VARCHAR( 255 ) NOT NULL ,
 10+`alternative_1` VARCHAR( 255 ) NOT NULL ,
 11+`alternative_2` VARCHAR( 255 ) NOT NULL ,
 12+`alternative_3` VARCHAR( 255 ) NOT NULL ,
 13+`alternative_4` VARCHAR( 255 ) NOT NULL ,
 14+`alternative_5` VARCHAR( 255 ) NOT NULL ,
 15+`alternative_6` VARCHAR( 255 ) NOT NULL
 16+) /*$wgDBTableOptions*/;
\ No newline at end of file
Property changes on: trunk/extensions/Poll/Poll.sql
___________________________________________________________________
Added: svn:eol-style
117 + native
Index: trunk/extensions/Poll/Poll_body.php
@@ -27,77 +27,88 @@
2828 $this->submit();
2929 }
3030 }
31 - public function create() {
32 - global $wgRequest, $wgOut, $wgUser;
3331
34 - $wgOut->setPagetitle( wfMsg( 'poll-title-create' ) );
 32+ public function create() {
 33+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 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' => $wgTitle->getFullURL('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('type', '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 = $_POST['type'];
 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+ }
3593
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 - }
4294 else {
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 - }
 95+ $dbw = wfGetDB( DB_MASTER );
 96+ $question = $_POST['question'];
 97+ $alternative_1 = $_POST['poll_alternative_1'];
 98+ $alternative_2 = $_POST['poll_alternative_2'];
 99+ $alternative_3 = ($_POST['poll_alternative_3'] != "")? $_POST['poll_alternative_3'] : "";
 100+ $alternative_4 = ($_POST['poll_alternative_4'] != "")? $_POST['poll_alternative_4'] : "";
 101+ $alternative_5 = ($_POST['poll_alternative_5'] != "")? $_POST['poll_alternative_5'] : "";
 102+ $alternative_6 = ($_POST['poll_alternative_6'] != "")? $_POST['poll_alternative_6'] : "";
 103+
 104+ if($question != "" && $alternative_1 != "" && $alternative_2 != "") {
 105+ $dbw->insert( 'poll', array( 'question' => $question, 'alternative_1' => $alternative_1, 'alternative_2' => $alternative_2,
 106+ 'alternative_3' => $alternative_3, 'alternative_4' => $alternative_4, 'alternative_5' => $alternative_5,
 107+ 'alternative_6' => $alternative_6 ) );
 108+ }
 109+ else {
 110+ $wgOut->addWikiMsg( 'poll-create-fields-error' );
 111+ }
 112+ }
 113+ }
 114+ }
104115 }
Index: trunk/extensions/Poll/Poll.php
@@ -55,3 +55,15 @@
5656 $wgExtensionAliasesFiles['Poll'] = $dir . 'Poll.alias.php';
5757 $wgSpecialPages['Poll'] = 'Poll'; # Let MediaWiki know about your new special page.
5858 $wgSpecialPageGroups['Poll'] = 'other';
 59+
 60+# Schema changes
 61+$wgHooks['LoadExtensionSchemaUpdates'][] = 'efPollSchemaUpdates';
 62+
 63+function efPollSchemaUpdates() {
 64+ global $wgDBtype, $wgExtNewFields, $wgExtPGNewFields, $wgExtNewIndexes, $wgExtNewTables;
 65+ $base = dirname(__FILE__);
 66+ if( $wgDBtype == 'mysql' ) {
 67+ $wgExtNewTables[] = array( 'poll', "$base/Poll.sql" ); // Initial install tables
 68+ }
 69+ return true;
 70+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r50524Fix for r50523: update author and extension's name :)ialex17:46, 12 May 2009

Status & tagging log