r72496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72495‎ | r72496 | r72497 >
Date:16:03, 6 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - Partial fix to non-functioning formatting
Modified paths:
  • /trunk/extensions/Validator/Validator.php (modified) (history)
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/ParameterCriterion.php (modified) (history)
  • /trunk/extensions/Validator/includes/Validator.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionTrue.php (added) (history)

Diff [purge]

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
134 + native
Index: trunk/extensions/Validator/includes/ParameterCriterion.php
@@ -51,7 +51,7 @@
5252 'unique_items' => 'CriterionUniqueItems',
5353 );
5454
55 - $className = $bcMap[$name];
 55+ $className = array_key_exists( $name, $bcMap ) ? $bcMap[$name] : 'CriterionTrue';
5656
5757 switch ( $name ) {
5858 case 'in_array':
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -134,11 +134,13 @@
135135 /**
136136 * The value of the parameter.
137137 *
 138+ * TODO: protected
 139+ *
138140 * @since 0.4
139141 *
140142 * @var mixed
141143 */
142 - protected $value;
 144+ public $value;
143145
144146 /**
145147 * 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 @@
296296 */
297297 public function formatParameters() {
298298 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+ }
301308 }
302309 }
303310 }
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 - }
335311
336312 /**
337313 * Returns the parameters.
Index: trunk/extensions/Validator/Validator.php
@@ -73,7 +73,8 @@
7474 $wgAutoloadClasses['CriterionIsNumeric'] = $incDir . 'criteria/CriterionIsNumeric.php';
7575 $wgAutoloadClasses['CriterionItemCount'] = $incDir . 'criteria/CriterionItemCount.php';
7676 $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';
7879 $wgAutoloadClasses['CriterionUniqueItems'] = $incDir . 'criteria/CriterionUniqueItems.php';
7980
8081 $wgAutoloadClasses['ValidatorListErrors'] = $incDir . 'parserHooks/Validator_ListErrors.php';

Status & tagging log