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

Revision: 72197
Author:   jeroendedauw
Date:     2010-09-02 14:13:31 +0000 (Thu, 02 Sep 2010)

Log Message:
-----------
Changes for 0.4 - follow up to r72194

Modified Paths:
--------------
    trunk/extensions/Validator/includes/ValidationManager.php
    trunk/extensions/Validator/includes/Validator.php
    trunk/extensions/Validator/includes/Validator_Error.php
    trunk/extensions/Validator/includes/Validator_ErrorHandler.php

Modified: trunk/extensions/Validator/includes/ValidationManager.php
===================================================================
--- trunk/extensions/Validator/includes/ValidationManager.php   2010-09-02 
13:27:50 UTC (rev 72196)
+++ trunk/extensions/Validator/includes/ValidationManager.php   2010-09-02 
14:13:31 UTC (rev 72197)
@@ -11,12 +11,12 @@
  * FIXME: missing required params should result in a no-go, no matter of the 
error level, as they can/are not defaulted.
  * TODO: make a distinction between fatal errors and regular errors by using 2 
seperate error levels.
  */
-final class ValidationManager {
+class ValidationManager {
 
        /**
         * @var Validator
         */
-       private $validator;
+       protected $validator;
        
        /**
         * Parses and validates the provided parameters, and corrects them 
depending on the error level.
@@ -83,6 +83,7 @@
         *
         * @return string
         */
+       /*
        public function getErrorList() {
                global $wgLang, $egValidatorErrorLevel;
                
@@ -174,5 +175,6 @@
                        return '';
                }
        }
+       */
        
 }
\ No newline at end of file

Modified: trunk/extensions/Validator/includes/Validator.php
===================================================================
--- trunk/extensions/Validator/includes/Validator.php   2010-09-02 13:27:50 UTC 
(rev 72196)
+++ trunk/extensions/Validator/includes/Validator.php   2010-09-02 14:13:31 UTC 
(rev 72197)
@@ -1,11 +1,11 @@
 <?php
 
 /**
- * Class for parameter validation.
+ * Class for parameter validation of a single parser hook or other 
parameterized construct.
  *
  * @since 0.1
  *
- * @file Validator.class.php
+ * @file Validator.php
  * @ingroup Validator
  *
  * @author Jeroen De Dauw
@@ -15,7 +15,7 @@
  * TODO: settings of defaults should happen as a default behaviour that can be 
overiden by the output format,
  *              as it is not wished for all output formats in every case, and 
now a hacky approach is required there.
  */
-final class Validator {
+class Validator {
 
        /**
         * @var boolean Indicates whether parameters not found in the criteria 
list
@@ -70,7 +70,7 @@
        /**
         * @var array Holder for the list validation functions.
         */
-       private static $mListValidationFunctions = array(
+       protected static $mListValidationFunctions = array(
                'item_count' => array( 'ValidationFunctions', 'has_item_count' 
),
                'unique_items' => array( 'ValidationFunctions', 
'has_unique_items' ),
        );
@@ -78,7 +78,7 @@
        /**
         * @var array Holder for the formatting functions.
         */
-       private static $mOutputFormats = array(
+       protected static $mOutputFormats = array(
                'array' => array( 'ValidationFormats', 'format_array' ),
                'list' => array( 'ValidationFormats', 'format_list' ),
                'boolean' => array( 'ValidationFormats', 'format_boolean' ),
@@ -95,7 +95,7 @@
         * 
         * @var associative array
         */
-       private $mParameterInfo;
+       protected $mParameterInfo;
        
        /**
         * An array initially containing the user provided values. Adittional 
data about
@@ -110,21 +110,21 @@
         * 
         * @var associative array
         */
-       private $mParameters = array();
+       protected $mParameters = array();
        
        /**
         * Arrays for holding the (main) names of valid, invalid and unknown 
parameters. 
         */
-       private $mValidParams = array();
-       private $mInvalidParams = array();
-       private $mUnknownParams = array();
+       protected $mValidParams = array();
+       protected $mInvalidParams = array();
+       protected $mUnknownParams = array();
 
        /**
         * Holds all errors and their meta data. 
         * 
         * @var associative array
         */
-       private $mErrors = array();
+       protected $mErrors = array();
        
        /**
         * List of ValidatorError.
@@ -135,6 +135,11 @@
         */
        protected $errors = array();
 
+       /**
+        * Constructor.
+        * 
+        * @since 0.4
+        */
        public function __construct() {
                // TODO
        }
@@ -147,6 +152,7 @@
         * @return string
         */
        protected function getElement() {
+               return '';
                // TODO
        } 
        
@@ -284,7 +290,14 @@
                        }
                        else { // If the parameter is not found in the list of 
allowed ones, add an item to the $this->mErrors array.
                                if ( self::$storeUnknownParameters ) 
$this->mUnknownParams[] = $paramName;
-                               $this->mErrors[] = array( 'type' => 'unknown', 
'name' => $paramName );
+                               $this->registerError(
+                                       wfMsgExt(
+                                               
'validator_error_unknown_argument',
+                                               'parsemag',
+                                               $paramName
+                                       ),
+                                       'unknown'               
+                               );              
                        }               
                }
        }
@@ -371,7 +384,14 @@
                                // If the parameter is required, add a new 
error of type 'missing'.
                                // TODO: break when has dependencies
                                if ( array_key_exists( 'required', $paramInfo ) 
&& $paramInfo['required'] ) {
-                                       $this->mErrors[] = array( 'type' => 
'missing', 'name' => $paramName );
+                                       $this->registerError(
+                                               wfMsgExt(
+                                                       
'validator_error_required_missing',
+                                                       'parsemag',
+                                                       $paramName
+                                               ),
+                                               'missing'               
+                                       );                                      
        
                                }
                                else {
                                        // Set the default value (or default 
'default value' if none is provided), and ensure the type is correct.
@@ -490,13 +510,27 @@
                                        if ( ! $isValid ) {
                                                $hasNoErrors = false;
                                                
+                                               $this->registerError(
+                                                       'Demo: List error 
invamid',
+                                                       /* TODO
+                                                       wfMsgExt(
+                                                               
'validator_error_required_missing',
+                                                               'parsemag',
+                                                               $paramName
+                                                       ),
+                                                       */
+                                                       $criteriaName           
+                                               );                              
                        
+                                               
+                                               /*
                                                $this->mErrors[] = array(
-                                                       'type' => $criteriaName,
+                                                       'type' => ,
                                                        'args' => $criteriaArgs,
                                                        'name' => 
$this->mParameters[$name]['original-name'],
                                                        'list' => true,
                                                        'value' => 
$this->mParameters[$name]['original-value']
                                                );
+                                               */
                                                
                                                if ( 
!self::$accumulateParameterErrors ) {
                                                        break;
@@ -563,6 +597,20 @@
                                                // If the value is valid, but 
there are invalid items, add an error with a list of these items.
                                                if ( $isValid && count( 
$invalidItems ) > 0 ) {
                                                        $value = $validItems;
+                                                       
+                                                       $this->registerError(
+                                                               'Demo: Invalid 
item in list',
+                                                               /* TODO
+                                                               wfMsgExt(
+                                                                       
'validator_error_required_missing',
+                                                                       
'parsemag',
+                                                                       
$paramName
+                                                               ),
+                                                               */
+                                                               $criteriaName   
        
+                                                       );
+                                                       
+                                                       /*                      
                
                                                        $this->mErrors[] = 
array(
                                                                'type' => 
$criteriaName,
                                                                'args' => 
$criteriaArgs,
@@ -570,6 +618,7 @@
                                                                'list' => true,
                                                                'invalid-items' 
=> $invalidItems
                                                        );
+                                                       */
                                                }
                                        }
                                }
@@ -580,6 +629,19 @@
 
                                // Add a new error when the validation failed, 
and break the loop if errors for one parameter should not be accumulated.
                                if ( !$isValid ) {
+                                       $this->registerError(
+                                               'Demo: parameter validation 
failed',
+                                               /* TODO
+                                               wfMsgExt(
+                                                       
'validator_error_required_missing',
+                                                       'parsemag',
+                                                       $paramName
+                                               ),
+                                               */
+                                               $criteriaName           
+                                       );      
+
+                                       /*
                                        $this->mErrors[] = array(
                                                'type' => $criteriaName,
                                                'args' => $criteriaArgs,
@@ -587,6 +649,7 @@
                                                'list' => is_array( $value ),
                                                'value' => 
$this->mParameters[$name]['original-value']
                                        );
+                                       */
                                        
                                        $hasNoErrors = false;
                                        if ( !self::$accumulateParameterErrors 
) break;
@@ -734,14 +797,14 @@
         * @return array
         */
        public function getErrors() {
-               return $this->mErrors;
+               return $this->errors;
        }
        
        /**
         * @return boolean
         */
        public function hasErrors() {
-               return count( $this->mErrors ) > 0;
+               return count( $this->errors ) > 0;
        }
        
        /**
@@ -751,19 +814,8 @@
         * @return boolean
         */
        public function hasFatalError() {
-               global $egValidatorErrorLevel;
-               $has = $this->hasErrors() && $egValidatorErrorLevel >= 
Validator_ERRORS_STRICT;
-               
-               if ( !$has ) {
-                       foreach ( $this->mErrors as $error ) {
-                               if ( $error['type'] == 'missing' ) {
-                                       $has = true;
-                                       break;
-                               }
-                       }
-               }
-
-               return $has;
+               // TODO
+               return false;
        }       
 
        /**

Modified: trunk/extensions/Validator/includes/Validator_Error.php
===================================================================
--- trunk/extensions/Validator/includes/Validator_Error.php     2010-09-02 
13:27:50 UTC (rev 72196)
+++ trunk/extensions/Validator/includes/Validator_Error.php     2010-09-02 
14:13:31 UTC (rev 72197)
@@ -39,7 +39,7 @@
         * 
         * @var mixed: string or false
         */
-       protected $element;
+       public $element;
        
        /**
         * @since 0.4

Modified: trunk/extensions/Validator/includes/Validator_ErrorHandler.php
===================================================================
--- trunk/extensions/Validator/includes/Validator_ErrorHandler.php      
2010-09-02 13:27:50 UTC (rev 72196)
+++ trunk/extensions/Validator/includes/Validator_ErrorHandler.php      
2010-09-02 14:13:31 UTC (rev 72197)
@@ -12,6 +12,11 @@
  */
 final class ValidatorErrorHandler {
        
+       /**
+        * @since 0.4
+        * 
+        * @var array of ValidatorError
+        */
        protected static $errors;
        
        /**



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

Reply via email to