http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72719
Revision: 72719
Author: jeroendedauw
Date: 2010-09-10 14:01:34 +0000 (Fri, 10 Sep 2010)
Log Message:
-----------
Changes for 0.4 - fixed issue with parameter value correction
Modified Paths:
--------------
trunk/extensions/Validator/includes/ListParameter.php
trunk/extensions/Validator/includes/Parameter.php
Modified: trunk/extensions/Validator/includes/ListParameter.php
===================================================================
--- trunk/extensions/Validator/includes/ListParameter.php 2010-09-10
13:20:10 UTC (rev 72718)
+++ trunk/extensions/Validator/includes/ListParameter.php 2010-09-10
14:01:34 UTC (rev 72719)
@@ -124,8 +124,13 @@
public function validate() {
$this->validateListCriteria();
- parent::validate();
+ $success = parent::doValidation();
+ if ( !$success && count( $this->value ) == 0 ) {
+ $this->value = (array)$this->default;
+ }
+
+ return $success;
// FIXME: it's possible the list criteria are not satisfied
here anymore due to filtering of invalid items.
}
Modified: trunk/extensions/Validator/includes/Parameter.php
===================================================================
--- trunk/extensions/Validator/includes/Parameter.php 2010-09-10 13:20:10 UTC
(rev 72718)
+++ trunk/extensions/Validator/includes/Parameter.php 2010-09-10 14:01:34 UTC
(rev 72719)
@@ -350,15 +350,30 @@
}
/**
- * Validates the parameter value against it's criteria.
- * If the parameter is invalid or not provided, it'll be set to it's
default,
- * or when it's required, a fatal error will be stored.
+ * Validates the parameter value and sets the value to it's default
when errors occur.
*
* @since 0.4
*
- * @return boolean If there where no fatal errors
+ * @return boolean Indicates if there was any validation error
*/
public function validate() {
+ $success = $this->doValidation();
+
+ if ( !$success ) {
+ $this->value = $this->default;
+ }
+
+ return $success;
+ }
+
+ /**
+ * Validates the parameter value.
+ *
+ * @since 0.4
+ *
+ * @return boolean Indicates if there was any validation error
+ */
+ protected function doValidation() {
if ( $this->setCount == 0 ) {
if ( $this->isRequired() ) {
// TODO: fatal error
@@ -372,14 +387,8 @@
else {
$this->value = $this->originalValue;
- list( $success, $hasError ) = $this->validateCriteria();
-
- if ( $hasError ) {
- $this->value = $this->default;
- }
- }
-
- return $success;
+ $success = $this->validateCriteria();
+ }
}
/**
@@ -387,7 +396,7 @@
*
* @since 0.4
*
- * @return boolean Indicates if there was any validation error.
+ * @return boolean Indicates if there was any validation error
*/
protected function validateCriteria() {
$success = true;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs