[TASK] Deprecation: <link> syntax parsing in RteHtmlParser 57/54457/9
authorBenni Mack <benni@typo3.org>
Fri, 20 Oct 2017 11:59:40 +0000 (13:59 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Mon, 11 Dec 2017 20:23:06 +0000 (21:23 +0100)
Functionality regarding parsing / resolving <link> tags is marked
as deprecated as it does not need to be called anymore.

Additionally, adding and calling the hooks
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksRte_PostProc']
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc']
will trigger deprecation errors.

Resolves: #83252
Releases: master
Change-Id: Id7998849f7039a0bd786321787ce87884b254b67
Reviewed-on: https://review.typo3.org/54457
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/core/Classes/Html/RteHtmlParser.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-83252-Link-tagSyntaxProcesssing.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php
typo3/sysext/core/Tests/Unit_Deprecated/Html/RteHtmlParserTest.php [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentUnusedMatcher.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php

index af9a562..33399a6 100644 (file)
@@ -253,7 +253,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
                             $value = $this->TS_images_rte($value);
                             break;
                         case 'ts_links':
-                            $value = $this->TS_links_rte($value);
+                            $value = $this->TS_links_rte($value, true);
                             break;
                         case 'css_transform':
                             $value = $this->TS_transform_rte($value);
@@ -542,24 +542,25 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
                 $linkService = GeneralUtility::makeInstance(LinkService::class);
                 $linkInformation = $linkService->resolve($tagAttributes['href'] ?? '');
 
-                $tagAttributes['href'] = $linkService->asString($linkInformation);
-                $blockSplit[$k] = '<a ' . GeneralUtility::implodeAttributes($tagAttributes, true) . '>'
-                    . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . '</a>';
-                $parameters = [
-                    'currentBlock' => $v,
-                    'linkInformation' => $linkInformation,
-                    'url' => $linkInformation['href'],
-                    'attributes' => $tagAttributes
-                ];
-                foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc'] ?? [] as $className) {
-                    $processor = GeneralUtility::makeInstance($className);
-                    $blockSplit[$k] = $processor->modifyParamsLinksDb($parameters, $this);
+                // Modify parameters, this hook should be deprecated
+                if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc'])) {
+                    trigger_error('The hook "t3lib/class.t3lib_parsehtml_proc.php->modifyParams_LinksDb_PostProc" will be removed in TYPO3 v10, use LinkService syntax to modify links to be stored in the database.', E_USER_DEPRECATED);
+                    $parameters = [
+                        'currentBlock' => $v,
+                        'linkInformation' => $linkInformation,
+                        'url' => $linkInformation['href'],
+                        'attributes' => $tagAttributes
+                    ];
+                    foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc'] ?? [] as $className) {
+                        $processor = GeneralUtility::makeInstance($className);
+                        $blockSplit[$k] = $processor->modifyParamsLinksDb($parameters, $this);
+                    }
+                } else {
+                    // Otherwise store the link as <a> tag as default by TYPO3, with the new link service syntax
+                    $tagAttributes['href'] = $linkService->asString($linkInformation);
+                    $blockSplit[$k] = '<a ' . GeneralUtility::implodeAttributes($tagAttributes, true) . '>'
+                        . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . '</a>';
                 }
-
-                // Otherwise store the link as <a> tag as default by TYPO3, with the new link service syntax
-                $tagAttributes['href'] = $linkService->asString($linkInformation);
-                $blockSplit[$k] = '<a ' . GeneralUtility::implodeAttributes($tagAttributes, true) . '>'
-                    . $this->TS_links_db($this->removeFirstAndLastTag($blockSplit[$k])) . '</a>';
             }
         }
         return implode('', $blockSplit);
@@ -573,16 +574,23 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
      * not be converted back to <link> tags anymore.
      *
      * @param string $value Content input
+     * @param bool $internallyCalledFromCore internal option for calls where the Core is still using this function, to supress method deprecations
      * @return string Content output
+     * @deprecated will be removed in TYPO3 v10, only ->TS_AtagToAbs() should be called directly, <link> syntax is deprecated
      */
