From fb6f4d35e757c502fb9358226ef366328b73d6b9 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 9 May 2017 12:12:41 -0400 Subject: [PATCH] Apply $wgShellLocale in Setup.php While most of MediaWiki ignores the shell's/C library's locale setting, there are some things other than shell execs that use it (e.g. the luasandbox PHP extension). To provide a consistent environment, set the locale in Setup.php instead of letting it be changed mid-request depending on whether something else happened to have called certain functions. Bug: T107128 Change-Id: I02943803d26d5b1b3ac00ef9216f69cdfa149585 --- RELEASE-NOTES-1.30 | 2 ++ includes/DefaultSettings.php | 1 - includes/GlobalFunctions.php | 21 +++------------------ includes/Setup.php | 4 ++++ 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index e61277a9f4..22fed0c84a 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -21,6 +21,8 @@ production. to plain class names, using the 'factory' key in the module description array. This allows dependency injection to be used for ResourceLoader modules. * $wgExceptionHooks has been removed. +* $wgShellLocale is now applied for all requests. wfInitShellLocale() is + deprecated and a no-op, as it is no longer needed. === New features in 1.30 === * (T37247) Output from Parser::parse() will now be wrapped in a div with diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 19c585d14c..f7f52e5130 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -8183,7 +8183,6 @@ $wgPhpCli = '/usr/bin/php'; * @note If multiple wikis are being served from the same process (e.g. the * same fastCGI or Apache server), this setting must be the same on all those * wikis. - * @see wfInitShellLocale() */ $wgShellLocale = 'C.UTF-8'; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 91503385c8..c6ccf31e63 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2192,8 +2192,6 @@ function wfIniGetBool( $setting ) { * @return string */ function wfEscapeShellArg( /*...*/ ) { - wfInitShellLocale(); - $args = func_get_args(); if ( count( $args ) === 1 && is_array( reset( $args ) ) ) { // If only one argument has been passed, and that argument is an array, @@ -2308,8 +2306,6 @@ function wfShellExec( $cmd, &$retval = null, $environ = [], $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr']; $profileMethod = isset( $options['profileMethod'] ) ? $options['profileMethod'] : wfGetCaller(); - wfInitShellLocale(); - $envcmd = ''; foreach ( $environ as $k => $v ) { if ( wfIsWindows() ) { @@ -2533,25 +2529,14 @@ function wfShellExecWithStderr( $cmd, &$retval = null, $environ = [], $limits = } /** - * Set the locale for locale-sensitive operations + * Formerly set the locale for locale-sensitive operations * - * Sets LC_ALL to a known value to work around issues like the following: - * - https://bugs.php.net/bug.php?id=45132 escapeshellarg() destroys non-ASCII - * characters if LANG is not a UTF-8 locale - * - T107128 Scribunto string comparison works case insensitive while the - * standard Lua case sensitive + * This is now done in Setup.php. * + * @deprecated since 1.30, no longer needed * @see $wgShellLocale */ function wfInitShellLocale() { - static $done = false; - if ( $done ) { - return; - } - $done = true; - global $wgShellLocale; - putenv( "LC_ALL=$wgShellLocale" ); - setlocale( LC_ALL, $wgShellLocale ); } /** diff --git a/includes/Setup.php b/includes/Setup.php index 5ea96dd040..b10cf23809 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -49,6 +49,10 @@ if ( !isset( $wgVersion ) ) { mb_internal_encoding( 'UTF-8' ); +// Set the configured locale on all requests for consisteny +putenv( "LC_ALL=$wgShellLocale" ); +setlocale( LC_ALL, $wgShellLocale ); + // Set various default paths sensibly... $ps_default = Profiler::instance()->scopedProfileIn( $fname . '-defaults' ); -- 2.20.1