3 * Output handler for the web installer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Output class modelled on OutputPage.
27 * I've opted to use a distinct class rather than derive from OutputPage here in
28 * the interests of separation of concerns: if we used a subclass, there would be
29 * quite a lot of things you could do in OutputPage that would break the installer,
30 * that wouldn't be immediately obvious.
35 class WebInstallerOutput
{
38 * The WebInstaller object this WebInstallerOutput is used by.
45 * Buffered contents that haven't been output yet
48 private $contents = '';
51 * Has the header (or short header) been output?
54 private $headerDone = false;
59 public $redirectTarget;
62 * Does the current page need to allow being used as a frame?
63 * If not, X-Frame-Options will be output to forbid it.
67 public $allowFrames = false;
70 * Whether to use the limited header (used during CC license callbacks)
73 private $useShortHeader = false;
76 * @param WebInstaller $parent
78 public function __construct( WebInstaller
$parent ) {
79 $this->parent
= $parent;
85 public function addHTML( $html ) {
86 $this->contents
.= $html;
92 * @deprecated since 1.32; use addWikiTextInterface instead
94 public function addWikiText( $text ) {
95 wfDeprecated( __METHOD__
, '1.32' );
96 $this->addWikiTextInterface( $text );
100 * @param string $text
102 public function addWikiTextInterface( $text ) {
103 $this->addHTML( $this->parent
->parse( $text ) );
107 * @param string $html
109 public function addHTMLNoFlush( $html ) {
110 $this->contents
.= $html;
116 * @throws MWException
118 public function redirect( $url ) {
119 if ( $this->headerDone
) {
120 throw new MWException( __METHOD__
. ' called after sending headers' );
122 $this->redirectTarget
= $url;
125 public function output() {
128 if ( !$this->redirectTarget
) {
129 $this->outputFooter();
134 * Get the stylesheet of the MediaWiki skin.
138 public function getCSS() {
139 global $wgStyleDirectory;
142 // Based on Skin::getDefaultModules
143 'mediawiki.legacy.shared',
144 // Based on Vector::setupSkinUserCss
145 'mediawiki.skinning.interface',
148 $resourceLoader = new ResourceLoader();
150 if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
151 // Force loading Vector skin if available as a fallback skin
152 // for whatever ResourceLoader wants to have as the default.
153 $registry = new ExtensionRegistry();
154 $data = $registry->readFromQueue( [
155 "$wgStyleDirectory/Vector/skin.json" => 1,
157 if ( isset( $data['globals']['wgResourceModules'] ) ) {
158 $resourceLoader->register( $data['globals']['wgResourceModules'] );
161 $moduleNames[] = 'skins.vector.styles';
164 $moduleNames[] = 'mediawiki.legacy.config';
166 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
168 'lang' => $this->getLanguageCode(),
173 foreach ( $moduleNames as $moduleName ) {
174 /** @var ResourceLoaderFileModule $module */
175 $module = $resourceLoader->getModule( $moduleName );
177 // T98043: Don't fatal, but it won't look as pretty.
181 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
182 $styles = array_merge( $styles, ResourceLoader
::makeCombinedStyles(
183 $module->readStyleFiles(
184 $module->getStyleFiles( $rlContext ),
185 $module->getFlip( $rlContext ),
190 return implode( "\n", $styles );
194 * "<link>" to index.php?css=1 for the "<head>"
198 private function getCssUrl() {
199 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
202 public function useShortHeader( $use = true ) {
203 $this->useShortHeader
= $use;
206 public function allowFrames( $allow = true ) {
207 $this->allowFrames
= $allow;
210 public function flush() {
211 if ( !$this->headerDone
) {
212 $this->outputHeader();
214 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
215 echo $this->contents
;
217 $this->contents
= '';
224 public function getDir() {
227 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
233 public function getLanguageCode() {
236 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
242 public function getHeadAttribs() {
244 'dir' => $this->getDir(),
245 'lang' => LanguageCode
::bcp47( $this->getLanguageCode() ),
250 * Get whether the header has been output
254 public function headerDone() {
255 return $this->headerDone
;
258 public function outputHeader() {
259 $this->headerDone
= true;
260 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
262 if ( !$this->allowFrames
) {
263 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
266 if ( $this->redirectTarget
) {
267 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
272 if ( $this->useShortHeader
) {
273 $this->outputShortHeader();
278 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
281 <meta name
="robots" content
="noindex, nofollow" />
282 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
283 <title
><?php
$this->outputTitle(); ?
></title
>
284 <?php
echo $this->getCssUrl() . "\n"; ?
>
285 <?php
echo $this->getJQuery() . "\n"; ?
>
286 <?php
echo Html
::linkedScript( 'config.js' ) . "\n"; ?
>
289 <?php
echo Html
::openElement( 'body', [ 'class' => $this->getDir() ] ) . "\n"; ?
>
290 <div id
="mw-page-base"></div
>
291 <div id
="mw-head-base"></div
>
292 <div id
="content" class="mw-body">
293 <div id
="bodyContent" class="mw-body-content">
295 <h1
><?php
$this->outputTitle(); ?
></h1
>
299 public function outputFooter() {
300 if ( $this->useShortHeader
) {
301 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
310 <div
class="portal" id
="p-logo">
311 <a style
="background-image: url(images/installer-logo.png);"
312 href
="https://www.mediawiki.org/"
313 title
="Main Page"></a
>
316 $message = wfMessage( 'config-sidebar' )->plain();
317 foreach ( explode( '----', $message ) as $section ) {
318 echo '<div class="portal"><div class="body">';
319 echo $this->parent
->parse( $section, true );
326 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
329 public function outputShortHeader() {
331 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
333 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
334 <meta name
="robots" content
="noindex, nofollow" />
335 <title
><?php
$this->outputTitle(); ?
></title
>
336 <?php
echo $this->getCssUrl() . "\n"; ?
>
337 <?php
echo $this->getJQuery(); ?
>
338 <?php
echo Html
::linkedScript( 'config.js' ); ?
>
341 <body style
="background-image: none">
345 public function outputTitle() {
347 echo wfMessage( 'config-title', $wgVersion )->escaped();
353 public function getJQuery() {
354 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );