[!!!][TASK] Move pages.url_scheme to compatibility7 77/51077/5
authorBenni Mack <benni@typo3.org>
Thu, 12 Jan 2017 14:26:02 +0000 (15:26 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 13 Jan 2017 08:47:47 +0000 (09:47 +0100)
Adding SSL support on a per-page basis is something that
does not happen very much in 2017 anymore, rather doing this
on a per-domain basis, and based on server-redirects makes
more sense these days.

The field and the functionality for links is moved to
EXT:compatibility7.

Resolves: #79302
Releases: master
Change-Id: I7ae1c59533bee1d015b39811f39d590e5488aabe
Reviewed-on: https://review.typo3.org/51077
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
14 files changed:
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/compatibility7/Classes/Hooks/EnforceUrlSchemeHook.php [new file with mode: 0644]
typo3/sysext/compatibility7/Configuration/TCA/Overrides/pages.php [new file with mode: 0644]
typo3/sysext/compatibility7/Resources/Private/Language/locallang_tca.xlf [new file with mode: 0644]
typo3/sysext/compatibility7/ext_localconf.php
typo3/sysext/compatibility7/ext_tables.sql [new file with mode: 0644]
typo3/sysext/core/Configuration/TCA/pages.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-79302-MovedPagesurlSchemeToCompatibility7Extension.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Functional/Tca/PagesVisibleFieldsTest.php
typo3/sysext/core/ext_tables.sql
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Resources/Private/Language/locallang_tca.xlf
typo3/sysext/viewpage/Classes/Controller/ViewModuleController.php

index c2a3041..c3b0947 100644 (file)
@@ -37,7 +37,6 @@ use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
@@ -3184,13 +3183,7 @@ class BackendUtility
         // Checks alternate domains
         if (!empty($rootLine)) {
             $urlParts = parse_url($domain);
-            /** @var PageRepository $sysPage */
-            $sysPage = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
-            $page = (array)$sysPage->getPage($pageId);
-            $protocol = 'http';
-            if ($page['url_scheme'] == HttpUtility::SCHEME_HTTPS || $page['url_scheme'] == 0 && GeneralUtility::getIndpEnv('TYPO3_SSL')) {
-                $protocol = 'https';
-            }
+            $protocol = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https' : 'http';
             $previewDomainConfig = static::getBackendUserAuthentication()->getTSConfig(
                 'TCEMAIN.previewDomain',
                 self::getPagesTSconfig($pageId)
diff --git a/typo3/sysext/compatibility7/Classes/Hooks/EnforceUrlSchemeHook.php b/typo3/sysext/compatibility7/Classes/Hooks/EnforceUrlSchemeHook.php
new file mode 100644 (file)
index 0000000..c1c0b97
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+namespace TYPO3\CMS\Compatibility7\Hooks;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\HttpUtility;
+use TYPO3\CMS\Frontend\ContentObject\TypolinkModifyLinkConfigForPageLinksHookInterface;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+
+/**
+ * Hooks for
+ *  - TypoLink when linking to a page and sets forceAbsoluteUrl if the page has
+ *  - TSFE to do a redirect if the url_scheme does not match
+ */
+class EnforceUrlSchemeHook implements TypolinkModifyLinkConfigForPageLinksHookInterface
+{
+    /**
+     * Hooks in typolink when linking to a page
+     *
+     * Checks if pages.url_scheme has a value and then enforces an absolute URL with the scheme set in there
+     *
+     * @param array $linkConfiguration the typolink configuration
+     * @param array $linkDetails
+     * @param array $pageRow the fetched page record
+     * @return array the modified link configuration
+     */
+    public function modifyPageLinkConfiguration(array $linkConfiguration, array $linkDetails, array $pageRow): array
+    {
+        // If pages.url_scheme is not set or not greater than zero, do not process
+        if (!isset($pageRow['url_scheme']) || !($pageRow['url_scheme'] > 0)) {
+            return $linkConfiguration;
+        }
+
+        // If an absolute URL with explicit scheme is already set, don't do anything
+        if (isset($linkConfiguration['forceAbsoluteUrl']) && $linkConfiguration['forceAbsoluteUrl']
+            && isset($conf['forceAbsoluteUrl.']['scheme']) && $conf['forceAbsoluteUrl.']['scheme']) {
+            return $linkConfiguration;
+        }
+
+        // Enable forceAbsoluteUrl so the link configuration actually enters the if() clause in TypoLink
+        $linkConfiguration['forceAbsoluteUrl'] = 1;
+
+        // Now explictly override the scheme
+        if (!isset($linkConfiguration['forceAbsoluteUrl.'])) {
+            $linkConfiguration['forceAbsoluteUrl.'] = [];
+        }
+        $linkConfiguration['forceAbsoluteUrl.']['scheme'] = (int)$pageRow['url_scheme'] === HttpUtility::SCHEME_HTTP ? 'http' : 'https';
+        return $linkConfiguration;
+    }
+
+    /**
+     * Checks if pages.url_scheme is set, and then redirects to enforce HTTP / HTTPS if it does not match
+     *
+     * @param array $parameters not in use, as it does not contain useful information for this hook
+     * @param TypoScriptFrontendController $parentObject
+     */
+    public function redirectIfUrlSchemeDoesNotMatch($parameters, $parentObject)
+    {
+        if (isset($parentObject->page['url_scheme']) && $parentObject->page['url_scheme'] > 0) {
+            $newUrl = '';
+            $requestUrlScheme = parse_url(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), PHP_URL_SCHEME);
+            if ((int)$parentObject->page['url_scheme'] === HttpUtility::SCHEME_HTTP && $requestUrlScheme == 'https') {
+                $newUrl = 'http://' . substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 8);
+            } elseif ((int)$parentObject->page['url_scheme'] === HttpUtility::SCHEME_HTTPS && $requestUrlScheme == 'http') {
+                $newUrl = 'https://' . substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 7);
+            }
+            if ($newUrl !== '') {
+                if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+                    $headerCode = HttpUtility::HTTP_STATUS_303;
+                } else {
+                    $headerCode = HttpUtility::HTTP_STATUS_301;
+                }
+                HttpUtility::redirect($newUrl, $headerCode);
+            }
+        }
+    }
+}
diff --git a/typo3/sysext/compatibility7/Configuration/TCA/Overrides/pages.php b/typo3/sysext/compatibility7/Configuration/TCA/Overrides/pages.php
new file mode 100644 (file)
index 0000000..fe6521b
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+defined('TYPO3_MODE') or die();
+
+// add pages.url_scheme
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', [
+    'url_scheme' => [
+        'exclude' => true,
+        'label' => 'LLL:EXT:compatibility7/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme',
+        'config' => [
+            'type' => 'select',
+            'renderType' => 'selectSingle',
+            'items' => [
+                [
+                    'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.default_value',
+                    0
+                ],
+                [
+                    'LLL:EXT:compatibility7/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme.http',
+                    1
+                ],
+                [
+                    'LLL:EXT:compatibility7/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme.https',
+                    2
+                ]
+            ],
+            'default' => 0
+        ]
+    ]
+]);
+
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette('pages', 3, 'url_scheme', 'after:cache_tags');
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette('pages', 'links', '--linebreak--, url_scheme;LLL:EXT:compatibility7/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme_formlabel', 'after:target');
diff --git a/typo3/sysext/compatibility7/Resources/Private/Language/locallang_tca.xlf b/typo3/sysext/compatibility7/Resources/Private/Language/locallang_tca.xlf
new file mode 100644 (file)
index 0000000..b11523a
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+       <file t3:id="1484231191" source-language="en" datatype="plaintext" original="messages" date="2017-10-12T14:22:32Z" product-name="compatibility7">
+               <header/>
+               <body>
+                       <trans-unit id="pages.url_scheme">
+                               <source>Enforce Protocol:</source>
+                       </trans-unit>
+                       <trans-unit id="pages.url_scheme_formlabel">
+                               <source>Use Protocol</source>
+                       </trans-unit>
+                       <trans-unit id="pages.url_scheme.http">
+                               <source>http://</source>
+                       </trans-unit>
+                       <trans-unit id="pages.url_scheme.https">
+                               <source>https://</source>
+                       </trans-unit>
+               </body>
+       </file>
+</xliff>
index 9ce2c0f..c5d7676 100644 (file)
@@ -19,3 +19,10 @@ if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('indexed_search
         'defaultContentRendering'
     );
 }
+
+// Enable pages.url_scheme functionality again
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typolinkProcessing']['typolinkModifyParameterForPageLinks']['compatibility7_urlscheme']
+    = \TYPO3\CMS\Compatibility7\Hooks\EnforceUrlSchemeHook::class;
+
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing']['compatibility7_urlscheme']
+    = \TYPO3\CMS\Compatibility7\Hooks\EnforceUrlSchemeHook::class . '->redirectIfUrlSchemeDoesNotMatch';
diff --git a/typo3/sysext/compatibility7/ext_tables.sql b/typo3/sysext/compatibility7/ext_tables.sql
new file mode 100644 (file)
index 0000000..f6e29a8
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# Additional fields for table 'pages'
+#
+CREATE TABLE pages (
+       url_scheme tinyint(3) unsigned DEFAULT '0' NOT NULL
+);
index 5d9cdf8..4e34c2b 100644 (file)
@@ -241,29 +241,6 @@ return [
                 'default' => 0
             ]
         ],
-        'url_scheme' => [
-            'exclude' => true,
-            'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme',
-            'config' => [
-                'type' => 'select',
-                'renderType' => 'selectSingle',
-                'items' => [
-                    [
-                        'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.default_value',
-                        0
-                    ],
-                    [
-                        'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme.http',
-                        1
-                    ],
-                    [
-                        'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme.https',
-                        2
-                    ]
-                ],
-                'default' => 0
-            ]
-        ],
         'fe_group' => [
             'exclude' => true,
             'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.fe_group',
@@ -997,7 +974,7 @@ return [
             'showitem' => 'layout, lastUpdated, newUntil, no_search'
         ],
         '3' => [
-            'showitem' => 'alias, target, no_cache, cache_timeout, cache_tags, url_scheme'
+            'showitem' => 'alias, target, no_cache, cache_timeout, cache_tags'
         ],
         '5' => [
             'showitem' => 'author, author_email',
@@ -1066,7 +1043,7 @@ return [
             'showitem' => 'content_from_pid;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.content_from_pid_formlabel',
         ],
         'links' => [
-            'showitem' => 'alias;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.alias_formlabel, --linebreak--, target;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.target_formlabel, --linebreak--, url_scheme;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.url_scheme_formlabel',
+            'showitem' => 'alias;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.alias_formlabel, --linebreak--, target;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.target_formlabel',
         ],
         'caching' => [
             'showitem' => 'cache_timeout;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.cache_timeout_formlabel, cache_tags, no_cache;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.no_cache_formlabel',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-79302-MovedPagesurlSchemeToCompatibility7Extension.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-79302-MovedPagesurlSchemeToCompatibility7Extension.rst
new file mode 100644 (file)
index 0000000..a1432ad
--- /dev/null
@@ -0,0 +1,43 @@
+.. include:: ../../Includes.txt
+
+=====================================================================
+Breaking: #79302 - Moved pages.url_scheme to compatibility7 extension
+=====================================================================
+
+See :issue:`79302`
+
+Description
+===========
+
+The database field "pages.url_scheme" functionality has been moved to the compatibility7 extension.
+
+The field allows to force the HTTP or HTTPS protocol for a specific page to be set by an editor in the page properties on a per-page
+basis. However, it is common today to ensure (if a SSL certificate is available) to use HTTPS for a whole website or even only for a
+specific area (inc. subpages) to force the protocol.
+
+
+Impact
+======
+
+If the functionality was used before, it will not work anymore, thus links will not be forced to be generated with a forced HTTP/HTTPS url
+scheme and redirects on pages that had the option set will not happen anymore, unless the compatibility7 extension is installed.
+
+Generating preview links with pages that have an enforced scheme out of the TYPO3 backend will not work anymore.
+
+
+Affected Installations
+======================
+
+Any TYPO3 instance that depends on the `url_scheme` database field, having any value filled in.
+
+
+Migration
+=========
+
+Install the compatibility7 extension to have the same functionality as before, or use HTTPS enforcing via server configuration (.htaccess)
+or any SSL related extension in the TYPO3 Extension Repository (TER) that provides superior functionality.
+
+To ensure a certain protocol when previewing a page the TSconfig option `TCEMAIN.previewDomain` can be used to set a preview prefix including
+the URL scheme.
+
+.. index:: Database, Frontend
\ No newline at end of file
index 6091bb2..c29b3ed 100644 (file)
@@ -49,7 +49,6 @@ class PagesVisibleFieldsTest extends \TYPO3\CMS\Components\TestingFramework\Core
         'content_from_pid',
         'alias',
         'target',
-        'url_scheme',
         'cache_timeout',
         'cache_tags',
         'no_cache',
@@ -142,7 +141,6 @@ class PagesVisibleFieldsTest extends \TYPO3\CMS\Components\TestingFramework\Core
                 'content_from_pid',
                 'alias',
                 'target',
-                'url_scheme',
                 'cache_timeout',
                 'cache_tags',
                 'no_cache',
@@ -178,7 +176,6 @@ class PagesVisibleFieldsTest extends \TYPO3\CMS\Components\TestingFramework\Core
                 'content_from_pid',
                 'alias',
                 'target',
-                'url_scheme',
                 'cache_timeout',
                 'cache_tags',
                 'no_cache',
@@ -213,7 +210,6 @@ class PagesVisibleFieldsTest extends \TYPO3\CMS\Components\TestingFramework\Core
                 'content_from_pid',
                 'alias',
                 'target',
-                'url_scheme',
                 'cache_timeout',
                 'cache_tags',
                 'no_cache',
index 6f90ed9..a3de277 100644 (file)
@@ -135,7 +135,6 @@ CREATE TABLE pages (
        fe_group varchar(100) DEFAULT '0' NOT NULL,
        subtitle varchar(255) DEFAULT '' NOT NULL,
        layout int(11) unsigned DEFAULT '0' NOT NULL,
-       url_scheme tinyint(3) unsigned DEFAULT '0' NOT NULL,
        target varchar(80) DEFAULT '' NOT NULL,
        media int(11) unsigned DEFAULT '0' NOT NULL,
        lastUpdated int(10) unsigned DEFAULT '0' NOT NULL,
index d3c3e6a..2607288 100644 (file)
@@ -45,7 +45,6 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\DebugUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MailUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
@@ -6001,12 +6000,10 @@ class ContentObjectRenderer
                     }
                     $absoluteUrlScheme = 'http';
                     // URL shall be absolute:
-                    if (isset($conf['forceAbsoluteUrl']) && $conf['forceAbsoluteUrl'] || $page['url_scheme'] > 0) {
+                    if (isset($conf['forceAbsoluteUrl']) && $conf['forceAbsoluteUrl']) {
                         // Override scheme:
                         if (isset($conf['forceAbsoluteUrl.']['scheme']) && $conf['forceAbsoluteUrl.']['scheme']) {
                             $absoluteUrlScheme = $conf['forceAbsoluteUrl.']['scheme'];
-                        } elseif ($page['url_scheme'] > 0) {
-                            $absoluteUrlScheme = (int)$page['url_scheme'] === HttpUtility::SCHEME_HTTP ? 'http' : 'https';
                         } elseif ($this->getEnvironmentVariable('TYPO3_SSL')) {
                             $absoluteUrlScheme = 'https';
                         }
index baf23f8..7790ec8 100644 (file)
@@ -1458,25 +1458,6 @@ class TypoScriptFrontendController
             ];
             $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
         }
-        if ($this->page['url_scheme'] > 0) {
-            $newUrl = '';
-            $currentRequestIsSecure = GeneralUtility::getIndpEnv('TYPO3_SSL');
-            // force http
-            if ((int)$this->page['url_scheme'] === HttpUtility::SCHEME_HTTP && $currentRequestIsSecure) {
-                $newUrl = 'http://' . substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 8);
-            } elseif ((int)$this->page['url_scheme'] === HttpUtility::SCHEME_HTTPS && !$currentRequestIsSecure) {
-                // force https
-                $newUrl = 'https://' . substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 7);
-            }
-            if ($newUrl !== '') {
-                if ($_SERVER['REQUEST_METHOD'] === 'POST') {
-                    $headerCode = HttpUtility::HTTP_STATUS_303;
-                } else {
-                    $headerCode = HttpUtility::HTTP_STATUS_301;
-                }
-                HttpUtility::redirect($newUrl, $headerCode);
-            }
-        }
         // Set no_cache if set
         if ($this->page['no_cache']) {
             $this->set_no_cache('no_cache is set in page properties');
index ede7c95..2209fba 100644 (file)
                        <trans-unit id="pages.layout.I.3">
                                <source>Layout 3</source>
                        </trans-unit>
-                       <trans-unit id="pages.url_scheme">
-                               <source>Enforce Protocol:</source>
-                       </trans-unit>
-                       <trans-unit id="pages.url_scheme_formlabel">
-                               <source>Use Protocol</source>
-                       </trans-unit>
-                       <trans-unit id="pages.url_scheme.http">
-                               <source>http://</source>
-                       </trans-unit>
-                       <trans-unit id="pages.url_scheme.https">
-                               <source>https://</source>
-                       </trans-unit>
                        <trans-unit id="pages.extendToSubpages">
                                <source>Include Subpages:</source>
                        </trans-unit>
index 2169858..ac61d77 100644 (file)
@@ -147,11 +147,7 @@ class ViewModuleController extends ActionController
                 if (strpos($domainName, '://') !== false) {
                     $protocolAndHost = $domainName;
                 } else {
-                    $protocol = 'http';
-                    $page = (array)$sysPage->getPage($finalPageIdToShow);
-                    if ($page['url_scheme'] == 2 || $page['url_scheme'] == 0 && GeneralUtility::getIndpEnv('TYPO3_SSL')) {
-                        $protocol = 'https';
-                    }
+                    $protocol = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https' : 'http';
                     $protocolAndHost = $protocol . '://' . $domainName;
                 }
             }