Apply $wgShellLocale in Setup.php
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 9 May 2017 16:12:41 +0000 (12:12 -0400)
committerTim Starling <tstarling@wikimedia.org>
Thu, 1 Jun 2017 05:11:01 +0000 (15:11 +1000)
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
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/Setup.php

index e61277a..22fed0c 100644 (file)
@@ -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
index 19c585d..f7f52e5 100644 (file)
@@ -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';
 
index 9150338..c6ccf31 100644 (file)
@@ -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 );
 }
 
 /**
index 5ea96dd..b10cf23 100644 (file)
@@ -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' );