http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72420

Revision: 72420
Author:   jeroendedauw
Date:     2010-09-05 13:09:32 +0000 (Sun, 05 Sep 2010)

Log Message:
-----------
Implemented CriterionInRange validation

Modified Paths:
--------------
    trunk/extensions/Validator/includes/criteria/CriterionHasLength.php
    trunk/extensions/Validator/includes/criteria/CriterionInRange.php

Modified: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php
===================================================================
--- trunk/extensions/Validator/includes/criteria/CriterionHasLength.php 
2010-09-05 13:07:33 UTC (rev 72419)
+++ trunk/extensions/Validator/includes/criteria/CriterionHasLength.php 
2010-09-05 13:09:32 UTC (rev 72420)
@@ -36,11 +36,7 @@
         */     
        public function validate( $value ) {
                $strlen = strlen( $value );
-               
-               if ( $strlen > $this->upperBound ) return false;
-               if ( $strlen < $this->lowerBound ) return false;
-               
-               return true;
+               return $strlen <= $this->upperBound && $strlen >= 
$this->lowerBound;
        }
        
 }
\ No newline at end of file

Modified: trunk/extensions/Validator/includes/criteria/CriterionInRange.php
===================================================================
--- trunk/extensions/Validator/includes/criteria/CriterionInRange.php   
2010-09-05 13:07:33 UTC (rev 72419)
+++ trunk/extensions/Validator/includes/criteria/CriterionInRange.php   
2010-09-05 13:09:32 UTC (rev 72420)
@@ -13,20 +13,35 @@
  */
 class CriterionInRange extends ParameterCriterion {
        
+       protected $lowerBound;
+       protected $upperBound;  
+       
        /**
         * Constructor.
         * 
+        * @param integer $lowerBound
+        * @param integer $upperBound
+        * 
         * @since 0.4
         */
-       public function __construct(  ) {
+       public function __construct( $lowerBound, $upperBound ) {
                parent::__construct();
+               
+               $this->lowerBound = $lowerBound;
+               $this->upperBound = $upperBound;                
        }
        
        /**
         * @see ParameterCriterion::validate
         */     
        public function validate( $value ) {
+               if ( ! is_numeric( $value ) ) {
+                       return false;
+               }
                
+               $value = (int)$value;
+               
+               return $value <= $this->upperBound && $value >= 
$this->lowerBound;              
        }
        
 }
\ No newline at end of file



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to