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 // Horrible, horrible hack: the installer is currently hardcoded to use the Vector skin, so load
128 // it here. Include instead of require, as this will work without it, it will just look bad.
129 global $wgResourceModules;
130 global $wgStyleDirectory;
131 include_once "$wgStyleDirectory/Vector/Vector.php";
133 $moduleNames = array(
134 // See SkinTemplate::setupSkinUserCss
135 'mediawiki.legacy.shared',
136 // See Vector::setupSkinUserCss
137 'mediawiki.skinning.interface',
138 'skins.vector.styles',
140 'mediawiki.legacy.config',
145 $resourceLoader = new ResourceLoader();
146 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
148 'lang' => $this->getLanguageCode(),
152 foreach ( $moduleNames as $moduleName ) {
153 /** @var ResourceLoaderFileModule $module */
154 $module = $resourceLoader->getModule( $moduleName );
155 // One of the modules will be missing if Vector is unavailable
160 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
161 $styles = ResourceLoader
::makeCombinedStyles( $module->readStyleFiles(
162 $module->getStyleFiles( $rlContext ),
163 $module->getFlip( $rlContext )
166 $css .= implode( "\n", $styles );
173 * "<link>" to index.php?css=1 for the "<head>"
177 private function getCssUrl() {
178 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
181 public function useShortHeader( $use = true ) {
182 $this->useShortHeader
= $use;
185 public function allowFrames( $allow = true ) {
186 $this->allowFrames
= $allow;
189 public function flush() {
190 if ( !$this->headerDone
) {
191 $this->outputHeader();
193 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
194 echo $this->contents
;
196 $this->contents
= '';
203 public function getDir() {
206 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
212 public function getLanguageCode() {
215 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
221 public function getHeadAttribs() {
223 'dir' => $this->getDir(),
224 'lang' => $this->getLanguageCode(),
229 * Get whether the header has been output
233 public function headerDone() {
234 return $this->headerDone
;
237 public function outputHeader() {
238 $this->headerDone
= true;
239 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
241 if ( !$this->allowFrames
) {
242 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
245 if ( $this->redirectTarget
) {
246 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
251 if ( $this->useShortHeader
) {
252 $this->outputShortHeader();
257 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
259 <meta name
="robots" content
="noindex, nofollow" />
260 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
261 <title
><?php
$this->outputTitle(); ?
></title
>
262 <?php
echo $this->getCssUrl() . "\n"; ?
>
263 <?php
echo $this->getJQuery() . "\n"; ?
>
264 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
267 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
268 <div id
="mw-page-base"></div
>
269 <div id
="mw-head-base"></div
>
271 <div id
="bodyContent">
273 <h1
><?php
$this->outputTitle(); ?
></h1
>
277 public function outputFooter() {
278 if ( $this->useShortHeader
) {
279 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
288 <div
class="portal" id
="p-logo">
289 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
290 href
="https://www.mediawiki.org/"
291 title
="Main Page"></a
>
293 <div
class="portal"><div
class="body">
295 echo $this->parent
->parse( wfMessage( 'config-sidebar' )->plain(), true );
301 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
304 public function outputShortHeader() {
306 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
308 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
309 <meta name
="robots" content
="noindex, nofollow" />
310 <title
><?php
$this->outputTitle(); ?
></title
>
311 <?php
echo $this->getCssUrl() . "\n"; ?
>
312 <?php
echo $this->getJQuery(); ?
>
313 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
316 <body style
="background-image: none">
320 public function outputTitle() {
322 echo wfMessage( 'config-title', $wgVersion )->escaped();
328 public function getJQuery() {
329 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );