Commit 9d7e4758 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Reduce usages of GeneralUtility::linkThisScript and use proper routing

This change replaces some of the linkThisScript calls
to use the UriBuilder / Routing of TYPO3 Backend,
and corrects existing UriBuilder calls.

Resolves: #94663
Releases: master
Change-Id: If2dcb7c4f57b7357087eb88b7383576f3aaede1b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69916

Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent bcda6a33
...@@ -1308,7 +1308,7 @@ class EditDocumentController ...@@ -1308,7 +1308,7 @@ class EditDocumentController
$this->registerHistoryButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 1); $this->registerHistoryButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 1);
} }
$this->registerOpenInNewWindowButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 2); $this->registerOpenInNewWindowButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 2, $request);
$this->registerShortcutButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 3, $request); $this->registerShortcutButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 3, $request);
$this->registerCshButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 4); $this->registerCshButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 4);
} }
...@@ -1757,13 +1757,14 @@ class EditDocumentController ...@@ -1757,13 +1757,14 @@ class EditDocumentController
* @param string $position * @param string $position
* @param int $group * @param int $group
*/ */
protected function registerOpenInNewWindowButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group) protected function registerOpenInNewWindowButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group, ServerRequestInterface $request)
{ {
$closeUrl = $this->getCloseUrl(); $closeUrl = $this->getCloseUrl();
if ($this->returnUrl !== $closeUrl) { if ($this->returnUrl !== $closeUrl) {
$requestUri = GeneralUtility::linkThisScript([ // Generate a URL to the current edit form
'returnUrl' => $closeUrl, $arguments = $this->getUrlQueryParamsForCurrentRequest($request);
]); $arguments['returnUrl'] = $closeUrl;
$requestUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $arguments);
$openInNewWindowButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar() $openInNewWindowButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()
->makeLinkButton() ->makeLinkButton()
->setHref('#') ->setHref('#')
...@@ -1793,21 +1794,7 @@ class EditDocumentController ...@@ -1793,21 +1794,7 @@ class EditDocumentController
protected function registerShortcutButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group, ServerRequestInterface $request) protected function registerShortcutButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group, ServerRequestInterface $request)
{ {
if ($this->returnUrl !== $this->getCloseUrl()) { if ($this->returnUrl !== $this->getCloseUrl()) {
$queryParams = $request->getQueryParams(); $arguments = $this->getUrlQueryParamsForCurrentRequest($request);
$potentialArguments = [
'edit',
'defVals',
'overrideVals',
'columnsOnly',
'returnNewPageId',
'noView'
];
$arguments = [];
foreach ($potentialArguments as $argument) {
if (!empty($queryParams[$argument])) {
$arguments[$argument] = $queryParams[$argument];
}
}
$shortCutButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton(); $shortCutButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton();
$shortCutButton $shortCutButton
->setRouteIdentifier('record_edit') ->setRouteIdentifier('record_edit')
...@@ -1817,6 +1804,26 @@ class EditDocumentController ...@@ -1817,6 +1804,26 @@ class EditDocumentController
} }
} }
protected function getUrlQueryParamsForCurrentRequest(ServerRequestInterface $request): array
{
$queryParams = $request->getQueryParams();
$potentialArguments = [
'edit',
'defVals',
'overrideVals',
'columnsOnly',
'returnNewPageId',
'noView'
];
$arguments = [];
foreach ($potentialArguments as $argument) {
if (!empty($queryParams[$argument])) {
$arguments[$argument] = $queryParams[$argument];
}
}
return $arguments;
}
/** /**
* Register the CSH button to the button bar * Register the CSH button to the button bar
* *
......
...@@ -339,8 +339,9 @@ class NewRecordController ...@@ -339,8 +339,9 @@ class NewRecordController
// New page // New page
if ($this->isRecordCreationAllowedForTable('pages')) { if ($this->isRecordCreationAllowedForTable('pages')) {
$newPageButton = $buttonBar->makeLinkButton() $newPageButton = $buttonBar->makeLinkButton()
->setHref(GeneralUtility::linkThisScript(['pagesOnly' => '1'])) ->setHref($this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'pagesOnly' => 1, 'returnUrl' => $this->returnUrl]))
->setTitle($lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage')) ->setTitle($lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage'))
->setShowLabelText(true)
->setIcon($this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)); ->setIcon($this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL));
$buttonBar->addButton($newPageButton, ButtonBar::BUTTON_POSITION_LEFT, 20); $buttonBar->addButton($newPageButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
} }
...@@ -359,6 +360,7 @@ class NewRecordController ...@@ -359,6 +360,7 @@ class NewRecordController
$returnButton = $buttonBar->makeLinkButton() $returnButton = $buttonBar->makeLinkButton()
->setHref($this->returnUrl) ->setHref($this->returnUrl)
->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack')) ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
->setShowLabelText(true)
->setIcon($this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); ->setIcon($this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
$buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 10); $buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
} }
...@@ -505,7 +507,7 @@ class NewRecordController ...@@ -505,7 +507,7 @@ class NewRecordController
// New pages at selection position // New pages at selection position
if ($this->newPagesSelectPosition && $this->isRecordCreationAllowedForTable('pages')) { if ($this->newPagesSelectPosition && $this->isRecordCreationAllowedForTable('pages')) {
// Link to page-wizard: // Link to page-wizard:
$newPageLinks[] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['pagesOnly' => 1])) . '">' . $pageIcon . htmlspecialchars($lang->getLL('pageSelectPosition')) . '</a>'; $newPageLinks[] = '<a href="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'pagesOnly' => 1, 'returnUrl' => $this->returnUrl])) . '">' . $pageIcon . htmlspecialchars($lang->getLL('pageSelectPosition')) . '</a>';
} }
// Assemble all new page links // Assemble all new page links
$numPageLinks = count($newPageLinks); $numPageLinks = count($newPageLinks);
......
...@@ -324,7 +324,7 @@ class PageLayoutController ...@@ -324,7 +324,7 @@ class PageLayoutController
$menuItem = $actionMenu $menuItem = $actionMenu
->makeMenuItem() ->makeMenuItem()
->setTitle($action) ->setTitle($action)
->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key); ->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id, 'SET' => ['function' => $key]]));
if (!$foundDefaultKey) { if (!$foundDefaultKey) {
$defaultKey = $key; $defaultKey = $key;
...@@ -405,9 +405,9 @@ class PageLayoutController ...@@ -405,9 +405,9 @@ class PageLayoutController
} }
$message = htmlspecialchars($message); $message = htmlspecialchars($message);
if ($targetPage !== [] && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) { if ($targetPage !== [] && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
$linkToPid = GeneralUtility::linkThisScript(['id' => $targetPage['uid']]); $linkToPid = $this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $targetPage['id']]);
$path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000); $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
$linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>'; $linkedPath = '<a href="' . htmlspecialchars((string)$linkToPid) . '">' . htmlspecialchars($path) . '</a>';
$message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath); $message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath);
$message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', (string)$shortcutMode))) . ')'; $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', (string)$shortcutMode))) . ')';
$state = InfoboxViewHelper::STATE_INFO; $state = InfoboxViewHelper::STATE_INFO;
...@@ -448,9 +448,9 @@ class PageLayoutController ...@@ -448,9 +448,9 @@ class PageLayoutController
// If content from different pid is displayed // If content from different pid is displayed
if ($this->pageinfo['content_from_pid']) { if ($this->pageinfo['content_from_pid']) {
$contentPage = (array)BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']); $contentPage = (array)BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
$linkToPid = GeneralUtility::linkThisScript(['id' => $this->pageinfo['content_from_pid']]); $linkToPid = $this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->pageinfo['content_from_pid']]);
$title = BackendUtility::getRecordTitle('pages', $contentPage); $title = BackendUtility::getRecordTitle('pages', $contentPage);
$link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>'; $link = '<a href="' . htmlspecialchars((string)$linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
$message = sprintf($lang->getLL('content_from_pid_title'), $link); $message = sprintf($lang->getLL('content_from_pid_title'), $link);
$view->assignMultiple([ $view->assignMultiple([
'title' => $title, 'title' => $title,
...@@ -493,9 +493,9 @@ class PageLayoutController ...@@ -493,9 +493,9 @@ class PageLayoutController
$rows = $queryBuilder->execute()->fetchAllAssociative(); $rows = $queryBuilder->execute()->fetchAllAssociative();
if (!empty($rows)) { if (!empty($rows)) {
foreach ($rows as $row) { foreach ($rows as $row) {
$linkToPid = GeneralUtility::linkThisScript(['id' => $row['uid']]); $linkToPid = $this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $row['uid']]);
$title = BackendUtility::getRecordTitle('pages', $row); $title = BackendUtility::getRecordTitle('pages', $row);
$link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>'; $link = '<a href="' . htmlspecialchars((string)$linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
$links[] = $link; $links[] = $link;
} }
} }
...@@ -1016,7 +1016,7 @@ class PageLayoutController ...@@ -1016,7 +1016,7 @@ class PageLayoutController
$menuItem = $languageMenu $menuItem = $languageMenu
->makeMenuItem() ->makeMenuItem()
->setTitle($language) ->setTitle($language)
->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key); ->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id, 'SET' => ['language' => $key]]));
if ((int)$this->current_sys_language === $key) { if ((int)$this->current_sys_language === $key) {
$menuItem->setActive(true); $menuItem->setActive(true);
} }
......
...@@ -363,7 +363,7 @@ class InfoPageTyposcriptConfigController ...@@ -363,7 +363,7 @@ class InfoPageTyposcriptConfigController
$line = []; $line = [];
$line['padding'] = ($pageDepth * 20) + 10; $line['padding'] = ($pageDepth * 20) + 10;
if (isset($pageArray[$identifier . '_'])) { if (isset($pageArray[$identifier . '_'])) {
$line['link'] = GeneralUtility::linkThisScript(['id' => $identifier]); $line['link'] = $this->uriBuilder->buildUriFromRoute('web_info', ['id' => $identifier]);
$line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render(); $line['icon'] = $this->iconFactory->getIconForRecord('pages', BackendUtility::getRecordWSOL('pages', $identifier), Icon::SIZE_SMALL)->render();
$line['title'] = 'ID: ' . $identifier; $line['title'] = 'ID: ' . $identifier;
$line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30); $line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
......
...@@ -304,7 +304,7 @@ class DatabaseIntegrityController ...@@ -304,7 +304,7 @@ class DatabaseIntegrityController
$modules = []; $modules = [];
$availableModFuncs = ['records', 'relations', 'search', 'refindex']; $availableModFuncs = ['records', 'relations', 'search', 'refindex'];
foreach ($availableModFuncs as $modFunc) { foreach ($availableModFuncs as $modFunc) {
$modules[$modFunc] = (string)$this->uriBuilder->buildUriFromRoute('system_dbint') . '&SET[function]=' . $modFunc; $modules[$modFunc] = (string)$this->uriBuilder->buildUriFromRoute('system_dbint', ['SET' => ['function' => $modFunc]]);
} }
$this->view->assign('availableFunctions', $modules); $this->view->assign('availableFunctions', $modules);
} }
...@@ -458,7 +458,7 @@ class DatabaseIntegrityController ...@@ -458,7 +458,7 @@ class DatabaseIntegrityController
if (is_array($admin->getLRecords()[$t] ?? false)) { if (is_array($admin->getLRecords()[$t] ?? false)) {
foreach ($admin->getLRecords()[$t] as $data) { foreach ($admin->getLRecords()[$t] as $data) {
if (!GeneralUtility::inList($admin->getLostPagesList(), $data['pid'])) { if (!GeneralUtility::inList($admin->getLostPagesList(), $data['pid'])) {
$lr .= '<div class="record"><a href="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute('system_dbint') . '&SET[function]=records&fixLostRecords_table=' . $t . '&fixLostRecords_uid=' . $data['uid']) . '" title="' . htmlspecialchars($lang->getLL('fixLostRecord')) . '">' . $this->iconFactory->getIcon('status-dialog-error', Icon::SIZE_SMALL)->render() . '</a>uid:' . $data['uid'] . ', pid:' . $data['pid'] . ', ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(strip_tags($data['title']), 20)) . '</div>'; $lr .= '<div class="record"><a href="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute('system_dbint', ['SET' => ['function' => 'records'], 'fixLostRecords_table' => $t, 'fixLostRecords_uid' => $data['uid']])) . '" title="' . htmlspecialchars($lang->getLL('fixLostRecord')) . '">' . $this->iconFactory->getIcon('status-dialog-error', Icon::SIZE_SMALL)->render() . '</a>uid:' . $data['uid'] . ', pid:' . $data['pid'] . ', ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(strip_tags($data['title']), 20)) . '</div>';
} else { } else {
$lr .= '<div class="record-noicon">uid:' . $data['uid'] . ', pid:' . $data['pid'] . ', ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(strip_tags($data['title']), 20)) . '</div>'; $lr .= '<div class="record-noicon">uid:' . $data['uid'] . ', pid:' . $data['pid'] . ', ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(strip_tags($data['title']), 20)) . '</div>';
} }
......
...@@ -523,9 +523,9 @@ class RecordListController ...@@ -523,9 +523,9 @@ class RecordListController
) { ) {
// Export // Export
if (ExtensionManagementUtility::isLoaded('impexp')) { if (ExtensionManagementUtility::isLoaded('impexp')) {
$url = (string)$this->uriBuilder->buildUriFromRoute('tx_impexp_export'); $url = (string)$this->uriBuilder->buildUriFromRoute('tx_impexp_export', ['tx_impexp' => ['list' => [$table . ':' . $this->id]]]);
$exportButton = $buttonBar->makeLinkButton() $exportButton = $buttonBar->makeLinkButton()
->setHref($url . '&tx_impexp[list][]=' . rawurlencode($table . ':' . $this->id)) ->setHref($url)
->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.export')) ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.export'))
->setIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL)) ->setIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL))
->setShowLabelText(true); ->setShowLabelText(true);
......
...@@ -81,7 +81,7 @@ class ConfigurationStatus implements StatusProviderInterface ...@@ -81,7 +81,7 @@ class ConfigurationStatus implements StatusProviderInterface
if (!$count && $lastRefIndexUpdate) { if (!$count && $lastRefIndexUpdate) {
$value = $this->getLanguageService()->getLL('status_empty'); $value = $this->getLanguageService()->getLL('status_empty');
$severity = ReportStatus::WARNING; $severity = ReportStatus::WARNING;
$url = (string)$uriBuilder->buildUriFromRoute('system_dbint') . '&id=0&SET[function]=refindex'; $url = (string)$uriBuilder->buildUriFromRoute('system_dbint', ['id' => 0, 'SET' => ['function' => 'refindex']]);
$message = sprintf($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.backend_reference_index'), '<a href="' . htmlspecialchars($url) . '">', '</a>', BackendUtility::datetime($lastRefIndexUpdate)); $message = sprintf($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.backend_reference_index'), '<a href="' . htmlspecialchars($url) . '">', '</a>', BackendUtility::datetime($lastRefIndexUpdate));
} }
return GeneralUtility::makeInstance(ReportStatus::class, $this->getLanguageService()->getLL('status_referenceIndex'), $value, $message, $severity); return GeneralUtility::makeInstance(ReportStatus::class, $this->getLanguageService()->getLL('status_referenceIndex'), $value, $message, $severity);
......
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