[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContentElement / ElementHistoryController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\ContentElement;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ServerRequestInterface;
18 use Psr\Http\Message\ResponseInterface;
19 use TYPO3\CMS\Backend\History\RecordHistory;
20 use TYPO3\CMS\Backend\Module\AbstractModule;
21 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
22 use TYPO3\CMS\Backend\Template\DocumentTemplate;
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 use TYPO3\CMS\Core\Imaging\Icon;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26
27 /**
28 * Script Class for showing the history module of TYPO3s backend
29 * @see \TYPO3\CMS\Backend\History\RecordHistory
30 */
31 class ElementHistoryController extends AbstractModule
32 {
33 /**
34 * @var string
35 */
36 public $content;
37
38 /**
39 * Document template object
40 *
41 * @var DocumentTemplate
42 */
43 public $doc;
44
45 /**
46 * @var array
47 */
48 protected $pageInfo;
49
50 /**
51 * Constructor
52 */
53 public function __construct()
54 {
55 parent::__construct();
56 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_show_rechis.xlf');
57 $GLOBALS['SOBE'] = $this;
58
59 $this->init();
60 }
61
62 /**
63 * Injects the request object for the current request or subrequest
64 * As this controller goes only through the main() method, it is rather simple for now
65 *
66 * @param ServerRequestInterface $request the current request
67 * @param ResponseInterface $response
68 * @return ResponseInterface the response with the content
69 */
70 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
71 {
72 $this->main();
73
74 $response->getBody()->write($this->moduleTemplate->renderContent());
75 return $response;
76 }
77
78 /**
79 * Initialize the module output
80 *
81 * @return void
82 */
83 protected function init()
84 {
85 // Create internal template object
86 // This is ugly, we need to remove the dependency-wiring via GLOBALS['SOBE']
87 // In this case, RecordHistory.php depends on GLOBALS[SOBE] being set in here
88 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
89 }
90
91 /**
92 * Generate module output
93 *
94 * @return void
95 */
96 public function main()
97 {
98 $this->content = '<h1>' . $this->getLanguageService()->getLL('title') . '</h1>';
99 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation([]);
100
101 // Start history object
102 $historyObj = GeneralUtility::makeInstance(RecordHistory::class);
103
104 $elementData = GeneralUtility::trimExplode(':', $historyObj->element);
105 $this->setPagePath($elementData[0], $elementData[1]);
106
107 // Get content:
108 $this->content .= $historyObj->main();
109 // Setting up the buttons and markers for docheader
110 $this->getButtons();
111 // Build the <body> for the module
112 $this->moduleTemplate->setContent($this->content);
113 }
114
115 /**
116 * Creates the correct path to the current record
117 *
118 * @param string $table
119 * @param int $uid
120 */
121 protected function setPagePath($table, $uid)
122 {
123 $uid = (int)$uid;
124
125 if ($table === 'pages') {
126 $pageId = $uid;
127 } else {
128 $record = BackendUtility::getRecord($table, $uid, '*', '', false);
129 $pageId = $record['pid'];
130 }
131
132 $pageAccess = BackendUtility::readPageAccess($pageId, $this->getBackendUser()->getPagePermsClause(1));
133 if (is_array($pageAccess)) {
134 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageAccess);
135 }
136 }
137
138 /**
139 * Create the panel of buttons for submitting the form or otherwise perform operations.
140 *
141 * @return array All available buttons as an assoc. array
142 */
143 protected function getButtons()
144 {
145 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
146
147 $helpButton = $buttonBar->makeHelpButton()
148 ->setModuleName('xMOD_csh_corebe')
149 ->setFieldName('history_log');
150 $buttonBar->addButton($helpButton);
151
152 // Get returnUrl parameter
153 $returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
154 if ($returnUrl) {
155 $backButton = $buttonBar->makeLinkButton()
156 ->setHref($returnUrl)
157 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', true))
158 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
159 $buttonBar->addButton($backButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
160 }
161 }
162
163 /**
164 * Returns LanguageService
165 *
166 * @return \TYPO3\CMS\Lang\LanguageService
167 */
168 protected function getLanguageService()
169 {
170 return $GLOBALS['LANG'];
171 }
172
173 /**
174 * Gets the current backend user.
175 *
176 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
177 */
178 protected function getBackendUser()
179 {
180 return $GLOBALS['BE_USER'];
181 }
182 }