4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Installer
;
26 use MediaWiki\Html\Html
;
27 use MediaWiki\Language\Language
;
28 use MediaWiki\MediaWikiServices
;
29 use MediaWiki\Request\FauxRequest
;
30 use MediaWiki\ResourceLoader
as RL
;
31 use MediaWiki\ResourceLoader\ResourceLoader
;
34 * Output class modelled on OutputPage.
36 * I've opted to use a distinct class rather than derive from OutputPage here in
37 * the interests of separation of concerns: if we used a subclass, there would be
38 * quite a lot of things you could do in OutputPage that would break the installer,
39 * that wouldn't be immediately obvious.
45 class WebInstallerOutput
{
48 * The WebInstaller object this WebInstallerOutput is used by.
55 * Buffered contents that haven't been output yet
58 private $contents = '';
61 * Has the header been output?
64 private $headerDone = false;
69 public $redirectTarget;
72 * @param WebInstaller $parent
74 public function __construct( WebInstaller
$parent ) {
75 $this->parent
= $parent;
81 public function addHTML( $html ) {
82 $this->contents
.= $html;
90 public function addWikiTextAsInterface( $text ) {
91 $this->addHTML( $this->parent
->parse( $text ) );
97 public function addHTMLNoFlush( $html ) {
98 $this->contents
.= $html;
104 public function redirect( $url ) {
105 if ( $this->headerDone
) {
106 throw new LogicException( __METHOD__
. ' called after sending headers' );
108 $this->redirectTarget
= $url;
111 public function output() {
114 if ( !$this->redirectTarget
) {
115 $this->outputFooter();
120 * Get the stylesheet of the MediaWiki skin.
124 public function getCSS() {
125 $resourceLoader = MediaWikiServices
::getInstance()->getResourceLoader();
127 $rlContext = new RL\
Context( $resourceLoader, new FauxRequest( [
129 'lang' => $this->getLanguage()->getCode(),
133 $module = new RL\
SkinModule( [
136 'interface-message-box'
139 'mw-config/config.css',
142 $module->setConfig( $resourceLoader->getConfig() );
144 // Based on MediaWiki\ResourceLoader\FileModule::getStyles, without the DB query
145 $styles = ResourceLoader
::makeCombinedStyles(
146 $module->readStyleFiles(
147 $module->getStyleFiles( $rlContext ),
151 return implode( "\n", $styles );
155 * "<link>" to index.php?css=1 for the "<head>"
159 private function getCssUrl() {
160 return Html
::linkedStyle( $this->parent
->getUrl( [ 'css' => 1 ] ) );
163 public function flush() {
164 if ( !$this->headerDone
) {
165 $this->outputHeader();
167 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
168 echo $this->contents
;
170 $this->contents
= '';
178 private function getLanguage() {
181 return is_object( $wgLang ) ?
$wgLang
182 : MediaWikiServices
::getInstance()->getLanguageFactory()->getLanguage( 'en' );
188 public function getHeadAttribs() {
190 'dir' => $this->getLanguage()->getDir(),
191 'lang' => $this->getLanguage()->getHtmlCode(),
196 * Get whether the header has been output
200 public function headerDone() {
201 return $this->headerDone
;
204 public function outputHeader() {
205 $this->headerDone
= true;
206 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
207 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
209 if ( $this->redirectTarget
) {
210 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
215 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
218 <meta name
="robots" content
="noindex, nofollow" />
219 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
220 <title
><?php
$this->outputTitle(); ?
></title
>
221 <?php
echo $this->getCodex() . "\n"; ?
>
222 <?php
echo $this->getCssUrl() . "\n"; ?
>
223 <?php
echo $this->getJQuery() . "\n"; ?
>
224 <?php
echo Html
::linkedScript( 'config.js' ) . "\n"; ?
>
227 <?php
echo Html
::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?
>
228 <div id
="mw-page-base"></div
>
229 <div id
="mw-head-base"></div
>
230 <div id
="content" class="mw-body" role
="main">
231 <div id
="bodyContent" class="mw-body-content">
233 <h1
><?php
$this->outputTitle(); ?
></h1
>
237 public function outputFooter() {
242 <aside id
="mw-panel">
243 <div
class="portal" id
="p-logo">
244 <a href
="https://www.mediawiki.org/" title
="Main Page"></a
>
247 // @phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
248 $message = wfMessage( 'config-sidebar' )->plain();
249 // Section 1: External links
250 // @todo FIXME: Migrate to plain link label messages (T227297).
251 foreach ( explode( '----', $message ) as $section ) {
252 echo '<div class="portal"><div class="body">';
253 echo $this->parent
->parse( $section, true );
256 // Section 2: Installer pages
257 echo '<div class="portal"><div class="body"><ul>';
259 'config-sidebar-relnotes' => 'ReleaseNotes',
260 'config-sidebar-license' => 'Copying',
261 'config-sidebar-upgrade' => 'UpgradeDoc',
262 ] as $msgKey => $pageName ) {
263 echo $this->parent
->makeLinkItem(
264 $this->parent
->getDocUrl( $pageName ),
265 wfMessage( $msgKey )->text()
268 echo '</ul></div></div>';
274 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
277 public function outputTitle() {
278 echo wfMessage( 'config-title', MW_VERSION
)->escaped();
284 public function getJQuery() {
285 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );
291 public function getCodex() {
292 return Html
::linkedStyle( "../resources/lib/codex/codex.style.css" );