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.
36 class WebInstallerOutput
{
39 * The WebInstaller object this WebInstallerOutput is used by.
46 * Buffered contents that haven't been output yet
49 private $contents = '';
52 * Has the header (or short header) been output?
55 private $headerDone = false;
60 public $redirectTarget;
63 * Does the current page need to allow being used as a frame?
64 * If not, X-Frame-Options will be output to forbid it.
68 public $allowFrames = false;
71 * Whether to use the limited header (used during CC license callbacks)
74 private $useShortHeader = false;
77 * @param WebInstaller $parent
79 public function __construct( WebInstaller
$parent ) {
80 $this->parent
= $parent;
86 public function addHTML( $html ) {
87 $this->contents
.= $html;
93 * @deprecated since 1.32; use addWikiTextAsInterface instead
95 public function addWikiText( $text ) {
96 wfDeprecated( __METHOD__
, '1.32' );
97 $this->addWikiTextAsInterface( $text );
101 * @param string $text
104 public function addWikiTextAsInterface( $text ) {
105 $this->addHTML( $this->parent
->parse( $text ) );
109 * @param string $html
111 public function addHTMLNoFlush( $html ) {
112 $this->contents
.= $html;
118 * @throws MWException
120 public function redirect( $url ) {
121 if ( $this->headerDone
) {
122 throw new MWException( __METHOD__
. ' called after sending headers' );
124 $this->redirectTarget
= $url;
127 public function output() {
130 if ( !$this->redirectTarget
) {
131 $this->outputFooter();
136 * Get the stylesheet of the MediaWiki skin.
140 public function getCSS() {
141 global $wgStyleDirectory;
144 // Based on Skin::getDefaultModules
145 'mediawiki.legacy.shared',
146 // Based on Vector::setupSkinUserCss
147 'mediawiki.skinning.interface',
150 $resourceLoader = new ResourceLoader();
152 if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
153 // Force loading Vector skin if available as a fallback skin
154 // for whatever ResourceLoader wants to have as the default.
155 $registry = new ExtensionRegistry();
156 $data = $registry->readFromQueue( [
157 "$wgStyleDirectory/Vector/skin.json" => 1,
159 if ( isset( $data['globals']['wgResourceModules'] ) ) {
160 $resourceLoader->register( $data['globals']['wgResourceModules'] );
163 $moduleNames[] = 'skins.vector.styles';
166 $moduleNames[] = 'mediawiki.legacy.config';
168 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
170 'lang' => $this->getLanguage()->getCode(),
175 foreach ( $moduleNames as $moduleName ) {
176 /** @var ResourceLoaderFileModule $module */
177 $module = $resourceLoader->getModule( $moduleName );
179 // T98043: Don't fatal, but it won't look as pretty.
183 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
184 $styles = array_merge( $styles, ResourceLoader
::makeCombinedStyles(
185 $module->readStyleFiles(
186 $module->getStyleFiles( $rlContext ),
187 $module->getFlip( $rlContext ),
192 return implode( "\n", $styles );
196 * "<link>" to index.php?css=1 for the "<head>"
200 private function getCssUrl() {
201 return Html
::linkedStyle( $this->parent
->getUrl( [ 'css' => 1 ] ) );
204 public function useShortHeader( $use = true ) {
205 $this->useShortHeader
= $use;
208 public function allowFrames( $allow = true ) {
209 $this->allowFrames
= $allow;
212 public function flush() {
213 if ( !$this->headerDone
) {
214 $this->outputHeader();
216 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
217 echo $this->contents
;
219 $this->contents
= '';
227 private function getLanguage() {
230 return is_object( $wgLang ) ?
$wgLang : Language
::factory( 'en' );
236 public function getHeadAttribs() {
238 'dir' => $this->getLanguage()->getDir(),
239 'lang' => $this->getLanguage()->getHtmlCode(),
244 * Get whether the header has been output
248 public function headerDone() {
249 return $this->headerDone
;
252 public function outputHeader() {
253 $this->headerDone
= true;
254 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
256 if ( !$this->allowFrames
) {
257 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
260 if ( $this->redirectTarget
) {
261 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
266 if ( $this->useShortHeader
) {
267 $this->outputShortHeader();
272 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
275 <meta name
="robots" content
="noindex, nofollow" />
276 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
277 <title
><?php
$this->outputTitle(); ?
></title
>
278 <?php
echo $this->getCssUrl() . "\n"; ?
>
279 <?php
echo $this->getJQuery() . "\n"; ?
>
280 <?php
echo Html
::linkedScript( 'config.js' ) . "\n"; ?
>
283 <?php
echo Html
::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?
>
284 <div id
="mw-page-base"></div
>
285 <div id
="mw-head-base"></div
>
286 <div id
="content" class="mw-body">
287 <div id
="bodyContent" class="mw-body-content">
289 <h1
><?php
$this->outputTitle(); ?
></h1
>
293 public function outputFooter() {
294 if ( $this->useShortHeader
) {
295 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
304 <div
class="portal" id
="p-logo">
305 <a style
="background-image: url(images/installer-logo.png);"
306 href
="https://www.mediawiki.org/"
307 title
="Main Page"></a
>
310 $message = wfMessage( 'config-sidebar' )->plain();
311 foreach ( explode( '----', $message ) as $section ) {
312 echo '<div class="portal"><div class="body">';
313 echo $this->parent
->parse( $section, true );
320 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
323 public function outputShortHeader() {
325 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
327 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
328 <meta name
="robots" content
="noindex, nofollow" />
329 <title
><?php
$this->outputTitle(); ?
></title
>
330 <?php
echo $this->getCssUrl() . "\n"; ?
>
331 <?php
echo $this->getJQuery(); ?
>
332 <?php
echo Html
::linkedScript( 'config.js' ); ?
>
335 <body style
="background-image: none">
339 public function outputTitle() {
341 echo wfMessage( 'config-title', $wgVersion )->escaped();
347 public function getJQuery() {
348 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );