From 35c54900330b261d6b92062987bad3ce73a2f331 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Tue, 5 Jul 2022 16:21:06 +0200 Subject: [PATCH] [TASK] Deprecate various public TSFE properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Various properties can be accessed directly via TypoScript config settings. * $TSFE->spamProtectEmailAddresses * $TSFE->intTarget * $TSFE->extTarget * $TSFE->fileTarget * $TSFE->baseUrl They have been marked as deprecated. In addition, some internal functionality is now marked as @internal as well, somehow related to the deprecated properties. Resolves: #97866 Releases: main Change-Id: Ieecd1674783a1d9b9092528d16a988568e857e18 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75040 Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Benni Mack <benni@typo3.org> --- ...tion-97866-VariousPublicTSFEProperties.rst | 48 +++++++++++++++++++ .../TypoScriptFrontendController.php | 38 ++++++++++----- .../frontend/Classes/Http/RequestHandler.php | 5 +- .../Classes/Typolink/EmailLinkBuilder.php | 10 ++-- .../Typolink/ExternalUrlLinkBuilder.php | 2 +- .../Typolink/FileOrFolderLinkBuilder.php | 2 +- .../Classes/Typolink/LegacyLinkBuilder.php | 4 +- .../Classes/Typolink/PageLinkBuilder.php | 4 +- .../ContentObjectRendererTest.php | 2 +- .../ContentObjectRendererTest.php | 5 +- .../TypoScriptFrontendControllerTest.php | 2 +- .../Php/PropertyPublicMatcher.php | 25 ++++++++++ 12 files changed, 120 insertions(+), 27 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/12.0/Deprecation-97866-VariousPublicTSFEProperties.rst diff --git a/typo3/sysext/core/Documentation/Changelog/12.0/Deprecation-97866-VariousPublicTSFEProperties.rst b/typo3/sysext/core/Documentation/Changelog/12.0/Deprecation-97866-VariousPublicTSFEProperties.rst new file mode 100644 index 000000000000..30f65b804fe1 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/12.0/Deprecation-97866-VariousPublicTSFEProperties.rst @@ -0,0 +1,48 @@ +.. include:: /Includes.rst.txt + +.. _deprecation-97866-1657185866: + +==================================================== +Deprecation: #97866 - Various public TSFE properties +==================================================== + +See :issue:`97866` + +Description +=========== + +The following properties within TypoScriptFrontendController have been deprecated: + +* :php:`spamProtectEmailAddresses` +* :php:`intTarget` +* :php:`extTarget` +* :php:`fileTarget` +* :php:`baseUrl` + +All of these properties can be accessed through TypoScript's config array. + + +Impact +====== + +Accessing these properties via TypoScript `getData` or via PHP will trigger a PHP deprecation +notice. + + +Affected installations +====================== + +TYPO3 installations with TypoScript options such as :ts:`.data = TSFE:fileTarget` or +TYPO3 installations with third-party extensions accessing the properties via PHP. + + +Migration +========= + +Migrate the access to these properties to use the config property: + +In TypoScript you can access the TypoScript properties directly via +:ts:`.data = TSFE:config|config|fileTarget` and in PHP code via +:php:`$GLOBALS['TSFE']->config['config']['fileTarget']`. + +.. index:: Frontend, TypoScript, PartiallyScanned, ext:frontend \ No newline at end of file diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index f6b3da6900f9..6f5219a26ed9 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -24,6 +24,7 @@ use Psr\Log\LogLevel; use TYPO3\CMS\Backend\FrontendBackendUserAuthentication; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; +use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait; use TYPO3\CMS\Core\Configuration\PageTsConfig; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; @@ -93,6 +94,15 @@ use TYPO3\CMS\Frontend\Typolink\LinkVarsCalculator; class TypoScriptFrontendController implements LoggerAwareInterface { use LoggerAwareTrait; + use PublicPropertyDeprecationTrait; + + protected array $deprecatedPublicProperties = [ + 'intTarget' => '$TSFE->intTarget will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'intTarget\'] instead.', + 'extTarget' => '$TSFE->extTarget will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'extTarget\'] instead.', + 'fileTarget' => '$TSFE->fileTarget will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'fileTarget\'] instead.', + 'spamProtectEmailAddresses' => '$TSFE->spamProtectEmailAddresses will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'spamProtectEmailAddresses\'] instead.', + 'baseUrl' => '$TSFE->baseUrl will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'baseURL\'] instead.', + ]; /** * The page id (int) @@ -283,25 +293,29 @@ class TypoScriptFrontendController implements LoggerAwareInterface /** * Default internal target * @var string + * @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0. */ - public $intTarget = ''; + protected $intTarget = ''; /** * Default external target * @var string + * @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0. */ - public $extTarget = ''; + protected $extTarget = ''; /** * Default file link target * @var string + * @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0. */ - public $fileTarget = ''; + protected $fileTarget = ''; /** * If set, typolink() function encrypts email addresses. + * @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0. */ - public int $spamProtectEmailAddresses = 0; + protected int $spamProtectEmailAddresses = 0; /** * Absolute Reference prefix @@ -313,6 +327,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface * A string prepared for insertion in all links on the page as url-parameters. * Based on configuration in TypoScript where you defined which GET parameters you * would like to pass on. + * @internal if needed, generate linkVars via LinkVarsCalculator */ public string $linkVars = ''; @@ -359,8 +374,9 @@ class TypoScriptFrontendController implements LoggerAwareInterface /** * The base URL set for the page header. * @var string + * @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0. */ - public $baseUrl = ''; + protected $baseUrl = ''; /** * Page content render object @@ -1804,10 +1820,8 @@ class TypoScriptFrontendController implements LoggerAwareInterface public function preparePageContentGeneration(ServerRequestInterface $request) { $this->getTimeTracker()->push('Prepare page content generation'); - // Base url: - if (isset($this->config['config']['baseURL'])) { - $this->baseUrl = $this->config['config']['baseURL']; - } + // @deprecated: these properties can be removed in TYPO3 v13.0 + $this->baseUrl = (string)($this->config['config']['baseURL'] ?? ''); // Internal and External target defaults $this->intTarget = (string)($this->config['config']['intTarget'] ?? ''); $this->extTarget = (string)($this->config['config']['extTarget'] ?? ''); @@ -1816,6 +1830,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface $this->logDeprecatedTyposcript('config.spamProtectEmailAddresses = ascii', 'This setting has no effect anymore. Change it to a number between -10 and 10 or remove it completely'); $this->config['config']['spamProtectEmailAddresses'] = 0; } + // @deprecated: these properties can be removed in TYPO3 v13.0 $this->spamProtectEmailAddresses = (int)($this->config['config']['spamProtectEmailAddresses'] ?? 0); $this->spamProtectEmailAddresses = MathUtility::forceIntegerInRange($this->spamProtectEmailAddresses, -10, 10, 0); // calculate the absolute path prefix @@ -2287,13 +2302,14 @@ class TypoScriptFrontendController implements LoggerAwareInterface * * @param string $url Input URL, relative or absolute * @return string Processed input value. + * @internal only for TYPO3 Core internal purposes. Might be removed at a later point as it was related to RealURL functionality. */ public function baseUrlWrap($url) { - if ($this->baseUrl) { + if ($this->config['config']['baseURL'] ?? false) { $urlParts = parse_url($url); if (empty($urlParts['scheme']) && $url[0] !== '/') { - $url = $this->baseUrl . $url; + $url = $this->config['config']['baseURL'] . $url; } } return $url; diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php index 7e15fbd533ab..b54ce368c3ac 100644 --- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php +++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php @@ -376,8 +376,9 @@ class RequestHandler implements RequestHandlerInterface } $pageRenderer->setHeadTag($headTag); $pageRenderer->addInlineComment(GeneralUtility::makeInstance(Typo3Information::class)->getInlineHeaderComment()); - if ($controller->baseUrl) { - $pageRenderer->setBaseUrl($controller->baseUrl); + $baseUrl = $controller->config['config']['baseURL'] ?? ''; + if ($baseUrl) { + $pageRenderer->setBaseUrl($baseUrl); } if ($controller->pSetup['shortcutIcon'] ?? false) { try { diff --git a/typo3/sysext/frontend/Classes/Typolink/EmailLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/EmailLinkBuilder.php index 5dbdcc7501e2..7f23174e9af6 100644 --- a/typo3/sysext/frontend/Classes/Typolink/EmailLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/EmailLinkBuilder.php @@ -21,6 +21,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Core\LinkHandling\LinkService; use TYPO3\CMS\Core\Page\DefaultJavaScriptAssetTrait; +use TYPO3\CMS\Core\Utility\MathUtility; /** * Builds a TypoLink to an email address, also takes care of additional functionality for the time being @@ -64,11 +65,14 @@ class EmailLinkBuilder extends AbstractTypolinkBuilder implements LoggerAwareInt // no processing happened, therefore, the default processing kicks in $tsfe = $this->getTypoScriptFrontendController(); - if ($tsfe->spamProtectEmailAddresses) { - $mailToUrl = $this->encryptEmail($mailToUrl, $tsfe->spamProtectEmailAddresses); + $spamProtectEmailAddresses = (int)($tsfe->config['config']['spamProtectEmailAddresses'] ?? 0); + $spamProtectEmailAddresses = MathUtility::forceIntegerInRange($spamProtectEmailAddresses, -10, 10, 0); + + if ($spamProtectEmailAddresses) { + $mailToUrl = $this->encryptEmail($mailToUrl, $spamProtectEmailAddresses); $attributes = [ 'data-mailto-token' => $mailToUrl, - 'data-mailto-vector' => $tsfe->spamProtectEmailAddresses, + 'data-mailto-vector' => $spamProtectEmailAddresses, ]; $mailToUrl = '#'; $this->addDefaultFrontendJavaScript(); diff --git a/typo3/sysext/frontend/Classes/Typolink/ExternalUrlLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/ExternalUrlLinkBuilder.php index 30fdbd9f51ab..add64d074b2a 100644 --- a/typo3/sysext/frontend/Classes/Typolink/ExternalUrlLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/ExternalUrlLinkBuilder.php @@ -31,7 +31,7 @@ class ExternalUrlLinkBuilder extends AbstractTypolinkBuilder return (new LinkResult(LinkService::TYPE_URL, (string)$url)) ->withLinkConfiguration($conf) ->withTarget( - $target ?: $this->resolveTargetAttribute($conf, 'extTarget', true, $this->getTypoScriptFrontendController()->extTarget), + $target ?: $this->resolveTargetAttribute($conf, 'extTarget', true, (string)($this->getTypoScriptFrontendController()->config['config']['extTarget'] ?? '')), ) ->withLinkText($linkText); } diff --git a/typo3/sysext/frontend/Classes/Typolink/FileOrFolderLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/FileOrFolderLinkBuilder.php index 2ddcbe61f506..d3496a1ff9ce 100644 --- a/typo3/sysext/frontend/Classes/Typolink/FileOrFolderLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/FileOrFolderLinkBuilder.php @@ -50,7 +50,7 @@ class FileOrFolderLinkBuilder extends AbstractTypolinkBuilder $url .= '#' . $linkDetails['fragment']; } return (new LinkResult($linkDetails['type'], $this->forceAbsoluteUrl($url, $conf))) - ->withTarget($target ?: $this->resolveTargetAttribute($conf, 'fileTarget', false, $this->getTypoScriptFrontendController()->fileTarget)) + ->withTarget($target ?: $this->resolveTargetAttribute($conf, 'fileTarget', false, (string)($this->getTypoScriptFrontendController()->config['config']['fileTarget'] ?? ''))) ->withLinkText($linkText); } } diff --git a/typo3/sysext/frontend/Classes/Typolink/LegacyLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/LegacyLinkBuilder.php index 713219ac51c6..cf8b913d8cdb 100644 --- a/typo3/sysext/frontend/Classes/Typolink/LegacyLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/LegacyLinkBuilder.php @@ -36,10 +36,10 @@ class LegacyLinkBuilder extends AbstractTypolinkBuilder $linkLocation = (!str_starts_with($linkLocation, '/') ? $tsfe->absRefPrefix : '') . $linkLocation; $url = $linkLocation; $url = $this->forceAbsoluteUrl($url, $conf); - $target = $target ?: $this->resolveTargetAttribute($conf, 'fileTarget', false, $tsfe->fileTarget); + $target = $target ?: $this->resolveTargetAttribute($conf, 'fileTarget', false, (string)($tsfe->config['config']['fileTarget'] ?? '')); } elseif ($linkDetails['url']) { $linkDetails['type'] = LinkService::TYPE_URL; - $target = $target ?: $this->resolveTargetAttribute($conf, 'extTarget', true, $tsfe->extTarget); + $target = $target ?: $this->resolveTargetAttribute($conf, 'extTarget', true, (string)($tsfe->config['config']['extTarget'] ?? '')); $linkText = $this->encodeFallbackLinkTextIfLinkTextIsEmpty($linkText, $linkDetails['url']); $url = $linkDetails['url']; } else { diff --git a/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php index d0321627176e..d7b788d97671 100644 --- a/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php @@ -304,11 +304,11 @@ class PageLinkBuilder extends AbstractTypolinkBuilder { $tsfe = $this->getTypoScriptFrontendController(); if ($treatAsExternalLink) { - $target = $target ?: $this->resolveTargetAttribute($conf, 'extTarget', false, $tsfe->extTarget); + $target = $target ?: $this->resolveTargetAttribute($conf, 'extTarget', false, (string)($tsfe->config['config']['extTarget'] ?? '')); } else { $target = (isset($page['target']) && trim($page['target'])) ? $page['target'] : $target; if (empty($target)) { - $target = $this->resolveTargetAttribute($conf, 'target', true, $tsfe->intTarget); + $target = $this->resolveTargetAttribute($conf, 'target', true, (string)($tsfe->config['config']['intTarget'] ?? '')); } } return $target; diff --git a/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php index b3712ef69b42..fa534e92981d 100644 --- a/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php @@ -353,7 +353,7 @@ class ContentObjectRendererTest extends FunctionalTestCase $tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)->disableOriginalConstructor()->getMock(); $subject = new ContentObjectRenderer($tsfe); - $tsfe->spamProtectEmailAddresses = 1; + $tsfe->config['config']['spamProtectEmailAddresses'] = 1; $result = $subject->typoLink('Send me an email', ['parameter' => 'mailto:test@example.com']); self::assertEquals('<a href="#" data-mailto-token="nbjmup+uftuAfybnqmf/dpn" data-mailto-vector="1">Send me an email</a>', $result); } diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index ecf079b7fa37..d29bef5df5bf 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -1199,8 +1199,8 @@ class ContentObjectRendererTest extends UnitTestCase */ public function getDataWithTypeTsfe(): void { - $GLOBALS['TSFE']->intTarget = 'foo'; - self::assertEquals($GLOBALS['TSFE']->intTarget, $this->subject->getData('tsfe:intTarget')); + $GLOBALS['TSFE']->linkVars = 'foo'; + self::assertEquals($GLOBALS['TSFE']->linkVars, $this->subject->getData('tsfe:linkVars')); } /** @@ -2721,7 +2721,6 @@ class ContentObjectRendererTest extends UnitTestCase string $mailAddress, string $expected ): void { - $this->getFrontendController()->spamProtectEmailAddresses = $settings['spamProtectEmailAddresses']; $this->getFrontendController()->config['config'] = $settings; $typoScript = ['parameter' => $mailAddress]; GeneralUtility::addInstance(LinkFactory::class, $this->getLinkFactory()); diff --git a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php index f4d35dcf2da8..45a7c6ec1d21 100644 --- a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php @@ -273,7 +273,7 @@ class TypoScriptFrontendControllerTest extends UnitTestCase */ public function baseUrlWrapHandlesDifferentUrls(string $baseUrl, string $url, string $expected): void { - $this->subject->baseUrl = $baseUrl; + $this->subject->config['config']['baseURL'] = $baseUrl; self::assertSame($expected, $this->subject->baseUrlWrap($url)); } diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php index c1d6050d39c0..c8bb6443a3bd 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php @@ -964,4 +964,29 @@ return [ 'Deprecation-97549-ContentObjectRenderer-lastTypoLinkProperties.rst', ], ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->spamProtectEmailAddresses' => [ + 'restFiles' => [ + 'Deprecation-97866-VariousPublicTSFEProperties.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->intTarget' => [ + 'restFiles' => [ + 'Deprecation-97866-VariousPublicTSFEProperties.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->extTarget' => [ + 'restFiles' => [ + 'Deprecation-97866-VariousPublicTSFEProperties.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->fileTarget' => [ + 'restFiles' => [ + 'Deprecation-97866-VariousPublicTSFEProperties.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->baseUrl' => [ + 'restFiles' => [ + 'Deprecation-97866-VariousPublicTSFEProperties.rst', + ], + ], ]; -- GitLab