From 5b0c9821d3c55ce1a0b45d04ce6827d92cbc2f88 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Thu, 15 Mar 2018 13:27:04 +0100 Subject: [PATCH] [TASK] Use ServerRequestInterface in MoveElementController Change-Id: Id817e4aa991ddfccaf1fcb6838d7354bc64235d6 Resolves: #84285 Releases: master Reviewed-on: https://review.typo3.org/56163 Tested-by: TYPO3com Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../ContentElement/MoveElementController.php | 129 ++++++++++++------ .../View/ContentMovingPagePositionMap.php | 4 +- .../Tree/View/PageMovingPagePositionMap.php | 6 +- ...dsAndPropertiesInMoveElementController.rst | 58 ++++++++ .../Php/PropertyProtectedMatcher.php | 35 +++++ 5 files changed, 188 insertions(+), 44 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst diff --git a/typo3/sysext/backend/Classes/Controller/ContentElement/MoveElementController.php b/typo3/sysext/backend/Classes/Controller/ContentElement/MoveElementController.php index 61ff8d523ef9..fcb6c0d24a77 100644 --- a/typo3/sysext/backend/Classes/Controller/ContentElement/MoveElementController.php +++ b/typo3/sysext/backend/Classes/Controller/ContentElement/MoveElementController.php @@ -1,4 +1,5 @@ '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 @@ -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); } /** @@ -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(); @@ -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); @@ -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; @@ -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 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(); } /** @@ -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']; } diff --git a/typo3/sysext/backend/Classes/Tree/View/ContentMovingPagePositionMap.php b/typo3/sysext/backend/Classes/Tree/View/ContentMovingPagePositionMap.php index c72c676d78d0..aa2c85dcd2a2 100644 --- a/typo3/sysext/backend/Classes/Tree/View/ContentMovingPagePositionMap.php +++ b/typo3/sysext/backend/Classes/Tree/View/ContentMovingPagePositionMap.php @@ -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 '' . $str . ''; } @@ -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 = '' . $str . ''; } return parent::wrapRecordTitle($str, $row); diff --git a/typo3/sysext/backend/Classes/Tree/View/PageMovingPagePositionMap.php b/typo3/sysext/backend/Classes/Tree/View/PageMovingPagePositionMap.php index 10040dd06e5b..93f12c6aa0c2 100644 --- a/typo3/sysext/backend/Classes/Tree/View/PageMovingPagePositionMap.php +++ b/typo3/sysext/backend/Classes/Tree/View/PageMovingPagePositionMap.php @@ -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;'; } @@ -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 '' . $str . ''; } @@ -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); } } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst new file mode 100644 index 000000000000..73a3951ac4e1 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84285-ProtectedMethodsAndPropertiesInMoveElementController.rst @@ -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 diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php index b6c622fac667..f5734e49b462 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php @@ -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', + ], + ], ];