* Added a validateDate() function, the date preference option is somtimes not
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Wed, 20 Jul 2005 03:30:44 +0000 (03:30 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Wed, 20 Jul 2005 03:30:44 +0000 (03:30 +0000)
  an integer and this was causing an error that made the DateFormatter.php not
  work for ISO 8601 dates.

includes/SpecialPreferences.php

index 4616fcc..066db60 100644 (file)
@@ -121,8 +121,7 @@ class PreferencesForm {
                        $this->mainPrefsForm( '' );
                }
        }
-
-               /**
+       /**
         * @access private
         */
        function validateInt( &$val, $min=0, $max=0x7fffffff ) {
@@ -144,6 +143,16 @@ class PreferencesForm {
                }
        }
 
+       /**
+        * @access private
+        */
+       function validateDate( &$val, $min = 0, $max = 0, $max=0x7fffffff ) {
+               if ( ( sprintf('%d', $val) === $val && $val >= $min && $val <= $max ) || $val == 'ISO 8601' )
+                       return $val;
+               else
+                       return 0;
+       }
+
        /**
         * Used to validate the user inputed timezone before saving it as
         * 'timeciorrection', will return '00:00' if fed bogus data.
@@ -217,7 +226,7 @@ class PreferencesForm {
                if( $wgUseTeX ) {
                        $wgUser->setOption( 'math', $this->mMath );
                }
-               $wgUser->setOption( 'date', $this->validateInt( $this->mDate, 0, 10 ) );
+               $wgUser->setOption( 'date', $this->validateDate( $this->mDate, 0, 10 ) );
                $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
                $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
                $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );