r72984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72983‎ | r72984 | r72985 >
Date:15:53, 14 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - some fixes and removed ValidationManager class
Modified paths:
  • /trunk/extensions/Validator/Validator.php (modified) (history)
  • /trunk/extensions/Validator/includes/ListParameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/ValidationManager.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/ValidationManager.php
@@ -1,83 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Class for parameter handling.
6 - *
7 - * @deprecated
8 - *
9 - * @file ValidationManager.php
10 - * @ingroup Validator
11 - *
12 - * @author Jeroen De Dauw
13 - *
14 - * FIXME: missing required params should result in a no-go, no matter of the error level, as they can/are not defaulted.
15 - * TODO: make a distinction between fatal errors and regular errors by using 2 seperate error levels.
16 - */
17 -class ValidationManager {
18 -
19 - /**
20 - * @var Validator
21 - */
22 - protected $validator;
23 -
24 - /**
25 - * Parses and validates the provided parameters, and corrects them depending on the error level.
26 - *
27 - * @param array $rawParameters The raw parameters, as provided by the user.
28 - * @param array $parameterInfo Array containing the parameter definitions, which are needed for validation and defaulting.
29 - * @param array $defaultParams
30 - *
31 - * @return array or false The valid parameters or false when the output should not be shown.
32 - */
33 - public function manageParameters( array $rawParameters, array $parameterInfo, array $defaultParams = array() ) {
34 - global $egValidatorErrorLevel;
35 -
36 - $this->validator = new Validator();
37 -
38 - $this->validator->parseAndSetParams( $rawParameters, $parameterInfo, $defaultParams );
39 - $this->validator->validateAndFormatParameters();
40 -
41 - if ( $this->validator->hasErrors() && $egValidatorErrorLevel < Validator_ERRORS_STRICT ) {
42 - $this->validator->correctInvalidParams();
43 - }
44 -
45 - return !$this->validator->hasFatalError();
46 - }
47 -
48 - /**
49 - * Validates the provided parameters, and corrects them depending on the error level.
50 - *
51 - * @since 3.x
52 - *
53 - * @param $parameters Array
54 - * @param $parameterInfo Array
55 - */
56 - public function manageParsedParameters( array $parameters, array $parameterInfo ) {
57 - global $egValidatorErrorLevel;
58 -
59 - $this->validator = new Validator();
60 -
61 - $this->validator->setParameters( $parameters, $parameterInfo );
62 - $this->validator->validateAndFormatParameters();
63 -
64 - if ( $this->validator->hasErrors() && $egValidatorErrorLevel < Validator_ERRORS_STRICT ) {
65 - $this->validator->correctInvalidParams();
66 - }
67 -
68 - return !$this->validator->hasFatalError();
69 - }
70 -
71 - /**
72 - * Returns an array with the valid parameters.
73 - *
74 - * @since 3.x
75 - *
76 - * @param boolean $includeMetaData
77 - *
78 - * @return array
79 - */
80 - public function getParameters( $includeMetaData = true ) {
81 - return $this->validator->getValidParams( $includeMetaData );
82 - }
83 -
84 -}
\ No newline at end of file
Index: trunk/extensions/Validator/includes/ListParameter.php
@@ -74,7 +74,9 @@
7575 $default = null, array $aliases = array(), array $criteria = array() ) {
7676 $itemCriteria = array();
7777 $listCriteria = array();
78 -
 78+
 79+ $this->cleanCriteria( $criteria );
 80+
7981 foreach ( $criteria as $criterion ) {
8082 if ( $criterion->isForLists() ) {
8183 $listCriteria[] = $criterion;
@@ -83,13 +85,13 @@
8486 $itemCriteria[] = $criterion;
8587 }
8688 }
 89+
 90+ $this->listCriteria = $listCriteria;
8791
8892 parent::__construct( $name, $type, $default, $aliases, $itemCriteria );
8993
9094 $this->delimiter = $delimiter;
9195
92 - $this->cleanCriteria( $listCriteria );
93 - $this->listCriteria = $listCriteria;
9496 }
9597
9698 /**
@@ -113,7 +115,7 @@
114116
115117 if ( $this->lowerCaseValue ) {
116118 foreach ( $this->value as &$item ) {
117 - $item = strtolower( $this->value );
 119+ $item = strtolower( $item );
118120 }
119121 }
120122 }
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -174,7 +174,7 @@
175175 */
176176 public static function newFromArray( $name, array $definition ) {
177177 $isList = false;
178 - $delimiter = false;
 178+ $delimiter = ListParameter::DEFAULT_DELIMITER;
179179
180180 if ( array_key_exists( 'type', $definition ) ) {
181181 if ( is_array( $definition['type'] ) ) {
Index: trunk/extensions/Validator/Validator.php
@@ -63,7 +63,6 @@
6464 $wgAutoloadClasses['Validator'] = $incDir . 'Validator.php';
6565 $wgAutoloadClasses['TopologicalSort'] = $incDir . 'TopologicalSort.php';
6666 $wgAutoloadClasses['ValidationFormats'] = $incDir . 'ValidationFormats.php';
67 -$wgAutoloadClasses['ValidationManager'] = $incDir . 'ValidationManager.php'; // TODO: remove
6867 $wgAutoloadClasses['ValidationError'] = $incDir . 'ValidationError.php';
6968 $wgAutoloadClasses['ValidationErrorHandler'] = $incDir . 'ValidationErrorHandler.php';
7069

Status & tagging log