http://www.mediawiki.org/wiki/Special:Code/MediaWiki/74128

Revision: 74128
Author:   jeroendedauw
Date:     2010-10-02 06:38:54 +0000 (Sat, 02 Oct 2010)

Log Message:
-----------
Changes for 0.4 - fixed issues with parameter value defaulting

Modified Paths:
--------------
    trunk/extensions/Validator/Validator.i18n.php
    trunk/extensions/Validator/includes/ListParameter.php
    trunk/extensions/Validator/includes/Parameter.php
    trunk/extensions/Validator/includes/ParserHook.php
    trunk/extensions/Validator/includes/Validator.php

Modified: trunk/extensions/Validator/Validator.i18n.php
===================================================================
--- trunk/extensions/Validator/Validator.i18n.php       2010-10-02 01:47:16 UTC 
(rev 74127)
+++ trunk/extensions/Validator/Validator.i18n.php       2010-10-02 06:38:54 UTC 
(rev 74128)
@@ -19,7 +19,7 @@
 
        'validator-warning' => "'''Warning:''' $1",
        'validator-error' => "'''Error:''' $1",
-       'validator-fatal-error' => "'''Fatal error:''' $1",
+       'validator-fatal-error' => "Fatal error: $1",
        'validator_error_parameters' => 'The following {{PLURAL:$1|error 
has|errors have}} been detected in your syntax:',
        'validator_warning_parameters' => 'There {{PLURAL:$1|is an error|are 
errors}} in your syntax.',
        'validator-warning-adittional-errors' => '... and {{PLURAL:$1|one more 
issue|multiple more issues}}.',

Modified: trunk/extensions/Validator/includes/ListParameter.php
===================================================================
--- trunk/extensions/Validator/includes/ListParameter.php       2010-10-02 
01:47:16 UTC (rev 74127)
+++ trunk/extensions/Validator/includes/ListParameter.php       2010-10-02 
06:38:54 UTC (rev 74128)
@@ -124,23 +124,42 @@
         * @see Parameter::validate
         */
        public function validate() {
-               $this->validateListCriteria();
+               $listSuccess = $this->validateListCriteria();
                
-               $success = parent::doValidation();
-               
-               if ( !$success && count( $this->value ) == 0 ) {
-                       $this->value = is_array( $this->default ) ? 
$this->default : array( $this->default );
-               }       
-               
-               return $success;
+               if ( $listSuccess ) {
+                       $this->doValidation();
+               }
+               // TODO
+
                // FIXME: it's possible the list criteria are not satisfied 
here anymore due to filtering of invalid items.
        }       
        
        /**
+        * @see Parameter::setToDefaultIfNeeded
         * 
+        * @since 0.4
+        */     
+       protected function setToDefaultIfNeeded() {
+               if ( count( $this->errors ) > 0 && count( $this->value ) == 0 
&& !$this->hasFatalError() ) {
+                       $this->setToDefault();
+               }               
+       }
+       
+       /**
+        * @see Parameter::setToDefault
         * 
         * @since 0.4
+        */
+       protected function setToDefault() {
+               $this->defaulted = true;
+               $this->value = is_array( $this->default ) ? $this->default : 
array( $this->default );
+       }       
+       
+       /**
         * 
+        * 
+        * @since 0.4
+        * 
         * @param array $values
         */
        protected function validateListCriteria() {
@@ -155,6 +174,7 @@
                }
                
                // TODO
+               return true;
        }
        
        /**

Modified: trunk/extensions/Validator/includes/Parameter.php
===================================================================
--- trunk/extensions/Validator/includes/Parameter.php   2010-10-02 01:47:16 UTC 
(rev 74127)
+++ trunk/extensions/Validator/includes/Parameter.php   2010-10-02 06:38:54 UTC 
(rev 74128)
@@ -371,7 +371,6 @@
                                                'override'              
                                        );
                         */
-                       
                        return false;
                }
                else {
@@ -403,17 +402,9 @@
         * Validates the parameter value and sets the value to it's default 
when errors occur.
         * 
         * @since 0.4
-        * 
-        * @return boolean Indicates if there was any validation error
         */
        public function validate() {
-               $success = $this->doValidation();
-               
-               if ( !$success ) {
-                       $this->value = $this->default;
-               }       
-
-               return $success;
+               $this->doValidation();
        }
        
        /**
@@ -449,14 +440,22 @@
                }
                else {
                        $this->validateCriteria();
-                       
-                       if ( count( $this->errors ) > 0 && 
!$this->hasFatalError() ) {
-                               $this->setToDefault();
-                       }
+                       $this->setToDefaultIfNeeded();
                }
        }
        
        /**
+        * Sets the parameter value to the default if needed.
+        * 
+        * @since 0.4
+        */
+       protected function setToDefaultIfNeeded() {
+               if ( count( $this->errors ) > 0 && !$this->hasFatalError() ) {
+                       $this->setToDefault();
+               }               
+       }
+       
+       /**
         * Validates the provided value against all criteria.
         * 
         * @since 0.4

Modified: trunk/extensions/Validator/includes/ParserHook.php
===================================================================
--- trunk/extensions/Validator/includes/ParserHook.php  2010-10-02 01:47:16 UTC 
(rev 74127)
+++ trunk/extensions/Validator/includes/ParserHook.php  2010-10-02 06:38:54 UTC 
(rev 74128)
@@ -203,7 +203,9 @@
         * @return string
         */
        protected function renderFatalError( ValidationError $error ) {
-               return wfMsgExt( 'validator-fatal-error', 'parsemag', 
$error->getMessage() );
+               return '<span class="errorbox">' .
+                       htmlspecialchars( wfMsgExt( 'validator-fatal-error', 
'parsemag', $error->getMessage() ) ) . 
+                       '</span>';
        }
        
        /**

Modified: trunk/extensions/Validator/includes/Validator.php
===================================================================
--- trunk/extensions/Validator/includes/Validator.php   2010-10-02 01:47:16 UTC 
(rev 74127)
+++ trunk/extensions/Validator/includes/Validator.php   2010-10-02 06:38:54 UTC 
(rev 74128)
@@ -387,8 +387,6 @@
        
        /**
         * Returns false when there are no fatal errors or an ValidationError 
when one is found.
-        * Fatal errors are either missing or invalid required parameters, or 
simply any sort of
-        * error when the validation level is equal to (or bigger then) 
Validator_ERRORS_STRICT.
         * 
         * @return mixed false or ValidationError
         */



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to