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
71 public function __construct( WebInstaller $parent ) {
72 $this->parent = $parent;
73 }
74
78 public function addHTML( $html ) {
79 $this->contents .= $html;
80 $this->flush();
81 }
82
87 public function addWikiTextAsInterface( $text ) {
88 $this->addHTML( $this->parent->parse( $text ) );
89 }
90
94 public function addHTMLNoFlush( $html ) {
95 $this->contents .= $html;
96 }
97
101 public function redirect( $url ) {
102 if ( $this->headerDone ) {
103 throw new LogicException( __METHOD__ . ' called after sending headers' );
104 }
105 $this->redirectTarget = $url;
106 }
107
108 public function output() {
109 $this->flush();
110
111 if ( !$this->redirectTarget ) {
112 $this->outputFooter();
113 }
114 }
115
121 public function getCSS() {
122 $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
123
124 $rlContext = new RL\Context( $resourceLoader, new FauxRequest( [
125 'debug' => 'true',
126 'lang' => $this->getLanguage()->getCode(),
127 'only' => 'styles',
128 ] ) );
129
130 $module = new RL\SkinModule( [
131 'features' => [
132 'elements',
133 'interface-message-box'
134 ],
135 'styles' => [
136 'mw-config/config.css',
137 ],
138 ] );
139 $module->setConfig( $resourceLoader->getConfig() );
140
141 // Based on MediaWiki\ResourceLoader\FileModule::getStyles, without the DB query
142 $styles = ResourceLoader::makeCombinedStyles(
143 $module->readStyleFiles(
144 $module->getStyleFiles( $rlContext ),
145 $rlContext
146 ) );
147
148 return implode( "\n", $styles );
149 }
150
156 private function getCssUrl() {
157 return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
158 }
159
160 public function flush() {
161 if ( !$this->headerDone ) {
162 $this->outputHeader();
163 }
164 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
165 echo $this->contents;
166 flush();
167 $this->contents = '';
168 }
169 }
170
175 private function getLanguage() {
176 global $wgLang;
177
178 return is_object( $wgLang ) ? $wgLang
179 : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
180 }
181
185 public function getHeadAttribs() {
186 return [
187 'dir' => $this->getLanguage()->getDir(),
188 'lang' => $this->getLanguage()->getHtmlCode(),
189 ];
190 }
191
197 public function headerDone() {
198 return $this->headerDone;
199 }
200
201 public function outputHeader() {
202 $this->headerDone = true;
203 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
204 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
205
206 if ( $this->redirectTarget ) {
207 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
208
209 return;
210 }
211?>
212<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
213
214<head>
215 <meta name="robots" content="noindex, nofollow" />
216 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
217 <title><?php $this->outputTitle(); ?></title>
218 <?php echo $this->getCodex() . "\n"; ?>
219 <?php echo $this->getCssUrl() . "\n"; ?>
220 <?php echo $this->getJQuery() . "\n"; ?>
221 <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
222</head>
223
224<?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
225<div id="mw-page-base"></div>
226<div id="mw-head-base"></div>
227<div id="content" class="mw-body" role="main">
228<div id="bodyContent" class="mw-body-content">
229
230<h1><?php $this->outputTitle(); ?></h1>
231<?php
232 }
233
234 public function outputFooter() {
235?>
236
237</div></div>
238
239<aside id="mw-panel">
240 <div class="portal" id="p-logo">
241 <a href="https://www.mediawiki.org/" title="Main Page"></a>
242 </div>
243<?php
244 // @phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
245 $message = wfMessage( 'config-sidebar' )->plain();
246 // Section 1: External links
247 // @todo FIXME: Migrate to plain link label messages (T227297).
248 foreach ( explode( '----', $message ) as $section ) {
249 echo '<div class="portal"><div class="body">';
250 echo $this->parent->parse( $section, true );
251 echo '</div></div>';
252 }
253 // Section 2: Installer pages
254 echo '<div class="portal"><div class="body"><ul>';
255 foreach ( [
256 'config-sidebar-relnotes' => 'ReleaseNotes',
257 'config-sidebar-license' => 'Copying',
258 'config-sidebar-upgrade' => 'UpgradeDoc',
259 ] as $msgKey => $pageName ) {
260 echo $this->parent->makeLinkItem(
261 $this->parent->getDocUrl( $pageName ),
262 wfMessage( $msgKey )->text()
263 );
264 }
265 echo '</ul></div></div>';
266 // @phpcs:enable
267?>
268</aside>
269
270<?php
271 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
272 }
273
274 public function outputTitle() {
275 echo wfMessage( 'config-title', MW_VERSION )->escaped();
276 }
277
281 public function getJQuery() {
282 return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
283 }
284
288 public function getCodex() {
289 return Html::linkedStyle( "../resources/lib/codex/codex.style.css" );
290 }
291
292}
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:558
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:82
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.