From 0f9a7eba9a3961ead24e1d3cd8d0bed29812b12f Mon Sep 17 00:00:00 2001
From: Benjamin Mack <benni@typo3.org>
Date: Mon, 8 Sep 2014 22:56:55 +0200
Subject: [PATCH] [TASK] Remove tslib directory

The frontend parts are split into EXT:cms and EXT:frontend,
and the legacy directory "tslib" and the constant PATH_tslib
are hardly used anymore.

The patch moves the respective eIDs in the correct folders,
moves index_ts.php into a class and moves the frontend
page template into EXT:frontend. Thus, the tslib directory
can be removed completely.

Additionally an old reference to tslib in indexed_search
can be safely removed as well.

Releases: 6.3
Resolves: #61459
Change-Id: I9c19dcbeb7c18ef24b2fee3f997a12b7b8d0f957
Reviewed-on: http://review.typo3.org/32660
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
---
 index.php                                     |  11 +-
 typo3/sysext/cms/ext_localconf.php            |   7 -
 typo3/sysext/cms/tslib/index_ts.php           | 288 ------------------
 .../Classes/Core/SystemEnvironmentBuilder.php |   7 +-
 .../master/Breaking-61459-RemovalTslib.rst    |  31 ++
 .../TypoScriptFrontendController.php          |   2 +-
 .../Classes/FrontendRequestHandler.php        | 288 ++++++++++++++++++
 .../Resources/PHP/Eid/ExtDirect.php}          |   0
 .../Resources/PHP/Eid/ShowPic.php}            |   0
 .../Private/Templates/MainPage.html}          |   0
 typo3/sysext/frontend/ext_localconf.php       |  12 +
 .../Classes/Controller/SearchController.php   |  14 -
 .../Controller/SearchFormController.php       |  15 -
 13 files changed, 341 insertions(+), 334 deletions(-)
 delete mode 100644 typo3/sysext/cms/tslib/index_ts.php
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-61459-RemovalTslib.rst
 create mode 100644 typo3/sysext/frontend/Classes/FrontendRequestHandler.php
 rename typo3/sysext/{cms/tslib/extdirecteid.php => frontend/Resources/PHP/Eid/ExtDirect.php} (100%)
 rename typo3/sysext/{cms/tslib/showpic.php => frontend/Resources/PHP/Eid/ShowPic.php} (100%)
 rename typo3/sysext/{cms/tslib/templates/tslib_page_frontend.html => frontend/Resources/Private/Templates/MainPage.html} (100%)

diff --git a/index.php b/index.php
index 1d52a83a1b7f..1a4da315ca99 100644
--- a/index.php
+++ b/index.php
@@ -16,13 +16,16 @@
  * This is the MAIN DOCUMENT of the TypoScript driven standard frontend.
  * Basically this is the "index.php" script which all requests for TYPO3
  * delivered pages goes to in the frontend (the website)
- *
- * @author René Fritz <r.fritz@colorcube.de>
  */
 
+define('TYPO3_MODE', 'FE');
+
 require __DIR__ . '/typo3/sysext/core/Classes/Core/Bootstrap.php';
 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
 	->baseSetup('')
-	->redirectToInstallerIfEssentialConfigurationDoesNotExist();
+	->redirectToInstallerIfEssentialConfigurationDoesNotExist()
+	->startOutputBuffering()
+	->loadConfigurationAndInitialize();
 
-require(PATH_tslib . 'index_ts.php');
+$frontendRequestHandler = new \TYPO3\CMS\Frontend\FrontendRequestHandler();
+$frontendRequestHandler->handleRequest();
diff --git a/typo3/sysext/cms/ext_localconf.php b/typo3/sysext/cms/ext_localconf.php
index 29c08f2d8b34..0da0a69e0a97 100644
--- a/typo3/sysext/cms/ext_localconf.php
+++ b/typo3/sysext/cms/ext_localconf.php
@@ -178,7 +178,6 @@ mod.wizards.newContentElement {
 
 ');
 
-$TYPO3_CONF_VARS['FE']['eID_include']['tx_cms_showpic'] = 'EXT:cms/tslib/showpic.php';
 
 if ((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
 	$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['compat_version']['cms'] = array(
@@ -193,12 +192,6 @@ $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapC
 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'TYPO3\\CMS\\Frontend\\Hooks\\TreelistCacheUpdateHooks';
 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'][] = 'TYPO3\\CMS\\Frontend\\Hooks\\TreelistCacheUpdateHooks';
 
-if (TYPO3_MODE === 'FE') {
-	// Register the core media wizard provider
-	\TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::registerMediaWizardProvider('TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProvider');
-	// Register eID provider for ExtDirect for the frontend
-	$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['ExtDirect'] = PATH_tslib . 'extdirecteid.php';
-}
 // Register search keys
 $GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch']['page'] = 'pages';
 $GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch']['content'] = 'tt_content';
diff --git a/typo3/sysext/cms/tslib/index_ts.php b/typo3/sysext/cms/tslib/index_ts.php
deleted file mode 100644
index cdf9fdffa3e1..000000000000
--- a/typo3/sysext/cms/tslib/index_ts.php
+++ /dev/null
@@ -1,288 +0,0 @@
-<?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!
- */
-
-/**
- * This is the MAIN DOCUMENT of the TypoScript driven standard front-end (from
- * the "cms" extension)
- *
- * Basically put this is the "index.php" script which all requests for TYPO3
- * delivered pages goes to in the frontend (the website) The script configures
- * constants, includes libraries and does a little logic here and there in order
- * to instantiate the right classes to create the webpage.
- *
- * All the real data processing goes on in the "tslib/" classes which this script
- * will include and use as needed.
- *
- * @author Kasper Skårhøj <kasperYYYY@typo3.com>
- */
-
-define('TYPO3_MODE', 'FE');
-
-\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
-	->startOutputBuffering()
-	->loadConfigurationAndInitialize()
-	->loadTypo3LoadedExtAndExtLocalconf(TRUE)
-	->applyAdditionalConfigurationSettings();
-
-// Timetracking started
-$configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
-if (empty($configuredCookieName)) {
-	$configuredCookieName = 'be_typo_user';
-}
-if ($_COOKIE[$configuredCookieName]) {
-	$TT = new \TYPO3\CMS\Core\TimeTracker\TimeTracker();
-} else {
-	$TT = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
-}
-
-$TT->start();
-
-\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeTypo3DbGlobal();
-// Hook to preprocess the current request:
-if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
-	foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
-		$hookParameters = array();
-		\TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
-	}
-	unset($hookFunction);
-	unset($hookParameters);
-}
-// Look for extension ID which will launch alternative output engine
-if ($temp_extId = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID')) {
-	if ($classPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
-		// Remove any output produced until now
-		ob_clean();
-		require $classPath;
-	}
-	die;
-}
-
-/** @var $TSFE \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
-$TSFE = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
-	'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
-	$TYPO3_CONF_VARS,
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'),
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type'),
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('no_cache'),
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cHash'),
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('jumpurl'),
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('MP'),
-	\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RDCT')
-);
-
-if ($TYPO3_CONF_VARS['FE']['pageUnavailable_force']
-	&& !\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(
-		\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'),
-		$TYPO3_CONF_VARS['SYS']['devIPmask'])
-) {
-	$TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
-}
-
-$TSFE->connectToDB();
-$TSFE->sendRedirect();
-
-// Output compression
-// Remove any output produced until now
-ob_clean();
-if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
-	if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
-		// Prevent errors if ini_set() is unavailable (safe mode)
-		@ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
-	}
-	ob_start(array(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Utility\\CompressionUtility'), 'compressionOutputHandler'));
-}
-
-// FE_USER
-$TT->push('Front End user initialized', '');
-/** @var $TSFE \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
-$TSFE->initFEuser();
-$TT->pull();
-
-// BE_USER
-/** @var $BE_USER \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
-$BE_USER = $TSFE->initializeBackendUser();
-
-// Process the ID, type and other parameters.
-// After this point we have an array, $page in TSFE, which is the page-record
-// of the current page, $id.
-$TT->push('Process ID', '');
-// Initialize admin panel since simulation settings are required here:
-if ($TSFE->isBackendUserLoggedIn()) {
-	$BE_USER->initializeAdminPanel();
-	\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(TRUE);
-} else {
-	\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadCachedTca();
-}
-$TSFE->checkAlternativeIdMethods();
-$TSFE->clear_preview();
-$TSFE->determineId();
-
-// Now, if there is a backend user logged in and he has NO access to this page,
-// then re-evaluate the id shown! _GP('ADMCMD_noBeUser') is placed here because
-// \TYPO3\CMS\Version\Hook\PreviewHook might need to know if a backend user is logged in.
-if (
-	$TSFE->isBackendUserLoggedIn()
-	&& (!$BE_USER->extPageReadAccess($TSFE->page) || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_noBeUser'))
-) {
-	// Remove user
-	unset($BE_USER);
-	$TSFE->beUserLogin = FALSE;
-	// Re-evaluate the page-id.
-	$TSFE->checkAlternativeIdMethods();
-	$TSFE->clear_preview();
-	$TSFE->determineId();
-}
-
-$TSFE->makeCacheHash();
-$TT->pull();
-
-// Admin Panel & Frontend editing
-if ($TSFE->isBackendUserLoggedIn()) {
-	$BE_USER->initializeFrontendEdit();
-	if ($BE_USER->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
-		\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
-			->initializeLanguageObject()
-			->initializeSpriteManager();
-	}
-	if ($BE_USER->frontendEdit instanceof \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController) {
-		$BE_USER->frontendEdit->initConfigOptions();
-	}
-}
-
-// Starts the template
-$TT->push('Start Template', '');
-$TSFE->initTemplate();
-$TT->pull();
-// Get from cache
-$TT->push('Get Page from cache', '');
-$TSFE->getFromCache();
-$TT->pull();
-// Get config if not already gotten
-// After this, we should have a valid config-array ready
-$TSFE->getConfigArray();
-// Setting language and locale
-$TT->push('Setting language and locale', '');
-$TSFE->settingLanguage();
-$TSFE->settingLocale();
-$TT->pull();
-
-// Convert POST data to internal "renderCharset" if different from the metaCharset
-$TSFE->convPOSTCharset();
-
-// Check JumpUrl
-$TSFE->setExternalJumpUrl();
-$TSFE->checkJumpUrlReferer();
-
-$TSFE->handleDataSubmission();
-
-// Check for shortcut page and redirect
-$TSFE->checkPageForShortcutRedirect();
-
-// Generate page
-$TSFE->setUrlIdToken();
-$TT->push('Page generation', '');
-if ($TSFE->isGeneratePage()) {
-	$TSFE->generatePage_preProcessing();
-	$temp_theScript = $TSFE->generatePage_whichScript();
-	if ($temp_theScript) {
-		include $temp_theScript;
-	} else {
-		\TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
-		// Global content object
-		$TSFE->newCObj();
-		// LIBRARY INCLUSION, TypoScript
-		$temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
-		foreach ($temp_incFiles as $temp_file) {
-			include_once './' . $temp_file;
-		}
-		// Content generation
-		if (!$TSFE->isINTincScript()) {
-			\TYPO3\CMS\Frontend\Page\PageGenerator::renderContent();
-			$TSFE->setAbsRefPrefix();
-		}
-	}
-	$TSFE->generatePage_postProcessing();
-} elseif ($TSFE->isINTincScript()) {
-	\TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
-	// Global content object
-	$TSFE->newCObj();
-	// LIBRARY INCLUSION, TypoScript
-	$temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
-	foreach ($temp_incFiles as $temp_file) {
-		include_once './' . $temp_file;
-	}
-}
-$TT->pull();
-
-// $TSFE->config['INTincScript']
-if ($TSFE->isINTincScript()) {
-	$TT->push('Non-cached objects', '');
-	$TSFE->INTincScript();
-	$TT->pull();
-}
-// Output content
-$sendTSFEContent = FALSE;
-if ($TSFE->isOutputting()) {
-	$TT->push('Print Content', '');
-	$TSFE->processOutput();
-	$sendTSFEContent = TRUE;
-	$TT->pull();
-}
-// Store session data for fe_users
-$TSFE->storeSessionData();
-// Statistics
-$TYPO3_MISC['microtime_end'] = microtime(TRUE);
-$TSFE->setParseTime();
-if (isset($TSFE->config['config']['debug'])) {
-	$debugParseTime = (bool)$TSFE->config['config']['debug'];
-} else {
-	$debugParseTime = !empty($TSFE->TYPO3_CONF_VARS['FE']['debug']);
-}
-if ($TSFE->isOutputting() && $debugParseTime) {
-	$TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
-}
-// Check JumpUrl
-$TSFE->jumpurl();
-// Preview info
-$TSFE->previewInfo();
-// Hook for end-of-frontend
-$TSFE->hook_eofe();
-// Finish timetracking
-$TT->pull();
-// Check memory usage
-\TYPO3\CMS\Core\Utility\MonitorUtility::peakMemoryUsage();
-// beLoginLinkIPList
-echo $TSFE->beLoginLinkIPList();
-
-// Admin panel
-if (
-	$TSFE->isBackendUserLoggedIn()
-	&& $BE_USER instanceof \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
-	&& $BE_USER->isAdminPanelVisible()
-) {
-	$TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
-	$TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
-}
-
-if ($sendTSFEContent) {
-	echo $TSFE->content;
-}
-// Debugging Output
-if (isset($error) && is_object($error) && @is_callable(array($error, 'debugOutput'))) {
-	$error->debugOutput();
-}
-if (TYPO3_DLOG) {
-	\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
-}
-\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->shutdown();
diff --git a/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php b/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
index 7f3da0c604f1..8da1c323e4d7 100644
--- a/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
+++ b/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
@@ -167,9 +167,6 @@ class SystemEnvironmentBuilder {
 		// Absolute path to the typo3conf directory with trailing slash
 		// Example "/var/www/instance-name/htdocs/typo3conf/"
 		define('PATH_typo3conf', PATH_site . 'typo3conf/');
-		// Absolute path to the tslib directory with trailing slash
-		// Example "/var/www/instance-name/htdocs/typo3/sysext/cms/tslib/"
-		define('PATH_tslib', PATH_typo3 . 'sysext/cms/tslib/');
 	}
 
 	/**
@@ -181,8 +178,8 @@ class SystemEnvironmentBuilder {
 		if (!is_file(PATH_thisScript)) {
 			die('Unable to determine path to entry script.');
 		}
-		if (!is_dir(PATH_tslib)) {
-			die('Calculated absolute path to tslib directory does not exist.');
+		if (!is_dir(PATH_typo3 . 'sysext')) {
+			die('Calculated absolute path to typo3/sysext directory does not exist.');
 		}
 	}
 
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-61459-RemovalTslib.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-61459-RemovalTslib.rst
new file mode 100644
index 000000000000..91e9271481c5
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-61459-RemovalTslib.rst
@@ -0,0 +1,31 @@
+===========================================================
+Breaking: #61459 - Removal of tslib directory and constant
+===========================================================
+
+Description
+===========
+
+The tslib/ directory and the constant PATH_tslib are removed.
+
+Impact
+======
+
+Extensions that still use PATH_tslib constant, and reference typo/sysext/cms/tslib/index_ts.php directly won't work.
+
+
+Affected installations
+======================
+
+A TYPO3 instance is affected if a 3rd party extension uses index_ts.php directly, or if the main index.php is not
+replaced with the TYPO3 Update (used on certain intallations). The index.php file must be replaced then with the
+current version from the TYPO3 CMS Core.
+
+Besides scripts are affected that access the time tracking ($TT) or typoscript frontend controller ($TSFE) objects without the
+$GLOBALS keyword.
+
+
+Migration
+=========
+
+Remove the constant PATH_tslib from the 3rd party extension, use a current version of index.php and use $GLOBALS['TT'] instead of
+$TT and/or $GLOBALS['TSFE'] instead of $TSFE to access the object.
\ No newline at end of file
diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index dce83dfb29f0..23b19cd58724 100644
--- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
@@ -1048,7 +1048,7 @@ class TypoScriptFrontendController {
 	public function getPageRenderer() {
 		if (!isset($this->pageRenderer)) {
 			$this->pageRenderer = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Page\\PageRenderer');
-			$this->pageRenderer->setTemplateFile(PATH_tslib . 'templates/tslib_page_frontend.html');
+			$this->pageRenderer->setTemplateFile('EXT:frontend/Resources/Private/Templates/MainPage.html');
 			$this->pageRenderer->setBackPath(TYPO3_mainDir);
 		}
 		return $this->pageRenderer;
diff --git a/typo3/sysext/frontend/Classes/FrontendRequestHandler.php b/typo3/sysext/frontend/Classes/FrontendRequestHandler.php
new file mode 100644
index 000000000000..78f53cb1091a
--- /dev/null
+++ b/typo3/sysext/frontend/Classes/FrontendRequestHandler.php
@@ -0,0 +1,288 @@
+<?php
+namespace TYPO3\CMS\Frontend;
+/**
+ * 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!
+ */
+
+/**
+ * This is the MAIN DOCUMENT of the TypoScript driven standard front-end
+ *
+ * Basically put this is the script which all requests for TYPO3
+ * delivered pages goes to in the frontend (the website). The script configures
+ * constants, includes libraries and does a little logic here and there in order
+ * to instantiate the right classes to create the webpage.
+ */
+class FrontendRequestHandler {
+
+	/**
+	 * Handles a frontend request
+	 *
+	 * @return void
+	 */
+	public function handleRequest() {
+		\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
+			->loadTypo3LoadedExtAndExtLocalconf(TRUE)
+			->applyAdditionalConfigurationSettings();
+
+		// Timetracking started
+		$configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
+		if (empty($configuredCookieName)) {
+			$configuredCookieName = 'be_typo_user';
+		}
+		if ($_COOKIE[$configuredCookieName]) {
+			$GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\TimeTracker();
+		} else {
+			$GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
+		}
+
+		$GLOBALS['TT']->start();
+
+		\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeTypo3DbGlobal();
+		// Hook to preprocess the current request:
+		if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
+			foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
+				$hookParameters = array();
+				\TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
+			}
+			unset($hookFunction);
+			unset($hookParameters);
+		}
+		// Look for extension ID which will launch alternative output engine
+		if ($temp_extId = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID')) {
+			if ($classPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$temp_extId])) {
+				// Remove any output produced until now
+				ob_clean();
+				require $classPath;
+			}
+			die;
+		}
+
+		/** @var $GLOBALS['TSFE'] \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
+		$GLOBALS['TSFE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+			'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
+			$GLOBALS['TYPO3_CONF_VARS'],
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'),
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type'),
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('no_cache'),
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cHash'),
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('jumpurl'),
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('MP'),
+			\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RDCT')
+		);
+
+		if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force']
+			&& !\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(
+				\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'),
+				$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])
+		) {
+			$GLOBALS['TSFE']->pageUnavailableAndExit('This page is temporarily unavailable.');
+		}
+
+		$GLOBALS['TSFE']->connectToDB();
+		$GLOBALS['TSFE']->sendRedirect();
+
+		// Output compression
+		// Remove any output produced until now
+		ob_clean();
+		if ($GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel'] && extension_loaded('zlib')) {
+			if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel'])) {
+				// Prevent errors if ini_set() is unavailable (safe mode)
+				@ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel']);
+			}
+			ob_start(array(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Utility\\CompressionUtility'), 'compressionOutputHandler'));
+		}
+
+		// FE_USER
+		$GLOBALS['TT']->push('Front End user initialized', '');
+		/** @var $GLOBALS['TSFE'] \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
+		$GLOBALS['TSFE']->initFEuser();
+		$GLOBALS['TT']->pull();
+
+		// BE_USER
+		/** @var $GLOBALS['BE_USER'] \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
+		$GLOBALS['BE_USER'] = $GLOBALS['TSFE']->initializeBackendUser();
+
+		// Process the ID, type and other parameters.
+		// After this point we have an array, $page in TSFE, which is the page-record
+		// of the current page, $id.
+		$GLOBALS['TT']->push('Process ID', '');
+		// Initialize admin panel since simulation settings are required here:
+		if ($GLOBALS['TSFE']->isBackendUserLoggedIn()) {
+			$GLOBALS['BE_USER']->initializeAdminPanel();
+			\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(TRUE);
+		} else {
+			\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadCachedTca();
+		}
+		$GLOBALS['TSFE']->checkAlternativeIdMethods();
+		$GLOBALS['TSFE']->clear_preview();
+		$GLOBALS['TSFE']->determineId();
+
+		// Now, if there is a backend user logged in and he has NO access to this page,
+		// then re-evaluate the id shown! _GP('ADMCMD_noBeUser') is placed here because
+		// \TYPO3\CMS\Version\Hook\PreviewHook might need to know if a backend user is logged in.
+		if (
+			$GLOBALS['TSFE']->isBackendUserLoggedIn()
+			&& (!$GLOBALS['BE_USER']->extPageReadAccess($GLOBALS['TSFE']->page) || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_noBeUser'))
+		) {
+			// Remove user
+			unset($GLOBALS['BE_USER']);
+			$GLOBALS['TSFE']->beUserLogin = FALSE;
+			// Re-evaluate the page-id.
+			$GLOBALS['TSFE']->checkAlternativeIdMethods();
+			$GLOBALS['TSFE']->clear_preview();
+			$GLOBALS['TSFE']->determineId();
+		}
+
+		$GLOBALS['TSFE']->makeCacheHash();
+		$GLOBALS['TT']->pull();
+
+		// Admin Panel & Frontend editing
+		if ($GLOBALS['TSFE']->isBackendUserLoggedIn()) {
+			$GLOBALS['BE_USER']->initializeFrontendEdit();
+			if ($GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
+				\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
+					->initializeLanguageObject()
+					->initializeSpriteManager();
+			}
+			if ($GLOBALS['BE_USER']->frontendEdit instanceof \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController) {
+				$GLOBALS['BE_USER']->frontendEdit->initConfigOptions();
+			}
+		}
+
+		// Starts the template
+		$GLOBALS['TT']->push('Start Template', '');
+		$GLOBALS['TSFE']->initTemplate();
+		$GLOBALS['TT']->pull();
+		// Get from cache
+		$GLOBALS['TT']->push('Get Page from cache', '');
+		$GLOBALS['TSFE']->getFromCache();
+		$GLOBALS['TT']->pull();
+		// Get config if not already gotten
+		// After this, we should have a valid config-array ready
+		$GLOBALS['TSFE']->getConfigArray();
+		// Setting language and locale
+		$GLOBALS['TT']->push('Setting language and locale', '');
+		$GLOBALS['TSFE']->settingLanguage();
+		$GLOBALS['TSFE']->settingLocale();
+		$GLOBALS['TT']->pull();
+
+		// Convert POST data to internal "renderCharset" if different from the metaCharset
+		$GLOBALS['TSFE']->convPOSTCharset();
+
+		// Check JumpUrl
+		$GLOBALS['TSFE']->setExternalJumpUrl();
+		$GLOBALS['TSFE']->checkJumpUrlReferer();
+
+		$GLOBALS['TSFE']->handleDataSubmission();
+
+		// Check for shortcut page and redirect
+		$GLOBALS['TSFE']->checkPageForShortcutRedirect();
+
+		// Generate page
+		$GLOBALS['TSFE']->setUrlIdToken();
+		$GLOBALS['TT']->push('Page generation', '');
+		if ($GLOBALS['TSFE']->isGeneratePage()) {
+			$GLOBALS['TSFE']->generatePage_preProcessing();
+			$temp_theScript = $GLOBALS['TSFE']->generatePage_whichScript();
+			if ($temp_theScript) {
+				include $temp_theScript;
+			} else {
+				\TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
+				// Global content object
+				$GLOBALS['TSFE']->newCObj();
+				// LIBRARY INCLUSION, TypoScript
+				$temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
+				foreach ($temp_incFiles as $temp_file) {
+					include_once './' . $temp_file;
+				}
+				// Content generation
+				if (!$GLOBALS['TSFE']->isINTincScript()) {
+					\TYPO3\CMS\Frontend\Page\PageGenerator::renderContent();
+					$GLOBALS['TSFE']->setAbsRefPrefix();
+				}
+			}
+			$GLOBALS['TSFE']->generatePage_postProcessing();
+		} elseif ($GLOBALS['TSFE']->isINTincScript()) {
+			\TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
+			// Global content object
+			$GLOBALS['TSFE']->newCObj();
+			// LIBRARY INCLUSION, TypoScript
+			$temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
+			foreach ($temp_incFiles as $temp_file) {
+				include_once './' . $temp_file;
+			}
+		}
+		$GLOBALS['TT']->pull();
+
+		// $GLOBALS['TSFE']->config['INTincScript']
+		if ($GLOBALS['TSFE']->isINTincScript()) {
+			$GLOBALS['TT']->push('Non-cached objects', '');
+			$GLOBALS['TSFE']->INTincScript();
+			$GLOBALS['TT']->pull();
+		}
+		// Output content
+		$sendTSFEContent = FALSE;
+		if ($GLOBALS['TSFE']->isOutputting()) {
+			$GLOBALS['TT']->push('Print Content', '');
+			$GLOBALS['TSFE']->processOutput();
+			$sendTSFEContent = TRUE;
+			$GLOBALS['TT']->pull();
+		}
+		// Store session data for fe_users
+		$GLOBALS['TSFE']->storeSessionData();
+		// Statistics
+		$GLOBALS['TYPO3_MISC']['microtime_end'] = microtime(TRUE);
+		$GLOBALS['TSFE']->setParseTime();
+		if (isset($GLOBALS['TSFE']->config['config']['debug'])) {
+			$debugParseTime = (bool)$GLOBALS['TSFE']->config['config']['debug'];
+		} else {
+			$debugParseTime = !empty($GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['debug']);
+		}
+		if ($GLOBALS['TSFE']->isOutputting() && $debugParseTime) {
+			$GLOBALS['TSFE']->content .= LF . '<!-- Parsetime: ' . $GLOBALS['TSFE']->scriptParseTime . 'ms -->';
+		}
+		// Check JumpUrl
+		$GLOBALS['TSFE']->jumpurl();
+		// Preview info
+		$GLOBALS['TSFE']->previewInfo();
+		// Hook for end-of-frontend
+		$GLOBALS['TSFE']->hook_eofe();
+		// Finish timetracking
+		$GLOBALS['TT']->pull();
+		// Check memory usage
+		\TYPO3\CMS\Core\Utility\MonitorUtility::peakMemoryUsage();
+		// beLoginLinkIPList
+		echo $GLOBALS['TSFE']->beLoginLinkIPList();
+
+		// Admin panel
+		if (
+			$GLOBALS['TSFE']->isBackendUserLoggedIn()
+			&& $GLOBALS['BE_USER'] instanceof \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
+			&& $GLOBALS['BE_USER']->isAdminPanelVisible()
+		) {
+			$GLOBALS['TSFE']->content = str_ireplace('</head>', $GLOBALS['BE_USER']->adminPanel->getAdminPanelHeaderData() . '</head>', $GLOBALS['TSFE']->content);
+			$GLOBALS['TSFE']->content = str_ireplace('</body>', $GLOBALS['BE_USER']->displayAdminPanel() . '</body>', $GLOBALS['TSFE']->content);
+		}
+
+		if ($sendTSFEContent) {
+			echo $GLOBALS['TSFE']->content;
+		}
+		// Debugging Output
+		if (isset($GLOBALS['error']) && is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'], 'debugOutput'))) {
+			$GLOBALS['error']->debugOutput();
+		}
+		if (TYPO3_DLOG) {
+			\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
+		}
+		\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->shutdown();
+	}
+}
\ No newline at end of file
diff --git a/typo3/sysext/cms/tslib/extdirecteid.php b/typo3/sysext/frontend/Resources/PHP/Eid/ExtDirect.php
similarity index 100%
rename from typo3/sysext/cms/tslib/extdirecteid.php
rename to typo3/sysext/frontend/Resources/PHP/Eid/ExtDirect.php
diff --git a/typo3/sysext/cms/tslib/showpic.php b/typo3/sysext/frontend/Resources/PHP/Eid/ShowPic.php
similarity index 100%
rename from typo3/sysext/cms/tslib/showpic.php
rename to typo3/sysext/frontend/Resources/PHP/Eid/ShowPic.php
diff --git a/typo3/sysext/cms/tslib/templates/tslib_page_frontend.html b/typo3/sysext/frontend/Resources/Private/Templates/MainPage.html
similarity index 100%
rename from typo3/sysext/cms/tslib/templates/tslib_page_frontend.html
rename to typo3/sysext/frontend/Resources/Private/Templates/MainPage.html
diff --git a/typo3/sysext/frontend/ext_localconf.php b/typo3/sysext/frontend/ext_localconf.php
index 5b0a27f7ccee..99d9ba52dbbf 100644
--- a/typo3/sysext/frontend/ext_localconf.php
+++ b/typo3/sysext/frontend/ext_localconf.php
@@ -16,3 +16,15 @@ if (TYPO3_MODE === 'FE' && !isset($_REQUEST['eID'])) {
 	'config.extTarget = _top'
 	. LF . 'config.uniqueLinkVars = 1'
 );
+
+
+if (TYPO3_MODE === 'FE') {
+
+	// Register eID provider for showpic
+	$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['tx_cms_showpic'] = 'EXT:frontend/Resources/PHP/Eid/ShowPic.php';
+	// Register eID provider for ExtDirect for the frontend
+	$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['ExtDirect'] = 'EXT:frontend/Resources/PHP/Eid/ExtDirect.php';
+
+	// Register the core media wizard provider
+	\TYPO3\CMS\Frontend\MediaWizard\MediaWizardProviderManager::registerMediaWizardProvider('TYPO3\\CMS\\Frontend\\MediaWizard\\MediaWizardProvider');
+}
diff --git a/typo3/sysext/indexed_search/Classes/Controller/SearchController.php b/typo3/sysext/indexed_search/Classes/Controller/SearchController.php
index 27d6e0e356f2..3b54a87a4014 100644
--- a/typo3/sysext/indexed_search/Classes/Controller/SearchController.php
+++ b/typo3/sysext/indexed_search/Classes/Controller/SearchController.php
@@ -492,20 +492,6 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
 				$cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
 				$cObj->setCurrentVal($row['sys_language_uid']);
 				$output = $cObj->cObjGetSingle($this->settings['flagRendering'], $this->settings['flagRendering.']);
-			} else {
-				// ... otherwise, get flag from sys_language record:
-				$languageRow = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('flag, title', 'sys_language', 'uid=' . (int)$row['sys_language_uid'] . $GLOBALS['TSFE']->cObj->enableFields('sys_language'));
-				// Flag code:
-				$flag = $languageRow['flag'];
-				if ($flag) {
-					// FIXME not all flags from typo3/gfx/flags
-					// are available in media/flags/
-					$file = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(PATH_tslib) . 'media/flags/flag_' . $flag;
-					$imgInfo = @getimagesize((PATH_site . $file));
-					if (is_array($imgInfo)) {
-						$output = '<img src="' . $file . '" ' . $imgInfo[3] . ' title="' . htmlspecialchars($languageRow['title']) . '" alt="' . htmlspecialchars($languageRow['title']) . '" />';
-					}
-				}
 			}
 		}
 		return $output;
diff --git a/typo3/sysext/indexed_search/Classes/Controller/SearchFormController.php b/typo3/sysext/indexed_search/Classes/Controller/SearchFormController.php
index d0c64f7cdad3..ade0eb017360 100644
--- a/typo3/sysext/indexed_search/Classes/Controller/SearchFormController.php
+++ b/typo3/sysext/indexed_search/Classes/Controller/SearchFormController.php
@@ -2085,21 +2085,6 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
 			if (is_array($this->conf['flagRendering.'])) {
 				$this->cObj->setCurrentVal($row['sys_language_uid']);
 				return $this->cObj->cObjGetSingle($this->conf['flagRendering'], $this->conf['flagRendering.']);
-			} else {
-				// ... otherwise, get flag from sys_language record:
-				// Get sys_language record
-				$rowDat = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_language', 'uid=' . (int)$row['sys_language_uid'] . ' ' . $this->cObj->enableFields('sys_language'));
-				// Flag code:
-				$flag = $rowDat['flag'];
-				if ($flag) {
-					// FIXME not all flags from typo3/gfx/flags are available in media/flags/
-					$file = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(PATH_tslib) . 'media/flags/flag_' . $flag;
-					$imgInfo = @getimagesize((PATH_site . $file));
-					if (is_array($imgInfo)) {
-						$output = '<img src="' . $file . '" ' . $imgInfo[3] . ' title="' . htmlspecialchars($rowDat['title']) . '" alt="' . htmlspecialchars($rowDat['title']) . '" />';
-						return $output;
-					}
-				}
 			}
 		}
 		return '&nbsp;';
-- 
GitLab