Index: trunk/extensions/Validator/includes/criteria/CriterionTrue.php |
— | — | @@ -0,0 +1,32 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Parameter criterion that is always true. |
| 6 | + * |
| 7 | + * @since 0.4 |
| 8 | + * |
| 9 | + * @file CriterionTrue.php |
| 10 | + * @ingroup Validator |
| 11 | + * @ingroup Criteria |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + */ |
| 15 | +class CriterionTrue extends ParameterCriterion { |
| 16 | + |
| 17 | + /** |
| 18 | + * Constructor. |
| 19 | + * |
| 20 | + * @since 0.4 |
| 21 | + */ |
| 22 | + public function __construct() { |
| 23 | + parent::__construct(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @see ParameterCriterion::validate |
| 28 | + */ |
| 29 | + public function validate( $value ) { |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Validator/includes/criteria/CriterionTrue.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 34 | + native |
Index: trunk/extensions/Validator/includes/ParameterCriterion.php |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | 'unique_items' => 'CriterionUniqueItems', |
53 | 53 | ); |
54 | 54 | |
55 | | - $className = $bcMap[$name]; |
| 55 | + $className = array_key_exists( $name, $bcMap ) ? $bcMap[$name] : 'CriterionTrue'; |
56 | 56 | |
57 | 57 | switch ( $name ) { |
58 | 58 | case 'in_array': |
Index: trunk/extensions/Validator/includes/Parameter.php |
— | — | @@ -134,11 +134,13 @@ |
135 | 135 | /** |
136 | 136 | * The value of the parameter. |
137 | 137 | * |
| 138 | + * TODO: protected |
| 139 | + * |
138 | 140 | * @since 0.4 |
139 | 141 | * |
140 | 142 | * @var mixed |
141 | 143 | */ |
142 | | - protected $value; |
| 144 | + public $value; |
143 | 145 | |
144 | 146 | /** |
145 | 147 | * Keeps track of how many times the parameter has been set by the user. |
Index: trunk/extensions/Validator/includes/Validator.php |
— | — | @@ -295,42 +295,18 @@ |
296 | 296 | */ |
297 | 297 | public function formatParameters() { |
298 | 298 | foreach ( $this->parameters as $parameter ) { |
299 | | - foreach ( $parameter->outputTypes as $outputType ) { |
300 | | - $this->setOutputType( $parameter->getName(), $outputType ); |
| 299 | + foreach ( $parameter->outputTypes as $outputType => $arguments ) { |
| 300 | + if ( array_key_exists( $outputType, self::$mOutputFormats ) ) { |
| 301 | + $parameters = array( &$parameter->value, $parameter->getName(), $this->parameters ); |
| 302 | + $parameters = array_merge( $parameters, $arguments ); |
| 303 | + call_user_func_array( self::$mOutputFormats[$outputType], $parameters ); |
| 304 | + } |
| 305 | + else { |
| 306 | + throw new Exception( 'There is no formatting function for output format ' . $outputType ); |
| 307 | + } |
301 | 308 | } |
302 | 309 | } |
303 | 310 | } |
304 | | - |
305 | | - /** |
306 | | - * @deprecated TODO: remove |
307 | | - * |
308 | | - * Calls the formatting function for the provided output format with these parameters: |
309 | | - * - parameter value: ByRef for easy manipulation. |
310 | | - * - parameter name: For lookups in the param info array. |
311 | | - * - parameter array: All data about the parameters gathered so far (this includes dependencies!). |
312 | | - * - output type info: Type info as provided by the parameter definition. This can be zero or more parameters. |
313 | | - * |
314 | | - * @param string $name |
315 | | - * @param array $typeInfo |
316 | | - */ |
317 | | - protected function setOutputType( $name, array $typeInfo ) { |
318 | | - // The output type is the first value in the type info array. |
319 | | - // The remaining ones will be any extra arguments. |
320 | | - $outputType = strtolower( array_shift( $typeInfo ) ); |
321 | | - |
322 | | - if ( !array_key_exists( 'formatted-value', $this->parameters[$name] ) ) { |
323 | | - $this->parameters[$name]['formatted-value'] = $this->parameters[$name]['value']; |
324 | | - } |
325 | | - |
326 | | - if ( array_key_exists( $outputType, self::$mOutputFormats ) ) { |
327 | | - $parameters = array( &$this->parameters[$name]['formatted-value'], $name, $this->parameters ); |
328 | | - $parameters = array_merge( $parameters, $typeInfo ); |
329 | | - call_user_func_array( self::$mOutputFormats[$outputType], $parameters ); |
330 | | - } |
331 | | - else { |
332 | | - throw new Exception( 'There is no formatting function for output format ' . $outputType ); |
333 | | - } |
334 | | - } |
335 | 311 | |
336 | 312 | /** |
337 | 313 | * Returns the parameters. |
Index: trunk/extensions/Validator/Validator.php |
— | — | @@ -73,7 +73,8 @@ |
74 | 74 | $wgAutoloadClasses['CriterionIsNumeric'] = $incDir . 'criteria/CriterionIsNumeric.php'; |
75 | 75 | $wgAutoloadClasses['CriterionItemCount'] = $incDir . 'criteria/CriterionItemCount.php'; |
76 | 76 | $wgAutoloadClasses['CriterionMatchesRegex'] = $incDir . 'criteria/CriterionMatchesRegex.php'; |
77 | | -$wgAutoloadClasses['CriterionNotEmpty'] = $incDir . 'criteria/CriterionNotEmpty.php'; |
| 77 | +$wgAutoloadClasses['CriterionNotEmpty'] = $incDir . 'criteria/CriterionNotEmpty.php'; |
| 78 | +$wgAutoloadClasses['CriterionTrue'] = $incDir . 'criteria/CriterionTrue.php'; |
78 | 79 | $wgAutoloadClasses['CriterionUniqueItems'] = $incDir . 'criteria/CriterionUniqueItems.php'; |
79 | 80 | |
80 | 81 | $wgAutoloadClasses['ValidatorListErrors'] = $incDir . 'parserHooks/Validator_ListErrors.php'; |