Index: trunk/extensions/Contest/Contest.i18n.php |
— | — | @@ -105,6 +105,11 @@ |
106 | 106 | 'contest-signup-readrules' => 'I confirm that I have read, and agree to, [[$1|the contest rules]]', |
107 | 107 | 'contest-signup-challange' => 'What challange do you want to take on?', |
108 | 108 | |
| 109 | + // Special:ContestSubmission |
| 110 | + 'contest-submission-submit' => 'Submit', |
| 111 | + 'contest-submission-unknown' => 'There is no contest with the provided name.', |
| 112 | + 'contest-submission-header' => 'On this page you can modify your submission untill the deadline.', |
| 113 | + |
109 | 114 | // Special:Contest |
110 | 115 | 'contest-contest-title' => 'Contest: $1', |
111 | 116 | 'contest-contest-no-results' => 'There are no contestants to list.', |
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php |
— | — | @@ -36,7 +36,166 @@ |
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
| 40 | + if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
| 41 | + $contestant = ContestContestant::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontestant-id' ) ) ); |
| 42 | + $this->showPage( $contestant ); |
| 43 | + } |
| 44 | + else { |
| 45 | + $this->handleViewRequest( $subPage ); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * |
| 51 | + * |
| 52 | + * @since 0.1 |
| 53 | + * |
| 54 | + * @param string $contestName |
| 55 | + */ |
| 56 | + protected function handleViewRequest( $contestName ) { |
| 57 | + $out = $this->getOutput(); |
40 | 58 | |
| 59 | + $contest = Contest::s()->selectRow( null, array( 'name' => $contestName ) ); |
| 60 | + |
| 61 | + if ( $contest === false ) { |
| 62 | + $this->showError( 'contest-submission-unknown' ); |
| 63 | + $out->addHTML( '<br /><br /><br /><br />' ); |
| 64 | + $out->returnToMain(); |
| 65 | + } |
| 66 | + else { |
| 67 | + // Check if the user is already a contestant in this contest. |
| 68 | + // If he is, reirect to submission page, else show signup form. |
| 69 | + $contestant = ContestContestant::s()->selectRow( |
| 70 | + 'id', |
| 71 | + array( |
| 72 | + 'contest_id' => $contest->getId(), |
| 73 | + 'user_id' => $this->getUser()->getId() |
| 74 | + ) |
| 75 | + ); |
| 76 | + |
| 77 | + if ( $contestant === false ) { |
| 78 | + $out->redirect( SpecialPage::getTitleFor( 'ContestSignup', $contestName )->getLocalURL() ); |
| 79 | + } |
| 80 | + else { |
| 81 | + $contestant->setContest( $contest ); |
| 82 | + $this->showPage( $contestant ); |
| 83 | + } |
| 84 | + } |
41 | 85 | } |
42 | 86 | |
43 | | -} |
\ No newline at end of file |
| 87 | + protected function showPage( ContestContestant $contestant ) { |
| 88 | + $this->getOutput()->setPageTitle( $contestant->getContest()->getField( 'name' ) ); |
| 89 | + $this->getOutput()->addWikiMsg( 'contest-submission-header', $contestant->getContest()->getField( 'name' ) ); |
| 90 | + |
| 91 | + $form = new HTMLForm( $this->getFormFields( $contestant ), $this->getContext() ); |
| 92 | + |
| 93 | + $form->setSubmitCallback( array( __CLASS__, 'handleSubmission' ) ); |
| 94 | + $form->setSubmitText( wfMsg( 'contest-submission-submit' ) ); |
| 95 | + |
| 96 | + if( $form->show() ){ |
| 97 | + // TODO: we might want to have a title field here |
| 98 | + $this->getOutput()->redirect( $this->getTitle( $contestant->getContest()->getField( 'name' ) )->getLocalURL() ); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Handle form submission. |
| 104 | + * |
| 105 | + * @since 0.1 |
| 106 | + * |
| 107 | + * @return true|array |
| 108 | + */ |
| 109 | + public static function handleSubmission( array $data ) { |
| 110 | + $user = $GLOBALS['wgUser']; //$this->getUser(); |
| 111 | + |
| 112 | + $user->setEmail( $data['contestant-email'] ); |
| 113 | + $user->setRealName( $data['contestant-realname'] ); |
| 114 | + |
| 115 | + $contestant = new ContestContestant( array( |
| 116 | + 'id' => $data['contestant-id'], |
| 117 | + |
| 118 | + 'volunteer' => $data['contestant-volunteer'], |
| 119 | + 'wmf' => $data['contestant-wmf'], |
| 120 | + ) ); |
| 121 | + |
| 122 | + return $contestant->writeToDB(); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Gets the field definitions for the form. |
| 127 | + * |
| 128 | + * @since 0.1 |
| 129 | + * |
| 130 | + * @param ContestContestant $contest |
| 131 | + */ |
| 132 | + protected function getFormFields( ContestContestant $contestant ) { |
| 133 | + $fields = array(); |
| 134 | + |
| 135 | + $user = $this->getUser(); |
| 136 | + |
| 137 | + $fields['contestant-id'] = array( |
| 138 | + 'type' => 'hidden', |
| 139 | + 'default' => $contestant->getId(), |
| 140 | + 'id' => 'contest-id', |
| 141 | + ); |
| 142 | + |
| 143 | + $fields['contestant-realname'] = array( |
| 144 | + 'type' => 'text', |
| 145 | + 'default' => $user->getRealName(), |
| 146 | + 'label-message' => 'contest-signup-realname', |
| 147 | + 'required' => true, |
| 148 | + 'validation-callback' => array( __CLASS__, 'validateNameField' ) |
| 149 | + ); |
| 150 | + |
| 151 | + $fields['contestant-email'] = array( |
| 152 | + 'type' => 'text', |
| 153 | + 'default' => $user->getEmail(), |
| 154 | + 'label-message' => 'contest-signup-email', |
| 155 | + 'required' => true, |
| 156 | + 'validation-callback' => array( __CLASS__, 'validateEmailField' ) |
| 157 | + ); |
| 158 | + |
| 159 | + $fields['contestant-volunteer'] = array( |
| 160 | + 'type' => 'check', |
| 161 | + 'default' => '0', |
| 162 | + 'label-message' => 'contest-signup-volunteer', |
| 163 | + ); |
| 164 | + |
| 165 | + $fields['contestant-wmf'] = array( |
| 166 | + 'type' => 'check', |
| 167 | + 'default' => '0', |
| 168 | + 'label-message' => 'contest-signup-wmf', |
| 169 | + ); |
| 170 | + |
| 171 | + return $fields; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * HTMLForm field validation-callback for name field. |
| 176 | + * |
| 177 | + * @since 0.1 |
| 178 | + * |
| 179 | + * @param $value String |
| 180 | + * @param $alldata Array |
| 181 | + * |
| 182 | + * @return true|string |
| 183 | + */ |
| 184 | + public static function validateNameField( $value, $alldata = null ) { |
| 185 | + return strlen( $value ) > 1; |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * HTMLForm field validation-callback for email field. |
| 190 | + * |
| 191 | + * @since 0.1 |
| 192 | + * |
| 193 | + * @param $value String |
| 194 | + * @param $alldata Array |
| 195 | + * |
| 196 | + * @return true|string |
| 197 | + */ |
| 198 | + public static function validateEmailField( $value, $alldata = null ) { |
| 199 | + return Sanitizer::validateEmail( $value ); |
| 200 | + } |
| 201 | + |
| 202 | +} |
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php |
— | — | @@ -172,6 +172,7 @@ |
173 | 173 | 'default' => $user->getEmail(), |
174 | 174 | 'label-message' => 'contest-signup-email', |
175 | 175 | 'required' => true, |
| 176 | + 'validation-callback' => array( __CLASS__, 'validateEmailField' ) |
176 | 177 | ); |
177 | 178 | |
178 | 179 | $fields['contestant-challangeid'] = array( |
— | — | @@ -224,9 +225,9 @@ |
225 | 226 | } |
226 | 227 | |
227 | 228 | /** |
228 | | - * HTMLForm field validation-callback for Target field. |
| 229 | + * HTMLForm field validation-callback for name field. |
229 | 230 | * |
230 | | - * @since 1.18 |
| 231 | + * @since 0.1 |
231 | 232 | * |
232 | 233 | * @param $value String |
233 | 234 | * @param $alldata Array |
— | — | @@ -237,4 +238,18 @@ |
238 | 239 | return strlen( $value ) > 1; |
239 | 240 | } |
240 | 241 | |
| 242 | + /** |
| 243 | + * HTMLForm field validation-callback for email field. |
| 244 | + * |
| 245 | + * @since 0.1 |
| 246 | + * |
| 247 | + * @param $value String |
| 248 | + * @param $alldata Array |
| 249 | + * |
| 250 | + * @return true|string |
| 251 | + */ |
| 252 | + public static function validateEmailField( $value, $alldata = null ) { |
| 253 | + return Sanitizer::validateEmail( $value ); |
| 254 | + } |
| 255 | + |
241 | 256 | } |
Index: trunk/extensions/Contest/includes/ContestContestant.php |
— | — | @@ -14,6 +14,8 @@ |
15 | 15 | */ |
16 | 16 | class ContestContestant extends ContestDBObject { |
17 | 17 | |
| 18 | + protected $contest = null; |
| 19 | + |
18 | 20 | /** |
19 | 21 | * Method to get an instance so methods that ought to be static, |
20 | 22 | * but can't be due to PHP 5.2 not having LSB, can be called on |
— | — | @@ -88,7 +90,7 @@ |
89 | 91 | |
90 | 92 | 'full_name' => 'str', |
91 | 93 | 'user_name' => 'str', |
92 | | - 'email_name' => 'str', |
| 94 | + 'email' => 'str', |
93 | 95 | |
94 | 96 | 'country' => 'str', |
95 | 97 | 'volunteer' => 'bool', |
— | — | @@ -109,7 +111,7 @@ |
110 | 112 | return array( |
111 | 113 | 'full_name' => '', |
112 | 114 | 'user_name' => '', |
113 | | - 'email_name' => '', |
| 115 | + 'email' => '', |
114 | 116 | |
115 | 117 | 'country' => '', |
116 | 118 | 'volunteer' => false, |
— | — | @@ -117,4 +119,30 @@ |
118 | 120 | ); |
119 | 121 | } |
120 | 122 | |
| 123 | + /** |
| 124 | + * Gets the contest for this participant. |
| 125 | + * |
| 126 | + * @since 0.1 |
| 127 | + * |
| 128 | + * @return Contest |
| 129 | + */ |
| 130 | + public function getContest() { |
| 131 | + if ( is_null( $this->contest ) ) { |
| 132 | + $this->contest = Contest::s()->selectRow( null, array( 'id' => $this->getField( 'contest_id' ) ) ); |
| 133 | + } |
| 134 | + |
| 135 | + return $this->contest; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Sets the contest for this participant. |
| 140 | + * |
| 141 | + * @since 0.1 |
| 142 | + * |
| 143 | + * @param Contest $contest |
| 144 | + */ |
| 145 | + public function setContest( Contest $contest ) { |
| 146 | + $this->contest = $contest; |
| 147 | + } |
| 148 | + |
121 | 149 | } |