r98712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98711‎ | r98712 | r98713 >
Date:20:43, 2 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed form validation messages
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.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
@@ -112,6 +112,12 @@
113113 'contest-signup-draft' => 'This contest has not started yet. Please be patient.',
114114 'contest-signup-country' => 'Your country',
115115
 116+ 'contest-signup-require-rules' => 'You need to agree to the contest rules.',
 117+ 'contest-signup-require-country' => 'You need to provide your country of residence.',
 118+ 'contest-signup-invalid-email' => 'The email address you provided is not valid.',
 119+ 'contest-signup-invalid-name' => 'The name you provided is to short.',
 120+ 'contest-signup-require-challange' => 'You must select a challange.',
 121+
116122 // Special:ContestSubmission
117123 'contest-submission-submit' => 'Submit',
118124 'contest-submission-unknown' => 'There is no contest with the provided name.',
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php
@@ -225,6 +225,7 @@
226226 'label-message' => 'contest-signup-challange',
227227 'options' => $this->getChallangesList( $contest ),
228228 'required' => true,
 229+ 'validation-callback' => array( __CLASS__, 'validateChallangeField' )
229230 );
230231
231232 if ( $challangeId !== false ) {
@@ -247,6 +248,7 @@
248249 'type' => 'check',
249250 'default' => '0',
250251 'label-message' => array( 'contest-signup-readrules', $contest->getField( 'rules_page' ) ),
 252+ 'validation-callback' => array( __CLASS__, 'validateRulesField' )
251253 );
252254
253255 return $fields;
@@ -284,7 +286,11 @@
285287 * @return true|string
286288 */
287289 public static function validateNameField( $value, $alldata = null ) {
288 - return strlen( $value ) > 1;
 290+ if ( strlen( $value ) < 2 ) {
 291+ return wfMsg( 'contest-signup-invalid-name' );
 292+ }
 293+
 294+ return true;
289295 }
290296
291297 /**
@@ -298,7 +304,11 @@
299305 * @return true|string
300306 */
301307 public static function validateEmailField( $value, $alldata = null ) {
302 - return Sanitizer::validateEmail( $value );
 308+ if ( !Sanitizer::validateEmail( $value ) ) {
 309+ return wfMsg( 'contest-signup-invalid-email' );
 310+ }
 311+
 312+ return true;
303313 }
304314
305315 /**
@@ -312,6 +322,47 @@
313323 * @return true|string
314324 */
315325 public static function validateCountryField( $value, $alldata = null ) {
316 - return $value !== '';
 326+ if ( $value === '' ) {
 327+ return wfMsg( 'contest-signup-require-country' );
 328+ }
 329+
 330+ return true;
317331 }
 332+
 333+ /**
 334+ * HTMLForm field validation-callback for rules field.
 335+ *
 336+ * @since 0.1
 337+ *
 338+ * @param $value String
 339+ * @param $alldata Array
 340+ *
 341+ * @return true|string
 342+ */
 343+ public static function validateRulesField( $value, $alldata = null ) {
 344+ if ( !$value ) {
 345+ return wfMsg( 'contest-signup-require-rules' );
 346+ }
 347+
 348+ return true;
 349+ }
 350+
 351+ /**
 352+ * HTMLForm field validation-callback for challange field.
 353+ *
 354+ * @since 0.1
 355+ *
 356+ * @param $value String
 357+ * @param $alldata Array
 358+ *
 359+ * @return true|string
 360+ */
 361+ public static function validateChallangeField( $value, $alldata = null ) {
 362+ if ( is_null( $value ) ) {
 363+ return wfMsg( 'contest-signup-require-challange' );
 364+ }
 365+
 366+ return true;
 367+ }
 368+
318369 }
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php
@@ -95,7 +95,7 @@
9696 );
9797
9898 if ( $contestant === false ) {
99 - $out->redirect( SpecialPage::getTitleFor( 'ContestSignup', $contest->getField( 'name' ) )->getLocalURL() );
 99+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'ContestSignup', $contest->getField( 'name' ) )->getLocalURL() );
100100 }
101101 else {
102102 $contestant->setContest( $contest );
@@ -219,7 +219,11 @@
220220 * @return true|string
221221 */
222222 public static function validateNameField( $value, $alldata = null ) {
223 - return strlen( $value ) > 1;
 223+ if ( strlen( $value ) < 2 ) {
 224+ return wfMsg( 'contest-signup-invalid-name' );
 225+ }
 226+
 227+ return true;
224228 }
225229
226230 /**
@@ -233,7 +237,11 @@
234238 * @return true|string
235239 */
236240 public static function validateEmailField( $value, $alldata = null ) {
237 - return Sanitizer::validateEmail( $value );
 241+ if ( !Sanitizer::validateEmail( $value ) ) {
 242+ return wfMsg( 'contest-signup-invalid-email' );
 243+ }
 244+
 245+ return true;
238246 }
239247
240248 }

Status & tagging log