[BUGFIX] Ensure backwards compatibility in element browser 18/28618/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Fri, 21 Mar 2014 18:34:14 +0000 (19:34 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 23 Mar 2014 10:41:39 +0000 (11:41 +0100)
Hooks that used the element browser used the JavaScript
function jumpToUrl with relative URLs.

After refactoring the element browser, it was necessary
to compute the absolute URL.

To stay backwards compatible we catch this case
in JavaScript and rewrite the URL according
to the new requirements.

By doing so, we can simplify our code again.

The method getThisScript might still be needed in
Hooks for other purposes, so we make it public.

Resolves: #56721
Releases: 6.2
Change-Id: Ieed6d037b428c5c15d18905341ff46dece1d67a7
Reviewed-on: https://review.typo3.org/28618
Reviewed-by: Ernesto Baschny
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/rtehtmlarea/Classes/BrowseLinks.php

index a92f59c..b183b94 100644 (file)
@@ -262,9 +262,12 @@ class ElementBrowser {
        }
 
        /**
+        * Calculate path to this script.
+        * This method is public, to be used in hooks of this class only.
+        *
         * @return string
         */
-       protected function getThisScript() {
+       public function getThisScript() {
                return strpos($this->thisScript, '?') === FALSE ? $this->thisScript . '?' : $this->thisScript . '&';
        }
 
@@ -648,6 +651,9 @@ class ElementBrowser {
                // General "jumpToUrl" function:
                $JScode .= '
                        function jumpToUrl(URL,anchor) {        //
+                               if (URL.charAt(0) === \'?\') {
+                                       URL = ' . GeneralUtility::quoteJSvalue($this->getThisScript()) . ' + URL.substring(1);
+                               }
                                var add_act = URL.indexOf("act=")==-1 ? "&act=' . $this->act . '" : "";
                                var add_mode = URL.indexOf("mode=")==-1 ? "&mode=' . $this->mode . '" : "";
                                var theLocation = URL + add_act + add_mode + add_href + add_target + add_class + add_title + add_params'
@@ -893,37 +899,37 @@ class ElementBrowser {
                        $menuDef['page']['isActive'] = $this->act == 'page';
                        $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', TRUE);
                        $menuDef['page']['url'] = '#';
-                       $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=page') . ');return false;"';
+                       $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=page') . ');return false;"';
                }
                if (in_array('file', $allowedItems)) {
                        $menuDef['file']['isActive'] = $this->act == 'file';
                        $menuDef['file']['label'] = $GLOBALS['LANG']->getLL('file', TRUE);
                        $menuDef['file']['url'] = '#';
-                       $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=file') . ');return false;"';
+                       $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=file') . ');return false;"';
                }
                if (in_array('folder', $allowedItems)) {
                        $menuDef['folder']['isActive'] = $this->act == 'folder';
                        $menuDef['folder']['label'] = $GLOBALS['LANG']->getLL('folder', TRUE);
                        $menuDef['folder']['url'] = '#';
-                       $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=folder') . ');return false;"';
+                       $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=folder') . ');return false;"';
                }
                if (in_array('url', $allowedItems)) {
                        $menuDef['url']['isActive'] = $this->act == 'url';
                        $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', TRUE);
                        $menuDef['url']['url'] = '#';
-                       $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=url') . ');return false;"';
+                       $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=url') . ');return false;"';
                }
                if (in_array('mail', $allowedItems)) {
                        $menuDef['mail']['isActive'] = $this->act == 'mail';
                        $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', TRUE);
                        $menuDef['mail']['url'] = '#';
-                       $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=mail') . ');return false;"';
+                       $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=mail') . ');return false;"';
                }
                if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $allowedItems)) {
                        $menuDef['spec']['isActive'] = $this->act == 'spec';
                        $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', TRUE);
                        $menuDef['spec']['url'] = '#';
-                       $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=spec') . ');return false;"';
+                       $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=spec') . ');return false;"';
                }
                // Call hook for extra options
                foreach ($this->hookObjects as $hookObject) {
index 8d9868e..c371c82 100644 (file)
@@ -365,6 +365,9 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                // General "jumpToUrl" and launchView functions:
                $JScode .= '
                        function jumpToUrl(URL,anchor) {
+                               if (URL.charAt(0) === \'?\') {
+                                       URL = ' . GeneralUtility::quoteJSvalue($this->getThisScript()) . ' + URL.substring(1);
+                               }
                                var add_editorNo = URL.indexOf("editorNo=")==-1 ? "&editorNo=' . $this->editorNo . '" : "";
                                var add_contentTypo3Language = URL.indexOf("contentTypo3Language=")==-1 ? "&contentTypo3Language=' . $this->contentTypo3Language . '" : "";
                                var add_act = URL.indexOf("act=")==-1 ? "&act=' . $this->act . '" : "";
@@ -447,37 +450,37 @@ class BrowseLinks extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                        $menuDef['page']['isActive'] = $this->act == 'page';
                        $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page', TRUE);
                        $menuDef['page']['url'] = '#';
-                       $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue(($this->getThisScript() . 'act=page&mode=' . $this->mode . '&bparams=' . $this->bparams)) . ');return false;"';
+                       $menuDef['page']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=page&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('file', $this->allowedItems)) {
                        $menuDef['file']['isActive'] = $this->act == 'file';
                        $menuDef['file']['label'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:file', TRUE);
                        $menuDef['file']['url'] = '#';
-                       $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue(($this->getThisScript() . 'act=file&mode=' . $this->mode . '&bparams=' . $this->bparams)) . ');return false;"';
+                       $menuDef['file']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=file&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('folder', $this->allowedItems)) {
                        $menuDef['folder']['isActive'] = $this->act == 'folder';
                        $menuDef['folder']['label'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:folder', TRUE);
                        $menuDef['folder']['url'] = '#';
-                       $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue(($this->getThisScript() . 'act=folder&mode=' . $this->mode . '&bparams=' . $this->bparams)) . ');return false;"';
+                       $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=folder&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('url', $this->allowedItems)) {
                        $menuDef['url']['isActive'] = $this->act == 'url';
                        $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl', TRUE);
                        $menuDef['url']['url'] = '#';
-                       $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue(($this->getThisScript() . 'act=url&mode=' . $this->mode . '&bparams=' . $this->bparams)) . ');return false;"';
+                       $menuDef['url']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=url&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('mail', $this->allowedItems)) {
                        $menuDef['mail']['isActive'] = $this->act == 'mail';
                        $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email', TRUE);
                        $menuDef['mail']['url'] = '#';
-                       $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue(($this->getThisScript() . 'act=mail&mode=' . $this->mode . '&bparams=' . $this->bparams)) . ');return false;"';
+                       $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=mail&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
                }
                if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $this->allowedItems)) {
                        $menuDef['spec']['isActive'] = $this->act == 'spec';
                        $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special', TRUE);
                        $menuDef['spec']['url'] = '#';
-                       $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue(($this->getThisScript() . 'act=spec&mode=' . $this->mode . '&bparams=' . $this->bparams)) . ');return false;"';
+                       $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(' . GeneralUtility::quoteJSvalue('?act=spec&mode=' . $this->mode . '&bparams=' . $this->bparams) . ');return false;"';
                }
                // call hook for extra options
                foreach ($this->hookObjects as $hookObject) {