From 7a2c44a7db1f43337e6f1e935bc6c938a3bcebbf Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Thu, 14 Apr 2016 17:07:21 +0200 Subject: [PATCH] [TASK] Deprecate GeneralUtility methods There are some methods within GeneralUtility that are not used within TYPO3 anymore or a now just plain stubs for PHP methods. Additionally, there are some parameters within wrapJS() that have no effect at all, and are removed without substitution. Resolves: #75621 Releases: master Change-Id: I1ad6c73b4733db172b37999b38d0a7b098d4e191 Reviewed-on: https://review.typo3.org/47669 Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> --- .../Cache/Backend/SimpleFileBackend.php | 4 +- .../AbstractConditionMatcher.php | 3 +- .../core/Classes/Utility/GeneralUtility.php | 64 +++++++++++-------- ...eprecation-75621-GeneralUtilityMethods.rst | 48 ++++++++++++++ .../ContentObject/ContentObjectRenderer.php | 2 +- .../Classes/RecordList/DatabaseRecordList.php | 5 +- 6 files changed, 94 insertions(+), 32 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-75621-GeneralUtilityMethods.rst diff --git a/typo3/sysext/core/Classes/Cache/Backend/SimpleFileBackend.php b/typo3/sysext/core/Classes/Cache/Backend/SimpleFileBackend.php index 52ec30a47eb4..f7c24f7c0dd0 100644 --- a/typo3/sysext/core/Classes/Cache/Backend/SimpleFileBackend.php +++ b/typo3/sysext/core/Classes/Cache/Backend/SimpleFileBackend.php @@ -92,8 +92,8 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im unset($this->temporaryCacheDirectory); $this->cacheDirectory = $finalCacheDirectory; $this->cacheEntryFileExtension = $cache instanceof \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend ? '.php' : ''; - if (strlen($this->cacheDirectory) + 23 > \TYPO3\CMS\Core\Utility\GeneralUtility::getMaximumPathLength()) { - throw new \TYPO3\CMS\Core\Cache\Exception('The length of the temporary cache file path "' . $this->cacheDirectory . '" exceeds the ' . 'maximum path length of ' . (\TYPO3\CMS\Core\Utility\GeneralUtility::getMaximumPathLength() - 23) . '. Please consider ' . 'setting the temporaryDirectoryBase option to a shorter path.', 1248710426); + if (strlen($this->cacheDirectory) + 23 > PHP_MAXPATHLEN) { + throw new \TYPO3\CMS\Core\Cache\Exception('The length of the temporary cache file path "' . $this->cacheDirectory . '" exceeds the ' . 'maximum path length of ' . (PHP_MAXPATHLEN - 23) . '. Please consider ' . 'setting the temporaryDirectoryBase option to a shorter path.', 1248710426); } } diff --git a/typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php b/typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php index 927a6e09f910..e83ea56a0e37 100644 --- a/typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php +++ b/typo3/sysext/core/Classes/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcher.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching; */ use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; /** * Matching TypoScript conditions @@ -286,7 +287,7 @@ abstract class AbstractConditionMatcher return false; break; case 'compatVersion': - return GeneralUtility::compat_version($value); + return VersionNumberUtility::convertVersionNumberToInteger(TYPO3_branch) >= VersionNumberUtility::convertVersionNumberToInteger($value); break; case 'loginUser': if ($this->isUserLoggedIn()) { diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index eef021e4564d..02bf72401585 100755 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -694,9 +694,11 @@ class GeneralUtility * @param string $verNumberStr Minimum branch number required (format x.y / e.g. "4.0" NOT "4.0.0"!) * @return bool Returns TRUE if this setup is compatible with the provided version number * @todo Still needs a function to convert versions to branches + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ public static function compat_version($verNumberStr) { + static::logDeprecatedFunction(); return VersionNumberUtility::convertVersionNumberToInteger(TYPO3_branch) >= VersionNumberUtility::convertVersionNumberToInteger($verNumberStr); } @@ -891,9 +893,11 @@ class GeneralUtility * * @param string $microtime Microtime * @return int Microtime input string converted to an integer (milliseconds) + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ public static function convertMicrotime($microtime) { + static::logDeprecatedFunction(); $parts = explode(' ', $microtime); return round(($parts[0] + $parts[1]) * 1000); } @@ -928,10 +932,11 @@ class GeneralUtility * * @param string $str String which contains eg. "&amp;" which should stay "&". Or "&#1234;" to "Ӓ". Or "&#x1b;" to " * @return string Converted result. - * + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ public static function deHSCentities($str) { + static::logDeprecatedFunction(); return preg_replace('/&([#[:alnum:]]*;)/', '&\\1', $str); } @@ -942,9 +947,11 @@ class GeneralUtility * @param bool $extended If set, also backslashes are escaped. * @param string $char The character to escape, default is ' (single-quote) * @return string Processed input string + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ public static function slashJS($string, $extended = false, $char = '\'') { + static::logDeprecatedFunction(); if ($extended) { $string = str_replace('\\', '\\\\', $string); } @@ -957,9 +964,11 @@ class GeneralUtility * * @param string $str String to raw-url-encode with spaces preserved * @return string Rawurlencoded result of input string, but with all %20 (space chars) converted to real spaces. + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, implement directly via PHP instead */ public static function rawUrlEncodeJS($str) { + static::logDeprecatedFunction(); return str_replace('%20', ' ', rawurlencode($str)); } @@ -969,9 +978,11 @@ class GeneralUtility * * @param string $str Input string * @return string Output string + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use the PHP methods directly instead */ public static function rawUrlEncodeFP($str) { + static::logDeprecatedFunction(); return str_replace('%2F', '/', rawurlencode($str)); } @@ -1094,8 +1105,7 @@ class GeneralUtility */ public static function underscoredToUpperCamelCase($string) { - $upperCamelCase = str_replace(' ', '', ucwords(str_replace('_', ' ', self::strtolower($string)))); - return $upperCamelCase; + return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($string)))); } /** @@ -1107,9 +1117,7 @@ class GeneralUtility */ public static function underscoredToLowerCamelCase($string) { - $upperCamelCase = str_replace(' ', '', ucwords(str_replace('_', ' ', self::strtolower($string)))); - $lowerCamelCase = self::lcfirst($upperCamelCase); - return $lowerCamelCase; + return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($string))))); } /** @@ -1130,10 +1138,12 @@ class GeneralUtility * * @param string $string The string to be used to lowercase the first character * @return string The string with the first character as lowercase + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ public static function lcfirst($string) { - return self::strtolower($string[0]) . substr($string, 1); + static::logDeprecatedFunction(); + return lcfirst($string); } /** @@ -1514,28 +1524,30 @@ class GeneralUtility * This is nice for indenting JS code with PHP code on the same level. * * @param string $string JavaScript code - * @param bool $linebreak Wrap script element in line breaks? Default is TRUE. + * @param null $_ unused, will be removed in TYPO3 CMS 9 * @return string The wrapped JS code, ready to put into a XHTML page */ - public static function wrapJS($string, $linebreak = true) + public static function wrapJS($string, $_ = null) { + if ($_ !== null) { + self::deprecationLog('Parameter 2 of GeneralUtility::wrapJS is obsolete and can be omitted.'); + } + if (trim($string)) { - // <script wrapped in nl? - $cr = $linebreak ? LF : ''; // remove nl from the beginning - $string = preg_replace('/^\\n+/', '', $string); + $string = ltrim($string, LF); // re-ident to one tab using the first line as reference $match = array(); if (preg_match('/^(\\t+)/', $string, $match)) { $string = str_replace($match[1], TAB, $string); } - $string = $cr . '<script type="text/javascript"> + return '<script type="text/javascript"> /*<![CDATA[*/ ' . $string . ' /*]]>*/ -</script>' . $cr; +</script>'; } - return trim($string); + return ''; } /** @@ -1942,7 +1954,7 @@ class GeneralUtility * * @param string $xmlData XML data * @return array Attributes of the xml prologue (header) - * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9. + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9. */ public static function xmlGetHeaderAttribs($xmlData) { @@ -2611,9 +2623,11 @@ class GeneralUtility * Retrieves the maximum path length that is valid in the current environment. * * @return int The maximum available path length + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ public static function getMaximumPathLength() { + static::logDeprecatedFunction(); return PHP_MAXPATHLEN; } @@ -3178,6 +3192,7 @@ class GeneralUtility return $bInfo; } + /** * Get the fully-qualified domain name of the host. * @@ -3188,7 +3203,6 @@ class GeneralUtility { $host = ''; // If not called from the command-line, resolve on getIndpEnv() - // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined if ($requestHost && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) { $host = self::getIndpEnv('HTTP_HOST'); } @@ -3402,18 +3416,19 @@ class GeneralUtility */ public static function upload_copy_move($source, $destination) { + $result = false; if (is_uploaded_file($source)) { - $uploaded = true; - // Return the value of move_uploaded_file, and if FALSE the temporary $source is still around so the user can use unlink to delete it: - $uploadedResult = move_uploaded_file($source, $destination); + // Return the value of move_uploaded_file, and if FALSE the temporary $source is still + // around so the user can use unlink to delete it: + $result = move_uploaded_file($source, $destination); } else { - $uploaded = false; @copy($source, $destination); } // Change the permissions of the file self::fixPermissions($destination); - // If here the file is copied and the temporary $source is still around, so when returning FALSE the user can try unlink to delete the $source - return $uploaded ? $uploadedResult : false; + // If here the file is copied and the temporary $source is still around, + // so when returning FALSE the user can try unlink to delete the $source + return $result; } /** @@ -4190,9 +4205,8 @@ class GeneralUtility public static function initSysLog() { // For CLI logging name is <fqdn-hostname>:<TYPO3-path> - // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) { - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getHostname(($requestHost = false)) . ':' . PATH_site; + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getHostname() . ':' . PATH_site; } else { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getIndpEnv('TYPO3_SITE_URL'); } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75621-GeneralUtilityMethods.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75621-GeneralUtilityMethods.rst new file mode 100644 index 000000000000..18559ee2b329 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75621-GeneralUtilityMethods.rst @@ -0,0 +1,48 @@ +============================================ +Deprecation: #75621 - GeneralUtility methods +============================================ + +Description +=========== + +The following methods within GeneralUtility have been marked as deprecated: + +* compat_version() +* convertMicrotime() +* deHSCentities() +* slashJS() +* rawUrlEncodeJS() +* rawUrlEncodeFP() +* lcfirst() +* getMaximumPathLength() + +The second parameter of :php:`GeneralUtility::wrapJS()` has been removed. + + +Impact +====== + +Calling any of the methods above will trigger a deprecation log entry. + +Calling :php:`GeneralUtility::wrapJS()` with the second parameter will trigger a PHP notice message. + + +Affected Installations +====================== + +Any installation with a third-party extension calling one of the methods in its PHP code. + + +Migration +========= + +For the following methods, use the used PHP methods and constants directly that are used within these methods: + +* compat_version() +* convertMicrotime() +* deHSCentities() +* slashJS() +* rawUrlEncodeJS() +* rawUrlEncodeFP() +* lcfirst() +* getMaximumPathLength() diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index 0db0ca3cf3bd..107552f90424 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -1173,7 +1173,7 @@ class ContentObjectRenderer return ''; } if (is_file(PATH_site . $info['3'])) { - $source = $tsfe->absRefPrefix . GeneralUtility::rawUrlEncodeFP($info['3']); + $source = $tsfe->absRefPrefix . str_replace('%2F', '/', rawurlencode($info['3'])); } else { $source = $info[3]; } diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php index 6571263cba12..dd7aa95577c7 100644 --- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php @@ -1575,8 +1575,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList if ($this->isRecordCurrentBackendUser($table, $row)) { $deleteAction = $this->spaceIcon; } else { - $titleOrig = BackendUtility::getRecordTitle($table, $row, false, true); - $title = GeneralUtility::slashJS(GeneralUtility::fixed_lgd_cs($titleOrig, $this->fixedL), true); + $title = BackendUtility::getRecordTitle($table, $row); $warningText = $this->getLanguageService()->getLL($actionName . 'Warning') . ' "' . $title . '" ' . '[' . $table . ':' . $row['uid'] . ']' . $refCountMsg; $params = 'cmd[' . $table . '][' . $row['uid'] . '][delete]=1'; @@ -1584,7 +1583,7 @@ class DatabaseRecordList extends AbstractDatabaseRecordList $linkTitle = $this->getLanguageService()->getLL($actionName, true); $deleteAction = '<a class="btn btn-default t3js-record-delete" href="#" ' . ' data-l10parent="' . htmlspecialchars($row['l10n_parent']) . '"' - . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($titleOrig) . '"' + . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($title) . '"' . ' data-message="' . htmlspecialchars($warningText) . '" title="' . $linkTitle . '"' . '>' . $icon . '</a>'; } -- GitLab