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
$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->registerCshButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 4);
}
......@@ -1757,13 +1757,14 @@ class EditDocumentController
* @param string $position
* @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();
if ($this->returnUrl !== $closeUrl) {
$requestUri = GeneralUtility::linkThisScript([
'returnUrl' => $closeUrl,
]);
// Generate a URL to the current edit form
$arguments = $this->getUrlQueryParamsForCurrentRequest($request);
$arguments['returnUrl'] = $closeUrl;
$requestUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $arguments);
$openInNewWindowButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()
->makeLinkButton()
->setHref('#')
......@@ -1793,21 +1794,7 @@ class EditDocumentController
protected function registerShortcutButtonToButtonBar(ButtonBar $buttonBar, string $position, int $group, ServerRequestInterface $request)
{
if ($this->returnUrl !== $this->getCloseUrl()) {
$queryParams = $request->getQueryParams();
$potentialArguments = [
'edit',
'defVals',
'overrideVals',
'columnsOnly',
'returnNewPageId',
'noView'
];
$arguments = [];
foreach ($potentialArguments as $argument) {
if (!empty($queryParams[$argument])) {
$arguments[$argument] = $queryParams[$argument];
}
}
$arguments = $this->getUrlQueryParamsForCurrentRequest($request);
$shortCutButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton();
$shortCutButton
->setRouteIdentifier('record_edit')
......@@ -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
*
......
......@@ -339,8 +339,9 @@ class NewRecordController
// New page
if ($this->isRecordCreationAllowedForTable('pages')) {
$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'))
->setShowLabelText(true)
->setIcon($this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL));
$buttonBar->addButton($newPageButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
}
......@@ -359,6 +360,7 @@ class NewRecordController
$returnButton = $buttonBar->makeLinkButton()
->setHref($this->returnUrl)
->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));
$buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
}
......@@ -505,7 +507,7 @@ class NewRecordController
// New pages at selection position
if ($this->newPagesSelectPosition && $this->isRecordCreationAllowedForTable('pages')) {
// 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
$numPageLinks = count($newPageLinks);
......
......@@ -324,7 +324,7 @@ class PageLayoutController
$menuItem = $actionMenu
->makeMenuItem()
->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) {
$defaultKey = $key;
......@@ -405,9 +405,9 @@ class PageLayoutController
}
$message = htmlspecialchars($message);
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);
$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 .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', (string)$shortcutMode))) . ')';
$state = InfoboxViewHelper::STATE_INFO;
......@@ -448,9 +448,9 @@ class PageLayoutController
// If content from different pid is displayed
if ($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);
$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);
$view->assignMultiple([
'title' => $title,
......@@ -493,9 +493,9 @@ class PageLayoutController
$rows = $queryBuilder->execute()->fetchAllAssociative();
if (!empty($rows)) {
foreach ($rows as $row) {
$linkToPid = GeneralUtility::linkThisScript(['id' => $row['uid']]);
$linkToPid = $this->uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $row['uid']]);
$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;
}
}
......@@ -1016,7 +1016,7 @@ class PageLayoutController
$menuItem = $languageMenu
->makeMenuItem()
->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) {
$menuItem->setActive(true);
}
......
......@@ -363,7 +363,7 @@ class InfoPageTyposcriptConfigController
$line = [];
$line['padding'] = ($pageDepth * 20) + 10;
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['title'] = 'ID: ' . $identifier;
$line['pageTitle'] = GeneralUtility::fixed_lgd_cs($pageArray[$identifier], 30);
......
......@@ -304,7 +304,7 @@ class DatabaseIntegrityController
$modules = [];
$availableModFuncs = ['records', 'relations', 'search', 'refindex'];
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);
}
......@@ -458,7 +458,7 @@ class DatabaseIntegrityController
if (is_array($admin->getLRecords()[$t] ?? false)) {
foreach ($admin->getLRecords()[$t] as $data) {
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 {
$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
) {
// Export
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()
->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'))
->setIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL))
->setShowLabelText(true);
......
......@@ -81,7 +81,7 @@ class ConfigurationStatus implements StatusProviderInterface
if (!$count && $lastRefIndexUpdate) {
$value = $this->getLanguageService()->getLL('status_empty');
$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));
}
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