MediaWiki REL1_35
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 $moduleNames = [
135 'mediawiki.skinning.interface',
136 'mediawiki.legacy.config'
137 ];
138
139 $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
140
141 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
142 'debug' => 'true',
143 'lang' => $this->getLanguage()->getCode(),
144 'only' => 'styles',
145 ] ) );
146
147 $styles = [];
148 foreach ( $moduleNames as $moduleName ) {
150 $module = $resourceLoader->getModule( $moduleName );
151 '@phan-var ResourceLoaderFileModule $module';
152 if ( !$module ) {
153 // T98043: Don't fatal, but it won't look as pretty.
154 continue;
155 }
156
157 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
158 $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
159 $module->readStyleFiles(
160 $module->getStyleFiles( $rlContext ),
161 $rlContext
162 ) ) );
163 }
164
165 return implode( "\n", $styles );
166 }
167
173 private function getCssUrl() {
174 return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
175 }
176
177 public function useShortHeader( $use = true ) {
178 $this->useShortHeader = $use;
179 }
180
181 public function allowFrames( $allow = true ) {
182 $this->allowFrames = $allow;
183 }
184
185 public function flush() {
186 if ( !$this->headerDone ) {
187 $this->outputHeader();
188 }
189 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
190 echo $this->contents;
191 flush();
192 $this->contents = '';
193 }
194 }
195
200 private function getLanguage() {
201 global $wgLang;
202
203 return is_object( $wgLang ) ? $wgLang
204 : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
205 }
206
210 public function getHeadAttribs() {
211 return [
212 'dir' => $this->getLanguage()->getDir(),
213 'lang' => $this->getLanguage()->getHtmlCode(),
214 ];
215 }
216
222 public function headerDone() {
223 return $this->headerDone;
224 }
225
226 public function outputHeader() {
227 $this->headerDone = true;
228 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
229
230 if ( !$this->allowFrames ) {
231 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
232 }
233
234 if ( $this->redirectTarget ) {
235 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
236
237 return;
238 }
239
240 if ( $this->useShortHeader ) {
241 $this->outputShortHeader();
242
243 return;
244 }
245
246?>
247<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
248
249<head>
250 <meta name="robots" content="noindex, nofollow" />
251 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
252 <title><?php $this->outputTitle(); ?></title>
253 <?php echo $this->getCssUrl() . "\n"; ?>
254 <?php echo $this->getJQuery() . "\n"; ?>
255 <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
256</head>
257
258<?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
259<div id="mw-page-base"></div>
260<div id="mw-head-base"></div>
261<div id="content" class="mw-body" role="main">
262<div id="bodyContent" class="mw-body-content">
263
264<h1><?php $this->outputTitle(); ?></h1>
265<?php
266 }
267
268 public function outputFooter() {
269 if ( $this->useShortHeader ) {
270 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
271
272 return;
273 }
274?>
275
276</div></div>
277
278<div id="mw-panel">
279 <div class="portal" id="p-logo">
280 <a href="https://www.mediawiki.org/" title="Main Page"></a>
281 </div>
282<?php
283 $message = wfMessage( 'config-sidebar' )->plain();
284 // Section 1: External links
285 // @todo FIXME: Migrate to plain link label messages (T227297).
286 foreach ( explode( '----', $message ) as $section ) {
287 echo '<div class="portal"><div class="body">';
288 echo $this->parent->parse( $section, true );
289 echo '</div></div>';
290 }
291 // Section 2: Installer pages
292 echo '<div class="portal"><div class="body"><ul>';
293 foreach ( [
294 'config-sidebar-relnotes' => 'ReleaseNotes',
295 'config-sidebar-license' => 'Copying',
296 'config-sidebar-upgrade' => 'UpgradeDoc',
297 ] as $msgKey => $pageName ) {
298 echo $this->parent->makeLinkItem(
299 $this->parent->getDocUrl( $pageName ),
300 wfMessage( $msgKey )->text()
301 );
302 }
303 echo '</ul></div></div>';
304?>
305</div>
306
307<?php
308 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
309 }
310
311 public function outputShortHeader() {
312?>
313<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
314
315<head>
316 <meta name="robots" content="noindex, nofollow" />
317 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
318 <title><?php $this->outputTitle(); ?></title>
319 <?php echo $this->getCssUrl() . "\n"; ?>
320 <?php echo $this->getJQuery() . "\n"; ?>
321 <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
322</head>
323
324<body style="background-image: none">
325<?php
326 }
327
328 public function outputTitle() {
329 echo wfMessage( 'config-title', MW_VERSION )->escaped();
330 }
331
335 public function getJQuery() {
336 return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
337 }
338
339}
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:40
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
$wgLang
Definition Setup.php:781
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.
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.