-    public function TS_links_rte($value)
+    public function TS_links_rte($value, $internallyCalledFromCore = null)
     {
+        if ($internallyCalledFromCore === null) {
+            trigger_error('This method will be removed in TYPO3 v10, use TS_AtagToAbs() directly and do not use <link> syntax anymore', E_USER_DEPRECATED);
+        }
+        $hasLinkTags = false;
         $value = $this->TS_AtagToAbs($value);
         // Split content by the TYPO3 pseudo tag "<link>"
         $blockSplit = $this->splitIntoBlock('link', $value, true);
         foreach ($blockSplit as $k => $v) {
             // Block
             if ($k % 2) {
+                $hasLinkTags = true;
                 // Split away the first "<link " part
                 $typoLinkData = explode(' ', substr($this->getFirstTag($v), 0, -1), 2)[1];
                 $tagCode = GeneralUtility::makeInstance(TypoLinkCodecService::class)->decode($typoLinkData);
@@ -599,6 +607,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
 
                 // Modify parameters by a hook
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksRte_PostProc'] ?? false)) {
+                    trigger_error('The hook "t3lib/class.t3lib_parsehtml_proc.php->modifyParams_LinksRte_PostProc" will be removed in TYPO3 v10, use the link service to properly use ', E_USER_DEPRECATED);
                     // backwards-compatibility: show an error message if the page is not found
                     $error = '';
                     if ($linkInformation['type'] === LinkService::TYPE_PAGE) {
@@ -629,11 +638,14 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
 
                     // Setting the <a> tag
                     $blockSplit[$k] = '<a ' . GeneralUtility::implodeAttributes($anchorAttributes, true) . '>'
-                        . $this->TS_links_rte($this->removeFirstAndLastTag($blockSplit[$k]))
+                        . $this->TS_links_rte($this->removeFirstAndLastTag($blockSplit[$k]), $internallyCalledFromCore)
                         . '</a>';
                 }
             }
         }
+        if ($hasLinkTags) {
+            trigger_error('Content with <link> syntax was found, update your content to use the t3:// syntax, and migrate your content via the upgrade wizard in the install tool', E_USER_DEPRECATED);
+        }
         return implode('', $blockSplit);
     }
 
@@ -716,9 +728,11 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
      *
      * @param string $value Content input
      * @return string Content output
