r98557 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98556‎ | r98557 | r98558 >
Date:19:54, 30 September 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
work on submission page
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSignup.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSubmission.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -105,6 +105,11 @@
106106 'contest-signup-readrules' => 'I confirm that I have read, and agree to, [[$1|the contest rules]]',
107107 'contest-signup-challange' => 'What challange do you want to take on?',
108108
 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+
109114 // Special:Contest
110115 'contest-contest-title' => 'Contest: $1',
111116 'contest-contest-no-results' => 'There are no contestants to list.',
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php
@@ -36,7 +36,166 @@
3737 return;
3838 }
3939
 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();
4058
 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+ }
4185 }
4286
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 @@
173173 'default' => $user->getEmail(),
174174 'label-message' => 'contest-signup-email',
175175 'required' => true,
 176+ 'validation-callback' => array( __CLASS__, 'validateEmailField' )
176177 );
177178
178179 $fields['contestant-challangeid'] = array(
@@ -224,9 +225,9 @@
225226 }
226227
227228 /**
228 - * HTMLForm field validation-callback for Target field.
 229+ * HTMLForm field validation-callback for name field.
229230 *
230 - * @since 1.18
 231+ * @since 0.1
231232 *
232233 * @param $value String
233234 * @param $alldata Array
@@ -237,4 +238,18 @@
238239 return strlen( $value ) > 1;
239240 }
240241
 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+
241256 }
Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -14,6 +14,8 @@
1515 */
1616 class ContestContestant extends ContestDBObject {
1717
 18+ protected $contest = null;
 19+
1820 /**
1921 * Method to get an instance so methods that ought to be static,
2022 * but can't be due to PHP 5.2 not having LSB, can be called on
@@ -88,7 +90,7 @@
8991
9092 'full_name' => 'str',
9193 'user_name' => 'str',
92 - 'email_name' => 'str',
 94+ 'email' => 'str',
9395
9496 'country' => 'str',
9597 'volunteer' => 'bool',
@@ -109,7 +111,7 @@
110112 return array(
111113 'full_name' => '',
112114 'user_name' => '',
113 - 'email_name' => '',
 115+ 'email' => '',
114116
115117 'country' => '',
116118 'volunteer' => false,
@@ -117,4 +119,30 @@
118120 );
119121 }
120122
 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+
121149 }

Comments

#Comment by Nikerabbit (talk | contribs)   06:10, 1 October 2011

Typo: untill -> until

#Comment by Jeroen De Dauw (talk | contribs)   23:18, 1 October 2011

fixed by r98641

Status & tagging log