ApiQueryBase: Fix addWhereFld for PHP 7.2
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 404d115..1a33b76 100644 (file)
@@ -2225,7 +2225,23 @@ function wfPercent( $nr, $acc = 2, $round = true ) {
  * @return bool
  */
 function wfIniGetBool( $setting ) {
-       $val = strtolower( ini_get( $setting ) );
+       return wfStringToBool( ini_get( $setting ) );
+}
+
+/**
+ * Convert string value to boolean, when the following are interpreted as true:
+ * - on
+ * - true
+ * - yes
+ * - Any number, except 0
+ * All other strings are interpreted as false.
+ *
+ * @param string $val
+ * @return bool
+ * @since 1.31
+ */
+function wfStringToBool( $val ) {
+       $val = strtolower( $val );
        // 'on' and 'true' can't have whitespace around them, but '1' can.
        return $val == 'on'
                || $val == 'true'
@@ -2388,9 +2404,10 @@ function wfShellWikiCmd( $script, array $parameters = [], array $options = [] )
  * @param string $mine
  * @param string $yours
  * @param string &$result
+ * @param string &$mergeAttemptResult
  * @return bool
  */
-function wfMerge( $old, $mine, $yours, &$result ) {
+function wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult = null ) {
        global $wgDiff3;
 
        # This check may also protect against code injection in
@@ -2426,13 +2443,18 @@ function wfMerge( $old, $mine, $yours, &$result ) {
                $oldtextName, $yourtextName );
        $handle = popen( $cmd, 'r' );
 
-       if ( fgets( $handle, 1024 ) ) {
-               $conflict = true;
-       } else {
-               $conflict = false;
-       }
+       $mergeAttemptResult = '';
+       do {
+               $data = fread( $handle, 8192 );
+               if ( strlen( $data ) == 0 ) {
+                       break;
+               }
+               $mergeAttemptResult .= $data;
+       } while ( true );
        pclose( $handle );
 
+       $conflict = $mergeAttemptResult !== '';
+
        # Merge differences
        $cmd = Shell::escape( $wgDiff3, '-a', '-e', '--merge', $mytextName,
                $oldtextName, $yourtextName );