+     * @deprecated since TYPO3 v9.0, will be removed in TYPO3 v10, see comment above, adding attribuet "rteerror" is not necessary anymore.
      */
     public function transformStyledATags($value)
     {
+        trigger_error('This method will be removed in TYPO3 v10. TYPO3 can handle style attribute in anchor tags properly since TYPO3 v8 LTS', E_USER_DEPRECATED);
         $blockSplit = $this->splitIntoBlock('A', $value);
         foreach ($blockSplit as $k => $v) {
             // If an A-tag was found
@@ -895,7 +909,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
      * @param string $value Value to process.
      * @param int $count Recursion brake. Decremented on each recursion down to zero. Default is 5 (which equals the allowed nesting levels of p tags).
      * @param bool $returnArray If TRUE, an array with the lines is returned, otherwise a string of the processed input value.
-     * @return string Processed input value.
+     * @return string|array Processed input value.
      * @see setDivTags()
      */
     public function divideIntoLines($value, $count = 5, $returnArray = false)
@@ -1142,11 +1156,13 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
      * Converting <A>-tags to absolute URLs (+ setting rtekeep attribute)
      *
      * @param string $value Content input
-     * @param bool $dontSetRTEKEEP If TRUE, then the "rtekeep" attribute will not be set. (not in use anymore)
      * @return string Content output
      */
-    public function TS_AtagToAbs($value, $dontSetRTEKEEP = false)
+    public function TS_AtagToAbs($value)
     {
+        if (func_num_args() > 1) {
+            trigger_error('Second argument of TS_AtagToAbs() is not in use and is removed, however the argument in the callers code can be removed without side-effects.', E_USER_DEPRECATED);
+        }
         $blockSplit = $this->splitIntoBlock('A', $value);
         foreach ($blockSplit as $k => $v) {
             // Block
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83252-Link-tagSyntaxProcesssing.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83252-Link-tagSyntaxProcesssing.rst
new file mode 100644 (file)
index 0000000..271cff9
--- /dev/null
@@ -0,0 +1,47 @@
+.. include:: ../../Includes.txt
+
+=================================================
+Deprecation: #83252 - link-tag syntax processsing
+=================================================
+
+See :issue:`83252`
+
+Description
+===========
+
+The old-fashioned way of storing links as <link>-tags in the database was migrated in TYPO3 v8, however, the code
+is still in place.
+
+Using the following hooks is not encouraged:
+- $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksRte_PostProc']
+- $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc']
+
+The following public methods in RteHtmlParser have been marked as deprecated:
+- TYPO3\CMS\Core\Html\RteHtmlParser->TS_links_rte()
+- TYPO3\CMS\Core\Html\RteHtmlParser->transformStyledATags()
+
+The second argument of the PHP method `TYPO3\CMS\Core\Html\RteHtmlParser->TS_AtagToAbs()` has been marked
+as deprecated.
+
+
+Impact
+======
+
+Transforming any content with a <link> tag will trigger deprecation warning. Additionally, calling one of the
+deprecated methods or triggering any of the hooks within RteHtmlParser will trigger a deprecation warning.
+
+Using the method `TS_AtagToAbs()` with a second argument set will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+Any installation which makes use of the legacy <link> syntax or hasn't fully migrated to TYPO3 v8 yet.
+
+
+Migration
+=========
+
+Migrate all content to proper anchor-tags, so the hooks are not necessary anymore.
+
+.. index:: PHP-API, RTE, FullyScanned
\ No newline at end of file
index ee77a78..f0cb52f 100644 (file)
@@ -188,33 +188,6 @@ class RteHtmlParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
-     * Data provider for linkWithAtSignCorrectlyTransformedOnWayToRTE
-     */
-    public static function linkWithAtSignCorrectlyTransformedOnWayToRTEProvider()
-    {
-        return [
-            'external url with @ sign' => [
-                '<link http://www.example.org/at@sign>link text</link>',
-                '<p><a href="http://www.example.org/at@sign">link text</a></p>'
-            ],
-            'email address with @ sign' => [
-                '<link name@example.org - mail "Opens window for sending email">link text</link>',
-                '<p><a href="mailto:name@example.org" class="mail" title="Opens window for sending email">link text</a></p>'
-            ]
-        ];
-    }
-
-    /**
-     * @test
-     * @dataProvider linkWithAtSignCorrectlyTransformedOnWayToRTEProvider
-     */
-    public function linkWithAtSignCorrectlyTransformedOnWayToRTE($content, $expectedResult)
-    {
-        $thisConfig = ['proc.' => $this->subject->procOptions];
-        $this->assertEquals($expectedResult, $this->subject->RTE_transform($content, [], 'rte', $thisConfig));
-    }
-
-    /**
      * Data provider for paragraphCorrectlyTransformedOnWayToDatabase
      */
     public static function paragraphCorrectlyTransformedOnWayToDatabaseProvider()
diff --git a/typo3/sysext/core/Tests/Unit_Deprecated/Html/RteHtmlParserTest.php b/typo3/sysext/core/Tests/Unit_Deprecated/Html/RteHtmlParserTest.php
new file mode 100644 (file)
index 0000000..1a03661
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit_Deprecated\Html;
+
+/*
+ * 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!
+ */
+
+/**
+ * Testcase for \TYPO3\CMS\Core\Html\RteHtmlParser
+ */
+class RteHtmlParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+{
+    /**
+     * @var \TYPO3\CMS\Core\Html\RteHtmlParser
+     */
+    protected $subject = null;
+
+    protected function setUp()
+    {
+        $this->subject = new \TYPO3\CMS\Core\Html\RteHtmlParser();
+        $this->subject->procOptions = [
+            'allowTagsOutside' => 'hr, address',
+            'overruleMode' => 'default'
+        ];
+    }
+
+    /**
+     * Data provider for linkWithAtSignCorrectlyTransformedOnWayToRTE
+     */
+    public static function linkWithAtSignCorrectlyTransformedOnWayToRTEProvider()
+    {
+        return [
+            'external url with @ sign' => [
+                '<link http://www.example.org/at@sign>link text</link>',
+                '<p><a href="http://www.example.org/at@sign">link text</a></p>'
+            ],
+            'email address with @ sign' => [
+                '<link name@example.org - mail "Opens window for sending email">link text</link>',
+                '<p><a href="mailto:name@example.org" class="mail" title="Opens window for sending email">link text</a></p>'
+            ]
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider linkWithAtSignCorrectlyTransformedOnWayToRTEProvider
+     */
+    public function linkWithAtSignCorrectlyTransformedOnWayToRTE($content, $expectedResult)
+    {
+        $thisConfig = ['proc.' => $this->subject->procOptions];
+        $this->assertEquals($expectedResult, $this->subject->RTE_transform($content, [], 'rte', $thisConfig));
+    }
+}
index 397a71a..13cc1e5 100644 (file)
@@ -134,4 +134,14 @@ return [
             'Breaking-83081-RemovedConfigurationOptionBeFileExtensionsWebspace.rst',
         ],
     ],
+    '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'t3lib/class.t3lib_parsehtml_proc.php\'][\'modifyParams_LinksRte_PostProc\']' => [
+        'restFiles' => [
+            'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
+        ],
+    ],
+    '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'t3lib/class.t3lib_parsehtml_proc.php\'][\'modifyParams_LinksDb_PostProc\']' => [
+        'restFiles' => [
+            'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
+        ],
+    ],
 ];
index 64f3fe9..e3762fd 100644 (file)
@@ -27,4 +27,10 @@ return [
             'Deprecation-80485-MethodParameterOfTSFE-whichWorkspaceToReturnTheWorkspaceTitle.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Html\RteHtmlParser->TS_AtagToAbs' => [
+        'unusedArgumentNumbers' => [ 2 ],
+        'restFiles' => [
+            'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
+        ],
+    ],
 ];
index 16eee64..06eb3e7 100644 (file)
@@ -1535,4 +1535,18 @@ return [
             'Deprecation-83254-MovedPageGenerationMethodsIntoTSFE.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Html\RteHtmlParser->transformStyledATags' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
+        ],
+    ],
+    'TYPO3\CMS\Core\Html\RteHtmlParser->TS_links_rte' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
+        ],
+    ],
 ];