r98456 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98455‎ | r98456 | r98457 >
Date:21:16, 29 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on submission form
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSignup.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialEditContest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -103,6 +103,7 @@
104104 'contest-signup-volunteer' => 'I am interested in volunteer opportunities',
105105 'contest-signup-wmf' => 'I am interested in working for the Wikimedia Foundation',
106106 'contest-signup-readrules' => 'I confirm that I have read, and agree to, [[$1|the contest rules]]',
 107+ 'contest-signup-challange' => 'What challange do you want to take on?',
107108
108109 // Special:Contest
109110 'contest-contest-title' => 'Contest: $1',
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php
@@ -37,7 +37,7 @@
3838 }
3939
4040 if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
41 - $this->handleSubmission();
 41+ $this->showSignupForm( Contest::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontest-id' ) ) ) );
4242 }
4343 else {
4444 $this->showPage( $subPage );
@@ -48,11 +48,25 @@
4949 * Handle form submission.
5050 *
5151 * @since 0.1
 52+ *
 53+ * @return true|array
5254 */
53 - protected function handleSubmission() {
54 - $request = $this->getRequest();
 55+ public static function handleSubmission( array $data ) {
 56+ $user = $GLOBALS['wgUser']; //$this->getUser();
5557
 58+ $user->setEmail( $data['contestant-email'] );
 59+ $user->setRealName( $data['contestant-realname'] );
5660
 61+ $contestant = new ContestContestant( array(
 62+ 'contest_id' => $data['contest-id'],
 63+ 'user_id' => $user->getId(),
 64+ 'challange_id' => $data['contestant-challangeid'],
 65+
 66+ 'volunteer' => $data['contestant-volunteer'],
 67+ 'wmf' => $data['contestant-wmf'],
 68+ ) );
 69+
 70+ return $contestant->writeToDB();
5771 }
5872
5973 /**
@@ -89,14 +103,30 @@
90104 * @param Contest $contest
91105 */
92106 protected function showSignupForm( Contest $contest ) {
93 - $out = $this->getOutput();
94107 $form = new HTMLForm( $this->getFormFields( $contest ), $this->getContext() );
95108
 109+ $form->setSubmitCallback( array( __CLASS__, 'handleSubmission' ) );
96110 $form->setSubmitText( wfMsg( 'contest-signup-submit' ) );
97 - $form->show();
 111+
 112+ if( $form->show() ){
 113+ $this->showSucess( $contest );
 114+ }
98115 }
99116
100117 /**
 118+ * Display a success message and helpfull links for further contest participation.
 119+ *
 120+ * @since 0.1
 121+ *
 122+ * @param Contest $contest
 123+ */
 124+ protected function showSucess( Contest $contest ) {
 125+ $out = $this->getOutput();
 126+
 127+ // TODO
 128+ }
 129+
 130+ /**
101131 * Gets the field definitions for the form.
102132 *
103133 * @since 0.1
@@ -108,49 +138,88 @@
109139
110140 $user = $this->getUser();
111141
112 - $fields[] = array(
 142+ $fields['contest-id'] = array(
113143 'type' => 'hidden',
114144 'default' => $contest->getId(),
115 - 'name' => 'contest-id',
116145 'id' => 'contest-id',
117146 );
118147
119 - $fields[] = array(
 148+ $fields['contestant-realname'] = array(
120149 'type' => 'text',
121150 'default' => $user->getRealName(),
122151 'label-message' => 'contest-signup-realname',
123 - 'name' => 'contestant-realname',
 152+ 'required' => true,
 153+ 'validation-callback' => array( __CLASS__, 'validateNameField' )
124154 );
125155
126 - $fields[] = array(
 156+ $fields['contestant-email'] = array(
127157 'type' => 'text',
128158 'default' => $user->getEmail(),
129159 'label-message' => 'contest-signup-email',
130 - 'name' => 'contestant-email',
 160+ 'required' => true,
131161 );
132162
133 - $fields[] = array(
 163+ $fields['contestant-challangeid'] = array(
 164+ 'type' => 'radio',
 165+ 'label-message' => 'contest-signup-challange',
 166+ 'options' => $this->getChallangesList( $contest ),
 167+ 'required' => true,
 168+ );
 169+
 170+ $fields['contestant-volunteer'] = array(
134171 'type' => 'check',
135172 'default' => '0',
136173 'label-message' => 'contest-signup-volunteer',
137 - 'name' => 'contestant-volunteer',
138174 );
139175
140 - $fields[] = array(
 176+ $fields['contestant-wmf'] = array(
141177 'type' => 'check',
142178 'default' => '0',
143179 'label-message' => 'contest-signup-wmf',
144 - 'name' => 'contestant-wmf',
145180 );
146181
147 - $fields[] = array(
 182+ $fields['contestant-readrules'] = array(
148183 'type' => 'check',
149184 'default' => '0',
150185 'label-message' => array( 'contest-signup-readrules', $contest->getField( 'rules_page' ) ),
151 - 'name' => 'contestant-readrules',
152186 );
153187
154188 return $fields;
155189 }
156190
 191+ /**
 192+ * Gets a list of contests that can be fed directly to the options field of
 193+ * an HTMLForm radio input.
 194+ * challange title => challange id
 195+ *
 196+ * @since 0.1
 197+ *
 198+ * @param Contest $contest
 199+ *
 200+ * @return array
 201+ */
 202+ protected function getChallangesList( Contest $contest ) {
 203+ $list = array();
 204+
 205+ foreach ( $contest->getChallanges() as /* ContestChallange */ $challange ) {
 206+ $list[$challange->getField( 'title' )] = $challange->getId();
 207+ }
 208+
 209+ return $list;
 210+ }
 211+
 212+ /**
 213+ * HTMLForm field validation-callback for Target field.
 214+ *
 215+ * @since 1.18
 216+ *
 217+ * @param $value String
 218+ * @param $alldata Array
 219+ *
 220+ * @return true|string
 221+ */
 222+ public static function validateNameField( $value, $alldata = null ) {
 223+ return strlen( $value ) > 1;
 224+ }
 225+
157226 }
Index: trunk/extensions/Contest/specials/SpecialEditContest.php
@@ -159,7 +159,7 @@
160160 $fields['name'] = array (
161161 'type' => 'text',
162162 'label-message' => 'contest-edit-name',
163 - 'id' => 'contest-name-field'
 163+ 'id' => 'contest-name-field',
164164 );
165165
166166 $fields['status'] = array (

Status & tagging log