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

Revision: 72196
Author:   jeroendedauw
Date:     2010-09-02 13:27:50 +0000 (Thu, 02 Sep 2010)

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

Modified Paths:
--------------
    trunk/extensions/Validator/Validator.i18n.php
    trunk/extensions/Validator/Validator_Settings.php
    trunk/extensions/Validator/includes/ParserHook.php
    trunk/extensions/Validator/includes/Validator.php
    trunk/extensions/Validator/includes/Validator_Error.php
    trunk/extensions/Validator/includes/Validator_ErrorHandler.php
    trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php

Modified: trunk/extensions/Validator/Validator.i18n.php
===================================================================
--- trunk/extensions/Validator/Validator.i18n.php       2010-09-02 13:11:42 UTC 
(rev 72195)
+++ trunk/extensions/Validator/Validator.i18n.php       2010-09-02 13:27:50 UTC 
(rev 72196)
@@ -23,6 +23,7 @@
        // General errors
        'validator_error_unknown_argument' => '$1 is not a valid parameter.',
        'validator_error_required_missing' => 'The required parameter $1 is not 
provided.',
+       'validator-error-override-argument' => 'Tried to override parameter $1 
($2) with $3', 
 
        // Criteria errors for single values
        'validator_error_empty_argument' => 'Parameter $1 can not have an empty 
value.',

Modified: trunk/extensions/Validator/Validator_Settings.php
===================================================================
--- trunk/extensions/Validator/Validator_Settings.php   2010-09-02 13:11:42 UTC 
(rev 72195)
+++ trunk/extensions/Validator/Validator_Settings.php   2010-09-02 13:27:50 UTC 
(rev 72196)
@@ -20,17 +20,14 @@
 # Registration of the listerrors parser hooks.
 $wgHooks['ParserFirstCallInit'][] = 'ValidatorListErrors::staticInit';
 
-# Integer. The strictness of the parameter validation and resulting error 
report when using the ValidatorManager class.
-# This value also affects the error messages native to extensions that 
integrate Validator correctly.
 # Validator_ERRORS_NONE        : Validator will not show any errors, and make 
the best of the input it got.
 # Validator_ERRORS_WARN                : Validator will make the best of the 
input it got, but will show a warning that there are errors.
 # Validator_ERRORS_SHOW                : Validator will make the best of the 
input it got, but will show a list of all errors.
 # Validator_ERRORS_STRICT      : Validator will only show regular output when 
there are no errors, if there are, a list of them will be shown.
-$egValidatorErrorLevel = Validator_ERRORS_SHOW;
-
-# Integer. The strictness of the parameter validation and resulting error 
report when using the ValidatorManager class.
-# This value also affects the error messages native to extensions that 
integrate Validator correctly.
-# Validator_ERRORS_NONE        : Validator will not show any errors, and make 
the best of the input it got, if possible.
-# Validator_ERRORS_WARN                : Validator will make the best of the 
input it got, but will show a warning that there are errors.
-# Validator_ERRORS_SHOW                : Validator will make the best of the 
input it got, but will show a list of all errors.
-$egValidatorFatalLevel = Validator_ERRORS_SHOW;
\ No newline at end of file
+$egErrorLevel = array(
+       ValidatorError::SEVERITY_MINOR => Validator_ERRORS_LOG,
+       ValidatorError::SEVERITY_LOW => Validator_ERRORS_LOG,
+       ValidatorError::SEVERITY_NORMAL => Validator_ERRORS_WARN,
+       ValidatorError::SEVERITY_HIGH => Validator_ERRORS_SHOW,
+       ValidatorError::SEVERITY_CRITICAL => Validator_ERRORS_STRICT,
+);
\ No newline at end of file

Modified: trunk/extensions/Validator/includes/ParserHook.php
===================================================================
--- trunk/extensions/Validator/includes/ParserHook.php  2010-09-02 13:11:42 UTC 
(rev 72195)
+++ trunk/extensions/Validator/includes/ParserHook.php  2010-09-02 13:27:50 UTC 
(rev 72196)
@@ -150,15 +150,7 @@
         * @return string
         */
        protected function handleErrors( ValidatorManager $manager ) {
-               $errorList = $manager->getErrorList();
-
-               $output = '';
                
-               if ( $errorList != '' ) {
-                       $output .= '<br />' . $errorList;
-               }
-               
-               return $output;
        }
        
        /**

Modified: trunk/extensions/Validator/includes/Validator.php
===================================================================
--- trunk/extensions/Validator/includes/Validator.php   2010-09-02 13:11:42 UTC 
(rev 72195)
+++ trunk/extensions/Validator/includes/Validator.php   2010-09-02 13:27:50 UTC 
(rev 72196)
@@ -125,8 +125,43 @@
         * @var associative array
         */
        private $mErrors = array();
+       
+       /**
+        * List of ValidatorError.
+        * 
+        * @since 0.4
+        * 
+        * @var array
+        */
+       protected $errors = array();
 
