[TASK] Refactor init() function of ElementBrowser 31/27631/10
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 14 Feb 2014 12:29:01 +0000 (13:29 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 7 Mar 2014 12:39:04 +0000 (13:39 +0100)
Splits huge method (~450 lines) into several small methods,
in the similar way it was done for BrowseLinks and SelectImage.

It also removes some duplicated code between these classes.
This patch is not changing functionality, just moving code around.

Resolves: #55983
Releases: 6.2
Change-Id: I916058485acb9d9abe0086785763edc721a360f0
Reviewed-on: https://review.typo3.org/27631
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/rtehtmlarea/Classes/BrowseLinks.php
typo3/sysext/rtehtmlarea/Classes/SelectImage.php

index 9e597a5..4947a86 100644 (file)
@@ -254,10 +254,10 @@ class ElementBrowser {
         * Sets the script url depending on being a module or script request
         */
        protected function determineScriptUrl() {
-               if ($moduleName = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('M')) {
-                       $this->thisScript = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl($moduleName);
+               if ($moduleName = GeneralUtility::_GP('M')) {
+                       $this->thisScript = BackendUtility::getModuleUrl($moduleName);
                } else {
-                       $this->thisScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME');
+                       $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
                }
        }
 
@@ -277,19 +277,86 @@ class ElementBrowser {
         * @throws \UnexpectedValueException
         */
        public function init() {
+               $this->initVariables();
+
+               $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
+               $this->initConfiguration();
+               $this->initDocumentTemplate();
+               // init hook objects:
+               $this->initHookObjects('typo3/class.browse_links.php');
+
+               $this->initCurrentUrl();
+
+               // Determine nature of current url:
+               $this->act = GeneralUtility::_GP('act');
+               if (!$this->act) {
+                       $this->act = $this->curUrlInfo['act'];
+               }
+
+               // Initializing the target value (RTE)
+               $this->setTarget = $this->curUrlArray['target'] != '-' ? rawurlencode($this->curUrlArray['target']) : '';
+               if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
+                       $this->setTarget = $this->thisConfig['defaultLinkTarget'];
+               }
+               // Initializing the class value (RTE)
+               $this->setClass = $this->curUrlArray['class'] != '-' ? rawurlencode($this->curUrlArray['class']) : '';
+               // Initializing the title value (RTE)
+               $this->setTitle = $this->curUrlArray['title'] != '-' ? rawurlencode($this->curUrlArray['title']) : '';
+               // Initializing the params value
+               $this->setParams = $this->curUrlArray['params'] != '-' ? rawurlencode($this->curUrlArray['params']) : '';
+
+               // Finally, add the accumulated JavaScript to the template object:
+               $this->doc->JScode .= $this->doc->wrapScriptTags($this->getJSCode());
+       }
+
+       /**
+        * Initialize class variables
+        *
+        * @return void
+        */
+       public function initVariables() {
                // Main GPvars:
                $this->pointer = GeneralUtility::_GP('pointer');
                $this->bparams = GeneralUtility::_GP('bparams');
                $this->P = GeneralUtility::_GP('P');
-               $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
                $this->expandPage = GeneralUtility::_GP('expandPage');
                $this->expandFolder = GeneralUtility::_GP('expandFolder');
                $this->PM = GeneralUtility::_GP('PM');
+
+               // Site URL
+               // Current site url
+               $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
+               $this->determineScriptUrl();
+
                // Find "mode"
                $this->mode = GeneralUtility::_GP('mode');
                if (!$this->mode) {
                        $this->mode = 'rte';
                }
+
+               // Init fileProcessor
+               $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
+               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+       }
+
+       /**
+        * Initializes the configuration variables
+        *
+        * @return void
+        */
+       public function initConfiguration() {
+               // Rich Text Editor specific configuration:
+               if ((string) $this->mode === 'rte') {
+                       $this->thisConfig = $this->getRTEConfig();
+               }
+       }
+
+       /**
+        * Initialize document template object
+        *
+        *  @return void
+        */
+       protected function initDocumentTemplate() {
                // Creating backend template object:
                $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
                $this->doc->bodyTagId = 'typo3-browse-links-php';
@@ -300,10 +367,18 @@ class ElementBrowser {
                $this->doc->loadJavascriptLib('js/tree.js');
                $this->doc->getPageRenderer()->addInlineSetting('Tree.SC_alt_db_navframe', 'ajaxUrl', BackendUtility::getAjaxUrl('SC_alt_db_navframe::expandCollapse'));
                $this->doc->getPageRenderer()->addInlineSetting('Tree.SC_alt_file_navframe', 'ajaxUrl', BackendUtility::getAjaxUrl('SC_alt_file_navframe::expandCollapse'));
-               // init hook objects:
-               $this->hookObjects = array();
-               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
-                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
+       }
+
+       /**
+        * Initialize hook objects implementing the interface
+        *
+        * @param string $hookKey the hook key
+        * @throws \UnexpectedValueException
+        * @return void
+        */
+       protected function initHookObjects($hookKey) {
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'] as $classData) {
                                $processObject = GeneralUtility::getUserObj($classData);
                                if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
                                        throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195039394);
@@ -313,13 +388,14 @@ class ElementBrowser {
                                $this->hookObjects[] = $processObject;
                        }
                }
-               // Site URL
-               // Current site url
-               $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
-               $this->determineScriptUrl();
-               // Init fileProcessor
-               $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
-               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+       }
+
+       /**
+        * Initialize $this->curUrlArray and $this->curUrlInfo based on script parameters
+        *
+        * @return void
+        */
+       protected function initCurrentUrl() {
                // CurrentUrl - the current link url must be passed around if it exists
                if ($this->mode == 'wizard') {
                        $currentValues = GeneralUtility::trimExplode(LF, trim($this->P['currentValue']));
@@ -392,30 +468,31 @@ class ElementBrowser {
                        }
                        $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
                }
-               // Determine nature of current url:
-               $this->act = GeneralUtility::_GP('act');
-               if (!$this->act) {
-                       $this->act = $this->curUrlInfo['act'];
-               }
+       }
+
+       /**
+        * Get the RTE configuration from Page TSConfig
+        *
+        * @return array RTE configuration array
+        */
+       protected function getRTEConfig() {
+               $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
+               $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
+               return BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
+       }
+
+       /**
+        * Generate JS code to be used on the link insert/modify dialogue
+        *
+        * @return string the generated JS code
+        * @todo Define visibility
+        */
+       public function getJsCode() {
                // Rich Text Editor specific configuration:
                $addPassOnParams = '';
                if ((string) $this->mode == 'rte') {
-                       $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
                        $addPassOnParams .= '&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams);
-                       $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
-                       $this->thisConfig = BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
                }
-               // Initializing the target value (RTE)
-               $this->setTarget = ($this->curUrlArray['target'] != '-') ? $this->curUrlArray['target'] : '';
-               if ($this->thisConfig['defaultLinkTarget'] && !isset($this->curUrlArray['target'])) {
-                       $this->setTarget = $this->thisConfig['defaultLinkTarget'];
-               }
-               // Initializing the class value (RTE)
-               $this->setClass = ($this->curUrlArray['class'] != '-') ? $this->curUrlArray['class'] : '';
-               // Initializing the title value (RTE)
-               $this->setTitle = ($this->curUrlArray['title'] != '-') ? $this->curUrlArray['title'] : '';
-               // Initializing the params value
-               $this->setParams = ($this->curUrlArray['params'] != '-') ? $this->curUrlArray['params'] : '';
                // BEGIN accumulation of header JavaScript:
                $JScode = '
                        // This JavaScript is primarily for RTE/Link. jumpToUrl is used in the other cases as well...
@@ -721,8 +798,7 @@ class ElementBrowser {
                                $JScode .= $processor->extendJScode($_params, $this);
                        }
                }
-               // Finally, add the accumulated JavaScript to the template object:
-               $this->doc->JScode .= $this->doc->wrapScriptTags($JScode);
+               return $JScode;
        }
 
        /**
@@ -1755,7 +1831,7 @@ class ElementBrowser {
                                                ) . ' alt="" />' . $arrCol .
                                        '<a href="#" onclick="return link_folder(\'' . $itemUid . '\');">' .
                                                $icon .
-                                               htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) .
+                                               htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) .
                                        '</a><br />';
                        }
                }
@@ -2491,7 +2567,7 @@ class ElementBrowser {
                                . '&expandFolder=' . rawurlencode($this->selectedFolder->getCombinedIdentifier())
                                . '&bparams=' . rawurlencode($this->bparams);
                        $thumbNailCheck = BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'],
-                                       \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('M') ? '' : $this->thisScript, $addParams, 'id="checkDisplayThumbs"')
+                                       GeneralUtility::_GP('M') ? '' : $this->thisScript, $addParams, 'id="checkDisplayThumbs"')
                                . ' <label for="checkDisplayThumbs">'
                                . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', TRUE) . '</label>';
                        $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15);
index a42d145..87dc47a 100644 (file)
@@ -54,67 +54,33 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
         */
        public function init() {
                $this->initVariables();
-               // Create content laguage service
+               // Create content language service
                $this->contentLanguageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
                $this->contentLanguageService->init($this->contentTypo3Language);
                $this->initConfiguration();
-               // init fileProcessor
-               $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
-               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
-               // Creating backend template object:
-               $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
-               $this->doc->backPath = $GLOBALS['BACK_PATH'];
-               // Loading the Prototype library and browse_links.js
-               $this->doc->getPageRenderer()->loadPrototype();
-               $this->doc->loadJavascriptLib('js/tree.js');
-               $this->doc->getPageRenderer()->addInlineSetting('Tree.SC_alt_db_navframe', 'ajaxUrl', BackendUtility::getAjaxUrl('SC_alt_db_navframe::expandCollapse'));
-               $this->doc->getPageRenderer()->addInlineSetting('Tree.SC_alt_file_navframe', 'ajaxUrl', BackendUtility::getAjaxUrl('SC_alt_file_navframe::expandCollapse'));
-               $this->doc->loadJavascriptLib('js/browse_links.js');
-               // Adding context menu code
-               $this->doc->getContextMenuCode();
+
+               $this->initDocumentTemplate();
+
                // Initializing hooking browsers
                $this->initHookObjects('ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php');
-               // CurrentUrl - the current link url must be passed around if it exists
-               $this->curUrlArray = GeneralUtility::_GP('curUrl');
-               if ($this->curUrlArray['all']) {
-                       $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
-                       $this->curUrlArray['href'] = htmlspecialchars_decode($this->curUrlArray['href']);
-               }
-               // Note: parseCurUrl will invoke the hooks
-               $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
-               if (isset($this->curUrlArray['data-htmlarea-external']) && $this->curUrlInfo['act'] != 'mail') {
-                       $this->curUrlInfo['act'] = 'url';
-                       $this->curUrlInfo['info'] = $this->curUrlArray['href'];
-               }
+               $this->initCurrentUrl();
                // Determine nature of current url:
                $this->act = GeneralUtility::_GP('act');
                if (!$this->act) {
                        $this->act = $this->curUrlInfo['act'];
                }
-               // Setting intial values for link attributes
+               // Setting initial values for link attributes
                $this->initLinkAttributes();
-               // Apply the same styles as those of the base script
-               $this->doc->bodyTagId = 'typo3-browse-links-php';
-               $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
-               // Add attributes to body tag. Note: getBodyTagAdditions will invoke the hooks
-               $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
-               // Adding RTE JS code
-               $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode();
        }
 
        /**
         * Initialize class variables
         *
-        * @return      void
+        * @return void
         */
        public function initVariables() {
-               // Main GPvars:
-               $this->pointer = GeneralUtility::_GP('pointer');
-               $this->bparams = GeneralUtility::_GP('bparams');
-               $this->P = GeneralUtility::_GP('P');
-               $this->expandPage = GeneralUtility::_GP('expandPage');
-               $this->expandFolder = GeneralUtility::_GP('expandFolder');
-               $this->PM = GeneralUtility::_GP('PM');
+               parent::initVariables();
+
                // Process bparams
                $pArr = explode('|', $this->bparams);
                $pRteArr = explode(':', $pArr[1]);
@@ -129,20 +95,12 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                $pArr[1] = implode(':', array($this->editorNo, $this->contentTypo3Language, $this->contentTypo3Charset));
                $pArr[2] = $this->RTEtsConfigParams;
                $this->bparams = implode('|', $pArr);
-               // Find "mode"
-               $this->mode = GeneralUtility::_GP('mode');
-               if (!$this->mode) {
-                       $this->mode = 'rte';
-               }
-               // Current site url
-               $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
-               $this->determineScriptUrl();
        }
 
        /**
         * Initializes the configuration variables
         *
-        * @return      void
+        * @return void
         */
        public function initConfiguration() {
                $this->thisConfig = $this->getRTEConfig();
@@ -150,15 +108,52 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        }
 
        /**
+        * Initialize document template object
+        *
+        * @return void
+        */
+       protected function initDocumentTemplate() {
+               parent::initDocumentTemplate();
+               $this->doc->getContextMenuCode();
+               // Apply the same styles as those of the base script
+               $this->doc->bodyTagId = 'typo3-browse-links-php';
+               $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
+               // Add attributes to body tag. Note: getBodyTagAdditions will invoke the hooks
+               $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
+               // Adding RTE JS code
+               $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode();
+       }
+
+       /**
+        * Initialize $this->curUrlArray and $this->curUrlInfo based on script parameters
+        *
+        * @return void
+        */
+       protected function initCurrentUrl() {
+               // CurrentUrl - the current link url must be passed around if it exists
+               $this->curUrlArray = GeneralUtility::_GP('curUrl');
+               if ($this->curUrlArray['all']) {
+                       $this->curUrlArray = GeneralUtility::get_tag_attributes($this->curUrlArray['all']);
+                       $this->curUrlArray['href'] = htmlspecialchars_decode($this->curUrlArray['href']);
+               }
+               // Note: parseCurUrl will invoke the hooks
+               $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
+               if (isset($this->curUrlArray['data-htmlarea-external']) && $this->curUrlInfo['act'] != 'mail') {
+                       $this->curUrlInfo['act'] = 'url';
+                       $this->curUrlInfo['info'] = $this->curUrlArray['href'];
+               }
+       }
+
+       /**
         * Get the RTE configuration from Page TSConfig
         *
         * @return      array           RTE configuration array
         */
        protected function getRTEConfig() {
                $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
-               $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
+               $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
                $this->RTEProperties = $RTEsetup['properties'];
-               return \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($this->RTEProperties, $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
+               return BackendUtility::RTEsetup($this->RTEProperties, $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
        }
 
        /**
@@ -168,27 +163,9 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
         * @return      array           the configuration array of the image button
         */
        protected function getButtonConfig($buttonName) {
-               return is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonName . '.']) ? $this->thisConfig['buttons.'][$buttonName . '.'] : array();
-       }
-
-       /**
-        * Initialize hook objects implementing the interface
-        *
-        * @param       string          $hookKey: the hook key
-        * @return      void
-        */
-       protected function initHookObjects($hookKey) {
-               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'])) {
-                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'] as $classData) {
-                               $processObject = GeneralUtility::getUserObj($classData);
-                               if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
-                                       throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195115653);
-                               }
-                               $parameters = array();
-                               $processObject->init($this, $parameters);
-                               $this->hookObjects[] = $processObject;
-                       }
-               }
+               return is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonName . '.'])
+                       ? $this->thisConfig['buttons.'][$buttonName . '.']
+                       : array();
        }
 
        /**
index fe61014..a43170b 100644 (file)
@@ -100,44 +100,27 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        public function init() {
                $this->initVariables();
                $this->initConfiguration();
-               $this->initHookObjects();
-               // init fileProcessor
-               $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
-               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+               $this->initHookObjects('ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php');
+
                $this->allowedItems = $this->getAllowedItems('magic,plain,image');
                $this->insertImage();
-               // Creating backend template object:
-               $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
-               // Apply the same styles as those of the base script
-               $this->doc->bodyTagId = 'typo3-browse-links-php';
-               $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
-               $this->doc->backPath = $GLOBALS['BACK_PATH'];
-               // Load the Prototype library and browse_links.js
-               $this->doc->getPageRenderer()->loadPrototype();
-               $this->doc->loadJavascriptLib('js/tree.js');
-               $this->doc->getPageRenderer()->addInlineSetting('Tree.SC_alt_db_navframe', 'ajaxUrl', BackendUtility::getAjaxUrl('SC_alt_db_navframe::expandCollapse'));
-               $this->doc->getPageRenderer()->addInlineSetting('Tree.SC_alt_file_navframe', 'ajaxUrl', BackendUtility::getAjaxUrl('SC_alt_file_navframe::expandCollapse'));
-               $this->doc->loadJavascriptLib('js/browse_links.js');
-               $this->doc->JScode .= $this->doc->wrapScriptTags('
-                       Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
-               ');
-               $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
-               $this->doc->getContextMenuCode();
+
+               $this->initDocumentTemplate();
        }
 
        /**
         * Initialize class variables
         *
-        * @return      void
+        * @return void
         */
        public function initVariables() {
+               parent::initVariables();
                // Get "act"
                $this->act = GeneralUtility::_GP('act');
                if (!$this->act) {
                        $this->act = FALSE;
                }
                // Process bparams
-               $this->bparams = GeneralUtility::_GP('bparams');
                $pArr = explode('|', $this->bparams);
                $pRteArr = explode(':', $pArr[1]);
                $this->editorNo = $pRteArr[0];
@@ -148,8 +131,6 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                        $this->sys_language_content = GeneralUtility::_GP('sys_language_content');
                        $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
                }
-               $this->expandPage = GeneralUtility::_GP('expandPage');
-               $this->expandFolder = GeneralUtility::_GP('expandFolder');
                $pArr[1] = implode(':', array($this->editorNo, $this->sys_language_content));
                $pArr[2] = $this->RTEtsConfigParams;
                if ($this->act == 'dragdrop' || $this->act == 'plain') {
@@ -157,34 +138,24 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                }
                $pArr[3] = implode(',', $this->allowedFileTypes);
                $this->bparams = implode('|', $pArr);
-               // Find "mode"
-               $this->mode = GeneralUtility::_GP('mode');
-               if (!$this->mode) {
-                       $this->mode = 'rte';
-               }
-               // Site URL
-               $this->siteURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
-               $this->determineScriptUrl();
        }
 
        /**
-        * Initialize hook objects implementing the hook interface
+        * Initialize document template object
         *
-        * @return      void
-        * @throws \UnexpectedValueException
+        * @return void
         */
-       protected function initHookObjects() {
-               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'])) {
-                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'] as $classData) {
-                               $processObject = GeneralUtility::getUserObj($classData);
-                               if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
-                                       throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195115652);
-                               }
-                               $parameters = array();
-                               $processObject->init($this, $parameters);
-                               $this->hookObjects[] = $processObject;
-                       }
-               }
+       protected function initDocumentTemplate() {
+               parent::initDocumentTemplate();
+
+               $this->doc->bodyTagId = 'typo3-browse-links-php';
+               $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
+
+               $this->doc->JScode .= $this->doc->wrapScriptTags('
+                       Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
+               ');
+               $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
+               $this->doc->getContextMenuCode();
        }
 
        /**
@@ -871,17 +842,6 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        }
 
        /**
-        * Get the RTE configuration from Page TSConfig
-        *
-        * @return      array           RTE configuration array
-        */
-       protected function getRTEConfig() {
-               $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
-               $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
-               return \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
-       }
-
-       /**
         * Get the path of the image to be inserted or modified
         *
         * @return      string          path to the image