Skip to content

Commit

Permalink
[TASK] Use ServerRequestInterface in MoveElementController
Browse files Browse the repository at this point in the history
Change-Id: Id817e4aa991ddfccaf1fcb6838d7354bc64235d6
Resolves: #84285
Releases: master
Reviewed-on: https://review.typo3.org/56163
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mbrodala authored and lolli42 committed Mar 15, 2018
1 parent 5a255b0 commit 5b0c982
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 44 deletions.
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\Controller\ContentElement;

/*
Expand All @@ -20,8 +21,11 @@
use TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap;
use TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
Expand All @@ -31,54 +35,73 @@
*/
class MoveElementController
{
use PublicPropertyDeprecationTrait;

/**
* Properties which have been moved to protected status from public
*
* @var array
*/
protected $deprecatedPublicProperties = [
'sys_language' => 'Using $sys_language of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'page_id' => 'Using $page_id of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'table' => 'Using $table of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'R_URI' => 'Using $R_URI of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'input_moveUid' => 'Using $input_moveUid of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'moveUid' => 'Using $moveUid of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'makeCopy' => 'Using $makeCopy of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'perms_clause' => 'Using $perms_clause of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
'content' => 'Using $content of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
];

/**
* @var int
*/
public $sys_language = 0;
protected $sys_language = 0;

/**
* @var int
*/
public $page_id;
protected $page_id;

/**
* @var string
*/
public $table;
protected $table;

/**
* @var string
*/
public $R_URI;
protected $R_URI;

/**
* @var int
*/
public $input_moveUid;
protected $input_moveUid;

/**
* @var int
*/
public $moveUid;
protected $moveUid;

/**
* @var int
*/
public $makeCopy;
protected $makeCopy;

/**
* Pages-select clause
*
* @var string
*/
public $perms_clause;
protected $perms_clause;

/**
* Content for module accumulated here.
*
* @var string
*/
public $content;
protected $content;

/**
* ModuleTemplate object
Expand All @@ -94,25 +117,11 @@ public function __construct()
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
$GLOBALS['SOBE'] = $this;
$this->init();
}

/**
* Constructor, initializing internal variables.
*/
public function init()
{
// Setting internal vars:
$this->sys_language = (int)GeneralUtility::_GP('sys_language');
$this->page_id = (int)GeneralUtility::_GP('uid');
$this->table = GeneralUtility::_GP('table');
$this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
$this->input_moveUid = GeneralUtility::_GP('moveUid');
$this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
$this->makeCopy = GeneralUtility::_GP('makeCopy');
// Select-pages where clause for read-access:
$this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
// @deprecated since v9, will be obsolete in v10 with removal of init()
$request = $GLOBALS['TYPO3_REQUEST'];
// @deprecated since v9, will be moved out of __construct() in v10
$this->init($request);
}

/**
Expand All @@ -124,17 +133,46 @@ public function init()
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->main();
$this->moduleTemplate->setContent($this->content);
return new HtmlResponse($this->moduleTemplate->renderContent());
$this->renderContent();

return new HtmlResponse($this->content);
}

/**
* Constructor, initializing internal variables.
*
* @param ServerRequestInterface|null $request
*/
public function init(ServerRequestInterface $request = null)
{
if ($request === null) {
// Method signature in v10: protected function init(ServerRequestInterface $request)
trigger_error('Method init() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED);
$request = $GLOBALS['TYPO3_REQUEST'];
}

$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();

// Setting internal vars:
$this->sys_language = (int)($parsedBody['sys_language'] ?? $queryParams['sys_language'] ?? 0);
$this->page_id = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0);
$this->table = $parsedBody['table'] ?? $queryParams['table'] ?? null;
$this->R_URI = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
$this->input_moveUid = $parsedBody['moveUid'] ?? $queryParams['moveUid'] ?? null;
$this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
$this->makeCopy = $parsedBody['makeCopy'] ?? $queryParams['makeCopy'] ?? 0;
// Select-pages where clause for read-access:
$this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
}

/**
* Creating the module output.
*/
public function main()
protected function renderContent(): void
{
$lang = $this->getLanguageService();

if ($this->page_id) {
$assigns = [];
$backendUser = $this->getBackendUser();
Expand All @@ -158,6 +196,7 @@ public function main()
// Initialize the position map:
$posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
$posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
$posMap->moveUid = $this->moveUid;
// Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
if ($pageInfo['pid']) {
$pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
Expand Down Expand Up @@ -191,6 +230,7 @@ public function main()
// Initialize the position map:
$posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
$posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
$posMap->moveUid = $this->moveUid;
$posMap->cur_sys_language = $this->sys_language;
// Headerline for the parent page: Icon, record title:
$assigns['ttContent']['pageInfo'] = $pageInfo;
Expand Down Expand Up @@ -237,10 +277,25 @@ public function main()
$view->assignMultiple($assigns);
$this->content .= $view->render();
}

// Setting up the buttons and markers for docheader
$this->getButtons();
// Build the <body> for the module
$this->moduleTemplate->setTitle($lang->getLL('movingElement'));
$this->moduleTemplate->setContent($this->content);

$this->content = $this->moduleTemplate->renderContent();
}

/**
* Creating the module output.
*
* @deprecated since v9, will be removed in v10
*/
public function main()
{
trigger_error('Method main() will be replaced by protected method renderContent() in v10. Do not call from other extension', E_USER_DEPRECATED);
$this->renderContent();
}

/**
Expand Down Expand Up @@ -276,21 +331,17 @@ protected function getButtons()
}

/**
* Returns LanguageService
*
* @return \TYPO3\CMS\Core\Localization\LanguageService
* @return LanguageService
*/
protected function getLanguageService()
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

/**
* Returns the current BE user.
*
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
* @return BackendUserAuthentication
*/
protected function getBackendUser()
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
Expand Down
Expand Up @@ -41,7 +41,7 @@ class ContentMovingPagePositionMap extends PagePositionMap
*/
public function linkPageTitle($str, $rec)
{
$url = \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['uid' => (int)$rec['uid'], 'moveUid' => $GLOBALS['SOBE']->moveUid]);
$url = \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['uid' => (int)$rec['uid'], 'moveUid' => $this->moveUid]);
return '<a href="' . htmlspecialchars($url) . '">' . $str . '</a>';
}

