Make wfIniGetBool() more accurate:
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 26 Sep 2007 17:59:29 +0000 (17:59 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 26 Sep 2007 17:59:29 +0000 (17:59 +0000)
* accepts 'yes' as well as 'on' and 'true'
* accepts negative and non-1 integers, as well as garbage characters after the number (as C atoi() function for nonzero result)

includes/GlobalFunctions.php

index a67972d..b216eca 100644 (file)
@@ -1783,7 +1783,7 @@ function wfUrlProtocols() {
  * for code that just takes the ini_get() return value as a boolean.
  *
  * To make things extra interesting, setting via php_value accepts
- * "true" as true, but php.ini and php_flag consider it false. :)
+ * "true" and "yes" as true, but php.ini and php_flag consider them false. :)
  * Unrecognized values go false... again opposite PHP's own coercion
  * from string to bool.
  *
@@ -1798,9 +1798,10 @@ function wfUrlProtocols() {
 function wfIniGetBool( $setting ) {
        $val = ini_get( $setting );
        // 'on' and 'true' can't have whitespace around them, but '1' can.
-       return trim( $val ) == '1'
-               || strtolower( $val ) == 'on'
-               || strtolower( $val ) == 'true';
+       return strtolower( $val ) == 'on'
+               || strtolower( $val ) == 'true'
+               || strtolower( $val ) == 'yes'
+               || preg_match( "/^\s*[+-]?0*[1-9]/", $val ); // approx C atoi() function
 }
 
 /**