[TASK] Use ServerRequestInterface in FileSystemNavigationFrameController 56/56156/13
authorŁukasz Uznański <l.uznanski@macopedia.pl>
Thu, 15 Mar 2018 10:44:46 +0000 (11:44 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 15 Mar 2018 15:36:36 +0000 (16:36 +0100)
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>
typo3/sysext/backend/Classes/Controller/FileSystemNavigationFrameController.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php

index 7a47643..1bd29f5 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Backend\Controller;
 
 /*
@@ -20,10 +21,13 @@ use TYPO3\CMS\Backend\Routing\UriBuilder;
 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;
@@ -33,27 +37,41 @@ use TYPO3\CMS\Recordlist\Tree\View\DummyLinkParameterProvider;
  */
 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
@@ -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);
     }
 
     /**
@@ -82,24 +103,49 @@ class FileSystemNavigationFrameController
      */
     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);
@@ -128,45 +174,57 @@ class FileSystemNavigationFrameController
     /**
      * 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',
@@ -176,9 +234,20 @@ class FileSystemNavigationFrameController
 
     /**
      * 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();
         // Outputting page tree:
@@ -193,7 +262,7 @@ class FileSystemNavigationFrameController
     /**
      * Register docHeader buttons
      */
-    protected function getButtons()
+    protected function getButtons(): void
     {
         /** @var ButtonBar $buttonBar */
         $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
@@ -215,30 +284,10 @@ class FileSystemNavigationFrameController
         $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'];
     }
@@ -246,9 +295,9 @@ class FileSystemNavigationFrameController
     /**
      * Returns an instance of LanguageService
      *
-     * @return \TYPO3\CMS\Core\Localization\LanguageService
+     * @return LanguageService
      */
-    protected function getLanguageService()
+    protected function getLanguageService(): LanguageService
     {
         return $GLOBALS['LANG'];
     }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst
new file mode 100644 (file)
index 0000000..8d14f2c
--- /dev/null
@@ -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
\ No newline at end of file
index 72e92be..ad9f50f 100644 (file)
@@ -1906,4 +1906,11 @@ return [
             'Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.rst',
         ],
     ],
+    'TYPO3\CMS\Backend\Controller\FileSystemNavigationFrameController->initPage' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-84273-ProtectedMethodsAndPropertiesInFileSystemNavigationFrameController.rst',
+        ],
+    ],
 ];
index 4b776af..b6c622f 100644 (file)
@@ -257,4 +257,19 @@ return [
             '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',
+        ],
+    ],
 ];