* validateIntOrNull() returns null for empty input
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 21 May 2008 05:45:00 +0000 (05:45 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 21 May 2008 05:45:00 +0000 (05:45 +0000)
* NULL options become the defaults if saved (bug 14100)

includes/SpecialPreferences.php
includes/User.php

index 9f01ae2..be6d7fb 100644 (file)
@@ -151,7 +151,7 @@ class PreferencesForm {
        function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
                $val = trim($val);
                if($val === '') {
-                       return $val;
+                       return null;
                } else {
                        return $this->validateInt( $val, $min, $max );
                }
index ca88f5d..1804127 100644 (file)
@@ -1730,9 +1730,16 @@ class User {
                }
                // Filter out any newlines that may have passed through input validation.
                // Newlines are used to separate items in the options blob.
-               $val = str_replace( "\r\n", "\n", $val );
-               $val = str_replace( "\r", "\n", $val );
-               $val = str_replace( "\n", " ", $val );
+               if( $val ) {
+                       $val = str_replace( "\r\n", "\n", $val );
+                       $val = str_replace( "\r", "\n", $val );
+                       $val = str_replace( "\n", " ", $val );
+               }
+               // Explicitly NULL values should refer to defaults
+               global $wgDefaultUserOptions;
+               if( is_null($val) && isset($wgDefaultUserOptions[$oname]) ) {
+                       $val = $wgDefaultUserOptions[$oname];
+               }
                $this->mOptions[$oname] = $val;
        }