From 30bbb596947dd93e53bd69d0add290e88ca3f137 Mon Sep 17 00:00:00 2001
From: Wouter Wolters <typo3@wouterwolters.nl>
Date: Sun, 1 Mar 2015 22:09:31 +0100
Subject: [PATCH] [TASK] Introduce getters for $GLOBALS in
 TranslationStatusController

Resolves: #65441
Releases: master
Change-Id: Ic9e790d2b2db17e930558dbafe4f458af948fc9a
Reviewed-on: http://review.typo3.org/37435
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 .../TranslationStatusController.php           | 92 ++++++++++++-------
 1 file changed, 61 insertions(+), 31 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php b/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php
index 79007f995c4a..1d1cadbe7c88 100644
--- a/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php
@@ -30,13 +30,14 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 	 * @return array
 	 */
 	public function modMenu() {
+		$lang = $this->getLanguageService();
 		$menuArray = array(
 			'depth' => array(
-				0 => $GLOBALS['LANG']->getLL('depth_0'),
-				1 => $GLOBALS['LANG']->getLL('depth_1'),
-				2 => $GLOBALS['LANG']->getLL('depth_2'),
-				3 => $GLOBALS['LANG']->getLL('depth_3'),
-				999 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
+				0 => $lang->getLL('depth_0'),
+				1 => $lang->getLL('depth_1'),
+				2 => $lang->getLL('depth_2'),
+				3 => $lang->getLL('depth_3'),
+				999 => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
 			)
 		);
 		// Languages:
@@ -56,7 +57,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 	 * @return string Output HTML for the module.
 	 */
 	public function main() {
-		$theOutput = $this->pObj->doc->header($GLOBALS['LANG']->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_title'));
+		$theOutput = $this->pObj->doc->header($this->getLanguageService()->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_title'));
 		if ($this->pObj->id) {
 			// Depth selector:
 			$h_func = BackendUtility::getFuncMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
@@ -71,7 +72,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 			$depth = $this->pObj->MOD_SETTINGS['depth'];
 			// Initialize tree object:
 			$tree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageTreeView::class);
-			$tree->init('AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1));
+			$tree->init('AND ' . $this->getBackendUser()->getPagePermsClause(1));
 			$tree->addField('l18n_cfg');
 			// Creating top icon; the current page
 			$HTML = IconUtility::getSpriteIconForRecord('pages', $treeStartingRecord);
@@ -96,10 +97,11 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 	 * @return string HTML for the localization information table.
 	 */
 	public function renderL10nTable(&$tree) {
+		$lang = $this->getLanguageService();
 		// System languages retrieved:
 		$languages = $this->getSystemLanguages();
 		// Title length:
-		$titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
+		$titleLen = $this->getBackendUser()->uc['titleLen'];
 		// Put together the TREE:
 		$output = '';
 		$newOL_js = array();
@@ -112,7 +114,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 				$GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($data['HTML'], 'pages', $data['row']['uid']) .
 				'<a href="#" onclick="' . htmlspecialchars(
 					'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=0"); return false;'
-				) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPage') . '">' .
+				) . '" title="' . $lang->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPage') . '">' .
 				htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($data['row']['title'], $titleLen)) .
 				'</a>' .
 				((string)$data['row']['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($data['row']['nav_title'], $titleLen)) . '</em>]' : '') .
@@ -121,7 +123,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 			// "View page" link is created:
 			$viewPageLink = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick(
 					$data['row']['uid'], $GLOBALS['BACK_PATH'], '', '', '', '&L=###LANG_UID###')
-				) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_viewPage') . '">' .
+				) . '" title="' . $lang->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_viewPage') . '">' .
 				IconUtility::getSpriteIcon('actions-document-view') . '</a>';
 			$status = $data['row']['l18n_cfg'] & 1 ? 'danger' : 'success';
 			// Create links:
@@ -130,16 +132,16 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 			$params = '&edit[pages][' . $editUid . ']=edit';
 			$info .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
 					$params, $GLOBALS['BACK_PATH'])
-				) . '" title="' . $GLOBALS['LANG']->sL(
+				) . '" title="' . $lang->sL(
 					'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editDefaultLanguagePage'
 				) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
 			$info .= str_replace('###LANG_UID###', '0', $viewPageLink);
 			$info .= '&nbsp;';
-			$info .= $data['row']['l18n_cfg'] & 1 ? '<span title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_tca.xlf:pages.l18n_cfg.I.1', TRUE) . '">D</span>' : '&nbsp;';
-			$info .= \TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_tca.xlf:pages.l18n_cfg.I.2', TRUE) . '">N</span>' : '&nbsp;';
+			$info .= $data['row']['l18n_cfg'] & 1 ? '<span title="' . $lang->sL('LLL:EXT:cms/locallang_tca.xlf:pages.l18n_cfg.I.1', TRUE) . '">D</span>' : '&nbsp;';
+			$info .= \TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="' . $lang->sL('LLL:EXT:cms/locallang_tca.xlf:pages.l18n_cfg.I.2', TRUE) . '">N</span>' : '&nbsp;';
 			// Put into cell:
 			$tCells[] = '<td class="' . $status . ' col-border-left">' . $info . '</td>';
-			$tCells[] = '<td class="' . $status . '" title="' . $GLOBALS['LANG']->sL(
+			$tCells[] = '<td class="' . $status . '" title="' . $lang->sL(
 					'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_CEcount'
 				) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], 0) . '</td>';
 			$modSharedTSconfig = BackendUtility::getModTSconfig($data['row']['uid'], 'mod.SHARED');
@@ -161,13 +163,13 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 								\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $titleLen)
 							) . ((string)$row['nav_title'] !== '' ? ' [Nav: <em>' . htmlspecialchars(
 								\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['nav_title'], $titleLen)
-							) . '</em>]' : '') . ($row['_COUNT'] > 1 ? '<div>' . $GLOBALS['LANG']->sL(
+							) . '</em>]' : '') . ($row['_COUNT'] > 1 ? '<div>' . $lang->sL(
 								'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_badThingThereAre'
 							) . '</div>' : '');
 						$tCells[] = '<td class="' . $status . ' col-border-left">' .
 							'<a href="#" onclick="' . htmlspecialchars(
 								'top.loadEditId(' . (int)$data['row']['uid'] . ',"&SET[language]=' . $langRow['uid'] . '"); return false;'
-							) . '" title="' . $GLOBALS['LANG']->sL(
+							) . '" title="' . $lang->sL(
 								'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPageLang'
 							) . '">' . $info . '</a></td>';
 						// Edit whole record:
@@ -176,12 +178,12 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 						$params = '&edit[pages_language_overlay][' . $editUid . ']=edit';
 						$info .= '<a href="#" onclick="' . htmlspecialchars(
 								BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
-							) . '" title="' . $GLOBALS['LANG']->sL(
+							) . '" title="' . $lang->sL(
 								'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editLanguageOverlayRecord'
 							) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
 						$info .= str_replace('###LANG_UID###', $langRow['uid'], $viewPageLink);
 						$tCells[] = '<td class="' . $status . '">' . $info . '</td>';
-						$tCells[] = '<td class="' . $status . '" title="' . $GLOBALS['LANG']->sL(
+						$tCells[] = '<td class="' . $status . '" title="' . $lang->sL(
 								'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_CEcount'
 							) . '" align="center">' . $this->getContentElementCount($data['row']['uid'], $langRow['uid']) . '</td>';
 					} else {
@@ -210,18 +212,18 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 		}
 		// Put together HEADER:
 		$tCells = array();
-		$tCells[] = '<td>' . $GLOBALS['LANG']->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_page') . ':</td>';
+		$tCells[] = '<td>' . $lang->sL('LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_page') . ':</td>';
 		if (is_array($langRecUids[0])) {
 			$params = '&edit[pages][' . implode(',', $langRecUids[0]) . ']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
 			$editIco = '<a href="#" onclick="' . htmlspecialchars(
 					BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
-				) . '" title="' . $GLOBALS['LANG']->sL(
+				) . '" title="' . $lang->sL(
 					'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editPageProperties'
 				) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
 		} else {
 			$editIco = '';
 		}
-		$tCells[] = '<td class="col-border-left" colspan="2">' . $GLOBALS['LANG']->sL(
+		$tCells[] = '<td class="col-border-left" colspan="2">' . $lang->sL(
 				'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_default'
 			) . ':' . $editIco . '</td>';
 		foreach ($languages as $langRow) {
@@ -235,7 +237,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 						']=edit&columnsOnly=title,nav_title,hidden';
 					$tCells[] = '<td><a href="#" onclick="' . htmlspecialchars(
 							BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
-						) . '" title="' . $GLOBALS['LANG']->sL(
+						) . '" title="' . $lang->sL(
 							'LLL:EXT:cms/web_info/locallang.xlf:lang_renderl10n_editLangOverlays'
 						) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a></td>';
 				} else {
@@ -248,7 +250,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 					$langRow['uid'];
 				$tCells[] = '<td><a href="#" onclick="' . htmlspecialchars(
 						BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'])
-					) . '" title="' . $GLOBALS['LANG']->sL(
+					) . '" title="' . $lang->sL(
 						'LLL:EXT:cms/web_info/locallang.xlf:lang_getlangsta_createNewTranslationHeaders'
 					) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a></td>';
 			}
@@ -276,12 +278,12 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 	 * @return array System language records in an array.
 	 */
 	public function getSystemLanguages() {
-		if (!$GLOBALS['BE_USER']->user['admin'] && $GLOBALS['BE_USER']->groupData['allowed_languages'] !== '') {
-			$allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
+		if (!$this->getBackendUser()->user['admin'] && $this->getBackendUser()->groupData['allowed_languages'] !== '') {
+			$allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
 		}
-		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_language', '1=1' . BackendUtility::deleteClause('sys_language'));
+		$res = $this->getDatabaseConnection()->exec_SELECTquery('*', 'sys_language', '1=1' . BackendUtility::deleteClause('sys_language'));
 		$outputArray = array();
-		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+		while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
 			if (is_array($allowed_languages) && count($allowed_languages)) {
 				if (isset($allowed_languages[$row['uid']])) {
 					$outputArray[] = $row;
@@ -290,6 +292,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 				$outputArray[] = $row;
 			}
 		}
+		$this->getDatabaseConnection()->sql_free_result($res);
 		return $outputArray;
 	}
 
@@ -301,7 +304,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 	 * @return array pages_languages_overlay record
 	 */
 	public function getLangStatus($pageId, $langId) {
-		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+		$res = $this->getDatabaseConnection()->exec_SELECTquery(
 			'*',
 			'pages_language_overlay',
 			'pid=' . (int)$pageId .
@@ -309,10 +312,10 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 				BackendUtility::deleteClause('pages_language_overlay') .
 				BackendUtility::versioningPlaceholderClause('pages_language_overlay')
 		);
-		$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+		$row = $this->getDatabaseConnection()->sql_fetch_assoc($res);
 		BackendUtility::workspaceOL('pages_language_overlay', $row);
 		if (is_array($row)) {
-			$row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
+			$row['_COUNT'] = $this->getDatabaseConnection()->sql_num_rows($res);
 			$row['_HIDDEN'] = $row['hidden'] || (int)$row['endtime'] > 0 && (int)$row['endtime'] < $GLOBALS['EXEC_TIME'] || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'];
 		}
 		return $row;
@@ -326,8 +329,35 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
 	 * @return int Number of content elements from the PID where the language is set to a certain value.
 	 */
 	public function getContentElementCount($pageId, $sysLang) {
-		$count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'tt_content', 'pid=' . (int)$pageId . ' AND sys_language_uid=' . (int)$sysLang . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'));
+		$count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'tt_content', 'pid=' . (int)$pageId . ' AND sys_language_uid=' . (int)$sysLang . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'));
 		return $count ?: '-';
 	}
 
+	/**
+	 * Returns LanguageService
+	 *
+	 * @return \TYPO3\CMS\Lang\LanguageService
+	 */
+	protected function getLanguageService() {
+		return $GLOBALS['LANG'];
+	}
+
+	/**
+	 * Returns the database connection
+	 *
+	 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+	 */
+	protected function getDatabaseConnection() {
+		return $GLOBALS['TYPO3_DB'];
+	}
+
+	/**
+	 * Returns the current BE user.
+	 *
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+	 */
+	protected function getBackendUser() {
+		return $GLOBALS['BE_USER'];
+	}
+
 }
-- 
GitLab