Merge "Vector: Update comments in vector.js"
[mediawiki.git] / includes / installer / WebInstallerOutput.php
blobd81111b5fe2084a891b3a2a596b4fc902a2e7fb5
1 <?php
2 /**
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
20 * @file
21 * @ingroup Deployment
24 /**
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.
32 * @ingroup Deployment
33 * @since 1.17
35 class WebInstallerOutput {
37 /**
38 * The WebInstaller object this WebInstallerOutput is used by.
40 * @var WebInstaller
42 public $parent;
44 /**
45 * Buffered contents that haven't been output yet
46 * @var string
48 private $contents = '';
50 /**
51 * Has the header (or short header) been output?
52 * @var bool
54 private $headerDone = false;
56 /**
57 * @var string
59 public $redirectTarget;
61 /**
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.
65 * @var bool
67 public $allowFrames = false;
69 /**
70 * Whether to use the limited header (used during CC license callbacks)
71 * @var bool
73 private $useShortHeader = false;
75 /**
76 * @param WebInstaller $parent
78 public function __construct( WebInstaller $parent ) {
79 $this->parent = $parent;
82 /**
83 * @param string $html
85 public function addHTML( $html ) {
86 $this->contents .= $html;
87 $this->flush();
90 /**
91 * @param string $text
93 public function addWikiText( $text ) {
94 $this->addHTML( $this->parent->parse( $text ) );
97 /**
98 * @param string $html
100 public function addHTMLNoFlush( $html ) {
101 $this->contents .= $html;
105 * @param string $url
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() {
117 $this->flush();
118 $this->outputFooter();
122 * Get the stylesheet of the MediaWiki skin.
124 * @return string
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',
137 $css = '';
139 $resourceLoader = new ResourceLoader();
140 $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
141 'debug' => 'true',
142 'lang' => $this->getLanguageCode(),
143 'only' => 'styles',
144 'skin' => 'vector',
145 ) ) );
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 )
154 ) );
156 $css .= implode( "\n", $styles );
159 return $css;
163 * "<link>" to index.php?css=1 for the "<head>"
165 * @return string
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;
185 flush();
186 $this->contents = '';
191 * @return string
193 public function getDir() {
194 global $wgLang;
196 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
200 * @return string
202 public function getLanguageCode() {
203 global $wgLang;
205 return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
209 * @return string[]
211 public function getHeadAttribs() {
212 return array(
213 'dir' => $this->getDir(),
214 'lang' => $this->getLanguageCode(),
219 * Get whether the header has been output
221 * @return bool
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 );
238 return;
241 if ( $this->useShortHeader ) {
242 $this->outputShortHeader();
244 return;
247 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
248 <head>
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"; ?>
255 </head>
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>
260 <div id="content">
261 <div id="bodyContent">
263 <h1><?php $this->outputTitle(); ?></h1>
264 <?php
267 public function outputFooter() {
268 if ( $this->useShortHeader ) {
269 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
271 return;
275 </div></div>
277 <div id="mw-panel">
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>
282 </div>
283 <div class="portal"><div class="body">
284 <?php
285 echo $this->parent->parse( wfMessage( 'config-sidebar' )->plain(), true );
287 </div></div>
288 </div>
290 <?php
291 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
294 public function outputShortHeader() {
296 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
297 <head>
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' ); ?>
304 </head>
306 <body style="background-image: none">
307 <?php
310 public function outputTitle() {
311 global $wgVersion;
312 echo wfMessage( 'config-title', $wgVersion )->escaped();
316 * @return string
318 public function getJQuery() {
319 return Html::linkedScript( "../resources/lib/jquery/jquery.js" );