r72719 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72718‎ | r72719 | r72720 >
Date:14:01, 10 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - fixed issue with parameter value correction
Modified paths:
  • /trunk/extensions/Validator/includes/ListParameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/ListParameter.php
@@ -124,8 +124,13 @@
125125 public function validate() {
126126 $this->validateListCriteria();
127127
128 - parent::validate();
 128+ $success = parent::doValidation();
129129
 130+ if ( !$success && count( $this->value ) == 0 ) {
 131+ $this->value = (array)$this->default;
 132+ }
 133+
 134+ return $success;
130135 // FIXME: it's possible the list criteria are not satisfied here anymore due to filtering of invalid items.
131136 }
132137
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -350,15 +350,30 @@
351351 }
352352
353353 /**
354 - * Validates the parameter value against it's criteria.
355 - * If the parameter is invalid or not provided, it'll be set to it's default,
356 - * or when it's required, a fatal error will be stored.
 354+ * Validates the parameter value and sets the value to it's default when errors occur.
357355 *
358356 * @since 0.4
359357 *
360 - * @return boolean If there where no fatal errors
 358+ * @return boolean Indicates if there was any validation error
361359 */
362360 public function validate() {
 361+ $success = $this->doValidation();
 362+
 363+ if ( !$success ) {
 364+ $this->value = $this->default;
 365+ }
 366+
 367+ return $success;
 368+ }
 369+
 370+ /**
 371+ * Validates the parameter value.
 372+ *
 373+ * @since 0.4
 374+ *
 375+ * @return boolean Indicates if there was any validation error
 376+ */
 377+ protected function doValidation() {
363378 if ( $this->setCount == 0 ) {
364379 if ( $this->isRequired() ) {
365380 // TODO: fatal error
@@ -372,14 +387,8 @@
373388 else {
374389 $this->value = $this->originalValue;
375390
376 - list( $success, $hasError ) = $this->validateCriteria();
377 -
378 - if ( $hasError ) {
379 - $this->value = $this->default;
380 - }
381 - }
382 -
383 - return $success;
 391+ $success = $this->validateCriteria();
 392+ }
384393 }
385394
386395 /**
@@ -387,7 +396,7 @@
388397 *
389398 * @since 0.4
390399 *
391 - * @return boolean Indicates if there was any validation error.
 400+ * @return boolean Indicates if there was any validation error
392401 */
393402 protected function validateCriteria() {
394403 $success = true;

Status & tagging log