Commit 8419fc03 authored by Benni Mack's avatar Benni Mack Committed by Daniel Goerz
Browse files

[TASK] Move Copyright information generation out of TYPO3 Backend

The BackendUtility::getCopyRightNotice() is ugly, and can only be used
in Backend context (not install tool).

A new PHP class "Typo3Copyright" in EXT:core encapsulates this
information so it can be used in other places as well.

The old method is marked as deprecated.

Resolves: #89756
Releases: master
Change-Id: I5d793138324b315f4ad4873687f85b84120e271a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62420


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 4351529f
......@@ -17,8 +17,8 @@ namespace TYPO3\CMS\About\Controller;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Module\ModuleLoader;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Information\Typo3Copyright;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
......@@ -43,6 +43,15 @@ class AboutController
* @var ViewInterface
*/
protected $view;
/**
* @var \TYPO3\CMS\Core\Information\Typo3Copyright
*/
private $copyright;
public function __construct(Typo3Copyright $copyright)
{
$this->copyright = $copyright;
}
/**
* Main action: Show standard information
......@@ -63,11 +72,11 @@ class AboutController
}
$this->view->assignMultiple([
'copyrightYear' => TYPO3_copyright_year,
'copyrightYear' => $this->copyright->getCopyrightYear(),
'donationUrl' => TYPO3_URL_DONATE,
'currentVersion' => TYPO3_version,
'loadedExtensions' => $this->getLoadedExtensions(),
'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
'copyRightNotice' => $this->copyright->getCopyrightNotice(),
'warnings' => $warnings,
'modules' => $this->getModulesData()
]);
......
......@@ -6,3 +6,6 @@ services:
TYPO3\CMS\About\:
resource: '../Classes/*'
TYPO3\CMS\About\Controller\AboutController:
tags: ['backend.controller']
......@@ -20,11 +20,11 @@ use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Domain\Repository\TableManualRepository;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Information\Typo3Copyright;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
......@@ -56,14 +56,21 @@ class HelpController
/** @var ViewInterface */
protected $view;
/**
* @var Typo3Copyright
*/
private $copyright;
/**
* Instantiate the report controller
*
* @param Typo3Copyright $copyright
*/
public function __construct()
public function __construct(Typo3Copyright $copyright)
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$this->tableManualRepository = GeneralUtility::makeInstance(TableManualRepository::class);
$this->copyright = $copyright;
}
/**
......@@ -110,7 +117,7 @@ class HelpController
$this->view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']);
$this->view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
$this->view->getRequest()->setControllerExtensionName('Backend');
$this->view->assign('copyright', BackendUtility::TYPO3_copyRightNotice());
$this->view->assign('copyright', $this->copyright->getCopyrightNotice());
}
/**
......
......@@ -23,13 +23,13 @@ use TYPO3\CMS\Backend\Exception;
use TYPO3\CMS\Backend\LoginProvider\LoginProviderInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\DocumentTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\FormProtection\BackendFormProtection;
use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Information\Typo3Copyright;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Page\PageRenderer;
......@@ -99,6 +99,15 @@ class LoginController implements LoggerAwareInterface
* @var DocumentTemplate
*/
protected $documentTemplate;
/**
* @var \TYPO3\CMS\Core\Information\Typo3Copyright
*/
private $copyright;
public function __construct(Typo3Copyright $copyright)
{
$this->copyright = $copyright;
}
/**
* Injects the request and response objects for the current request or subrequest
......@@ -280,7 +289,7 @@ class LoginController implements LoggerAwareInterface
'capslock' => $this->getUriForFileName('EXT:backend/Resources/Public/Images/icon_capslock.svg'),
'typo3' => $this->getUriForFileName('EXT:backend/Resources/Public/Images/typo3_orange.svg'),
],
'copyright' => BackendUtility::TYPO3_copyRightNotice(),
'copyright' => $this->copyright->getCopyrightNotice(),
'redirectUrl' => $this->redirectUrl,
'loginRefresh' => $this->loginRefresh,
'loginNewsItems' => $this->getSystemNews(),
......
......@@ -37,6 +37,7 @@ use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Information\Typo3Copyright;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Resource\ProcessedFile;
......@@ -3817,46 +3818,13 @@ class BackendUtility
* Therefore preventing this notice from being properly shown is a violation of the license, regardless of whether you remove it or use a stylesheet to obstruct the display.
*
* @return string Text/Image (HTML) for copyright notice.
* @deprecated since TYPO3 v10.2, will be removed in TYPO3 v11.0
*/
public static function TYPO3_copyRightNotice()
{
// Copyright Notice
$loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
$loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
$lang = static::getLanguageService();
if (strlen($loginCopyrightWarrantyProvider) >= 2 && strlen($loginCopyrightWarrantyURL) >= 10) {
$warrantyNote = sprintf(
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:warranty.by'),
htmlspecialchars($loginCopyrightWarrantyProvider),
'<a href="' . htmlspecialchars($loginCopyrightWarrantyURL) . '" target="_blank" rel="noreferrer">',
'</a>'
);
} else {
$warrantyNote = sprintf(
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:no.warranty'),
'<a href="' . TYPO3_URL_LICENSE . '" target="_blank" rel="noreferrer">',
'</a>'
);
}
$cNotice = '<a href="' . TYPO3_URL_GENERAL . '" target="_blank" rel="noreferrer">' .
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:typo3.cms') . '</a>. ' .
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:copyright') . ' &copy; '
. htmlspecialchars(TYPO3_copyright_year) . ' Kasper Sk&aring;rh&oslash;j. ' .
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:extension.copyright') . ' ' .
sprintf(
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:details.link'),
'<a href="' . TYPO3_URL_GENERAL . '" target="_blank" rel="noreferrer">' . TYPO3_URL_GENERAL . '</a>'
) . ' ' .
strip_tags($warrantyNote, '<a>') . ' ' .
sprintf(
$lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:free.software'),
'<a href="' . TYPO3_URL_LICENSE . '" target="_blank" rel="noreferrer">',
'</a> '
)
. $lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:keep.notice');
return $cNotice;
trigger_error('BackendUtility::TYPO3_copyRightNotice() will be removed in TYPO3 v11.0, use the Typo3Copyright PHP class instead.', E_USER_DEPRECATED);
$copyrightGenerator = GeneralUtility::makeInstance(Typo3Copyright::class, static::getLanguageService());
return $copyrightGenerator->getCopyrightNotice();
}
/**
......
......@@ -19,6 +19,13 @@ services:
TYPO3\CMS\Backend\History\RecordHistoryRollback:
public: true
TYPO3\CMS\Backend\Controller\LoginController:
tags: ['backend.controller']
TYPO3\CMS\Backend\Controller\HelpController:
tags: ['backend.controller']
# Listener for old Signal Slots
TYPO3\CMS\Backend\Compatibility\SlotReplacement:
tags:
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Information;
/*
* 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 Psr\Http\Message\UriInterface;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class Typo3Copyright
{
/**
* @var LanguageService
*/
protected $languageService;
public function __construct(LanguageService $languageService = null)
{
if ($languageService) {
$this->languageService = $languageService;
} elseif ($GLOBALS['LANG'] instanceof LanguageService) {
$this->languageService = $GLOBALS['LANG'];
} else {
$this->languageService = GeneralUtility::makeInstance(LanguageService::class);
$this->languageService->init('default');
}
}
public function getCopyrightYear(): string
{
return TYPO3_copyright_year;
}
public function getCommunityWebsiteUrl(): UriInterface
{
return new Uri(TYPO3_URL_GENERAL);
}
public function getLicenseUrl(): UriInterface
{
return new Uri(TYPO3_URL_LICENSE);
}
/**
* Prints TYPO3 Copyright notice for About Modules etc. modules.
*
* Warning:
* DO NOT prevent this notice from being shown in ANY WAY.
* According to the GPL license an interactive application must show such a notice on start-up
* ('If the program is interactive, make it output a short notice... ' - see GPL.txt)
* Therefore preventing this notice from being properly shown is a violation of the license, regardless of whether
* you remove it or use a stylesheet to obstruct the display.
*
* @return string Text/Image (HTML) for copyright notice.
*/
public function getCopyrightNotice(): string
{
// Copyright Notice
$loginCopyrightWarrantyProvider = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyProvider']));
$loginCopyrightWarrantyURL = strip_tags(trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['loginCopyrightWarrantyURL']));
if (strlen($loginCopyrightWarrantyProvider) >= 2 && strlen($loginCopyrightWarrantyURL) >= 10) {
$warrantyNote = sprintf(
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:warranty.by'),
htmlspecialchars($loginCopyrightWarrantyProvider),
'<a href="' . htmlspecialchars($loginCopyrightWarrantyURL) . '" target="_blank" rel="noreferrer">',
'</a>'
);
} else {
$warrantyNote = sprintf(
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:no.warranty'),
'<a href="' . htmlspecialchars((string)$this->getLicenseUrl()) . '" target="_blank" rel="noreferrer">',
'</a>'
);
}
return '<a href="' . htmlspecialchars((string)$this->getCommunityWebsiteUrl()) . '" target="_blank" rel="noreferrer">' .
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:typo3.cms') . '</a>. ' .
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:copyright') . ' &copy; '
. htmlspecialchars($this->getCopyrightYear()) . ' Kasper Sk&aring;rh&oslash;j. ' .
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:extension.copyright') . ' ' .
sprintf(
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:details.link'),
'<a href="' . htmlspecialchars((string)$this->getCommunityWebsiteUrl()) . '" target="_blank" rel="noreferrer">' . htmlspecialchars((string)$this->getCommunityWebsiteUrl()) . '</a>'
) . ' ' .
strip_tags($warrantyNote, '<a>') . ' ' .
sprintf(
$this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:free.software'),
'<a href="' . htmlspecialchars((string)$this->getLicenseUrl()) . '" target="_blank" rel="noreferrer">',
'</a> '
)
. $this->languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf:keep.notice');
}
}
.. include:: ../../Includes.txt
===========================================================
Deprecation: #89756 - BackendUtility::TYPO3_copyRightNotice
===========================================================
See :issue:`89756`
Description
===========
The PHP method :php:`TYPO3\CMS\Backend\Utility\BackendUtility::TYPO3_copyRightNotice` that is
used to display information about the warranty and copyright of the product, e.g. used in the
login screen, has been superseded by a new API :php:`TYPO3\CMS\Core\Information\Typo3Copyright`.
The existing static method has been marked as deprecated.
Impact
======
Calling the method will trigger a deprecation warning, but work as
before until TYPO3 v11.0.
Affected Installations
======================
TYPO3 installations with custom extensions explicitly calling this
method. Run the Extension Scanner in the "Upgrade" module to see
if you are affected.
Migration
=========
Use the new :php:`Typo3Copyright` PHP class, and its method :php:`getCopyrightNotice()` which will return the same output.
.. index:: PHP-API, FullyScanned, ext:backend
......@@ -952,4 +952,11 @@ return [
'Deprecation-89718-LegacyPageTSconfigParsingLowlevelAPI.rst',
],
],
'TYPO3\CMS\Backend\Utility\BackendUtility::TYPO3_copyRightNotice' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-89756-BackendUtilityTYPO3_copyRightNotice.rst',
],
],
];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment