MediaWiki master
WebInstallerOutput.php
Go to the documentation of this file.
1<?php
2
23namespace MediaWiki\Installer;
24
25use LogicException;
32
46
52 public $parent;
53
58 private $contents = '';
59
64 private $headerDone = false;
65
70
74 public function __construct( WebInstaller $parent ) {
75 $this->parent = $parent;
76 }
77
81 public function addHTML( $html ) {
82 $this->contents .= $html;
83 $this->flush();
84 }
85
90 public function addWikiTextAsInterface( $text ) {
91 $this->addHTML( $this->parent->parse( $text ) );
92 }
93
97 public function addHTMLNoFlush( $html ) {
98 $this->contents .= $html;
99 }
100
104 public function redirect( $url ) {
105 if ( $this->headerDone ) {
106 throw new LogicException( __METHOD__ . ' called after sending headers' );
107 }
108 $this->redirectTarget = $url;
109 }
110
111 public function output() {
112 $this->flush();
113
114 if ( !$this->redirectTarget ) {
115 $this->outputFooter();
116 }
117 }
118
124 public function getCSS() {
125 $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
126
127 $rlContext = new RL\Context( $resourceLoader, new FauxRequest( [
128 'debug' => 'true',
129 'lang' => $this->getLanguage()->getCode(),
130 'only' => 'styles',
131 ] ) );
132
133 $module = new RL\SkinModule( [
134 'features' => [
135 'elements',
136 'interface-message-box'
137 ],
138 'styles' => [
139 'mw-config/config.css',
140 ],
141 ] );
142 $module->setConfig( $resourceLoader->getConfig() );
143
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 ) );
150
151 return implode( "\n", $styles );
152 }
153
159 private function getCssUrl() {
160 return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
161 }
162
163 public function flush() {
164 if ( !$this->headerDone ) {
165 $this->outputHeader();
166 }
167 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
168 echo $this->contents;
169 flush();
170 $this->contents = '';
171 }
172 }
173
178 private function getLanguage() {
179 global $wgLang;
180
181 return is_object( $wgLang ) ? $wgLang
182 : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
183 }
184
188 public function getHeadAttribs() {
189 return [
190 'dir' => $this->getLanguage()->getDir(),
191 'lang' => $this->getLanguage()->getHtmlCode(),
192 ];
193 }
194
200 public function headerDone() {
201 return $this->headerDone;
202 }
203
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' );
208
209 if ( $this->redirectTarget ) {
210 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
211
212 return;
213 }
214?>
215<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
216
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>
226
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">
232
233<h1><?php $this->outputTitle(); ?></h1>
234<?php
235 }
236
237 public function outputFooter() {
238?>
239
240</div></div>
241
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>';
255 }
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()
266 );
267 }
268 echo '</ul></div></div>';
269 // @phpcs:enable
270?>
271</aside>
272
273<?php
274 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
275 }
276
277 public function outputTitle() {
278 echo wfMessage( 'config-title', MW_VERSION )->escaped();
279 }
280
284 public function getJQuery() {
285 return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
286 }
287
291 public function getCodex() {
292 return Html::linkedStyle( "../resources/lib/codex/codex.style.css" );
293 }
294
295}
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:37
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
Definition Setup.php:572
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
Output class modelled on OutputPage.
headerDone()
Get whether the header has been output.
getCSS()
Get the stylesheet of the MediaWiki skin.
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
Class for the core installer web interface.
Base class for language-specific code.
Definition Language.php:80
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
WebRequest clone which takes values from a provided array.
Context object that contains information about the state of a specific ResourceLoader web request.
Definition Context.php:46
ResourceLoader is a loading system for JavaScript and CSS resources.
Module for skin stylesheets.