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
24 use MediaWiki\MediaWikiServices
;
27 * Output class modelled on OutputPage.
29 * I've opted to use a distinct class rather than derive from OutputPage here in
30 * the interests of separation of concerns: if we used a subclass, there would be
31 * quite a lot of things you could do in OutputPage that would break the installer,
32 * that wouldn't be immediately obvious.
38 class WebInstallerOutput
{
41 * The WebInstaller object this WebInstallerOutput is used by.
48 * Buffered contents that haven't been output yet
51 private $contents = '';
54 * Has the header (or short header) been output?
57 private $headerDone = false;
62 public $redirectTarget;
65 * Does the current page need to allow being used as a frame?
66 * If not, X-Frame-Options will be output to forbid it.
70 public $allowFrames = false;
73 * Whether to use the limited header (used during CC license callbacks)
76 private $useShortHeader = false;
79 * @param WebInstaller $parent
81 public function __construct( WebInstaller
$parent ) {
82 $this->parent
= $parent;
88 public function addHTML( $html ) {
89 $this->contents
.= $html;
95 * @deprecated since 1.32; use addWikiTextAsInterface instead
97 public function addWikiText( $text ) {
98 wfDeprecated( __METHOD__
, '1.32' );
99 $this->addWikiTextAsInterface( $text );
103 * @param string $text
106 public function addWikiTextAsInterface( $text ) {
107 $this->addHTML( $this->parent
->parse( $text ) );
111 * @param string $html
113 public function addHTMLNoFlush( $html ) {
114 $this->contents
.= $html;
120 * @throws MWException
122 public function redirect( $url ) {
123 if ( $this->headerDone
) {
124 throw new MWException( __METHOD__
. ' called after sending headers' );
126 $this->redirectTarget
= $url;
129 public function output() {
132 if ( !$this->redirectTarget
) {
133 $this->outputFooter();
138 * Get the stylesheet of the MediaWiki skin.
142 public function getCSS() {
143 global $wgStyleDirectory;
146 // Based on Skin::getDefaultModules
147 'mediawiki.legacy.shared',
148 // Based on Vector::setupSkinUserCss
149 'mediawiki.skinning.interface',
152 $resourceLoader = MediaWikiServices
::getInstance()->getResourceLoader();
154 if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
155 // Force loading Vector skin if available as a fallback skin
156 // for whatever ResourceLoader wants to have as the default.
157 $registry = new ExtensionRegistry();
158 $data = $registry->readFromQueue( [
159 "$wgStyleDirectory/Vector/skin.json" => 1,
161 if ( isset( $data['globals']['wgResourceModules'] ) ) {
162 $resourceLoader->register( $data['globals']['wgResourceModules'] );
165 $moduleNames[] = 'skins.vector.styles';
168 $moduleNames[] = 'mediawiki.legacy.config';
170 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
172 'lang' => $this->getLanguage()->getCode(),
177 foreach ( $moduleNames as $moduleName ) {
178 /** @var ResourceLoaderFileModule $module */
179 $module = $resourceLoader->getModule( $moduleName );
181 // T98043: Don't fatal, but it won't look as pretty.
185 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
186 $styles = array_merge( $styles, ResourceLoader
::makeCombinedStyles(
187 $module->readStyleFiles(
188 $module->getStyleFiles( $rlContext ),
189 $module->getFlip( $rlContext ),
194 return implode( "\n", $styles );
198 * "<link>" to index.php?css=1 for the "<head>"
202 private function getCssUrl() {
203 return Html
::linkedStyle( $this->parent
->getUrl( [ 'css' => 1 ] ) );
206 public function useShortHeader( $use = true ) {
207 $this->useShortHeader
= $use;
210 public function allowFrames( $allow = true ) {
211 $this->allowFrames
= $allow;
214 public function flush() {
215 if ( !$this->headerDone
) {
216 $this->outputHeader();
218 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
219 echo $this->contents
;
221 $this->contents
= '';
229 private function getLanguage() {
232 return is_object( $wgLang ) ?
$wgLang : Language
::factory( 'en' );
238 public function getHeadAttribs() {
240 'dir' => $this->getLanguage()->getDir(),
241 'lang' => $this->getLanguage()->getHtmlCode(),
246 * Get whether the header has been output
250 public function headerDone() {
251 return $this->headerDone
;
254 public function outputHeader() {
255 $this->headerDone
= true;
256 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
258 if ( !$this->allowFrames
) {
259 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
262 if ( $this->redirectTarget
) {
263 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
268 if ( $this->useShortHeader
) {
269 $this->outputShortHeader();
274 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
277 <meta name
="robots" content
="noindex, nofollow" />
278 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
279 <title
><?php
$this->outputTitle(); ?
></title
>
280 <?php
echo $this->getCssUrl() . "\n"; ?
>
281 <?php
echo $this->getJQuery() . "\n"; ?
>
282 <?php
echo Html
::linkedScript( 'config.js' ) . "\n"; ?
>
285 <?php
echo Html
::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?
>
286 <div id
="mw-page-base"></div
>
287 <div id
="mw-head-base"></div
>
288 <div id
="content" class="mw-body">
289 <div id
="bodyContent" class="mw-body-content">
291 <h1
><?php
$this->outputTitle(); ?
></h1
>
295 public function outputFooter() {
296 if ( $this->useShortHeader
) {
297 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
306 <div
class="portal" id
="p-logo">
307 <a href
="https://www.mediawiki.org/" 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" );