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 $moduleNames = array(
128 // See SkinTemplate::setupSkinUserCss
129 'mediawiki.legacy.shared',
130 // See Vector::setupSkinUserCss
131 'mediawiki.skinning.interface',
132 'skins.vector.styles',
134 'mediawiki.legacy.config',
139 $resourceLoader = new ResourceLoader();
140 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
142 'lang' => $this->getLanguageCode(),
146 foreach ( $moduleNames as $moduleName ) {
147 /** @var ResourceLoaderFileModule $module */
148 $module = $resourceLoader->getModule( $moduleName );
150 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
151 $styles = ResourceLoader
::makeCombinedStyles( $module->readStyleFiles(
152 $module->getStyleFiles( $rlContext ),
153 $module->getFlip( $rlContext )
156 $css .= implode( "\n", $styles );
163 * "<link>" to index.php?css=1 for the "<head>"
167 private function getCssUrl() {
168 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
171 public function useShortHeader( $use = true ) {
172 $this->useShortHeader
= $use;
175 public function allowFrames( $allow = true ) {
176 $this->allowFrames
= $allow;
179 public function flush() {
180 if ( !$this->headerDone
) {
181 $this->outputHeader();
183 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
184 echo $this->contents
;
186 $this->contents
= '';
193 public function getDir() {
196 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
202 public function getLanguageCode() {
205 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
211 public function getHeadAttribs() {
213 'dir' => $this->getDir(),
214 'lang' => $this->getLanguageCode(),
219 * Get whether the header has been output
223 public function headerDone() {
224 return $this->headerDone
;
227 public function outputHeader() {
228 $this->headerDone
= true;
229 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
231 if ( !$this->allowFrames
) {
232 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
235 if ( $this->redirectTarget
) {
236 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
241 if ( $this->useShortHeader
) {
242 $this->outputShortHeader();
247 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
249 <meta name
="robots" content
="noindex, nofollow" />
250 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
251 <title
><?php
$this->outputTitle(); ?
></title
>
252 <?php
echo $this->getCssUrl() . "\n"; ?
>
253 <?php
echo $this->getJQuery() . "\n"; ?
>
254 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
257 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
258 <div id
="mw-page-base"></div
>
259 <div id
="mw-head-base"></div
>
261 <div id
="bodyContent">
263 <h1
><?php
$this->outputTitle(); ?
></h1
>
267 public function outputFooter() {
268 if ( $this->useShortHeader
) {
269 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
278 <div
class="portal" id
="p-logo">
279 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
280 href
="https://www.mediawiki.org/"
281 title
="Main Page"></a
>
283 <div
class="portal"><div
class="body">
285 echo $this->parent
->parse( wfMessage( 'config-sidebar' )->plain(), true );
291 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
294 public function outputShortHeader() {
296 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
298 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
299 <meta name
="robots" content
="noindex, nofollow" />
300 <title
><?php
$this->outputTitle(); ?
></title
>
301 <?php
echo $this->getCssUrl() . "\n"; ?
>
302 <?php
echo $this->getJQuery(); ?
>
303 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
306 <body style
="background-image: none">
310 public function outputTitle() {
312 echo wfMessage( 'config-title', $wgVersion )->escaped();
318 public function getJQuery() {
319 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );