Index: trunk/extensions/Validator/includes/ValidationError.php |
— | — | @@ -54,4 +54,15 @@ |
55 | 55 | $this->tags = $tags; |
56 | 56 | } |
57 | 57 | |
| 58 | + /** |
| 59 | + * Returns the error message describing the error. |
| 60 | + * |
| 61 | + * @since 0.4 |
| 62 | + * |
| 63 | + * @return string |
| 64 | + */ |
| 65 | + public function getMessage() { |
| 66 | + return $this->message; |
| 67 | + } |
| 68 | + |
58 | 69 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/includes/ParserHook.php |
— | — | @@ -156,18 +156,30 @@ |
157 | 157 | |
158 | 158 | $this->validator->validateParameters(); |
159 | 159 | |
160 | | - if ( $this->validator->hasFatalError() ) { |
161 | | - // TODO |
162 | | - $output = 'Demo: fatal error'; |
| 160 | + $fatalError = $this->validator->hasFatalError(); |
| 161 | + |
| 162 | + if ( $fatalError === false ) { |
| 163 | + $output = $this->render( $this->validator->getParameterValues() ); |
163 | 164 | } |
164 | 165 | else { |
165 | | - $output = $this->render( $this->validator->getParameterValues() ); |
| 166 | + $output = $this->renderError( $fatalError ); |
166 | 167 | } |
167 | 168 | |
168 | 169 | return $output; |
169 | 170 | } |
170 | 171 | |
171 | 172 | /** |
| 173 | + * Creates and returns the output when a fatal error prevent regular rendering. |
| 174 | + * |
| 175 | + * @since 0.4 |
| 176 | + * |
| 177 | + * @return string |
| 178 | + */ |
| 179 | + protected function renderError( ValidationError $error ) { |
| 180 | + return wfMsgExt( 'validator-error', 'parsemag', $error->getMessage() ); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
172 | 184 | * Returns an array containing the parameter info. |
173 | 185 | * Override in deriving classes to add parameter info. |
174 | 186 | * |
Index: trunk/extensions/Validator/includes/Parameter.php |
— | — | @@ -441,8 +441,8 @@ |
442 | 442 | protected function doValidation() { |
443 | 443 | if ( $this->setCount == 0 ) { |
444 | 444 | if ( $this->isRequired() ) { |
445 | | - // TODO: fatal error |
446 | | - $success = false; |
| 445 | + // This should not occur, so thorw an exception. |
| 446 | + throw new Exception( 'Attempted to validate a required parameter without first setting a value.' ); |
447 | 447 | } |
448 | 448 | else { |
449 | 449 | $success = true; |
Index: trunk/extensions/Validator/includes/Validator.php |
— | — | @@ -243,8 +243,14 @@ |
244 | 244 | |
245 | 245 | $setUservalue = $this->attemptToSetUserValue( $parameter ); |
246 | 246 | |
| 247 | + // If the parameter is required but not provided, register a fatal error and stop processing. |
247 | 248 | if ( !$setUservalue && $parameter->isRequired() ) { |
248 | | - // TODO: FATAL |
| 249 | + $this->registerNewError( |
| 250 | + wfMsgExt( 'validator_error_required_missing', 'parsemag', $paramName ), |
| 251 | + array(), |
| 252 | + ValidationError::SEVERITY_CRITICAL |
| 253 | + ); |
| 254 | + break; |
249 | 255 | } |
250 | 256 | else { |
251 | 257 | $validationSucceeded = $parameter->validate(); |
— | — | @@ -375,22 +381,20 @@ |
376 | 382 | } |
377 | 383 | |
378 | 384 | /** |
379 | | - * Returns wether there are any fatal errors. Fatal errors are either missing or invalid required parameters, |
380 | | - * or simply any sort of error when the validation level is equal to (or bigger then) Validator_ERRORS_STRICT. |
| 385 | + * Returns false when there are no fatal errors or an ValidationError when one is found. |
| 386 | + * Fatal errors are either missing or invalid required parameters, or simply any sort of |
| 387 | + * error when the validation level is equal to (or bigger then) Validator_ERRORS_STRICT. |
381 | 388 | * |
382 | | - * @return boolean |
| 389 | + * @return mixed false or ValidationError |
383 | 390 | */ |
384 | 391 | public function hasFatalError() { |
385 | | - $has = false; |
386 | | - |
387 | 392 | foreach ( $this->errors as $error ) { |
388 | 393 | if ( $error->severity >= ValidationError::SEVERITY_CRITICAL ) { |
389 | | - $has = true; |
390 | | - break; |
| 394 | + return $error; |
391 | 395 | } |
392 | 396 | } |
393 | 397 | |
394 | | - return $has; |
| 398 | + return false; |
395 | 399 | } |
396 | 400 | |
397 | 401 | } |
\ No newline at end of file |
Index: trunk/extensions/Validator/Validator.i18n.php |
— | — | @@ -21,8 +21,9 @@ |
22 | 22 | 'validator_warning_parameters' => 'There {{PLURAL:$1|is an error|are errors}} in your syntax.', |
23 | 23 | |
24 | 24 | // General errors |
| 25 | + 'validator-error' => '<b>Error</b>: $1', |
25 | 26 | 'validator_error_unknown_argument' => '$1 is not a valid parameter.', |
26 | | - 'validator_error_required_missing' => 'The required parameter $1 is not provided.', |
| 27 | + 'validator_error_required_missing' => 'The required parameter "$1" is not provided.', |
27 | 28 | 'validator-error-override-argument' => 'Tried to override parameter $1 (value: $2) with value "$3"', |
28 | 29 | |
29 | 30 | // Criteria errors for single values |