Skip to content

Commit

Permalink
[TASK] Deprecate T3_THIS_LOCATION
Browse files Browse the repository at this point in the history
This patch deprecates the global variable `T3_THIS_LOCATION`. This
variable is mostly used to attach a returnUrl argument to links,
triggered via a redirect on an onclick event.

In most cases this is not necessary anymore, also it's considered bad
practice not to use regular links in an href attribute.

Resolves: #88854
Releases: master
Change-Id: I9d90a59b83b956f0bf1e380a55d6c3a4c2d469b5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61385
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Björn Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
andreaskienast authored and georgringer committed Jul 31, 2019
1 parent 33428b6 commit 81660b4
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 24 deletions.
1 change: 1 addition & 0 deletions typo3/sysext/backend/Classes/Template/DocumentTemplate.php
Expand Up @@ -364,6 +364,7 @@ public function redirectUrls($thisLocation = '')
$out = '
// @deprecated
var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
// @deprecated
var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
';
return $out;
Expand Down
1 change: 1 addition & 0 deletions typo3/sysext/backend/Classes/Template/ModuleTemplate.php
Expand Up @@ -651,6 +651,7 @@ public function redirectUrls($thisLocation = '')
$out = '
// @deprecated
var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
// @deprecated
var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
';
return $out;
Expand Down
1 change: 1 addition & 0 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -2484,6 +2484,7 @@ public static function getLinkToDataHandlerAction($parameters, $redirectUrl = ''
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('tce_db') . $parameters . '&redirect=';
if ((int)$redirectUrl === -1) {
trigger_error('Generating URLs to DataHandler for JavaScript click handlers is deprecated. Consider using the href attribute instead.', E_USER_DEPRECATED);
$url = GeneralUtility::quoteJSvalue($url) . '+T3_THIS_LOCATION';
} else {
$url .= rawurlencode($redirectUrl ?: GeneralUtility::getIndpEnv('REQUEST_URI'));
Expand Down
@@ -0,0 +1,34 @@
.. include:: ../../Includes.txt

=======================================================
Deprecation: #88854 - jumpExt() of RecordListController
=======================================================

See :issue:`88854`

Description
===========

The JavaScript function :js:`jumpExt()` used to generate URLs by attaching a returnUrl argument and an anchor has been
marked as deprecated.


Impact
======

Calling :js:`jumpExt()` will trigger a deprecation warning in the browser's console.


Affected Installations
======================

All third party extensions using :js:`jumpExt()` are affected.


Migration
=========

It is only possible to call this function via hooks. To migrate this call, append a `returnUrl` argument to the URL if
required and move the URL to the :html:`href` argument of the button the function was attached to.

.. index:: Backend, JavaScript, PHP-API, NotScanned, ext:backend
@@ -0,0 +1,41 @@
.. include:: ../../Includes.txt

======================================
Deprecation: #88854 - T3_THIS_LOCATION
======================================

See :issue:`88854`

Description
===========

The global JavaScript variable :js:`T3_THIS_LOCATION` containing the URL to the current document (if not modified) has
been marked as deprecated.


Impact
======

Since this is a global JavaScript variable, no proper deprecation layer applies and thus no deprecation notice is rendered.

Some PHP API uses :js:`T3_THIS_LOCATION` (e.g. :php:`BackendUtility::getLinkToDataHandlerAction()` with second argument
being `-1`) has been marked as deprecated as well.


Affected Installations
======================

All third party extensions using :js:`T3_THIS_LOCATION` are affected.


Migration
=========

When generating URLs containing a `returnUrl` (a common use-case for :js:`T3_THIS_LOCATION`), consider using either
:php:`rawurldecode(GeneralUtility::getIndpEnv('REQUEST_URI'))` or :php:`normalizedParams` in the PSR-7 ServerRequest object:
:php:`$request->getAttribute('normalizedParams')->getRequestUri()`.

In general, `onclick` handlers doing a redirect are considered bad practice. Use HTML's `href` attribute and attach
custom click handlers, if necessary.

.. index:: Backend, JavaScript, PHP-API, NotScanned, ext:backend
Expand Up @@ -147,7 +147,7 @@ public function render()
$dblist->script = $_SERVER['REQUEST_URI'];
$dblist->generateList();

$js = 'var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
$js = '// @deprecated' . CRLF . 'var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
$html = GeneralUtility::wrapJS($js) . $dblist->HTMLcode;

return $html;
Expand Down
Expand Up @@ -372,6 +372,7 @@ protected function main(ServerRequestInterface $request)
'RecordListInlineJS',
'
function jumpExt(URL,anchor) {
console.warn(\'jumpExt() has been marked as deprecated. Consider using regular links instead.\');
var anc = anchor?anchor:"";
window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
return false;
Expand Down
46 changes: 23 additions & 23 deletions typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
Expand Up @@ -634,10 +634,8 @@ public function getDocHeaderButtons(ModuleTemplate $moduleTemplate)
}
// New record on pages that are not locked by editlock
if (!$modulePageTsConfig['noCreateRecordsLink'] && $this->editLockPermissions()) {
$onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id])) . ');';
$newRecordButton = $buttonBar->makeLinkButton()
->setHref('#')
->setOnClick($onClick)
->setHref((string)$this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'returnUrl' => $this->listURL()]))
->setTitle($lang->getLL('newRecordGeneral'))
->setIcon($this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
$buttonBar->addButton($newRecordButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
Expand Down Expand Up @@ -1472,7 +1470,7 @@ public function renderListHeader($table, $currentIdList)
// The "edit marked" link:
$editUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit')
. '&edit[' . $table . '][{entityIdentifiers:editList}]=edit'
. '&returnUrl={T3_THIS_LOCATION}';
. '&returnUrl=' . rawurlencode($this->listURL());
$cells['edit'] = '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
. ' data-uri="' . htmlspecialchars($editUri) . '"'
. ' title="' . htmlspecialchars($lang->getLL('clip_editMarked')) . '">'
Expand Down Expand Up @@ -1562,7 +1560,7 @@ public function renderListHeader($table, $currentIdList)
$editUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit')
. '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
. '&columnsOnly=' . implode(',', $this->fieldArray)
. '&returnUrl={T3_THIS_LOCATION}';
. '&returnUrl=' . rawurlencode($this->listURL());
$icon .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
. ' data-uri="' . htmlspecialchars($editUri) . '"'
. ' title="' . htmlspecialchars($lang->getLL('editShownColumns')) . '">'
Expand Down Expand Up @@ -1620,7 +1618,7 @@ public function renderListHeader($table, $currentIdList)
$editUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit')
. '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
. '&columnsOnly=' . $fCol
. '&returnUrl={T3_THIS_LOCATION}';
. '&returnUrl=' . rawurlencode($this->listURL());
$iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
$theData[$fCol] .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
. ' data-uri="' . htmlspecialchars($editUri) . '"'
Expand Down Expand Up @@ -1854,20 +1852,26 @@ public function makeControl($table, $row)
if ($isL10nOverlay) {
$moveAction = $this->spaceIcon;
} else {
$onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('move_element') . '&table=' . $table . '&uid=' . $row['uid']) . ');';
$linkTitleLL = htmlspecialchars($this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page')));
$icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-move', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL));
$moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
$url = (string)$this->uriBuilder->buildUriFromRoute('move_element', [
'table' => $table,
'uid' => $row['uid'],
'returnUrl' => $this->listURL(),
]);
$moveAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
}
$this->addActionToCellGroup($cells, $moveAction, 'move');
}
// If the table is NOT a read-only table, then show these links:
if ($this->isEditable($table)) {
// "Revert" link (history/undo)
if ((bool)\trim($userTsConfig['options.']['showHistory.'][$table] ?? $userTsConfig['options.']['showHistory'] ?? '1')) {
$moduleUrl = (string)$this->uriBuilder->buildUriFromRoute('record_history', ['element' => $table . ':' . $row['uid']]);
$onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
$historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
$moduleUrl = $this->uriBuilder->buildUriFromRoute('record_history', [
'element' => $table . ':' . $row['uid'],
'returnUrl' => $this->listURL(),
]) . '#latest';
$historyAction = '<a class="btn btn-default" href="' . htmlspecialchars($moduleUrl) . '" title="'
. htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
. $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
$this->addActionToCellGroup($cells, $historyAction, 'history');
Expand Down Expand Up @@ -1909,9 +1913,8 @@ public function makeControl($table, $row)
if (!$isL10nOverlay && isset($this->currentTable['prev'][$row['uid']])) {
// Up
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
$moveUpAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveUpAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
. $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
} else {
$moveUpAction = $this->spaceIcon;
Expand All @@ -1921,9 +1924,8 @@ public function makeControl($table, $row)
if (!$isL10nOverlay && $this->currentTable['next'][$row['uid']]) {
// Down
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
$moveDownAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveDownAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
. $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
} else {
$moveDownAction = $this->spaceIcon;
Expand Down Expand Up @@ -2007,9 +2009,8 @@ public function makeControl($table, $row)
// Up (Paste as the page right after the current parent page)
if ($this->calcPerms & Permission::PAGE_NEW) {
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
$moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveLeftAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
. $this->iconFactory->getIcon('actions-move-left', Icon::SIZE_SMALL)->render() . '</a>';
$this->addActionToCellGroup($cells, $isL10nOverlay ? $this->spaceIcon : $moveLeftAction, 'moveLeft');
}
Expand All @@ -2018,9 +2019,8 @@ public function makeControl($table, $row)
$localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
if ($localCalcPerms & Permission::PAGE_NEW) {
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
$moveRightAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveRightAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
. $this->iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render() . '</a>';
} else {
$moveRightAction = $this->spaceIcon;
Expand Down

0 comments on commit 81660b4

Please sign in to comment.