X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=1a33b76357aad9081d23436a4393eafbee7f2f08;hp=01569e1afaa8cde30bcbe002f51304ab6b78baa0;hb=f938f15bea1a27f098fc7a0f93673adba31d2efe;hpb=4334552ecb3aebc31a30cc0ce760e73162b46569 diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 01569e1afa..1a33b76357 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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' @@ -2259,6 +2275,7 @@ function wfEscapeShellArg( /*...*/ ) { * @deprecated since 1.30 use MediaWiki\Shell::isDisabled() */ function wfShellExecDisabled() { + wfDeprecated( __FUNCTION__, '1.30' ); return Shell::isDisabled() ? 'disabled' : false; } @@ -2387,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 @@ -2425,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 ); @@ -2683,6 +2706,7 @@ function wfRelativePath( $path, $from ) { function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, $lowercase = true, $engine = 'auto' ) { + wfDeprecated( __FUNCTION__, '1.27' ); return Wikimedia\base_convert( $input, $sourceBase, $destBase, $pad, $lowercase, $engine ); } @@ -3046,6 +3070,8 @@ function wfWaitForSlaves( * Count down from $seconds to zero on the terminal, with a one-second pause * between showing each number. For use in command-line scripts. * + * @deprecated since 1.31, use Maintenance::countDown() + * * @codeCoverageIgnore * @param int $seconds */ @@ -3167,29 +3193,13 @@ function wfShorthandToInteger( $string = '', $default = -1 ) { * See unit test for examples. * See mediawiki.language.bcp47 for the JavaScript implementation. * + * @deprecated since 1.31, use LanguageCode::bcp47() directly. + * * @param string $code The language code. * @return string The language code which complying with BCP 47 standards. */ function wfBCP47( $code ) { - $codeSegment = explode( '-', $code ); - $codeBCP = []; - foreach ( $codeSegment as $segNo => $seg ) { - // when previous segment is x, it is a private segment and should be lc - if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) { - $codeBCP[$segNo] = strtolower( $seg ); - // ISO 3166 country code - } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) { - $codeBCP[$segNo] = strtoupper( $seg ); - // ISO 15924 script code - } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) { - $codeBCP[$segNo] = ucfirst( strtolower( $seg ) ); - // Use lowercase for other cases - } else { - $codeBCP[$segNo] = strtolower( $seg ); - } - } - $langCode = implode( '-', $codeBCP ); - return $langCode; + return LanguageCode::bcp47( $code ); } /** @@ -3244,6 +3254,7 @@ function wfGetParserCacheStorage() { * @deprecated since 1.25 - use Hooks::run */ function wfRunHooks( $event, array $args = [], $deprecatedVersion = null ) { + wfDeprecated( __METHOD__, '1.25' ); return Hooks::run( $event, $args, $deprecatedVersion ); } @@ -3498,3 +3509,37 @@ function wfArrayPlus2d( array $baseArray, array $newValues ) { return $baseArray; } + +/** + * Get system resource usage of current request context. + * Invokes the getrusage(2) system call, requesting RUSAGE_SELF if on PHP5 + * or RUSAGE_THREAD if on HHVM. Returns false if getrusage is not available. + * + * @since 1.24 + * @return array|bool Resource usage data or false if no data available. + */ +function wfGetRusage() { + if ( !function_exists( 'getrusage' ) ) { + return false; + } elseif ( defined( 'HHVM_VERSION' ) && PHP_OS === 'Linux' ) { + return getrusage( 2 /* RUSAGE_THREAD */ ); + } else { + return getrusage( 0 /* RUSAGE_SELF */ ); + } +} + +/** + * Begin profiling of a function + * @param string $functionname Name of the function we will profile + * @deprecated since 1.25 + */ +function wfProfileIn( $functionname ) { +} + +/** + * Stop profiling of a function + * @param string $functionname Name of the function we have profiled + * @deprecated since 1.25 + */ +function wfProfileOut( $functionname = 'missing' ) { +}