Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / installer / WebInstallerOutput.php
blob816e8b6ea25a4dd6e77a018dc0fd5649344d39b4
1 <?php
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
19 * @file
20 * @ingroup Installer
23 namespace MediaWiki\Installer;
25 use LogicException;
26 use MediaWiki\Html\Html;
27 use MediaWiki\Language\Language;
28 use MediaWiki\MediaWikiServices;
29 use MediaWiki\Request\FauxRequest;
30 use MediaWiki\ResourceLoader as RL;
31 use MediaWiki\ResourceLoader\ResourceLoader;
33 /**
34 * Output class modelled on OutputPage.
36 * I've opted to use a distinct class rather than derive from OutputPage here in
37 * the interests of separation of concerns: if we used a subclass, there would be
38 * quite a lot of things you could do in OutputPage that would break the installer,
39 * that wouldn't be immediately obvious.
41 * @ingroup Installer
42 * @since 1.17
43 * @internal
45 class WebInstallerOutput {
47 /**
48 * The WebInstaller object this WebInstallerOutput is used by.
50 * @var WebInstaller
52 public $parent;
54 /**
55 * Buffered contents that haven't been output yet
56 * @var string
58 private $contents = '';
60 /**
61 * Has the header been output?
62 * @var bool
64 private $headerDone = false;
66 /**
67 * @var string
69 public $redirectTarget;
71 /**
72 * @param WebInstaller $parent
74 public function __construct( WebInstaller $parent ) {
75 $this->parent = $parent;
78 /**
79 * @param string $html
81 public function addHTML( $html ) {
82 $this->contents .= $html;
83 $this->flush();
86 /**
87 * @param string $text
88 * @since 1.32
90 public function addWikiTextAsInterface( $text ) {
91 $this->addHTML( $this->parent->parse( $text ) );
94 /**
95 * @param string $html
97 public function addHTMLNoFlush( $html ) {
98 $this->contents .= $html;
102 * @param string $url
104 public function redirect( $url ) {
105 if ( $this->headerDone ) {
106 throw new LogicException( __METHOD__ . ' called after sending headers' );
108 $this->redirectTarget = $url;
111 public function output() {
112 $this->flush();
114 if ( !$this->redirectTarget ) {
115 $this->outputFooter();
120 * Get the stylesheet of the MediaWiki skin.
122 * @return string
124 public function getCSS() {
125 $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
127 $rlContext = new RL\Context( $resourceLoader, new FauxRequest( [
128 'debug' => 'true',
129 'lang' => $this->getLanguage()->getCode(),
130 'only' => 'styles',
131 ] ) );
133 $module = new RL\SkinModule( [
134 'features' => [
135 'elements',
136 'interface-message-box'
138 'styles' => [
139 'mw-config/config.css',
141 ] );
142 $module->setConfig( $resourceLoader->getConfig() );
144 // Based on MediaWiki\ResourceLoader\FileModule::getStyles, without the DB query
145 $styles = ResourceLoader::makeCombinedStyles(
146 $module->readStyleFiles(
147 $module->getStyleFiles( $rlContext ),
148 $rlContext
149 ) );
151 return implode( "\n", $styles );
155 * "<link>" to index.php?css=1 for the "<head>"
157 * @return string
159 private function getCssUrl() {
160 return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
163 public function flush() {
164 if ( !$this->headerDone ) {
165 $this->outputHeader();
167 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
168 echo $this->contents;
169 flush();
170 $this->contents = '';
175 * @since 1.33
176 * @return Language
178 private function getLanguage() {
179 global $wgLang;
181 return is_object( $wgLang ) ? $wgLang
182 : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
186 * @return string[]
188 public function getHeadAttribs() {
189 return [
190 'dir' => $this->getLanguage()->getDir(),
191 'lang' => $this->getLanguage()->getHtmlCode(),
196 * Get whether the header has been output
198 * @return bool
200 public function headerDone() {
201 return $this->headerDone;
204 public function outputHeader() {
205 $this->headerDone = true;
206 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
207 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
209 if ( $this->redirectTarget ) {
210 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
212 return;
215 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
217 <head>
218 <meta name="robots" content="noindex, nofollow" />
219 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
220 <title><?php $this->outputTitle(); ?></title>
221 <?php echo $this->getCodex() . "\n"; ?>
222 <?php echo $this->getCssUrl() . "\n"; ?>
223 <?php echo $this->getJQuery() . "\n"; ?>
224 <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
225 </head>
227 <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
228 <div id="mw-page-base"></div>
229 <div id="mw-head-base"></div>
230 <div id="content" class="mw-body" role="main">
231 <div id="bodyContent" class="mw-body-content">
233 <h1><?php $this->outputTitle(); ?></h1>
234 <?php
237 public function outputFooter() {
240 </div></div>
242 <aside id="mw-panel">
243 <div class="portal" id="p-logo">
244 <a href="https://www.mediawiki.org/" title="Main Page"></a>
245 </div>
246 <?php
247 // @phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
248 $message = wfMessage( 'config-sidebar' )->plain();
249 // Section 1: External links
250 // @todo FIXME: Migrate to plain link label messages (T227297).
251 foreach ( explode( '----', $message ) as $section ) {
252 echo '<div class="portal"><div class="body">';
253 echo $this->parent->parse( $section, true );
254 echo '</div></div>';
256 // Section 2: Installer pages
257 echo '<div class="portal"><div class="body"><ul>';
258 foreach ( [
259 'config-sidebar-relnotes' => 'ReleaseNotes',
260 'config-sidebar-license' => 'Copying',
261 'config-sidebar-upgrade' => 'UpgradeDoc',
262 ] as $msgKey => $pageName ) {
263 echo $this->parent->makeLinkItem(
264 $this->parent->getDocUrl( $pageName ),
265 wfMessage( $msgKey )->text()
268 echo '</ul></div></div>';
269 // @phpcs:enable
271 </aside>
273 <?php
274 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
277 public function outputTitle() {
278 echo wfMessage( 'config-title', MW_VERSION )->escaped();
282 * @return string
284 public function getJQuery() {
285 return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
289 * @return string
291 public function getCodex() {
292 return Html::linkedStyle( "../resources/lib/codex/codex.style.css" );