+       public function __construct() {
+               // TODO
+       }
+       
        /**
+        * 
+        * 
+        * @since 0.4
+        * 
+        * @return string
+        */
+       protected function getElement() {
+               // TODO
+       } 
+       
+       protected function registerError( $message, $tags = array(), $severity 
= ValidatorError::SEVERITY_NORMAL ) {
+               ValidatorErrorHandler::addError( 
+                       new ValidatorError(
+                               $message,
+                               $severity,
+                               $this->getElement(),
+                               (array)$tags
+                       )
+               );
+       }
+       
+       /**
         * Determines the names and values of all parameters. Also takes care 
of default parameters. 
         * After that the resulting parameter list is passed to 
Validator::setParameters
         * 
@@ -235,7 +270,16 @@
                                        }
                                }
                                else {
-                                       $this->mErrors[] = array( 'type' => 
'override', 'name' => $mainName );
+                                       $this->registerError(
+                                               wfMsgExt(
+                                                       
'validator-error-override-argument',
+                                                       'parsemag',
+                                                       $mainName,
+                                                       
$this->mParameters[$mainName]['original-value'],
+                                                       'demo new value' // 
TODO: get new value
+                                               ),
+                                               'override'              
+                                       );
                                }
                        }
                        else { // If the parameter is not found in the list of 
allowed ones, add an item to the $this->mErrors array.

Modified: trunk/extensions/Validator/includes/Validator_Error.php
===================================================================
--- trunk/extensions/Validator/includes/Validator_Error.php     2010-09-02 
13:11:42 UTC (rev 72195)
+++ trunk/extensions/Validator/includes/Validator_Error.php     2010-09-02 
13:27:50 UTC (rev 72196)
@@ -22,6 +22,17 @@
        public $severity;
        
        /**
+        * List of 'tags' for the error. This is mainly ment for indicating an 
error
+        * type, such as 'missing parameter' or 'invalid value', but allows for 
multiple
+        * such indications.
+        * 
+        * @since 0.4
+        * 
+        * @var array
+        */
+       public $tags;
+       
+       /**
         * Where the error occured.
         * 
         * @since 0.4
@@ -36,10 +47,11 @@
         * @param string $message
         * @param integer $severity
         */
-       public function __construct( $message, $severity = 
ValidatorError::SEVERITY_NORMAL, $element = false ) {
+       public function __construct( $message, $severity = 
ValidatorError::SEVERITY_NORMAL, $element = false, array $tags = array() ) {
                $this->message = $message;
                $this->severity = $severity;
                $this->element = $element;
+               $this->tags = $tags;
        }
        
 }
\ No newline at end of file

Modified: trunk/extensions/Validator/includes/Validator_ErrorHandler.php
===================================================================
--- trunk/extensions/Validator/includes/Validator_ErrorHandler.php      
2010-09-02 13:11:42 UTC (rev 72195)
+++ trunk/extensions/Validator/includes/Validator_ErrorHandler.php      
2010-09-02 13:27:50 UTC (rev 72196)
@@ -51,6 +51,10 @@
        public static function getErrorList( $minSeverity = 
ValidatorError::SEVERITY_MINOR ) {
                $elementHtml = array();
                
+               if ( count( self::$errors ) == 0 ) {
+                       return false;
+               }
+               
                $elements = array_keys( self::$errors );
                natcasesort( $elements );
                
@@ -62,7 +66,8 @@
                        }
                }
                
-               return implode( "\n", $elementHtml );
+               // TODO: i18n
+               return "== Errors ==\n\n" . implode( "\n\n", $elementHtml );
        }
        
        /**
@@ -94,7 +99,7 @@
                                $lines[] = "* $error->message";
                        }
                        
-                       return "== $element ==\n\n" . implode( "\n", $lines );
+                       return "=== $element ===\n\n" . implode( "\n", $lines );
                }
                else {
                        return false;

Modified: 
trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php
===================================================================
--- trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php    
2010-09-02 13:11:42 UTC (rev 72195)
+++ trunk/extensions/Validator/includes/parserHooks/Validator_ListErrors.php    
2010-09-02 13:27:50 UTC (rev 72196)
@@ -13,6 +13,22 @@
 class ValidatorListErrors extends ParserHook {
        
        /**
+        * Array to map the possible values for the 'minseverity' parameter
+        * to their equivalent in the ValidatorError::SEVERITY_ enum.
+        * 
+        * @since 0.4
+        * 
+        * @var array
+        */
+       protected static $severityMap = array(
+               'minor' => ValidatorError::SEVERITY_MINOR,
+               'low' => ValidatorError::SEVERITY_LOW,
+               'normal' => ValidatorError::SEVERITY_NORMAL,
+               'high' => ValidatorError::SEVERITY_HIGH,
+               'critical' => ValidatorError::SEVERITY_CRITICAL,
+       );
+       
+       /**
         * No LST in pre-5.3 PHP *sigh*.
         * This is to be refactored as soon as php >=5.3 becomes acceptable.
         */
@@ -54,6 +70,12 @@
         */
        protected function getParameterInfo() {
                return array(
+                       'minseverity' => array(
+                               'criteria' => array(
+                                       'in_array' => array_keys( 
self::$severityMap )
+                               ),
+                               'default' => 'minor'
+                       )
                );
        }
        
@@ -66,7 +88,7 @@
         * @return array
         */
        protected function getDefaultParameters() {
-               return array( );
+               return array( 'minseverity' );
        }
        
        /**
@@ -80,11 +102,15 @@
         * @return string
         */
        public function render( array $parameters ) {
-               $output = ''; // TODO
+               $errorList = ValidatorErrorHandler::getErrorList( 
self::$severityMap[$parameters['minseverity']] );
                
-               
-               
-               return $output;         
+               if ( $errorList ) {
+                       // TODO: render wikitext
+                       return $errorList;
+               }
+               else {
+                       return '';
+               }
        }
        
 }
\ No newline at end of file



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

Reply via email to