fd6ed009941679b21b770e32df5f75eaf24b76eb
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.
35 class WebInstallerOutput
{
38 * The WebInstaller object this WebInstallerOutput is used by.
45 * Buffered contents that haven't been output yet
48 private $contents = '';
51 * Has the header (or short header) been output?
54 private $headerDone = false;
59 public $redirectTarget;
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.
67 public $allowFrames = false;
70 * Whether to use the limited header (used during CC license callbacks)
73 private $useShortHeader = false;
76 * @param WebInstaller $parent
78 public function __construct( WebInstaller
$parent ) {
79 $this->parent
= $parent;
85 public function addHTML( $html ) {
86 $this->contents
.= $html;
93 public function addWikiText( $text ) {
94 $this->addHTML( $this->parent
->parse( $text ) );
100 public function addHTMLNoFlush( $html ) {
101 $this->contents
.= $html;
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() {
118 $this->outputFooter();
122 * Get the raw vector CSS, flipping if needed
124 * @todo Possibly get rid of this function and use ResourceLoader in the manner it was
125 * designed to be used in, rather than just grabbing a list of filenames from it,
126 * and not properly handling such details as media types in module definitions.
130 public function getCSS() {
131 // All CSS files these modules reference will be concatenated in sequence
132 // and loaded as one file.
133 $moduleNames = array(
134 'mediawiki.legacy.shared',
135 'mediawiki.skinning.interface',
136 'skins.vector.styles',
137 'mediawiki.legacy.config',
143 $resourceLoader = new ResourceLoader();
144 foreach ( $moduleNames as $moduleName ) {
145 /** @var ResourceLoaderFileModule $module */
146 $module = $resourceLoader->getModule( $moduleName );
147 $cssFileNames = $module->getAllStyleFiles();
149 wfSuppressWarnings();
150 foreach ( $cssFileNames as $cssFileName ) {
151 if ( !file_exists( $cssFileName ) ) {
152 $prepend .= ResourceLoader
::makeComment( "Unable to find $cssFileName." );
156 if ( !is_readable( $cssFileName ) ) {
157 $prepend .= ResourceLoader
::makeComment( "Unable to read $cssFileName. " .
158 "Please check file permissions." );
164 if ( preg_match( '/\.less$/', $cssFileName ) ) {
165 // Run the LESS compiler for *.less files (bug 55589)
166 $compiler = ResourceLoader
::getLessCompiler();
167 $cssFileContents = $compiler->compileFile( $cssFileName );
170 $cssFileContents = file_get_contents( $cssFileName );
173 if ( $cssFileContents ) {
174 // Rewrite URLs, though don't bother embedding images. While static image
175 // files may be cached, CSS returned by this function is definitely not.
176 $cssDirName = dirname( $cssFileName );
177 $css .= CSSMin
::remap(
178 /* source */ $cssFileContents,
179 /* local */ $cssDirName,
180 /* remote */ '..' . str_replace(
181 array( $GLOBALS['IP'], DIRECTORY_SEPARATOR
),
185 /* embedData */ false
188 $prepend .= ResourceLoader
::makeComment( "Unable to read $cssFileName." );
190 } catch ( Exception
$e ) {
191 $prepend .= ResourceLoader
::formatException( $e );
199 $css = $prepend . $css;
201 if ( $this->getDir() == 'rtl' ) {
202 $css = CSSJanus
::transform( $css, true );
209 * "<link>" to index.php?css=1 for the "<head>"
213 private function getCssUrl() {
214 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
217 public function useShortHeader( $use = true ) {
218 $this->useShortHeader
= $use;
221 public function allowFrames( $allow = true ) {
222 $this->allowFrames
= $allow;
225 public function flush() {
226 if ( !$this->headerDone
) {
227 $this->outputHeader();
229 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
230 echo $this->contents
;
232 $this->contents
= '';
239 public function getDir() {
242 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
248 public function getLanguageCode() {
251 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
257 public function getHeadAttribs() {
259 'dir' => $this->getDir(),
260 'lang' => $this->getLanguageCode(),
265 * Get whether the header has been output
269 public function headerDone() {
270 return $this->headerDone
;
273 public function outputHeader() {
274 $this->headerDone
= true;
275 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
277 if ( !$this->allowFrames
) {
278 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
281 if ( $this->redirectTarget
) {
282 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
287 if ( $this->useShortHeader
) {
288 $this->outputShortHeader();
293 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
295 <meta name
="robots" content
="noindex, nofollow" />
296 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
297 <title
><?php
$this->outputTitle(); ?
></title
>
298 <?php
echo $this->getCssUrl() . "\n"; ?
>
299 <?php
echo $this->getJQuery() . "\n"; ?
>
300 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
303 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
304 <div id
="mw-page-base"></div
>
305 <div id
="mw-head-base"></div
>
307 <div id
="bodyContent">
309 <h1
><?php
$this->outputTitle(); ?
></h1
>
313 public function outputFooter() {
314 if ( $this->useShortHeader
) {
315 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
324 <div
class="portal" id
="p-logo">
325 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
326 href
="https://www.mediawiki.org/"
327 title
="Main Page"></a
>
329 <div
class="portal"><div
class="body">
331 echo $this->parent
->parse( wfMessage( 'config-sidebar' )->plain(), true );
337 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
340 public function outputShortHeader() {
342 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
344 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
345 <meta name
="robots" content
="noindex, nofollow" />
346 <title
><?php
$this->outputTitle(); ?
></title
>
347 <?php
echo $this->getCssUrl() . "\n"; ?
>
348 <?php
echo $this->getJQuery(); ?
>
349 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
352 <body style
="background-image: none">
356 public function outputTitle() {
358 echo wfMessage( 'config-title', $wgVersion )->escaped();
364 public function getJQuery() {
365 return Html
::linkedScript( "../resources/lib/jquery/jquery.js" );