r71452 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71451‎ | r71452 | r71453 >
Date:22:26, 22 August 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added support for per parameter lowercasing indication
Modified paths:
  • /trunk/extensions/Validator/Validator.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/Validator.class.php
@@ -161,9 +161,12 @@
162162 if ( count( $parts ) == 1 ) {
163163 // Default parameter assignment is only possible when there are default parameters!
164164 if ( count( $defaultParams ) > 0 ) {
165 - $defaultParam = array_shift( $defaultParams );
166 - $parameters[strtolower( $defaultParam )] = array(
167 - 'original-value' => trim( $toLower ? strtolower( $parts[0] ) : $parts[0] ),
 165+ $defaultParam = strtolower( array_shift( $defaultParams ) );
 166+
 167+ $this->lowerCaseIfNeeded( $parts[0], $defaultParam, $parameterInfo, $toLower );
 168+
 169+ $parameters[$defaultParam] = array(
 170+ 'original-value' => trim( $parts[0] ),
168171 'default' => $defaultNr,
169172 'position' => $nr
170173 );
@@ -175,8 +178,10 @@
176179 } else {
177180 $paramName = trim( strtolower( $parts[0] ) );
178181
 182+ $this->lowerCaseIfNeeded( $parts[1], $paramName, $parameterInfo, $toLower );
 183+
179184 $parameters[$paramName] = array(
180 - 'original-value' => trim( $toLower ? strtolower( $parts[1] ) : $parts[1] ),
 185+ 'original-value' => trim( $parts[1] ),
181186 'default' => false,
182187 'position' => $nr
183188 );
@@ -230,7 +235,7 @@
231236 else {
232237 if ( is_string( $paramData ) ) {
233238 $paramData = trim( $paramData );
234 - if ( $toLower ) $paramData = strtolower( $paramData );
 239+ $this->lowerCaseIfNeeded( $paramData, $mainName, $this->mParameterInfo, $toLower );
235240 }
236241
237242 $this->mParameters[$mainName] = array(
@@ -251,6 +256,21 @@
252257 }
253258
254259 /**
 260+ * Lowercases the provided $paramValue if needed.
 261+ *
 262+ * @since 0.3.6
 263+ *
 264+ * @param $paramValue String
 265+ * @param $paramName String
 266+ * @param $parameterInfo Array
 267+ * @param $globalDefault Boolean
 268+ */
 269+ protected function lowerCaseIfNeeded( &$paramValue, $paramName, array $parameterInfo, $globalDefault ) {
 270+ $lowerCase = array_key_exists( 'tolower', $parameterInfo[$paramName] ) ? $parameterInfo[$paramName]['tolower'] : $globalDefault;
 271+ if ( $lowerCase ) $paramValue = strtolower( $paramValue );
 272+ }
 273+
 274+ /**
255275 * Returns the main parameter name for a given parameter or alias, or false
256276 * when it is not recognized as main parameter or alias.
257277 *
@@ -258,7 +278,7 @@
259279 *
260280 * @return string or false
261281 */
262 - private function getMainParamName( $paramName ) {
 282+ protected function getMainParamName( $paramName ) {
263283 $result = false;
264284
265285 if ( array_key_exists( $paramName, $this->mParameterInfo ) ) {

Status & tagging log