Merge "jobqueue: migrate root job deduplication to the WAN cache"
[lhc/web/wiklou.git] / includes / Setup.php
index 071b7c6..df53c99 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 );
@@ -143,6 +149,9 @@ if ( $wgScript === false ) {
 if ( $wgLoadScript === false ) {
        $wgLoadScript = "$wgScriptPath/load.php";
 }
+if ( $wgRestPath === false ) {
+       $wgRestPath = "$wgScriptPath/rest.php";
+}
 
 if ( $wgArticlePath === false ) {
        if ( $wgUsePathInfo ) {
@@ -518,9 +527,61 @@ foreach ( LanguageCode::getNonstandardLanguageCodeMapping() as $code => $bcp47 )
 // To determine the user language, use $wgLang->getCode()
 $wgContLanguageCode = $wgLanguageCode;
 
+// Temporary backwards-compatibility reading of old Squid-named CDN settings as of MediaWiki 1.34,
+// to support sysadmins who fail to update their settings immediately:
+
+if ( isset( $wgUseSquid ) ) {
+       // If the sysadmin is still setting a value of $wgUseSquid to true but $wgUseCdn is the default of
+       // false, to be safe, assume they do want this still, so enable it.
+       if ( !$wgUseCdn && $wgUseSquid ) {
+               $wgUseCdn = $wgUseSquid;
+               wfDeprecated( '$wgUseSquid enabled but $wgUseCdn disabled; enabling CDN functions', '1.34' );
+       }
+} else {
+       // Backwards-compatibility for extensions that read this value.
+       $wgUseSquid = $wgUseCdn;
+}
+
+if ( isset( $wgSquidServers ) ) {
+       // If the sysadmin is still setting a value of $wgSquidServers but $wgCdnServers is the default of
+       // empty, to be safe, assume they do want these servers to be still used, so use them.
+       if ( !empty( $wgSquidServers ) && empty( $wgCdnServers ) ) {
+               $wgCdnServers = $wgSquidServers;
+               wfDeprecated( '$wgSquidServers set, $wgCdnServers empty; using them', '1.34' );
+       }
+} else {
+       // Backwards-compatibility for extensions that read this value.
+       $wgSquidServers = $wgCdnServers;
+}
+
+if ( isset( $wgSquidServersNoPurge ) ) {
+       // If the sysadmin is still setting values in $wgSquidServersNoPurge but $wgCdnServersNoPurge is
+       // the default of empty, to be safe, assume they do want these servers to be still used, so use
+       // them.
+       if ( !empty( $wgSquidServersNoPurge ) && empty( $wgCdnServersNoPurge ) ) {
+               $wgCdnServersNoPurge = $wgSquidServersNoPurge;
+               wfDeprecated( '$wgSquidServersNoPurge set, $wgCdnServersNoPurge empty; using them', '1.34' );
+       }
+} else {
+       // Backwards-compatibility for extensions that read this value.
+       $wgSquidServersNoPurge = $wgCdnServersNoPurge;
+}
+
+if ( isset( $wgSquidMaxage ) ) {
+       // If the sysadmin is still setting a value of $wgSquidMaxage and it's higher than $wgCdnMaxAge,
+       // to be safe, assume they want the higher (lower performance requirement) value, so use that.
+       if ( $wgCdnMaxAge < $wgSquidMaxage ) {
+               $wgCdnMaxAge = $wgSquidMaxage;
+               wfDeprecated( '$wgSquidMaxage set higher than $wgCdnMaxAge; using the higher value', '1.34' );
+       }
+} else {
+       // Backwards-compatibility for extensions that read this value.
+       $wgSquidMaxage = $wgCdnMaxAge;
+}
+
 // Easy to forget to falsify $wgDebugToolbar for static caches.
 // If file cache or CDN cache is on, just disable this (DWIMD).
-if ( $wgUseFileCache || $wgUseSquid ) {
+if ( $wgUseFileCache || $wgUseCdn ) {
        $wgDebugToolbar = false;
 }
 
@@ -605,20 +666,6 @@ if ( $wgDebugToolbar && !$wgCommandLineMode ) {
 // re-created while taking into account any custom settings and extensions.
 MediaWikiServices::resetGlobalInstance( new GlobalVarConfig(), 'quick' );
 
-if ( $wgSharedDB && $wgSharedTables ) {
-       // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
-       MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
-               array_fill_keys(
-                       $wgSharedTables,
-                       [
-                               'dbname' => $wgSharedDB,
-                               'schema' => $wgSharedSchema,
-                               'prefix' => $wgSharedPrefix
-                       ]
-               )
-       );
-}
-
 // Define a constant that indicates that the bootstrapping of the service locator
 // is complete.
 define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
@@ -694,12 +741,28 @@ if ( $wgMainWANCache === false ) {
        ];
 }
 
+if ( $wgSharedDB && $wgSharedTables ) {
+       // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
+       MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
+               array_fill_keys(
+                       $wgSharedTables,
+                       [
+                               'dbname' => $wgSharedDB,
+                               'schema' => $wgSharedSchema,
+                               'prefix' => $wgSharedPrefix
+                       ]
+               )
+       );
+}
+
 Profiler::instance()->scopedProfileOut( $ps_default2 );
 
 $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc' );
 
 // Raise the memory limit if it's too low
-wfMemoryLimit();
+// Note, this makes use of wfDebug, and thus should not be before
+// MWDebug::init() is called.
+wfMemoryLimit( $wgMemoryLimit );
 
 /**
  * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
@@ -752,7 +815,9 @@ if ( $wgRequest->getCookie( 'UseDC', '' ) === 'master' ) {
 
 // Useful debug output
 if ( $wgCommandLineMode ) {
-       wfDebug( "\n\nStart command line script $self\n" );
+       if ( isset( $self ) ) {
+               wfDebug( "\n\nStart command line script $self\n" );
+       }
 } else {
        $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";