r65066 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65065‎ | r65066 | r65067 >
Date:14:33, 15 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.3 - changed function name
Modified paths:
  • /trunk/extensions/Validator/Validator.class.php (modified) (history)
  • /trunk/extensions/Validator/Validator_Manager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/Validator.class.php
@@ -19,8 +19,6 @@
2020 * @ingroup Validator
2121 *
2222 * @author Jeroen De Dauw
23 - *
24 - * TODO: add native suport for default parameters as present in Maps 0.6.
2523 */
2624 final class Validator {
2725
@@ -55,6 +53,7 @@
5654 'in_array' => array( 'ValidatorFunctions', 'in_array' ),
5755 'in_range' => array( 'ValidatorFunctions', 'in_range' ),
5856 'is_numeric' => 'is_numeric',
 57+ 'is_float' => 'is_float',
5958 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ),
6059 'not_empty' => array( 'ValidatorFunctions', 'not_empty' ),
6160 'has_length' => array( 'ValidatorFunctions', 'has_length' ),
@@ -121,17 +120,21 @@
122121 */
123122 public function parseAndSetParams( array $rawParams, array $defaultParams = array() ) {
124123 $parameters = array();
125 -
 124+ //var_dump($rawParams); exit;
126125 foreach( $rawParams as $arg ) {
127 - $parts = explode( '=', $arg );
128 - if ( count( $parts ) == 1 ) {
129 - if ( count( $defaultParams ) > 0 ) {
130 - $defaultParam = array_shift( $defaultParams );
131 - $parameters[$defaultParam] = trim( $parts[0] );
132 - }
 126+ if ( is_array( $arg ) ) {
 127+
133128 } else {
134 - $name = strtolower( trim( array_shift( $parts ) ) );
135 - $parameters[$name] = trim( implode( $parts ) );
 129+ $parts = explode( '=', $arg );
 130+ if ( count( $parts ) == 1 ) {
 131+ if ( count( $defaultParams ) > 0 ) {
 132+ $defaultParam = array_shift( $defaultParams );
 133+ $parameters[$defaultParam] = trim( $parts[0] );
 134+ }
 135+ } else {
 136+ $name = strtolower( trim( array_shift( $parts ) ) );
 137+ $parameters[$name] = trim( implode( $parts ) );
 138+ }
136139 }
137140 }
138141
@@ -253,8 +256,7 @@
254257 $this->addTypeCriteria( $name, 'is_integer' );
255258 break;
256259 case 'float':
257 - // FIXME: only accept floats, not the weird crap is_numeric also accepts
258 - $this->addTypeCriteria( $name, 'is_numeric' );
 260+ $this->addTypeCriteria( $name, 'is_float' );
259261 break;
260262 case 'number': // Note: This accepts non-decimal notations!
261263 $this->addTypeCriteria( $name, 'is_numeric' );
Index: trunk/extensions/Validator/Validator_Manager.php
@@ -36,7 +36,7 @@
3737 * @param array $defaultParams
3838 * @return array or false The valid parameters or false when the output should not be shown.
3939 */
40 - public function manageMapparameters( array $rawParameters, array $parameterInfo, array $defaultParams = array() ) {
 40+ public function manageParameters( array $rawParameters, array $parameterInfo, array $defaultParams = array() ) {
4141 global $egValidatorErrorLevel;
4242
4343 $validator = new Validator();

Follow-up revisions

RevisionCommit summaryAuthorDate
r65068Follow up to r65066 - non-raw parameters are now ignored more neatlyjeroendedauw14:43, 15 April 2010

Status & tagging log