From c2af04eb7c748af65d893575c3bf7f9a08f3c4b8 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 5 Oct 2015 11:45:34 +0100
Subject: [PATCH] Issue #2528988 by znerol: Remove the option to specify a
 base_url from within settings.php

---
 core/lib/Drupal/Core/DrupalKernel.php  | 51 +++++++++-----------------
 core/lib/Drupal/Core/Site/Settings.php |  2 +-
 sites/default/default.settings.php     | 22 -----------
 3 files changed, 19 insertions(+), 56 deletions(-)

diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 2ddc3eebfdf6..16b3baca2a18 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -992,47 +992,32 @@ protected function initializeSettings(Request $request) {
    * @todo D8: Eliminate this entirely in favor of Request object.
    */
   protected function initializeRequestGlobals(Request $request) {
-    // Provided by settings.php.
     global $base_url;
     // Set and derived from $base_url by this function.
     global $base_path, $base_root;
     global $base_secure_url, $base_insecure_url;
 
-    // @todo Refactor with the Symfony Request object.
-    if (isset($base_url)) {
-      // Parse fixed base URL from settings.php.
-      $parts = parse_url($base_url);
-      if (!isset($parts['path'])) {
-        $parts['path'] = '';
-      }
-      $base_path = $parts['path'] . '/';
-      // Build $base_root (everything until first slash after "scheme://").
-      $base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
-    }
-    else {
-      // Create base URL.
-      $base_root = $request->getSchemeAndHttpHost();
-
-      $base_url = $base_root;
-
-      // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
-      // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
-      if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME')), '\/')) {
-        // Remove "core" directory if present, allowing install.php,
-        // authorize.php, and others to auto-detect a base path.
-        $core_position = strrpos($dir, '/core');
-        if ($core_position !== FALSE && strlen($dir) - 5 == $core_position) {
-          $base_path = substr($dir, 0, $core_position);
-        }
-        else {
-          $base_path = $dir;
-        }
-        $base_url .= $base_path;
-        $base_path .= '/';
+    // Create base URL.
+    $base_root = $request->getSchemeAndHttpHost();
+    $base_url = $base_root;
+
+    // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
+    // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
+    if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME')), '\/')) {
+      // Remove "core" directory if present, allowing install.php,
+      // authorize.php, and others to auto-detect a base path.
+      $core_position = strrpos($dir, '/core');
+      if ($core_position !== FALSE && strlen($dir) - 5 == $core_position) {
+        $base_path = substr($dir, 0, $core_position);
       }
       else {
-        $base_path = '/';
+        $base_path = $dir;
       }
+      $base_url .= $base_path;
+      $base_path .= '/';
+    }
+    else {
+      $base_path = '/';
     }
     $base_secure_url = str_replace('http://', 'https://', $base_url);
     $base_insecure_url = str_replace('https://', 'http://', $base_url);
diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php
index 3b3706385101..ee786db89119 100644
--- a/core/lib/Drupal/Core/Site/Settings.php
+++ b/core/lib/Drupal/Core/Site/Settings.php
@@ -112,7 +112,7 @@ public static function getAll() {
    */
   public static function initialize($app_root, $site_path, &$class_loader) {
     // Export these settings.php variables to the global namespace.
-    global $base_url, $config_directories, $config;
+    global $config_directories, $config;
     $settings = array();
     $config = array();
     $databases = array();
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index 1ea5d727efa7..7d3a3ae44292 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -527,28 +527,6 @@
  */
 # $settings['maintenance_theme'] = 'bartik';
 
-/**
- * Base URL (optional).
- *
- * If Drupal is generating incorrect URLs on your site, which could
- * be in HTML headers (links to CSS and JS files) or visible links on pages
- * (such as in menus), uncomment the Base URL statement below (remove the
- * leading hash sign) and fill in the absolute URL to your Drupal installation.
- *
- * You might also want to force users to use a given domain.
- * See the .htaccess file for more information.
- *
- * Examples:
- *   $base_url = 'http://www.example.com';
- *   $base_url = 'http://www.example.com:8888';
- *   $base_url = 'http://www.example.com/drupal';
- *   $base_url = 'https://www.example.com:8888/drupal';
- *
- * It is not allowed to have a trailing slash; Drupal will add it
- * for you.
- */
-# $base_url = 'http://www.example.com';  // NO trailing slash!
-
 /**
  * PHP settings:
  *
-- 
GitLab