Skip to content

Commit

Permalink
[TASK] Use ServerRequestInterface in FileSystemNavigationFrameController
Browse files Browse the repository at this point in the history
Change public properties to protected, add protected methods in
replacement of public, deprecate public methods, rewrite _GP

Resolves: #84273
Releases: master
Change-Id: I927829018e4e477e8176bfc3df0a21582f5d2261
Reviewed-on: https://review.typo3.org/56156
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
Łukasz Uznański authored and lolli42 committed Mar 15, 2018
1 parent 93b4b08 commit 72805b4
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\Controller;

/*
Expand All @@ -20,10 +21,13 @@
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Tree\View\ElementBrowserFolderTreeView;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Filelist\FileListFolderTree;
use TYPO3\CMS\Recordlist\Tree\View\DummyLinkParameterProvider;
Expand All @@ -33,27 +37,41 @@
*/
class FileSystemNavigationFrameController
{
use PublicPropertyDeprecationTrait;

/**
* Properties which have been moved to protected status from public
*
* @var array
*/
protected $deprecatedPublicProperties = [
'content' => 'Using $content of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
'foldertree' => 'Using $foldertree of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
'currentSubScript' => 'Using $currentSubScript of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
'cMR' => 'Using $cMR of class FileSystemNavigationFrameController from the outside is discouraged, as this variable is only used for internal storage.',
];

/**
* Content accumulates in this variable.
*
* @var string
*/
public $content;
protected $content;

/**
* @var \TYPO3\CMS\Backend\Tree\View\FolderTreeView
*/
public $foldertree;
protected $foldertree;

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

/**
* @var bool
*/
public $cMR;
protected $cMR;

/**
* @var array
Expand All @@ -72,8 +90,11 @@ class FileSystemNavigationFrameController
*/
public function __construct()
{
// @deprecated since v9, will be obsolete in v10 with removal of init()
$request = $GLOBALS['TYPO3_REQUEST'];
$GLOBALS['SOBE'] = $this;
$this->init();
// @deprecated since v9, will be moved out of __construct() in v10
$this->init($request);
}

/**
Expand All @@ -82,24 +103,49 @@ public function __construct()
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
$this->initPage();
$this->main();
$this->initializePageTemplate();
$this->renderFolderTree();
return new HtmlResponse($this->content);
}

/**
* Initialiation of the script class
* Makes the AJAX call to expand or collapse the foldertree.
* Called by an AJAX Route, see AjaxRequestHandler
*
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function ajaxExpandCollapse(ServerRequestInterface $request): ResponseInterface
{
$tree = $this->foldertree->getBrowsableTree();
if ($this->foldertree->getAjaxStatus() === false) {
return new JsonResponse(null, 500);
}
return new JsonResponse([$tree]);
}

/**
* Initialization of the script class
*
* @param ServerRequestInterface $request the current request
*/
protected function init()
protected 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'];
}

$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);

// Setting GPvars:
$this->currentSubScript = GeneralUtility::_GP('currentSubScript');
$this->cMR = GeneralUtility::_GP('cMR');
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();

$scopeData = (string)GeneralUtility::_GP('scopeData');
$scopeHash = (string)GeneralUtility::_GP('scopeHash');
$this->currentSubScript = $parsedBody['currentSubScript'] ?? $queryParams['currentSubScript'] ?? null;
$this->cMR = (bool)($parsedBody['cMR'] ?? $queryParams['cMR'] ?? false);
$scopeData = $parsedBody['scopeData'] ?? $queryParams['scopeData'] ?? '';
$scopeHash = $parsedBody['scopeHash'] ?? $queryParams['scopeHash'] ?? '';

if (!empty($scopeData) && hash_equals(GeneralUtility::hmac($scopeData), $scopeHash)) {
$this->scopeData = unserialize($scopeData);
Expand Down Expand Up @@ -128,45 +174,57 @@ protected function init()
/**
* initialization for the visual parts of the class
* Use template rendering only if this is a non-AJAX call
*
* @deprecated since v9, will be removed in v10
*/
public function initPage()
{
trigger_error('Method initPage() will be replaced by protected method initializePageTemplate() in v10. Do not call from other extension', E_USER_DEPRECATED);
$this->initializePageTemplate();
}

/**
* Initialization for the visual parts of the class
* Use template rendering only if this is a non-AJAX call
*/
protected function initializePageTemplate(): void
{
$this->moduleTemplate->setBodyTag('<body id="ext-backend-Modules-FileSystemNavigationFrame-index-php">');

// Adding javascript code for drag&drop and the file tree as well as the click menu code
$hlClass = $this->getBackendUser()->workspace === 0 ? 'active' : 'active active-ws wsver' . $GLOBALS['BE_USER']->workspace;
$dragDropCode = '
Tree.highlightClass = "' . $hlClass . '";
Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
';
Tree.highlightClass = "' . $hlClass . '";
Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);
';

// Adding javascript for drag & drop activation and highlighting
$pageRenderer = $this->moduleTemplate->getPageRenderer();
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
DragDrop.table = "folders";
Tree.registerDragDropHandlers();
Tree.registerDragDropHandlers();
' . $dragDropCode . '
}');

// Setting JavaScript for menu.
$inlineJs = ($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
// Function, loading the list frame from navigation tree:
function jumpTo(id, linkObj, highlightID, bank) {
var theUrl = top.currentSubScript;
if (theUrl.indexOf("?") != -1) {
theUrl += "&id=" + id
} else {
theUrl += "?id=" + id
}
top.fsMod.currentBank = bank;
top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
Tree.highlightActiveItem("file", highlightID + "_" + bank);
if (linkObj) { linkObj.blur(); }
return false;
}
' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');
// Function, loading the list frame from navigation tree:
function jumpTo(id, linkObj, highlightID, bank) {
var theUrl = top.currentSubScript;
if (theUrl.indexOf("?") != -1) {
theUrl += "&id=" + id
} else {
theUrl += "?id=" + id
}
top.fsMod.currentBank = bank;
top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
Tree.highlightActiveItem("file", highlightID + "_" + bank);
if (linkObj) { linkObj.blur(); }
return false;
}
' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : '');

$this->moduleTemplate->getPageRenderer()->addJsInlineCode(
'FileSystemNavigationFrame',
Expand All @@ -176,8 +234,19 @@ function jumpTo(id, linkObj, highlightID, bank) {

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

/**
* Main function, rendering the folder tree
*/
protected function renderFolderTree(): void
{
// Produce browse-tree:
$tree = $this->foldertree->getBrowsableTree();
Expand All @@ -193,7 +262,7 @@ public function main()
/**
* Register docHeader buttons
*/
protected function getButtons()
protected function getButtons(): void
{
/** @var ButtonBar $buttonBar */
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
Expand All @@ -215,40 +284,20 @@ protected function getButtons()
$buttonBar->addButton($cshButton);
}

/**********************************
* AJAX Calls
**********************************/
/**
* Makes the AJAX call to expand or collapse the foldertree.
* Called by an AJAX Route, see AjaxRequestHandler
*
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function ajaxExpandCollapse(ServerRequestInterface $request): ResponseInterface
{
$this->init();
$tree = $this->foldertree->getBrowsableTree();
if ($this->foldertree->getAjaxStatus() === false) {
return new JsonResponse(null, 500);
}
return new JsonResponse([$tree]);
}

/**
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
* @return BackendUserAuthentication
*/
protected function getBackendUser()
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}

/**
* Returns an instance of LanguageService
*
* @return \TYPO3\CMS\Core\Localization\LanguageService
* @return LanguageService
*/
protected function getLanguageService()
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.. include:: ../../Includes.txt

=============================================================================================
Deprecation: #84273 - Protected methods and properties in FileSystemNavigationFrameController
=============================================================================================

See :issue:`84273`

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

This file is about third party usage (consumer that call the class as well as
signals or hooks depending on it) of :php:`TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController`.

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

* [not scanned] :php:`$content`
* :php:`$foldertree`
* :php:`$currentSubScript`
* :php:`$cMR`

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:

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


Impact
======

Calling one of the above methods or accessing one of the above properties on an instance of
:php:`FileSystemNavigationFrameController` 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:`FileSystemNavigationFrameController`. 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
Original file line number Diff line number Diff line change
Expand Up @@ -1906,4 +1906,11 @@
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController->initPage' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst',
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,19 @@
'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
],
],
'TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController->foldertree' => [
'restFiles' => [
'Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst',
],
],
'TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController->currentSubScript' => [
'restFiles' => [
'Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst',
],
],
'TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController->cMR' => [
'restFiles' => [
'Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst',
],
],
];

0 comments on commit 72805b4

Please sign in to comment.