Skip to content

Commit

Permalink
[TASK] Deprecate various public TSFE properties
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bmack committed Jul 7, 2022
1 parent 2164222 commit 35c5490
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 27 deletions.
@@ -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
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -93,6 +94,15 @@
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)
Expand Down Expand Up @@ -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
Expand All @@ -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 = '';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1804,10 +1820,8 @@ protected function resolveContentPid(ServerRequestInterface $request): int
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'] ?? '');
Expand All @@ -1816,6 +1830,7 @@ public function preparePageContentGeneration(ServerRequestInterface $request)
$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
Expand Down Expand Up @@ -2287,13 +2302,14 @@ protected function setAbsRefPrefix()
*
* @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;
Expand Down
5 changes: 3 additions & 2 deletions typo3/sysext/frontend/Classes/Http/RequestHandler.php
Expand Up @@ -376,8 +376,9 @@ protected function processHtmlBasedRenderingSettings(TypoScriptFrontendControlle
}
$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 {
Expand Down
10 changes: 7 additions & 3 deletions typo3/sysext/frontend/Classes/Typolink/EmailLinkBuilder.php
Expand Up @@ -21,6 +21,7 @@
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
Expand Down Expand Up @@ -64,11 +65,14 @@ public function processEmailLink(string $mailAddress, string $linkText): array

// 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();
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function build(array &$linkDetails, string $linkText, string $target, arr
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);
}
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function build(array &$linkDetails, string $linkText, string $target, arr
$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);
}
}
4 changes: 2 additions & 2 deletions typo3/sysext/frontend/Classes/Typolink/LegacyLinkBuilder.php
Expand Up @@ -36,10 +36,10 @@ public function build(array &$linkDetails, string $linkText, string $target, arr
$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 {
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
Expand Up @@ -304,11 +304,11 @@ protected function calculateTargetAttribute(array $page, array $conf, bool $trea
{
$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;
Expand Down
Expand Up @@ -353,7 +353,7 @@ public function typolinkReturnsCorrectLinkForSpamEncryptedEmails(): void
$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);
}
Expand Down
Expand Up @@ -1199,8 +1199,8 @@ public function getDataWithTypeGp(string $key, string $expectedValue): void
*/
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'));
}

/**
Expand Down Expand Up @@ -2721,7 +2721,6 @@ public function typoLinkEncodesMailAddressForSpamProtection(
string $mailAddress,
string $expected
): void {
$this->getFrontendController()->spamProtectEmailAddresses = $settings['spamProtectEmailAddresses'];
$this->getFrontendController()->config['config'] = $settings;
$typoScript = ['parameter' => $mailAddress];
GeneralUtility::addInstance(LinkFactory::class, $this->getLinkFactory());
Expand Down
Expand Up @@ -273,7 +273,7 @@ public function baseUrlWrapHandlesDifferentUrlsDataProvider(): array
*/
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));
}

Expand Down
Expand Up @@ -964,4 +964,29 @@
'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',
],
],
];

0 comments on commit 35c5490

Please sign in to comment.