Setup: Move mb_internal_encoding() call earlier
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 13 Jul 2019 00:46:56 +0000 (01:46 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 13 Jul 2019 00:48:11 +0000 (01:48 +0100)
This is an unconditional and unconfigurable changes to PHP behaviour.
The earlier the better so that there is less code that can run
without it.

Also improve some documentation of other setup logic bits being
documented by the referenced task.

Bug: T189966
Change-Id: Ia8e1478cf0841d80b1c61c266f2ece75be2303e1

includes/Setup.php

index 641f1f9..f34b176 100644 (file)
@@ -55,7 +55,7 @@ if ( ini_get( 'mbstring.func_overload' ) ) {
 // Start the autoloader, so that extensions can derive classes from core files
 require_once "$IP/includes/AutoLoader.php";
 
-// Load up some global defines
+// Load global constants
 require_once "$IP/includes/Defines.php";
 
 // Load default settings
@@ -89,9 +89,17 @@ if ( !interface_exists( 'Psr\Log\LoggerInterface' ) ) {
        die( 1 );
 }
 
+/**
+ * Changes to the PHP environment that don't vary on configuration.
+ */
+
 // Install a header callback
 MediaWiki\HeaderCallback::register();
 
+// Set the encoding used by reading HTTP input, writing HTTP output.
+// This is also the default for mbstring functions.
+mb_internal_encoding( 'UTF-8' );
+
 /**
  * Load LocalSettings.php
  */
@@ -128,8 +136,6 @@ ExtensionRegistry::getInstance()->loadFromQueue();
 // Don't let any other extensions load
 ExtensionRegistry::getInstance()->finish();
 
-mb_internal_encoding( 'UTF-8' );
-
 // Set the configured locale on all requests for consisteny
 putenv( "LC_ALL=$wgShellLocale" );
 setlocale( LC_ALL, $wgShellLocale );
@@ -754,6 +760,8 @@ Profiler::instance()->scopedProfileOut( $ps_default2 );
 $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc' );
 
 // Raise the memory limit if it's too low
+// Note, this makes use of wfDebug, and thus should not be before
+// MWDebug::init() is called.
 wfMemoryLimit();
 
 /**