MediaWiki REL1_37
WebInstallerOutput.php
Go to the documentation of this file.
1<?php
25
39
45 public $parent;
46
51 private $contents = '';
52
57 private $headerDone = false;
58
63
70 public $allowFrames = false;
71
76 private $useShortHeader = false;
77
81 public function __construct( WebInstaller $parent ) {
82 $this->parent = $parent;
83 }
84
88 public function addHTML( $html ) {
89 $this->contents .= $html;
90 $this->flush();
91 }
92
97 public function addWikiTextAsInterface( $text ) {
98 $this->addHTML( $this->parent->parse( $text ) );
99 }
100
104 public function addHTMLNoFlush( $html ) {
105 $this->contents .= $html;
106 }
107
113 public function redirect( $url ) {
114 if ( $this->headerDone ) {
115 throw new MWException( __METHOD__ . ' called after sending headers' );
116 }
117 $this->redirectTarget = $url;
118 }
119
120 public function output() {
121 $this->flush();
122
123 if ( !$this->redirectTarget ) {
124 $this->outputFooter();
125 }
126 }
127
133 public function getCSS() {
134 $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
135
136 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
137 'debug' => 'true',
138 'lang' => $this->getLanguage()->getCode(),
139 'only' => 'styles',
140 ] ) );
141
142 $module = new ResourceLoaderSkinModule( [
143 'features' => [
144 'elements',
145 'interface-message-box'
146 ],
147 'styles' => [
148 'mw-config/config.css',
149 ],
150 ] );
151 $module->setConfig( $resourceLoader->getConfig() );
152
153 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
155 $module->readStyleFiles(
156 $module->getStyleFiles( $rlContext ),
157 $rlContext
158 ) );
159
160 return implode( "\n", $styles );
161 }
162
168 private function getCssUrl() {
169 return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
170 }
171
172 public function useShortHeader( $use = true ) {
173 $this->useShortHeader = $use;
174 }
175
176 public function allowFrames( $allow = true ) {
177 $this->allowFrames = $allow;
178 }
179
180 public function flush() {
181 if ( !$this->headerDone ) {
182 $this->outputHeader();
183 }
184 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
185 echo $this->contents;
186 flush();
187 $this->contents = '';
188 }
189 }
190
195 private function getLanguage() {
196 global $wgLang;
197
198 return is_object( $wgLang ) ? $wgLang
199 : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
200 }
201
205 public function getHeadAttribs() {
206 return [
207 'dir' => $this->getLanguage()->getDir(),
208 'lang' => $this->getLanguage()->getHtmlCode(),
209 ];
210 }
211
217 public function headerDone() {
218 return $this->headerDone;
219 }
220
221 public function outputHeader() {
222 $this->headerDone = true;
223 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
224
225 if ( !$this->allowFrames ) {
226 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
227 }
228
229 if ( $this->redirectTarget ) {
230 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
231
232 return;
233 }
234
235 if ( $this->useShortHeader ) {
236 $this->outputShortHeader();
237
238 return;
239 }
240
241?>
242<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
243
244<head>
245 <meta name="robots" content="noindex, nofollow" />
246 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
247 <title><?php $this->outputTitle(); ?></title>
248 <?php echo $this->getCssUrl() . "\n"; ?>
249 <?php echo $this->getJQuery() . "\n"; ?>
250 <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
251</head>
252
253<?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
254<div id="mw-page-base"></div>
255<div id="mw-head-base"></div>
256<div id="content" class="mw-body" role="main">
257<div id="bodyContent" class="mw-body-content">
258
259<h1><?php $this->outputTitle(); ?></h1>
260<?php
261 }
262
263 public function outputFooter() {
264 if ( $this->useShortHeader ) {
265 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
266
267 return;
268 }
269?>
270
271</div></div>
272
273<div id="mw-panel">
274 <div class="portal" id="p-logo">
275 <a href="https://www.mediawiki.org/" title="Main Page"></a>
276 </div>
277<?php
278 $message = wfMessage( 'config-sidebar' )->plain();
279 // Section 1: External links
280 // @todo FIXME: Migrate to plain link label messages (T227297).
281 foreach ( explode( '----', $message ) as $section ) {
282 echo '<div class="portal"><div class="body">';
283 echo $this->parent->parse( $section, true );
284 echo '</div></div>';
285 }
286 // Section 2: Installer pages
287 echo '<div class="portal"><div class="body"><ul>';
288 foreach ( [
289 'config-sidebar-relnotes' => 'ReleaseNotes',
290 'config-sidebar-license' => 'Copying',
291 'config-sidebar-upgrade' => 'UpgradeDoc',
292 ] as $msgKey => $pageName ) {
293 echo $this->parent->makeLinkItem(
294 $this->parent->getDocUrl( $pageName ),
295 wfMessage( $msgKey )->text()
296 );
297 }
298 echo '</ul></div></div>';
299?>
300</div>
301
302<?php
303 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
304 }
305
306 public function outputShortHeader() {
307?>
308<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
309
310<head>
311 <meta name="robots" content="noindex, nofollow" />
312 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
313 <title><?php $this->outputTitle(); ?></title>
314 <?php echo $this->getCssUrl() . "\n"; ?>
315 <?php echo $this->getJQuery() . "\n"; ?>
316 <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
317</head>
318
319<body style="background-image: none">
320<?php
321 }
322
323 public function outputTitle() {
324 echo wfMessage( 'config-title', MW_VERSION )->escaped();
325 }
326
330 public function getJQuery() {
331 return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
332 }
333
334}
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:36
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
$wgLang
Definition Setup.php:831
WebRequest clone which takes values from a provided array.
MediaWiki exception.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Context object that contains information about the state of a specific ResourceLoader web request.
Module for skin stylesheets.
static makeCombinedStyles(array $stylePairs)
Combines an associative array mapping media type to CSS into a single stylesheet with "@media" blocks...
Output class modelled on OutputPage.
bool $useShortHeader
Whether to use the limited header (used during CC license callbacks)
__construct(WebInstaller $parent)
string $contents
Buffered contents that haven't been output yet.
getCssUrl()
"<link>" to index.php?css=1 for the "<head>"
getCSS()
Get the stylesheet of the MediaWiki skin.
bool $allowFrames
Does the current page need to allow being used as a frame? If not, X-Frame-Options will be output to ...
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
bool $headerDone
Has the header (or short header) been output?
headerDone()
Get whether the header has been output.
Class for the core installer web interface.