http://www.mediawiki.org/wiki/Special:Code/MediaWiki/74050
Revision: 74050
Author: jeroendedauw
Date: 2010-10-01 01:52:20 +0000 (Fri, 01 Oct 2010)
Log Message:
-----------
Changes for 0.4 - work on handling conditional parameters with dependencies
correctly
Modified Paths:
--------------
trunk/extensions/Validator/Validator.php
trunk/extensions/Validator/includes/Parameter.php
trunk/extensions/Validator/includes/ParserHook.php
trunk/extensions/Validator/includes/Validator.php
Modified: trunk/extensions/Validator/Validator.php
===================================================================
--- trunk/extensions/Validator/Validator.php 2010-10-01 01:51:22 UTC (rev
74049)
+++ trunk/extensions/Validator/Validator.php 2010-10-01 01:52:20 UTC (rev
74050)
@@ -24,7 +24,7 @@
die( 'Not an entry point.' );
}
-define( 'Validator_VERSION', '0.4 alpha-5' );
+define( 'Validator_VERSION', '0.4 alpha-6' );
// Constants indicating the strictness of the parameter validation.
define( 'Validator_ERRORS_NONE', 0 );
Modified: trunk/extensions/Validator/includes/Parameter.php
===================================================================
--- trunk/extensions/Validator/includes/Parameter.php 2010-10-01 01:51:22 UTC
(rev 74049)
+++ trunk/extensions/Validator/includes/Parameter.php 2010-10-01 01:52:20 UTC
(rev 74050)
@@ -168,9 +168,18 @@
*
* @var boolean
*/
- protected $applyManipulationsToDefault = false;
+ protected $applyManipulationsToDefault = true;
/**
+ * Indicates if the parameter was set to it's default.
+ *
+ * @since 0.4
+ *
+ * @var boolean
+ */
+ protected $defaulted = false;
+
+ /**
* Returns a new instance of Parameter by converting a Validator
3.x-style parameter array definition.
* Note: this method is for backward compatibility and should not be
used in new code.
*
@@ -415,8 +424,10 @@
* @param array $parameters
*/
public function format( array &$parameters ) {
- foreach ( $this->getManipulations() as $manipulation ) {
- $manipulation->manipulate( $this, $parameters );
+ if ( $this->applyManipulationsToDefault ||
!$this->wasSetToDefault() ) {
+ foreach ( $this->getManipulations() as $manipulation ) {
+ $manipulation->manipulate( $this, $parameters );
+ }
}
}
@@ -435,7 +446,7 @@
}
else {
$success = true;
- $this->value = $this->default;
+ $this->setToDefault();
}
}
else {
@@ -661,9 +672,30 @@
}
return $manipulations;
- }
+ }
/**
+ * Sets the parameter value to the default.
+ *
+ * @since 0.4
+ */
+ protected function setToDefault() {
+ $this->defaulted = true;
+ $this->value = $this->default;
+ }
+
+ /**
+ * Gets if the parameter was set to it's default.
+ *
+ * @since 0.4
+ *
+ * @return boolean
+ */
+ public function wasSetToDefault() {
+ return $this->defaulted;
+ }
+
+ /**
* Returns the criteria that apply to the list as a whole.
*
* @since 0.4
Modified: trunk/extensions/Validator/includes/ParserHook.php
===================================================================
--- trunk/extensions/Validator/includes/ParserHook.php 2010-10-01 01:51:22 UTC
(rev 74049)
+++ trunk/extensions/Validator/includes/ParserHook.php 2010-10-01 01:52:20 UTC
(rev 74050)
@@ -129,7 +129,7 @@
$this->parser = array_shift( $args );
- return array( $this->validateAndRender( $args, false ) );
+ return array( $this->validateAndRender( $args, false ),
'noparse' => true, 'isHTML' => true );
}
/**
Modified: trunk/extensions/Validator/includes/Validator.php
===================================================================
--- trunk/extensions/Validator/includes/Validator.php 2010-10-01 01:51:22 UTC
(rev 74049)
+++ trunk/extensions/Validator/includes/Validator.php 2010-10-01 01:52:20 UTC
(rev 74050)
@@ -30,11 +30,20 @@
*
* @since 0.4
*
- * @var array
+ * @var array of string
*/
protected $rawParameters = array();
/**
+ * Array containing the names of the parameters to handle, ordered by
priority.
+ *
+ * @since 0.4
+ *
+ * @var array
+ */
+ protected $paramsToHandle = array();
+
+ /**
* List of ValidationError.
*
* @since 0.4
@@ -212,9 +221,7 @@
* @since 0.4
*/
public function validateParameters() {
- // Start processing at the first parameter.
- $keys = array_keys( $this->parameters );
- $this->doParamProcessing( $keys[0] );
+ $this->doParamProcessing();
// Loop over the remaining raw parameters.
// These are unrecognized parameters, as they where not used by
any parameter definition.
@@ -227,14 +234,11 @@
* Does the actual parameter processing.
*
* @since 0.4
- *
- * @param string $firstParamName
- * @param boolean $incFirst
*/
- protected function doParamProcessing( $firstParamName, $incFirst = true
) {
- $orderedParameters = $this->getParamsToProcess(
$firstParamName, $incFirst );
+ protected function doParamProcessing() {
+ $this->getParamsToProcess( array(), $this->parameters );
- foreach ( $orderedParameters as $paramName ) {
+ while ( $paramName = array_shift( $this->paramsTohandle ) ) {
$parameter = $this->parameters[$paramName];
$setUservalue = $this->attemptToSetUserValue(
$parameter );
@@ -251,19 +255,13 @@
}
}
- $paramCount = count( $this->parameters );
+ $initialSet = $this->parameters;
$parameter->format( $this->parameters );
- // This means additional parameters where added
while formatting the param value.
- // To correctly handle dependencies, this
function is called again for the remaining
- // parameters, and after execution, the current
loop will be aborted.
- if ( $paramCount !== count( $this->parameters )
) {
- $this->doParamProcessing(
$parameter->getName(), false );
- break;
- }
+ $this->getParamsToProcess( $initialSet,
$this->parameters );
}
- }
+ }
}
/**
@@ -271,33 +269,34 @@
*
* @since 0.4
*
- * @param string $firstParamName
- * @param boolean $incFirst
- *
- * @return array
+ * @param array $initialParamSet
+ * @param array $resultingParamSet
*/
- protected function getParamsToProcess( $firstParamName, $incFirst ) {
- $dependencyList = array();
-
- $reachedStart = false;
-
- foreach ( $this->parameters as $paramName => $parameter ) {
- $reachedStart = $reachedStart || $paramName ==
$firstParamName;
+ protected function getParamsToProcess( array $initialParamSet, array
$resultingParamSet ) {
+ if ( count( $initialParamSet ) == 0 ) {
+ $this->paramsTohandle = array_keys( $resultingParamSet
);
+ }
+ else {
+ if ( !is_array( $this->paramsTohandle ) ) {
+ $this->paramsTohandle = array();
+ }
- if ( $reachedStart ) {
- // If $incFirst is false, the first parameter
should be ignored.
- if ( $incFirst ) {
- $dependencyList[$paramName] =
$parameter->getDependencies();
+ foreach ( $resultingParamSet as $paramName =>
$parameter ) {
+ if ( !array_key_exists( $paramName,
$initialParamSet ) ) {
+ $this->paramsTohandle[] = $paramName;
}
- else {
- $incFirst = true;
- }
- }
+ }
}
- $sorter = new TopologicalSort( $dependencyList, true );
+ $dependencies = array();
+
+ foreach ( $this->paramsTohandle as $paramName ) {
+ $dependencies[$paramName] =
array();//$this->parameters[$paramName]->getDependencies();
+ }
- return $sorter->doSort();
+ $sorter = new TopologicalSort( $dependencies, true );
+
+ $this->paramsTohandle = $sorter->doSort();
}
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs