[TASK] Use UTF-8 as default for LanguageService 45/46545/2
authorBenni Mack <benni@typo3.org>
Tue, 9 Feb 2016 11:07:57 +0000 (12:07 +0100)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 12 Feb 2016 08:00:35 +0000 (09:00 +0100)
The TYPO3 Backend is utf-8 by default since TYPO3 4.5, but certain
places read the value still from $GLOBALS['LANG']->charSet, which
is now always "utf-8".

All occurrences are replaced by "utf-8" for now. Future cleanups
will further simplify these code changes.

Resolves: #73194
Releases: master
Change-Id: I4b68a168ee7f2468b196cd3ccd1336cf6ba8a1df
Reviewed-on: https://review.typo3.org/46545
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
14 files changed:
typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/core/Classes/Configuration/FlexForm/FlexFormTools.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php
typo3/sysext/impexp/Classes/Controller/ImportExportController.php
typo3/sysext/impexp/Classes/Export.php
typo3/sysext/impexp/Classes/Import.php
typo3/sysext/indexed_search/Classes/Example/CrawlerHook.php
typo3/sysext/indexed_search/Classes/Hook/CrawlerHook.php
typo3/sysext/lang/Classes/LanguageService.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php

index 3efd2a7..38d3de7 100644 (file)
@@ -174,9 +174,9 @@ class SuggestWizardDefaultReceiver
                     $languageService = $this->getLanguageService();
                     $croppedPath = '<abbr title="' . htmlspecialchars($path) . '">' .
                         htmlspecialchars(
-                                $languageService->csConvObj->crop($languageService->charSet, $path, 10)
+                                $languageService->csConvObj->crop('utf-8', $path, 10)
                                 . '...'
-                                . $languageService->csConvObj->crop($languageService->charSet, $path, -20)
+                                . $languageService->csConvObj->crop('utf-8', $path, -20)
                         ) .
                         '</abbr>';
                 } else {
index 3878420..c656413 100644 (file)
@@ -786,7 +786,6 @@ class BackendUtilityTest extends UnitTestCase
         );
         // Stub LanguageService and let sL() return the same value that came in again
         $GLOBALS['LANG'] = $this->getMock(LanguageService::class, array(), array(), '', false);
-        $GLOBALS['LANG']->charSet = 'utf-8';
         $GLOBALS['LANG']->csConvObj = $this->getMock(CharsetConverter::class);
         $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
 
@@ -818,7 +817,6 @@ class BackendUtilityTest extends UnitTestCase
         );
         // Stub LanguageService and let sL() return the same value that came in again
         $GLOBALS['LANG'] = $this->getMock(LanguageService::class, array(), array(), '', false);
-        $GLOBALS['LANG']->charSet = 'utf-8';
         $GLOBALS['LANG']->csConvObj = $this->getMock(CharsetConverter::class);
         $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
 
index 4e8b821..8116712 100644 (file)
@@ -111,8 +111,7 @@ class FlexFormTools
                 $xmlHeaderAttributes = GeneralUtility::xmlGetHeaderAttribs($xmlData);
                 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
                 if ($storeInCharset) {
-                    $currentCharset = $GLOBALS['LANG']->charSet;
-                    $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData, $storeInCharset, $currentCharset, 1);
+                    $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData, $storeInCharset, 'utf-8', 1);
                 }
             }
             $editData = GeneralUtility::xml2array($xmlData);
index 845ef8b..789f6b4 100644 (file)
@@ -1763,7 +1763,7 @@ class DataHandler
         }
         // Secures the string-length to be less than max.
         if ((int)$tcaFieldConf['max'] > 0) {
-            $value = $GLOBALS['LANG']->csConvObj->substr($GLOBALS['LANG']->charSet, (string)$value, 0, (int)$tcaFieldConf['max']);
+            $value = $GLOBALS['LANG']->csConvObj->substr('utf-8', (string)$value, 0, (int)$tcaFieldConf['max']);
         }
         // Checking range of value:
         // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
@@ -2684,10 +2684,10 @@ class DataHandler
                     $value = trim($value);
                     break;
                 case 'upper':
-                    $value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toUpper');
+                    $value = $GLOBALS['LANG']->csConvObj->conv_case('utf-8', $value, 'toUpper');
                     break;
                 case 'lower':
-                    $value = $GLOBALS['LANG']->csConvObj->conv_case($GLOBALS['LANG']->charSet, $value, 'toLower');
+                    $value = $GLOBALS['LANG']->csConvObj->conv_case('utf-8', $value, 'toLower');
                     break;
                 case 'required':
                     if (!isset($value) || $value === '') {
index 2f1ecc4..388a92d 100755 (executable)
@@ -274,7 +274,7 @@ class GeneralUtility
     public static function fixed_lgd_cs($string, $chars, $appendString = '...')
     {
         if (is_object($GLOBALS['LANG'])) {
-            return $GLOBALS['LANG']->csConvObj->crop($GLOBALS['LANG']->charSet, $string, $chars, $appendString);
+            return $GLOBALS['LANG']->csConvObj->crop('utf-8', $string, $chars, $appendString);
         } elseif (is_object($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']->csConvObj)) {
             $charSet = $GLOBALS['TSFE']->renderCharset != '' ? $GLOBALS['TSFE']->renderCharset : $GLOBALS['TSFE']->defaultCharSet;
             return $GLOBALS['TSFE']->csConvObj->crop($charSet, $string, $chars, $appendString);
index 6246473..27b88f1 100644 (file)
@@ -166,7 +166,7 @@ class LocalizationUtility
         }
         $locallangPathAndFilename = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/' . self::$locallangPath . 'locallang.xlf';
         self::setLanguageKeys();
-        $renderCharset = TYPO3_MODE === 'FE' ? self::getTypoScriptFrontendController()->renderCharset : self::getLanguageService()->charSet;
+        $renderCharset = TYPO3_MODE === 'FE' ? self::getTypoScriptFrontendController()->renderCharset : 'utf-8';
 
         /** @var $languageFactory LocalizationFactory */
         $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
@@ -298,7 +298,7 @@ class LocalizationUtility
         if (TYPO3_MODE === 'FE') {
             return self::getTypoScriptFrontendController()->csConv($value, $charset);
         } else {
-            $convertedValue = self::getLanguageService()->csConvObj->conv($value, self::getLanguageService()->csConvObj->parse_charset($charset), self::getLanguageService()->charSet, 1);
+            $convertedValue = self::getLanguageService()->csConvObj->conv($value, self::getLanguageService()->csConvObj->parse_charset($charset), 'utf-8', 1);
             return $convertedValue !== null ? $convertedValue : $value;
         }
     }
index 12cddbf..c35b2c7 100644 (file)
@@ -149,11 +149,7 @@ class CropViewHelper extends AbstractViewHelper
         }
         // preparing renderCharset
         if (!is_object($GLOBALS['TSFE']->renderCharset)) {
-            if (is_object($GLOBALS['LANG'])) {
-                $GLOBALS['TSFE']->renderCharset = $GLOBALS['LANG']->charSet;
-            } else {
-                $GLOBALS['TSFE']->renderCharset = 'utf-8';
-            }
+            $GLOBALS['TSFE']->renderCharset = 'utf-8';
         }
     }
 
index 1a9f380..2bdc26d 100644 (file)
@@ -345,7 +345,6 @@ class ImportExportController extends BaseScriptClass
         // Create export object and configure it:
         $this->export = GeneralUtility::makeInstance(Export::class);
         $this->export->init(0);
-        $this->export->setCharset($this->lang->charSet);
         $this->export->maxFileSize = $inData['maxFileSize'] * 1024;
         $this->export->excludeMap = (array)$inData['exclude'];
         $this->export->softrefCfg = (array)$inData['softrefCfg'];
index 1ebfaee..d26c83a 100644 (file)
@@ -174,6 +174,7 @@ class Export extends ImportExport
         $this->dat['header']['softrefCfg'] = $this->softrefCfg;
         // List of extensions the import depends on.
         $this->dat['header']['extensionDependencies'] = $this->extensionDependencies;
