Commit d5f61990 authored by Aljoscha Weber's avatar Aljoscha Weber Committed by Christian Kuhn
Browse files

[TASK] Use ServerRequestInterface in PageLayoutController

Replace _GP, getIndpEnv usages with request related functions.

Also deprecate public access to all method except the entry point.

Resolves: #84375
Releases: master
Change-Id: I8050afe519dcbabfd6381c55844c81713482687e
Reviewed-on: https://review.typo3.org/57329

Reviewed-by: Mathias Brodala's avatarMathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala's avatarMathias Brodala <mbrodala@pagemachine.de>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent ff4341c5
......@@ -849,8 +849,7 @@ class PageLayoutView implements LoggerAwareInterface
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
$userCanEditPage = $this->ext_CALC_PERMS & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
if ($userCanEditPage) {
if ($this->isPageEditable()) {
$languageOverlayId = 0;
$pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->tt_contentConfig['sys_language_uid']);
if (is_array($pageLocalizationRecord)) {
......@@ -929,7 +928,7 @@ class PageLayoutView implements LoggerAwareInterface
$content[$columnId] .= '">';
// Add new content at the top most position
$link = '';
if ($this->getPageLayoutController()->contentIsNotLockedForEditors()
if ($this->isContentEditable()
&& (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
) {
if ($this->option_newWizard) {
......@@ -1041,7 +1040,7 @@ class PageLayoutView implements LoggerAwareInterface
'-' . StringUtility::getUniqueId() . '">';
// Add icon "new content element below"
if (!$disableMoveAndNewButtons
&& $this->getPageLayoutController()->contentIsNotLockedForEditors()
&& $this->isContentEditable()
&& $this->getBackendUser()->checkLanguageAccess($lP)
&& (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
&& $columnId !== 'unused'
......@@ -1229,7 +1228,7 @@ class PageLayoutView implements LoggerAwareInterface
}
}
$elFromTable = $this->clipboard->elFromTable('tt_content');
if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
if (!empty($elFromTable) && $this->isPageEditable()) {
$pasteItem = substr(key($elFromTable), 11);
$pasteRecord = BackendUtility::getRecord('tt_content', (int)$pasteItem);
$pasteTitle = $pasteRecord['header'] ? $pasteRecord['header'] : $pasteItem;
......@@ -2433,7 +2432,7 @@ class PageLayoutView implements LoggerAwareInterface
. ' href="#"'
. ' class="btn btn-default btn-sm t3js-localize disabled"'
. ' title="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate')) . '"'
. ' data-page="' . htmlspecialchars($this->getPageLayoutController()->getLocalizedPageTitle()) . '"'
. ' data-page="' . htmlspecialchars($this->getLocalizedPageTitle()) . '"'
. ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP]) . '"'
. ' data-allow-copy="' . (int)$allowCopy . '"'
. ' data-allow-translate="' . (int)$allowTranslate . '"'
......@@ -4480,6 +4479,60 @@ class PageLayoutView implements LoggerAwareInterface
return $htmlCode;
}
/**
* @return string $title
*/
protected function getLocalizedPageTitle(): string
{
if ($this->tt_contentConfig['sys_language_uid'] ?? 0 > 0) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
$localizedPage = $queryBuilder
->select('*')
->from('pages')
->where(
$queryBuilder->expr()->eq(
$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
$queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
$GLOBALS['TCA']['pages']['ctrl']['languageField'],
$queryBuilder->createNamedParameter($this->tt_contentConfig['sys_language_uid'], \PDO::PARAM_INT)
)
)
->setMaxResults(1)
->execute()
->fetch();
BackendUtility::workspaceOL('pages', $localizedPage);
return $localizedPage['title'];
}
return $this->pageinfo['title'];
}
/**
* Check if page can be edited by current user
*
* @return bool
*/
protected function isPageEditable()
{
return !$this->pageinfo['editlock'] && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT);
}
/**
* Check if content can be edited by current user
*
* @return bool
*/
protected function isContentEditable()
{
return !$this->pageinfo['editlock'] && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT);
}
/**
* Returns the language service
* @return LanguageService
......
<?php
namespace TYPO3\CMS\Backend\Tests\Unit\Controller;
/*
* 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\Backend\Controller\PageLayoutController;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
/**
* Class PageLayoutControllerTest
*/
class PageLayoutControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
/**
* @test
* @dataProvider pageIsNotLockedForEditorsReturnsCorrectValueDataProvider
* @param bool $isAdmin
* @param int $permissions
* @param bool $editLock
* @param bool $expected
*/
public function pageIsNotLockedForEditorsReturnsCorrectValue($isAdmin, $permissions, $editLock, $expected)
{
/** @var BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject $beUserMock */
$beUserMock = $this->getMockBuilder(BackendUserAuthentication::class)
->setMethods(['isAdmin'])
->getMock();
$beUserMock->method('isAdmin')->will($this->returnValue($isAdmin));
/** @var PageLayoutController|\PHPUnit_Framework_MockObject_MockObject $pageController */
$pageController = $this->getMockBuilder(PageLayoutController::class)
->setMethods(['getBackendUser'])
->getMock();
$pageController->method('getBackendUser')->will($this->returnValue($beUserMock));
$pageController->CALC_PERMS = $permissions;
$pageController->pageinfo = ['editlock' => $editLock];
$this->assertTrue($pageController->pageIsNotLockedForEditors() === $expected);
}
/**
* @return array
*/
public function pageIsNotLockedForEditorsReturnsCorrectValueDataProvider()
{
return [
'user is admin' => [ true, 0, false, true],
'user has permission' => [ false, Permission::PAGE_EDIT, false, true],
'page has permission, but editlock set' => [ false, Permission::PAGE_EDIT, true, false],
'user does not have permission' => [ false, 0, false, false],
];
}
}
.. include:: ../../Includes.txt
==============================================================================
Deprecation: #84375 - Protected methods and properties in PageLayoutController
==============================================================================
See :issue:`84375`
Description
===========
Some methods in the :php:`TYPO3\CMS\Backend\Controller\PageLayoutController`
have been marked as deprecated and will be removed in TYPO3 v10:
* [not scanned] :php:`init()`
* [not scanned] :php:`main()`
* [not scanned] :php:`menuConfig()`
* [not scanned] :php:`renderContent()`
* [not scanned] :php:`clearCache()`
* [not scanned] :php:`getModuleTemplate()`
* :php:`getLocalizedPageTitle()`
* :php:`getNumberOfHiddenElements()`
* :php:`local_linkThisScript()`
* :php:`pageIsNotLockedForEditors()`
* :php:`contentIsNotLockedForEditors()`
Likewise some properties have been marked as deprecated:
* [not scanned] :php:`pointer`
* [not scanned] :php:`imagemode`
* [not scanned] :php:`search_field`
* [not scanned] :php:`search_levels`
* [not scanned] :php:`showLimit`
* [not scanned] :php:`returnUrl`
* [not scanned] :php:`clear_cache`
* :php:`popView`
* [not scanned] :php:`perms_clause`
* [not scanned] :php:`modTSconfig`
* :php:`modSharedTSconfig`
* [not scanned] :php:`descrTable`
* :php:`colPosList`
* :php:`EDIT_CONTENT`
* :php:`CALC_PERMS`
* :php:`current_sys_language`
* :php:`MCONF`
* :php:`MOD_MENU`
* [not scanned] :php:`content`
* :php:`activeColPosList`
Impact
======
Accessing the properties or calling the methods will trigger a deprecation warning.
Affected Installations
======================
Third party code which accesses the properties directly or calls the methods.
Migration
=========
In general, extensions should not instantiate and re-use controllers of the core. Existing
usages should be rewritten to be free of calls like these.
.. index:: Backend, PHP-API, PartiallyScanned
......@@ -2942,4 +2942,39 @@ return [
'Deprecation-85892-VariousMethodsRegardingSysDomainResolving.rst',
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->getLocalizedPageTitle' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst',
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->getNumberOfHiddenElements' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst',
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->local_linkThisScript' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst',
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->pageIsNotLockedForEditors' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst',
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->contentIsNotLockedForEditors' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst',
],
],
];
......@@ -647,4 +647,49 @@ return [
'Deprecation-85735-DeprecateMethodAndPropertyInDocumentTemplate.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->popView' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->modSharedTSconfig' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->colPosList' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->EDIT_CONTENT' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->CALC_PERMS' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->MCONF' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->MOD_MENU' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->current_sys_language' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.rst'
],
],
'TYPO3\CMS\Backend\Controller\PageLayoutController->activeColPosList' => [
'restFiles' => [
'Deprecation-84375-ProtectedMethodsAndPropertiesInPageLayoutController.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