From 9c45facf739f50a36d1a11aa8b61938366548d84 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Mon, 2 Oct 2017 09:39:01 +0200 Subject: [PATCH] [TASK] Cleanup inline JavaScript in Backend This patch removes the global "TS." JavaScript option, as well as unused code in EditDocumentController, BackendController and PreviewController. Resolves: #82631 Releases: master Change-Id: I5de0af0acbac798bc9a57875a0631766a8016fa8 Reviewed-on: https://review.typo3.org/54254 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/Controller/BackendController.php | 22 ++++------------ .../Controller/EditDocumentController.php | 25 +++---------------- .../Public/JavaScript/LoginRefresh.js | 2 +- .../Public/JavaScript/UserPassLogin.js | 4 +-- .../Resources/Public/JavaScript/backend.js | 2 +- .../Classes/Controller/PreviewController.php | 15 +---------- 6 files changed, 14 insertions(+), 56 deletions(-) diff --git a/typo3/sysext/backend/Classes/Controller/BackendController.php b/typo3/sysext/backend/Classes/Controller/BackendController.php index 2c5200d2db7e..e4d689f2e6b8 100644 --- a/typo3/sysext/backend/Classes/Controller/BackendController.php +++ b/typo3/sysext/backend/Classes/Controller/BackendController.php @@ -626,23 +626,12 @@ class BackendController } $t3Configuration = [ 'username' => htmlspecialchars($beUser->user['username']), - 'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)), 'pageModule' => $pageModule, 'inWorkspace' => $beUser->workspace !== 0, 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false ]; $this->js .= ' TYPO3.configuration = ' . json_encode($t3Configuration) . '; - - /** - * TypoSetup object. - */ - function typoSetup() { // - this.username = TYPO3.configuration.username; - this.uniqueID = TYPO3.configuration.uniqueID; - } - var TS = new typoSetup(); - //backwards compatibility /** * Frameset Module object * @@ -651,12 +640,11 @@ class BackendController * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.(int)$this->id.\'"; * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)..."; */ - function fsModules() { // - this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame. - this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time - this.currentBank="0"; - } - var fsMod = new fsModules(); + var fsMod = { + recentIds: [], // used by frameset modules to track the most recent used id for list frame. + navFrameHighlightedID: [], // used by navigation frames to track which row id was highlighted last time + currentBank: "0" + }; top.goToModule = function(modName, cMR_flag, addGetVars) { TYPO3.ModuleMenu.App.showModule(modName, addGetVars); diff --git a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php index 844d2eac70ab..567490b77d61 100644 --- a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php +++ b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php @@ -733,39 +733,22 @@ class EditDocumentController extends AbstractModule formEl.checked = formEl.checked ? 0 : 1; } } -' - ); - $t3Configuration = []; - - $javascript = ' - TYPO3.configuration = ' . json_encode($t3Configuration) . '; - // Object: TS: - // TS object overwrites the object declared in tbe_editor.js - function typoSetup() { // - this.uniqueID = ""; - } - var TS = new typoSetup(); // Info view: - function launchView(table,uid) { // + function launchView(table,uid) { var thePreviewWindow = window.open( ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('show_item') . '&table=') . ' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid), - "ShowItem" + TS.uniqueID, + "ShowItem" + Math.random().toString(16).slice(2), "height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0" ); if (thePreviewWindow && thePreviewWindow.focus) { thePreviewWindow.focus(); } } - function deleteRecord(table,id,url) { // + function deleteRecord(table,id,url) { window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url); } - '; - - $previewCode = isset($_POST['_savedokview']) && $this->popViewId ? $this->generatePreviewCode() : ''; - $this->moduleTemplate->addJavaScriptCode( - 'PreviewCode', - $javascript . $previewCode + ' . (isset($_POST['_savedokview']) && $this->popViewId ? $this->generatePreviewCode() : '') ); // Setting up the context sensitive menu: $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu'); diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js b/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js index 02fd17c60d29..e1a86a235238 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js @@ -278,7 +278,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'bootstrap'], function($, Ty * Opens the login form in a new window. */ LoginRefresh.showLoginPopup = function() { - var vHWin = window.open(LoginRefresh.loginFramesetUrl, 'relogin_' + TYPO3.configuration.uniqueID, 'height=450,width=700,status=0,menubar=0,location=1'); + var vHWin = window.open(LoginRefresh.loginFramesetUrl, 'relogin_' + Math.random().toString(16).slice(2), 'height=450,width=700,status=0,menubar=0,location=1'); if (vHWin) { vHWin.focus(); } diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/UserPassLogin.js b/typo3/sysext/backend/Resources/Public/JavaScript/UserPassLogin.js index 7de688dd6586..9ca7dc509c65 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/UserPassLogin.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/UserPassLogin.js @@ -94,8 +94,8 @@ define(['jquery', 'TYPO3/CMS/Backend/Login'], function($, Login) { // If the login screen is shown in the login_frameset window for re-login, // then try to get the username of the current/former login from opening windows main frame: try { - if (parent.opener && parent.opener.TS && parent.opener.TS.username) { - $usernameField.val(parent.opener.TS.username); + if (parent.opener && parent.opener.TYPO3 && parent.opener.TYPO3.configuration && parent.opener.TYPO3.configuration.username) { + $usernameField.val(parent.opener.TYPO3.configuration.username); } } catch (error) {} // continue diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/backend.js b/typo3/sysext/backend/Resources/Public/JavaScript/backend.js index b4f82879e3c7..dd5778c42338 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/backend.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/backend.js @@ -76,7 +76,7 @@ function str_replace(match,replace,string) { // */ function launchView(table, uid) { var thePreviewWindow = window.open(TYPO3.settings.ShowItem.moduleUrl + '&table=' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid), - "ShowItem" + TS.uniqueID, + "ShowItem" + Math.random().toString(16).slice(2), "width=650,height=600,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0"); if (thePreviewWindow && thePreviewWindow.focus) { thePreviewWindow.focus(); diff --git a/typo3/sysext/workspaces/Classes/Controller/PreviewController.php b/typo3/sysext/workspaces/Classes/Controller/PreviewController.php index 7945dcc6d0bb..29b7659f22ad 100644 --- a/typo3/sysext/workspaces/Classes/Controller/PreviewController.php +++ b/typo3/sysext/workspaces/Classes/Controller/PreviewController.php @@ -217,25 +217,12 @@ class PreviewController extends AbstractController } $t3Configuration = [ 'username' => htmlspecialchars($backendUser->user['username']), - 'uniqueID' => GeneralUtility::shortMD5(uniqid('', true)), 'pageModule' => $pageModule, 'inWorkspace' => $backendUser->workspace !== 0, 'showRefreshLoginPopup' => isset($GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup']) ? (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] : false ]; - return ' - TYPO3.configuration = ' . json_encode($t3Configuration) . '; - - /** - * TypoSetup object. - */ - function typoSetup() { // - this.username = TYPO3.configuration.username; - this.uniqueID = TYPO3.configuration.uniqueID; - } - var TS = new typoSetup(); - //backwards compatibility - '; + return 'TYPO3.configuration = ' . json_encode($t3Configuration) . ';'; } /** -- GitLab