+$ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
+
+if ( $wgCanonicalServer === false ) {
+ $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
+}
+
+// Set server name
+$serverParts = wfParseUrl( $wgCanonicalServer );
+if ( $wgServerName !== false ) {
+ wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
+ . 'not customized. Overwriting $wgServerName.' );
+}
+$wgServerName = $serverParts['host'];
+unset( $serverParts );
+
+// Set defaults for configuration variables
+// that are derived from the server name by default
+// Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
+if ( !$wgEmergencyContact ) {
+ $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
+}
+if ( !$wgPasswordSender ) {
+ $wgPasswordSender = 'apache@' . $wgServerName;
+}
+if ( !$wgNoReplyAddress ) {
+ $wgNoReplyAddress = $wgPasswordSender;
+}
+
+if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
+ $wgSecureLogin = false;
+ wfWarn( 'Secure login was enabled on a server that only supports '
+ . 'HTTP or HTTPS. Disabling secure login.' );
+}
+
+$wgVirtualRestConfig['global']['domain'] = $wgCanonicalServer;
+
+// Now that GlobalFunctions is loaded, set defaults that depend on it.
+if ( $wgTmpDirectory === false ) {
+ $wgTmpDirectory = wfTempDir();
+}
+
+// We don't use counters anymore. Left here for extensions still
+// expecting this to exist. Should be removed sometime 1.26 or later.
+if ( !isset( $wgDisableCounters ) ) {
+ $wgDisableCounters = true;
+}
+
+if ( $wgMainWANCache === false ) {
+ // Setup a WAN cache from $wgMainCacheType with no relayer.
+ // Sites using multiple datacenters can configure a relayer.
+ $wgMainWANCache = 'mediawiki-main-default';
+ $wgWANObjectCaches[$wgMainWANCache] = [
+ 'class' => 'WANObjectCache',
+ 'cacheId' => $wgMainCacheType,
+ 'channels' => [ 'purge' => 'wancache-main-default-purge' ]
+ ];
+}
+
+Profiler::instance()->scopedProfileOut( $ps_default2 );
+
+$ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
+
+// Raise the memory limit if it's too low
+wfMemoryLimit();
+
+/**
+ * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
+ * that happens whenever you use a date function without the timezone being
+ * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
+ */
+if ( is_null( $wgLocaltimezone ) ) {
+ MediaWiki\suppressWarnings();
+ $wgLocaltimezone = date_default_timezone_get();
+ MediaWiki\restoreWarnings();
+}
+
+date_default_timezone_set( $wgLocaltimezone );
+if ( is_null( $wgLocalTZoffset ) ) {
+ $wgLocalTZoffset = date( 'Z' ) / 60;
+}
+// The part after the System| is ignored, but rest of MW fills it
+// out as the local offset.
+$wgDefaultUserOptions['timecorrection'] = "System|$wgLocalTZoffset";
+
+if ( !$wgDBerrorLogTZ ) {
+ $wgDBerrorLogTZ = $wgLocaltimezone;
+}
+
+// initialize the request object in $wgRequest
+$wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
+// Set user IP/agent information for causal consistency purposes
+MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [
+ 'IPAddress' => $wgRequest->getIP(),
+ 'UserAgent' => $wgRequest->getHeader( 'User-Agent' ),
+ 'ChronologyProtection' => $wgRequest->getHeader( 'ChronologyProtection' )
+] );
+
+// Useful debug output
+if ( $wgCommandLineMode ) {
+ wfDebug( "\n\nStart command line script $self\n" );
+} else {
+ $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
+
+ if ( $wgDebugPrintHttpHeaders ) {
+ $debug .= "HTTP HEADERS:\n";
+
+ foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
+ $debug .= "$name: $value\n";
+ }