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;
93 public function addWikiText( $text ) {
94 $this->addHTML( $this->parent
->parse( $text ) );
100 public function addHTMLNoFlush( $html ) {
101 $this->contents
.= $html;
107 * @throws MWException
109 public function redirect( $url ) {
110 if ( $this->headerDone
) {
111 throw new MWException( __METHOD__
. ' called after sending headers' );
113 $this->redirectTarget
= $url;
116 public function output() {
118 $this->outputFooter();
122 * Get the stylesheet of the MediaWiki skin.
126 public function getCSS() {
127 global $wgStyleDirectory;
129 $moduleNames = array(
130 // See SkinTemplate::setupSkinUserCss
131 'mediawiki.legacy.shared',
132 // See Vector::setupSkinUserCss
133 'mediawiki.skinning.interface',
136 $resourceLoader = new ResourceLoader();
138 if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
139 // Force loading Vector skin if available as a fallback skin
140 // for whatever ResourceLoader wants to have as the default.
141 $registry = new ExtensionRegistry();
142 $data = $registry->readFromQueue( array(
143 "$wgStyleDirectory/Vector/skin.json" => 1,
145 if ( isset( $data['globals']['wgResourceModules'] ) ) {
146 $resourceLoader->register( $data['globals']['wgResourceModules'] );
149 $moduleNames[] = 'skins.vector.styles';
152 $moduleNames[] = 'mediawiki.legacy.config';
154 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
156 'lang' => $this->getLanguageCode(),
161 foreach ( $moduleNames as $moduleName ) {
162 /** @var ResourceLoaderFileModule $module */
163 $module = $resourceLoader->getModule( $moduleName );
165 // T98043: Don't fatal, but it won't look as pretty.
169 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
170 $styles = array_merge( $styles, ResourceLoader
::makeCombinedStyles(
171 $module->readStyleFiles(
172 $module->getStyleFiles( $rlContext ),
173 $module->getFlip( $rlContext ),
178 return implode( "\n", $styles );
182 * "<link>" to index.php?css=1 for the "<head>"
186 private function getCssUrl() {
187 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
190 public function useShortHeader( $use = true ) {
191 $this->useShortHeader
= $use;
194 public function allowFrames( $allow = true ) {
195 $this->allowFrames
= $allow;
198 public function flush() {
199 if ( !$this->headerDone
) {
200 $this->outputHeader();
202 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
203 echo $this->contents
;
205 $this->contents
= '';
212 public function getDir() {
215 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
221 public function getLanguageCode() {
224 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
230 public function getHeadAttribs() {
232 'dir' => $this->getDir(),
233 'lang' => wfBCP47( $this->getLanguageCode() ),
238 * Get whether the header has been output
242 public function headerDone() {
243 return $this->headerDone
;
246 public function outputHeader() {
247 $this->headerDone
= true;
248 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
250 if ( !$this->allowFrames
) {
251 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
254 if ( $this->redirectTarget
) {
255 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
260 if ( $this->useShortHeader
) {
261 $this->outputShortHeader();
266 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
268 <meta name
="robots" content
="noindex, nofollow" />
269 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
270 <title
><?php
$this->outputTitle(); ?
></title
>
271 <?php
echo $this->getCssUrl() . "\n"; ?
>
272 <?php
echo $this->getJQuery() . "\n"; ?
>
273 <?php
echo Html
::linkedScript( 'config.js' ) . "\n"; ?
>
276 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
277 <div id
="mw-page-base"></div
>
278 <div id
="mw-head-base"></div
>
279 <div id
="content" class="mw-body">
280 <div id
="bodyContent" class="mw-body-content">
282 <h1
><?php
$this->outputTitle(); ?
></h1
>
286 public function outputFooter() {
287 if ( $this->useShortHeader
) {
288 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
297 <div
class="portal" id
="p-logo">
298 <a style
="background-image: url(images/installer-logo.png);"
299 href
="https://www.mediawiki.org/"
300 title
="Main Page"></a
>
303 $message = wfMessage( 'config-sidebar' )->plain();
304 foreach ( explode( '----', $message ) as $section ) {
305 echo '<div class="portal"><div class="body">';
306 echo $this->parent
->parse( $section, true );
313 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
316 public function outputShortHeader() {
318 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
320 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
321 <meta name
="robots" content
="noindex, nofollow" />
322 <title
><?php
$this->outputTitle(); ?
></title
>
323 <?php
echo $this->getCssUrl() . "\n"; ?
>
324 <?php
echo $this->getJQuery(); ?
>
325 <?php
echo Html
::linkedScript( 'config.js' ); ?
>
328 <body style
="background-image: none">
332 public function outputTitle() {
334 echo wfMessage( 'config-title', $wgVersion )->escaped();
340 public function getJQuery() {
341 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );