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;
97 public function addWikiTextAsInterface( $text ) {
98 $this->addHTML( $this->parent
->parse( $text ) );
102 * @param string $html
104 public function addHTMLNoFlush( $html ) {
105 $this->contents
.= $html;
111 * @throws MWException
113 public function redirect( $url ) {
114 if ( $this->headerDone
) {
115 throw new MWException( __METHOD__
. ' called after sending headers' );
117 $this->redirectTarget
= $url;
120 public function output() {
123 if ( !$this->redirectTarget
) {
124 $this->outputFooter();
129 * Get the stylesheet of the MediaWiki skin.
133 public function getCSS() {
134 global $wgStyleDirectory;
137 // Based on Skin::getDefaultModules
138 'mediawiki.legacy.shared',
139 // Based on Vector::setupSkinUserCss
140 'mediawiki.skinning.interface',
143 $resourceLoader = MediaWikiServices
::getInstance()->getResourceLoader();
145 if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
146 // Force loading Vector skin if available as a fallback skin
147 // for whatever ResourceLoader wants to have as the default.
148 $registry = new ExtensionRegistry();
149 $data = $registry->readFromQueue( [
150 "$wgStyleDirectory/Vector/skin.json" => 1,
152 if ( isset( $data['globals']['wgResourceModules'] ) ) {
153 $resourceLoader->register( $data['globals']['wgResourceModules'] );
156 $moduleNames[] = 'skins.vector.styles';
159 $moduleNames[] = 'mediawiki.legacy.config';
161 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
163 'lang' => $this->getLanguage()->getCode(),
168 foreach ( $moduleNames as $moduleName ) {
169 /** @var ResourceLoaderFileModule $module */
170 $module = $resourceLoader->getModule( $moduleName );
172 // T98043: Don't fatal, but it won't look as pretty.
176 // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
177 $styles = array_merge( $styles, ResourceLoader
::makeCombinedStyles(
178 $module->readStyleFiles(
179 $module->getStyleFiles( $rlContext ),
180 $module->getFlip( $rlContext ),
185 return implode( "\n", $styles );
189 * "<link>" to index.php?css=1 for the "<head>"
193 private function getCssUrl() {
194 return Html
::linkedStyle( $this->parent
->getUrl( [ 'css' => 1 ] ) );
197 public function useShortHeader( $use = true ) {
198 $this->useShortHeader
= $use;
201 public function allowFrames( $allow = true ) {
202 $this->allowFrames
= $allow;
205 public function flush() {
206 if ( !$this->headerDone
) {
207 $this->outputHeader();
209 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
210 echo $this->contents
;
212 $this->contents
= '';
220 private function getLanguage() {
223 return is_object( $wgLang ) ?
$wgLang : Language
::factory( 'en' );
229 public function getHeadAttribs() {
231 'dir' => $this->getLanguage()->getDir(),
232 'lang' => $this->getLanguage()->getHtmlCode(),
237 * Get whether the header has been output
241 public function headerDone() {
242 return $this->headerDone
;
245 public function outputHeader() {
246 $this->headerDone
= true;
247 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
249 if ( !$this->allowFrames
) {
250 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
253 if ( $this->redirectTarget
) {
254 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
259 if ( $this->useShortHeader
) {
260 $this->outputShortHeader();
265 <?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', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?
>
277 <div id
="mw-page-base"></div
>
278 <div id
="mw-head-base"></div
>
279 <div id
="content" class="mw-body" role
="main">
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 href
="https://www.mediawiki.org/" title
="Main Page"></a
>
301 $message = wfMessage( 'config-sidebar' )->plain();
302 // Section 1: External links
303 // @todo FIXME: Migrate to plain link label messages (T227297).
304 foreach ( explode( '----', $message ) as $section ) {
305 echo '<div class="portal"><div class="body">';
306 echo $this->parent
->parse( $section, true );
309 // Section 2: Installer pages
310 echo '<div class="portal"><div class="body"><ul>';
312 'config-sidebar-readme' => 'Readme',
313 'config-sidebar-relnotes' => 'ReleaseNotes',
314 'config-sidebar-license' => 'Copying',
315 'config-sidebar-upgrade' => 'UpgradeDoc',
316 ] as $msgKey => $pageName ) {
317 echo $this->parent
->makeLinkItem(
318 $this->parent
->getDocUrl( $pageName ),
319 wfMessage( $msgKey )->text()
322 echo '</ul></div></div>';
327 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
330 public function outputShortHeader() {
332 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
335 <meta name
="robots" content
="noindex, nofollow" />
336 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
337 <title
><?php
$this->outputTitle(); ?
></title
>
338 <?php
echo $this->getCssUrl() . "\n"; ?
>
339 <?php
echo $this->getJQuery() . "\n"; ?
>
340 <?php
echo Html
::linkedScript( 'config.js' ) . "\n"; ?
>
343 <body style
="background-image: none">
347 public function outputTitle() {
349 echo wfMessage( 'config-title', $wgVersion )->escaped();
355 public function getJQuery() {
356 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );