Commit b52f67b6 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Benni Mack

[TASK] Fetch route from request instead of GET parameter

The "route" GET parameter is deprecated since #93048.
Therefore the route path has now to be fetched from the
request object instead.

This patch replaces all places in core where the route
is still fetched via GET. It's currently often necessary
to access $GLOBALS['TYPO3_REQUEST'] therefore, since the
request object is not always present at those places. This
will be tackeled in upcoming patches.

Resolves: #93158
Releases: master
Change-Id: I6e163919b19484171b6ebf8087fdc650cf977c9c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67355Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent f179a57f
......@@ -266,12 +266,9 @@ abstract class AbstractTreeView
*/
protected function determineScriptUrl()
{
if ($routePath = GeneralUtility::_GP('route')) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$this->thisScript = (string)$uriBuilder->buildUriFromRoutePath($routePath);
} else {
$this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
}
$this->thisScript = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoutePath(
$GLOBALS['TYPO3_REQUEST']->getAttribute('route')->getPath()
);
}
/**
......
......@@ -15,8 +15,10 @@
namespace TYPO3\CMS\Backend\Utility;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher;
use TYPO3\CMS\Backend\Routing\Route;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
......@@ -2578,6 +2580,7 @@ class BackendUtility
* @param string $addParams Additional parameters to pass to the script.
* @param string $script The script to send the &id to, if empty it's automatically found
* @return string The complete script URL
* @todo Check if this can be removed or replaced by routing
*/
protected static function buildScriptUrl($mainParams, $addParams, $script = '')
{
......@@ -2588,9 +2591,11 @@ class BackendUtility
$script = PathUtility::basename(Environment::getCurrentScript());
}
if ($routePath = GeneralUtility::_GP('route')) {
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ($route = $GLOBALS['TYPO3_REQUEST']->getAttribute('route')) instanceof Route
) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$scriptUrl = (string)$uriBuilder->buildUriFromRoutePath($routePath, $mainParams);
$scriptUrl = (string)$uriBuilder->buildUriFromRoutePath($route->getPath(), $mainParams);
$scriptUrl .= $addParams;
} else {
$scriptUrl = $script . HttpUtility::buildQueryString($mainParams, '?') . $addParams;
......
......@@ -16,6 +16,7 @@
namespace TYPO3\CMS\Beuser\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Authentication\Event\SwitchUserEvent;
use TYPO3\CMS\Backend\Authentication\PasswordReset;
use TYPO3\CMS\Backend\Routing\UriBuilder;
......@@ -126,7 +127,7 @@ class BackendUserController extends ActionController
{
$view->assignMultiple([
'shortcutLabel' => 'backendUsers',
'route' => GeneralUtility::_GP('route'),
'route' => $this->getRequest()->getAttribute('route')->getPath(),
'action' => $this->request->getControllerActionName(),
'controller' => $this->request->getControllerName(),
'dateFormat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],
......@@ -265,7 +266,7 @@ class BackendUserController extends ActionController
);
} else {
GeneralUtility::makeInstance(PasswordReset::class)->initiateReset(
$GLOBALS['TYPO3_REQUEST'],
$this->getRequest(),
$context,
$user->getEmail()
);
......@@ -416,6 +417,14 @@ class BackendUserController extends ActionController
return $GLOBALS['BE_USER'];
}
/**
* @return ServerRequestInterface
*/
protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
/**
* Create an array with the uids of online users as the keys
* [
......
......@@ -16,12 +16,12 @@
namespace TYPO3\CMS\Beuser\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup;
use TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository;
use TYPO3\CMS\Beuser\Service\UserInformationService;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
......@@ -73,7 +73,7 @@ class BackendUserGroupController extends ActionController
'paginator' => $paginator,
'pagination' => $pagination,
'totalAmountOfBackendUserGroups' => $backendUsers->count(),
'route' => GeneralUtility::_GP('route'),
'route' => $this->getRequest()->getAttribute('route')->getPath(),
'action' => $this->request->getControllerActionName(),
'controller' => $this->request->getControllerName(),
'compareGroupUidList' => array_map(static function ($value) { // uid as key and force value to 1
......@@ -102,7 +102,7 @@ class BackendUserGroupController extends ActionController
$this->view->assignMultiple([
'shortcutLabel' => 'compareBackendUsersGroups',
'route' => GeneralUtility::_GP('route'),
'route' => $this->getRequest()->getAttribute('route')->getPath(),
'action' => $this->request->getControllerActionName(),
'controller' => $this->request->getControllerName(),
'compareGroupList' => $compareData,
......@@ -160,4 +160,12 @@ class BackendUserGroupController extends ActionController
{
return $GLOBALS['BE_USER'];
}
/**
* @return ServerRequestInterface
*/
protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
......@@ -17,8 +17,10 @@ declare(strict_types=1);
namespace TYPO3\CMS\Extbase\Mvc\Web\Routing;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Exception\ResourceNotFoundException;
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Backend\Routing\Route;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
......@@ -650,13 +652,15 @@ class UriBuilder
}
} else {
$id = GeneralUtility::_GP('id');
$route = GeneralUtility::_GP('route');
if ($id !== null) {
$arguments['id'] = $id;
}
if ($route !== null) {
$arguments['route'] = $route;
}
}
// @todo Should be replaced as soon as we have a PSR-7 object here
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ($route = $GLOBALS['TYPO3_REQUEST']->getAttribute('route')) instanceof Route
) {
$arguments['route'] = $route->getPath();
}
ArrayUtility::mergeRecursiveWithOverrule($arguments, $this->arguments);
$arguments = $this->convertDomainObjectsToIdentityArrays($arguments);
......
......@@ -17,8 +17,11 @@ declare(strict_types=1);
namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Web\Routing;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Route;
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
......@@ -205,7 +208,7 @@ class UriBuilderTest extends UnitTestCase
*/
public function buildBackendUriKeepsQueryParametersIfAddQueryStringIsSet()
{
$_GET['route'] = '/test/Path';
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute();
$_GET['id'] = 'pageId';
$_GET['foo'] = 'bar';
$_POST = [];
......@@ -215,6 +218,20 @@ class UriBuilderTest extends UnitTestCase
self::assertEquals($expectedResult, $actualResult);
}
/**
* @test
*/
public function buildBackendUriRouteAttributeOverrulesGetParameterIfAddQueryStringIsSet(): void
{
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute('test/Path2');
$_GET = ['route' => 'test/Path', 'id' => 'pageId', 'foo' => 'bar'];
$_POST = [];
$this->uriBuilder->setAddQueryString(true);
$expectedResult = '/typo3/test/Path2?token=dummyToken&id=pageId&foo=bar';
$actualResult = $this->uriBuilder->buildBackendUri();
self::assertEquals($expectedResult, $actualResult);
}
/**
* return array
*/
......@@ -301,7 +318,8 @@ class UriBuilderTest extends UnitTestCase
*/
public function buildBackendUriKeepsModuleQueryParametersIfAddQueryStringIsNotSet()
{
$_GET = (['route' => '/test/Path', 'id' => 'pageId', 'foo' => 'bar']);
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute();
$_GET = (['id' => 'pageId', 'foo' => 'bar']);
$expectedResult = '/typo3/test/Path?token=dummyToken&id=pageId';
$actualResult = $this->uriBuilder->buildBackendUri();
self::assertEquals($expectedResult, $actualResult);
......@@ -312,7 +330,8 @@ class UriBuilderTest extends UnitTestCase
*/
public function buildBackendUriMergesAndOverrulesQueryParametersWithArguments()
{
$_GET = ['route' => '/test/Path', 'id' => 'pageId', 'foo' => 'bar'];
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute();
$_GET = ['id' => 'pageId', 'foo' => 'bar'];
$this->uriBuilder->setArguments(['route' => '/test/Path2', 'somePrefix' => ['bar' => 'baz']]);
$expectedResult = '/typo3/test/Path2?token=dummyToken&id=pageId&somePrefix%5Bbar%5D=baz';
$actualResult = $this->uriBuilder->buildBackendUri();
......@@ -324,7 +343,7 @@ class UriBuilderTest extends UnitTestCase
*/
public function buildBackendUriConvertsDomainObjectsAfterArgumentsHaveBeenMerged()
{
$_GET['route'] = '/test/Path';
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute();
$mockDomainObject = $this->getAccessibleMock(AbstractEntity::class, ['dummy']);
$mockDomainObject->_set('uid', '123');
$this->uriBuilder->setArguments(['somePrefix' => ['someDomainObject' => $mockDomainObject]]);
......@@ -338,7 +357,7 @@ class UriBuilderTest extends UnitTestCase
*/
public function buildBackendUriRespectsSection()
{
$_GET['route'] = '/test/Path';
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute();
$this->uriBuilder->setSection('someSection');
$expectedResult = '/typo3/test/Path?token=dummyToken#someSection';
$actualResult = $this->uriBuilder->buildBackendUri();
......@@ -350,7 +369,7 @@ class UriBuilderTest extends UnitTestCase
*/
public function buildBackendUriCreatesAbsoluteUrisIfSpecified()
{
$_GET['route'] = '/test/Path';
$GLOBALS['TYPO3_REQUEST'] = $this->getRequestWithRouteAttribute();
$_SERVER['HTTP_HOST'] = 'baseuri';
$_SERVER['SCRIPT_NAME'] = '/typo3/index.php';
$_SERVER['ORIG_SCRIPT_NAME'] = '/typo3/index.php';
......@@ -859,4 +878,9 @@ class UriBuilderTest extends UnitTestCase
$result = $this->uriBuilder->_call('convertIteratorToArray', $iterator);
self::assertTrue(is_array($result));
}
protected function getRequestWithRouteAttribute(string $path = '/test/Path'): ServerRequestInterface
{
return (new ServerRequest(new Uri('')))->withAttribute('route', new Route($path, []));
}
}
......@@ -15,11 +15,16 @@
namespace TYPO3\CMS\Impexp\Tests\Functional;
use TYPO3\CMS\Backend\Routing\Route;
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Tree\View\PageTreeView;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Impexp\Export;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
......@@ -83,6 +88,10 @@ abstract class AbstractImportExportTestCase extends FunctionalTestCase
protected function setPageTree(Export $export, $pidToStart, $depth = 1)
{
$permsClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
GeneralUtility::makeInstance(Router::class)->addRoute('module_key', new Route('/some/Path', []));
$GLOBALS['TYPO3_REQUEST'] = (new ServerRequest(new Uri()))
->withAttribute('route', new Route('/some/Path', []))
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
$tree = GeneralUtility::makeInstance(PageTreeView::class);
$tree->init('AND ' . $permsClause);
......
......@@ -19,7 +19,6 @@ namespace TYPO3\CMS\Lowlevel\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\View\ArrayBrowser;
......@@ -83,8 +82,7 @@ class ConfigurationController
$moduleState['regexSearch'] = (bool)($postValues['regexSearch'] ?? $moduleState['regexSearch'] ?? false);
// Prepare array renderer class, apply search and expand / collapse states
$route = GeneralUtility::makeInstance(Router::class)->match(GeneralUtility::_GP('route'));
$arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class, $route);
$arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class, $request->getAttribute('route'));
$arrayBrowser->regexMode = $moduleState['regexSearch'];
$node = $queryParams['node'];
if ($searchString) {
......
......@@ -101,12 +101,9 @@ abstract class AbstractElementBrowser
*/
protected function determineScriptUrl()
{
if ($routePath = GeneralUtility::_GP('route')) {
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$this->thisScript = (string)$uriBuilder->buildUriFromRoutePath($routePath);
} else {
$this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
}
$this->thisScript = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoutePath(
$GLOBALS['TYPO3_REQUEST']->getAttribute('route')->getPath()
);
}
protected function initVariables()
......
......@@ -46,7 +46,6 @@ use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\CsvUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
use TYPO3\CMS\Fluid\View\StandaloneView;
......@@ -3162,14 +3161,10 @@ class DatabaseRecordList
$urlParameters['sortRev'] = $this->sortRev;
}
$urlParameters = array_merge_recursive($urlParameters, $this->overrideUrlParameters);
if ($routePath = GeneralUtility::_GP('route')) {
$url = (string)$this->uriBuilder->buildUriFromRoutePath($routePath, $urlParameters);
} else {
$url = GeneralUtility::getIndpEnv('SCRIPT_NAME') . HttpUtility::buildQueryString($urlParameters, '?');
}
return $url;
return (string)$this->uriBuilder->buildUriFromRoutePath(
$GLOBALS['TYPO3_REQUEST']->getAttribute('route')->getPath(),
array_merge_recursive($urlParameters, $this->overrideUrlParameters)
);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment