r72275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72274‎ | r72275 | r72276 >
Date:10:54, 3 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - improvements to ParserHook class
Modified paths:
  • /trunk/extensions/Validator/includes/ParserHook.php (modified) (history)
  • /trunk/extensions/Validator/includes/Validator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/ParserHook.php
@@ -74,10 +74,13 @@
7575 * @param array $args
7676 * @param Parser $parser
7777 * @param PPFrame $frame
 78+ *
 79+ * @return string
7880 */
7981 public function renderTag( $input, array $args, Parser $parser, PPFrame $frame ) {
8082 $defaultParam = array_shift( $this->getDefaultParameters() );
8183
 84+ // If there is a first default parameter, set the tag contents as it's value.
8285 if ( !is_null( $defaultParam ) ) {
8386 $args[$defaultParam] = $input;
8487 }
@@ -92,6 +95,8 @@
9396 *
9497 * @param Parser $parser
9598 * ... further arguments ...
 99+ *
 100+ * @return array
96101 */
97102 public function renderFunction() {
98103 $args = func_get_args();
@@ -113,47 +118,35 @@
114119 * @return string
115120 */
116121 public function validateAndRender( array $arguments, $parsed ) {
117 - $manager = new ValidationManager();
 122+ global $egValidatorErrorLevel;
 123+
 124+ $validator = new Validator();
118125
119126 if ( $parsed ) {
120 - $doRender = $manager->manageParsedParameters(
121 - $arguments,
122 - $this->getParameterInfo()
123 - );
 127+ $validator->setParameters( $arguments, $this->getParameterInfo() );
124128 }
125129 else {
126 - $doRender = $manager->manageParameters(
127 - $arguments,
128 - $this->getParameterInfo(),
129 - $this->getDefaultParameters()
130 - );
 130+ $validator->parseAndSetParams( $arguments, $this->getParameterInfo(), $this->getDefaultParameters() );
131131 }
132132
133 - if ( $doRender ) {
134 - $output = $this->render( $manager->getParameters( false ) );
 133+ $validator->validateAndFormatParameters();
 134+
 135+ if ( $validator->hasErrors() && $egValidatorErrorLevel < Validator_ERRORS_STRICT ) {
 136+ $validator->correctInvalidParams();
135137 }
 138+
 139+ if ( $validator->hasFatalError() ) {
 140+ // TODO
 141+ $output = 'Demo: fatal error';
 142+ }
136143 else {
137 - $output = $this->handleErrors( $manager );
 144+ $output = $this->render( $validator->getValidParams( false ) );
138145 }
139146
140147 return $output;
141148 }
142149
143150 /**
144 - * Handles any errors that occured. Messages that should be added the the regular
145 - * output are returned.
146 - *
147 - * @since 0.4
148 - *
149 - * @param ValidatorManager $manager
150 - *
151 - * @return string
152 - */
153 - protected function handleErrors( ValidatorManager $manager ) {
154 -
155 - }
156 -
157 - /**
158151 * Returns an array containing the parameter info.
159152 * Override in deriving classes to add parameter info.
160153 *
Index: trunk/extensions/Validator/includes/Validator.php
@@ -56,7 +56,7 @@
5757 /**
5858 * @var array Holder for the validation functions.
5959 */
60 - private static $mValidationFunctions = array(
 60+ protected static $mValidationFunctions = array(
6161 'in_array' => array( 'ValidationFunctions', 'in_array' ),
6262 'in_range' => array( 'ValidationFunctions', 'in_range' ),
6363 'is_numeric' => array( 'ValidationFunctions', 'is_numeric' ),
@@ -118,13 +118,6 @@
119119 protected $mValidParams = array();
120120 protected $mInvalidParams = array();
121121 protected $mUnknownParams = array();
122 -
123 - /**
124 - * Holds all errors and their meta data.
125 - *
126 - * @var associative array
127 - */
128 - protected $mErrors = array();
129122
130123 /**
131124 * List of ValidatorError.
@@ -156,6 +149,13 @@
157150 // TODO
158151 }
159152
 153+ /**
 154+ * Registers an error.
 155+ *
 156+ * @param string $message
 157+ * @param mixed $tags string or array
 158+ * @param integer $severity
 159+ */
160160 protected function registerError( $message, $tags = array(), $severity = ValidatorError::SEVERITY_NORMAL ) {
161161 $error = new ValidatorError(
162162 $message,

Status & tagging log