+        $this->dat['header']['charset'] = 'utf-8';
     }
 
     /**
index f4d376b..c599ed4 100644 (file)
@@ -2168,19 +2168,19 @@ class Import extends ImportExport
     {
         $importCharset = $this->dat['header']['charset'];
         if ($importCharset) {
-            if ($importCharset !== $this->getLanguageService()->charSet) {
-                $this->error('CHARSET: Converting charset of input file (' . $importCharset . ') to the system charset (' . $this->getLanguageService()->charSet . ')');
+            if ($importCharset !== 'utf-8') {
+                $this->error('CHARSET: Converting charset of input file (' . $importCharset . ') to the system charset (utf-8)');
                 // Convert meta data:
                 if (is_array($this->dat['header']['meta'])) {
-                    $this->getLanguageService()->csConvObj->convArray($this->dat['header']['meta'], $importCharset, $this->getLanguageService()->charSet);
+                    $this->getLanguageService()->csConvObj->convArray($this->dat['header']['meta'], $importCharset, 'utf-8');
                 }
                 // Convert record headers:
                 if (is_array($this->dat['header']['records'])) {
-                    $this->getLanguageService()->csConvObj->convArray($this->dat['header']['records'], $importCharset, $this->getLanguageService()->charSet);
+                    $this->getLanguageService()->csConvObj->convArray($this->dat['header']['records'], $importCharset, 'utf-8');
                 }
                 // Convert records themselves:
                 if (is_array($this->dat['records'])) {
-                    $this->getLanguageService()->csConvObj->convArray($this->dat['records'], $importCharset, $this->getLanguageService()->charSet);
+                    $this->getLanguageService()->csConvObj->convArray($this->dat['records'], $importCharset, 'utf-8');
                 }
             }
         } else {
index b68f932..c2c7b61 100644 (file)
@@ -85,7 +85,7 @@ class CrawlerHook
                     $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']);
                     $indexerObj->forceIndexing = true;
                     // Indexing the content of the item (see \TYPO3\CMS\IndexedSearch\Indexer::backend_indexAsTYPO3Page() for options)
-                    $indexerObj->backend_indexAsTYPO3Page($item['title'], '', '', $item['content'], $GLOBALS['LANG']->charSet, $item['tstamp'], $item['create_date'], $item['ID']);
+                    $indexerObj->backend_indexAsTYPO3Page($item['title'], '', '', $item['content'], 'utf-8', $item['tstamp'], $item['create_date'], $item['ID']);
                 }
                 break;
             case 2:
index 453e3d2..64c13d8 100644 (file)
@@ -556,7 +556,7 @@ class CrawlerHook
             }
         }
         // Indexing the record as a page (but with parameters set, see ->backend_setFreeIndexUid())
-        $indexerObj->backend_indexAsTYPO3Page(strip_tags(str_replace('<', ' <', $theTitle)), '', '', strip_tags(str_replace('<', ' <', $theContent)), $GLOBALS['LANG']->charSet, $r[$GLOBALS['TCA'][$cfgRec['table2index']]['ctrl']['tstamp']], $r[$GLOBALS['TCA'][$cfgRec['table2index']]['ctrl']['crdate']], $r['uid']);
+        $indexerObj->backend_indexAsTYPO3Page(strip_tags(str_replace('<', ' <', $theTitle)), '', '', strip_tags(str_replace('<', ' <', $theContent)), 'utf-8', $r[$GLOBALS['TCA'][$cfgRec['table2index']]['ctrl']['tstamp']], $r[$GLOBALS['TCA'][$cfgRec['table2index']]['ctrl']['crdate']], $r['uid']);
     }
 
     /**
index a1ce077..10131c6 100755 (executable)
@@ -38,7 +38,8 @@ class LanguageService
     public $lang = 'default';
 
     /**
-     * Default charset in backend
+     * Default charset in backend, is always UTF-8, option is not in use anymore, but is kept for third-party extensions
+     * using this option. Will be removed in future versions
      *
      * @var string
      */
@@ -406,7 +407,7 @@ class LanguageService
         }
         $localLanguage = array();
         foreach ($languages as $language) {
-            $tempLL = $languageFactory->getParsedData($fileRef, $language, $this->charSet);
+            $tempLL = $languageFactory->getParsedData($fileRef, $language, 'utf-8');
             $localLanguage['default'] = $tempLL['default'];
             if (!isset($localLanguage[$this->lang])) {
                 $localLanguage[$this->lang] = $localLanguage['default'];
index 479e1bf..0cf41e3 100644 (file)
@@ -67,10 +67,10 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 'setup' => $lang->getLL('setup')
             ),
             'ts_browser_toplevel_setup' => array(
-                '0' => $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('all'), 'toUpper')
+                '0' => $lang->csConvObj->conv_case('utf-8', $lang->getLL('all'), 'toUpper')
             ),
             'ts_browser_toplevel_const' => array(
-                '0' => $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('all'), 'toUpper')
+                '0' => $lang->csConvObj->conv_case('utf-8', $lang->getLL('all'), 'toUpper')
             ),
             'ts_browser_const' => array(
                 '0' => $lang->getLL('plainSubstitution'),
@@ -292,7 +292,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 $out = '<div class="form-group">';
                 $out .= '      <div class="checkbox">';
                 $out .= '              <label>';
-                $out .= '                      ' . htmlspecialchars($this->pObj->sObj) . ' ' . $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('clear'), 'toUpper');
+                $out .= '                      ' . htmlspecialchars($this->pObj->sObj) . ' ' . $lang->csConvObj->conv_case('utf-8', $lang->getLL('clear'), 'toUpper');
                 $out .= '                      <input type="checkbox" name="data[' . htmlspecialchars($this->pObj->sObj) . '][clearValue]" value="1" />';
                 $out .= '              </label>';
                 $out .= '              <input class="btn btn-default" type="submit" name="clear_object" value="' . $lang->getLL('clearButton') . '" />';
@@ -423,7 +423,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 $remove = '';
             }
 
-            $label = $theKey ? $theKey : ($bType == 'setup' ? $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('setupRoot'), 'toUpper') : $lang->csConvObj->conv_case($lang->charSet, $lang->getLL('constantRoot'), 'toUpper'));
+            $label = $theKey ? $theKey : ($bType == 'setup' ? $lang->csConvObj->conv_case('utf-8', $lang->getLL('setupRoot'), 'toUpper') : $lang->csConvObj->conv_case('utf-8', $lang->getLL('constantRoot'), 'toUpper'));
 
             $theOutput .= '<div class="panel panel-space panel-default">';
             $theOutput .= '<div class="panel-heading">';