From 89bbde3816474c395d2e6023fd246253d6b86530 Mon Sep 17 00:00:00 2001
From: Wouter Wolters <typo3@wouterwolters.nl>
Date: Sun, 1 Mar 2015 14:50:48 +0100
Subject: [PATCH] [TASK] Make logout.php dispatched

Use dispatching for logout.php

Resolves: #65291
Releases: master
Change-Id: Ic003ec6dda083f69da2aaf0373ad48ea3bf4f56f
Reviewed-on: http://review.typo3.org/37411
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
---
 typo3/logout.php                              |  4 +++
 .../Backend/ToolbarItems/UserToolbarItem.php  |  2 +-
 .../Classes/Controller/BackendController.php  |  1 +
 .../backend/Classes/View/ModuleMenuView.php   |  2 +-
 typo3/sysext/backend/Modules/Logout/conf.php  |  3 +++
 typo3/sysext/backend/Modules/Logout/index.php | 23 +++++++++++++++++
 .../Public/JavaScript/LoginRefresh.js         | 14 ++++++++---
 typo3/sysext/backend/ext_tables.php           |  6 +++++
 ...cation-65291-DeprecateLogoutEntryPoint.rst | 25 +++++++++++++++++++
 9 files changed, 75 insertions(+), 5 deletions(-)
 create mode 100644 typo3/sysext/backend/Modules/Logout/conf.php
 create mode 100644 typo3/sysext/backend/Modules/Logout/index.php
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-65291-DeprecateLogoutEntryPoint.rst

diff --git a/typo3/logout.php b/typo3/logout.php
index cdf7766b2cea..8b57d7d1d80d 100644
--- a/typo3/logout.php
+++ b/typo3/logout.php
@@ -20,5 +20,9 @@
  */
 require __DIR__ . '/init.php';
 
+\TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog(
+	'The entry point to logout was moved to an own module. Please use BackendUtility::getModuleUrl(\'logout\') to link to logout.php. This script will be removed in TYPO3 CMS 8.'
+);
+
 $logoutController = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Controller\LogoutController::class);
 $logoutController->logout();
diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/UserToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/UserToolbarItem.php
index 80816f68cbd0..ae483b4b4f42 100644
--- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/UserToolbarItem.php
+++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/UserToolbarItem.php
@@ -104,7 +104,7 @@ class UserToolbarItem implements ToolbarItemInterface {
 		// Logout button
 		$buttonLabel = 'LLL:EXT:lang/locallang_core.xlf:' . ($backendUser->user['ses_backuserid'] ? 'buttons.exit' : 'buttons.logout');
 		$dropdown[] = '<li class="reset-dropdown">';
-		$dropdown[] = '<a href="logout.php" class="btn btn-danger pull-right" target="_top"><i class="fa fa-power-off"></i> ';
+		$dropdown[] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('logout')) . '" class="btn btn-danger pull-right" target="_top"><i class="fa fa-power-off"></i> ';
 		$dropdown[] = $languageService->sL($buttonLabel, TRUE);
 		$dropdown[] = '</a>';
 		$dropdown[] = '</li>';
diff --git a/typo3/sysext/backend/Classes/Controller/BackendController.php b/typo3/sysext/backend/Classes/Controller/BackendController.php
index c34cdd39aa40..a397ff6e86cd 100644
--- a/typo3/sysext/backend/Classes/Controller/BackendController.php
+++ b/typo3/sysext/backend/Classes/Controller/BackendController.php
@@ -130,6 +130,7 @@ class BackendController {
 		if (!$this->debug) {
 			$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LoginRefresh', 'function(LoginRefresh) {
 				LoginRefresh.setLoginFramesetUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('login_frameset')) . ');
+				LoginRefresh.setLogoutUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('logout')) . ');
 			}');
 		}
 
diff --git a/typo3/sysext/backend/Classes/View/ModuleMenuView.php b/typo3/sysext/backend/Classes/View/ModuleMenuView.php
index b1fc442e56d9..342e0c700c86 100644
--- a/typo3/sysext/backend/Classes/View/ModuleMenuView.php
+++ b/typo3/sysext/backend/Classes/View/ModuleMenuView.php
@@ -357,7 +357,7 @@ class ModuleMenuView {
 	public function renderLogoutButton() {
 		$buttonLabel = $GLOBALS['BE_USER']->user['ses_backuserid'] ? 'LLL:EXT:lang/locallang_core.xlf:buttons.exit' : 'LLL:EXT:lang/locallang_core.xlf:buttons.logout';
 		$buttonForm = '
-		<form action="logout.php" target="_top">
+		<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('logout')) . '" target="_top">
 			<input class="btn btn-default" type="submit" id="logout-submit-button" value="' . $GLOBALS['LANG']->sL($buttonLabel, TRUE) . '" />
 		</form>';
 		return $buttonForm;
diff --git a/typo3/sysext/backend/Modules/Logout/conf.php b/typo3/sysext/backend/Modules/Logout/conf.php
new file mode 100644
index 000000000000..34db869f5781
--- /dev/null
+++ b/typo3/sysext/backend/Modules/Logout/conf.php
@@ -0,0 +1,3 @@
+<?php
+$MCONF['script'] = '_DISPATCH';
+$MCONF['name'] = 'logout';
\ No newline at end of file
diff --git a/typo3/sysext/backend/Modules/Logout/index.php b/typo3/sysext/backend/Modules/Logout/index.php
new file mode 100644
index 000000000000..baefe670b59a
--- /dev/null
+++ b/typo3/sysext/backend/Modules/Logout/index.php
@@ -0,0 +1,23 @@
+<?php
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Logout script for the backend
+ * This script saves the interface positions and calls the closeTypo3Windows in the frameset
+ *
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+
+$logoutController = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Controller\LogoutController::class);
+$logoutController->logout();
\ No newline at end of file
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js b/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js
index 12fb18ce0723..86dbd7fbbc74 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js
@@ -34,7 +34,8 @@ define('TYPO3/CMS/Backend/LoginRefresh', ['jquery'], function($) {
 		$timeoutModal: '',
 		$backendLockedModal: '',
 		$loginForm: '',
-		loginFramesetUrl: ''
+		loginFramesetUrl: '',
+		logoutUrl: ''
 	};
 
 	/**
@@ -75,6 +76,13 @@ define('TYPO3/CMS/Backend/LoginRefresh', ['jquery'], function($) {
 		);
 	};
 
+	/**
+	 * Set logout url
+	 */
+	LoginRefresh.setLogoutUrl = function(logoutUrl) {
+		LoginRefresh.logoutUrl = logoutUrl;
+	};
+
 	/**
 	 * Generates the modal displayed on near session time outs
 	 */
@@ -105,7 +113,7 @@ define('TYPO3/CMS/Backend/LoginRefresh', ['jquery'], function($) {
 				});
 			}),
 			$('<button />', {class: 'btn btn-default', 'data-action': 'logout'}).text(TYPO3.LLL.core.refresh_direct_logout_button).on('click', function() {
-				top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + 'logout.php';
+				top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + LoginRefresh.logoutUrl;
 			})
 		);
 
@@ -196,7 +204,7 @@ define('TYPO3/CMS/Backend/LoginRefresh', ['jquery'], function($) {
 		LoginRefresh.$loginForm.find('.modal-footer').append(
 			$('<button />', {type: 'submit', form: 'beLoginRefresh', class: 'btn btn-default', 'data-action': 'refreshSession'}).text(TYPO3.LLL.core.refresh_login_button),
 			$('<button />', {class: 'btn btn-default', 'data-action': 'logout'}).text(TYPO3.LLL.core.refresh_direct_logout_button).on('click', function() {
-				top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + 'logout.php';
+				top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + LoginRefresh.logoutUrl;
 			})
 		);
 
diff --git a/typo3/sysext/backend/ext_tables.php b/typo3/sysext/backend/ext_tables.php
index 98b0c5706fe4..52d48b99c768 100644
--- a/typo3/sysext/backend/ext_tables.php
+++ b/typo3/sysext/backend/ext_tables.php
@@ -14,6 +14,12 @@ if (TYPO3_MODE === 'BE') {
 		\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Modules/LoginFrameset/'
 	);
 
+	// Register logout
+	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModulePath(
+		'logout',
+		\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Modules/Logout/'
+	);
+
 	// Register file_edit
 	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModulePath(
 		'file_edit',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-65291-DeprecateLogoutEntryPoint.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-65291-DeprecateLogoutEntryPoint.rst
new file mode 100644
index 000000000000..6308736274ba
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-65291-DeprecateLogoutEntryPoint.rst
@@ -0,0 +1,25 @@
+==================================================
+Deprecation: #65283 - Deprecate logout entry point
+==================================================
+
+Description
+===========
+
+The following entry point has been marked as deprecated:
+
+* typo3/logout.php
+
+
+Impact
+======
+
+Using this entry points in a backend module will throw a deprecation message.
+
+
+Migration
+=========
+
+Use ``\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl()`` instead with the according module name.
+
+typo3/logout.php
+``\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('logout')``
\ No newline at end of file
-- 
GitLab