Expand All @@ -54,7 +54,7 @@ public function linkPageTitle($str, $rec)
*/
public function wrapRecordTitle($str, $row)
{
if ($GLOBALS['SOBE']->moveUid == $row['uid']) {
if ($this->moveUid == $row['uid']) {
$str = '<strong>' . $str . '</strong>';
}
return parent::wrapRecordTitle($str, $row);
Expand Down
Expand Up @@ -46,7 +46,7 @@ public function onClickEvent($pid, $newPagePID)
{
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return 'window.location.href=' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('tce_db', [
'cmd[pages][' . $GLOBALS['SOBE']->moveUid . '][' . $this->moveOrCopy . ']' => $pid,
'cmd[pages][' . $this->moveUid . '][' . $this->moveOrCopy . ']' => $pid,
'redirect' => $this->R_URI,
])) . ';return false;';
}
Expand All @@ -60,7 +60,7 @@ public function onClickEvent($pid, $newPagePID)
*/
public function linkPageTitle($str, $rec)
{
$url = GeneralUtility::linkThisScript(['uid' => (int)$rec['uid'], 'moveUid' => $GLOBALS['SOBE']->moveUid]);
$url = GeneralUtility::linkThisScript(['uid' => (int)$rec['uid'], 'moveUid' => $this->moveUid]);
return '<a href="' . htmlspecialchars($url) . '">' . $str . '</a>';
}

Expand All @@ -74,6 +74,6 @@ public function linkPageTitle($str, $rec)
*/
public function boldTitle($t_code, $dat, $id)
{
return parent::boldTitle($t_code, $dat, $GLOBALS['SOBE']->moveUid);
return parent::boldTitle($t_code, $dat, $this->moveUid);
}
}
@@ -0,0 +1,58 @@
.. include:: ../../Includes.txt

===============================================================================
Deprecation: #84285 - Protected methods and properties in MoveElementController
===============================================================================

See :issue:`84285`

Description
===========

This file is about third party usage of :php:`TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController`.

A series of class properties has been set to protected.
They will throw deprecation warnings if called public from outside:

* :php:`sys_language`
* :php:`page_id`
* [not scanned] :php:`table`
* :php:`R_URI`
* :php:`input_moveUid`
* :php:`moveUid`
* :php:`makeCopy`
* :php:`perms_clause`
* [not scanned] :php:`content`

All methods not used as entry points by :php:`TYPO3\CMS\Backend\Http\RouteDispatcher` will be
removed or set to protected in v10 and throw deprecation warnings if used from a third party:

* [not scanned] :php:`init()`
* [not scanned] :php:`main()`

Additionally :php:`$GLOBALS['SOBE']` is not set by the :php:`MoveElementController` constructor anymore.

Impact
======

Calling one of the above methods or accessing one of the above properties on an instance of
:php:`MoveElementController` will throw a deprecation warning in v9 and a PHP fatal in v10.


Affected Installations
======================

The extension scanner will find most usages, but may also find some false positives. The most
common property and method names like :php:`$content` are not registered and will not be found
if an extension uses that on an instance of :php:`MoveElementController`.

In general all extensions that set properties or call methods except :php:`mainAction()` are affected.


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
Expand Up @@ -272,4 +272,39 @@
'Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->sys_language' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->page_id' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->R_URI' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->input_moveUid' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->moveUid' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->perms_clause' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
'TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController->makeCopy' => [
'restFiles' => [
'Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst',
],
],
];

0 comments on commit 5b0c982

Please sign in to comment.