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
{
37 * The WebInstaller object this WebInstallerOutput is used by.
44 * Buffered contents that haven't been output yet
47 private $contents = '';
50 * Has the header (or short header) been output?
53 private $headerDone = false;
55 public $redirectTarget;
58 * Does the current page need to allow being used as a frame?
59 * If not, X-Frame-Options will be output to forbid it.
63 public $allowFrames = false;
66 * Whether to use the limited header (used during CC license callbacks)
69 private $useShortHeader = false;
74 * @param $parent WebInstaller
76 public function __construct( WebInstaller
$parent ) {
77 $this->parent
= $parent;
80 public function addHTML( $html ) {
81 $this->contents
.= $html;
85 public function addWikiText( $text ) {
86 $this->addHTML( $this->parent
->parse( $text ) );
89 public function addHTMLNoFlush( $html ) {
90 $this->contents
.= $html;
93 public function redirect( $url ) {
94 if ( $this->headerDone
) {
95 throw new MWException( __METHOD__
. ' called after sending headers' );
97 $this->redirectTarget
= $url;
100 public function output() {
102 $this->outputFooter();
106 * Get the raw vector CSS, flipping if needed
108 * @todo Possibly get rid of this function and use ResourceLoader in the manner it was
109 * designed to be used in, rather than just grabbing a list of filenames from it,
110 * and not properly handling such details as media types in module definitions.
112 * @param string $dir 'ltr' or 'rtl'
115 public function getCSS( $dir ) {
116 // All CSS files these modules reference will be concatenated in sequence
117 // and loaded as one file.
118 $moduleNames = array(
119 'mediawiki.legacy.shared',
121 'mediawiki.legacy.config',
127 $resourceLoader = new ResourceLoader();
128 foreach ( $moduleNames as $moduleName ) {
129 /** @var ResourceLoaderFileModule $module */
130 $module = $resourceLoader->getModule( $moduleName );
131 $cssFileNames = $module->getAllStyleFiles();
133 wfSuppressWarnings();
134 foreach ( $cssFileNames as $cssFileName ) {
135 if ( !file_exists( $cssFileName ) ) {
136 $prepend .= ResourceLoader
::makeComment( "Unable to find $cssFileName." );
140 if ( !is_readable( $cssFileName ) ) {
141 $prepend .= ResourceLoader
::makeComment( "Unable to read $cssFileName. " .
142 "Please check file permissions." );
148 if ( preg_match( '/\.less$/', $cssFileName ) ) {
149 // Run the LESS compiler for *.less files (bug 55589)
150 $compiler = ResourceLoader
::getLessCompiler();
151 $cssFileContents = $compiler->compileFile( $cssFileName );
154 $cssFileContents = file_get_contents( $cssFileName );
157 if ( $cssFileContents ) {
158 // Rewrite URLs, though don't bother embedding images. While static image
159 // files may be cached, CSS returned by this function is definitely not.
160 $cssDirName = dirname( $cssFileName );
161 $css .= CSSMin
::remap(
162 /* source */ $cssFileContents,
163 /* local */ $cssDirName,
164 /* remote */ '..' . str_replace(
165 array( $GLOBALS['IP'], DIRECTORY_SEPARATOR
),
169 /* embedData */ false
172 $prepend .= ResourceLoader
::makeComment( "Unable to read $cssFileName." );
174 } catch ( Exception
$e ) {
175 $prepend .= ResourceLoader
::formatException( $e );
183 $css = $prepend . $css;
185 if ( $dir == 'rtl' ) {
186 $css = CSSJanus
::transform( $css, true );
193 * "<link>" to index.php?css=foobar for the "<head>"
196 private function getCssUrl() {
197 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
200 public function useShortHeader( $use = true ) {
201 $this->useShortHeader
= $use;
204 public function allowFrames( $allow = true ) {
205 $this->allowFrames
= $allow;
208 public function flush() {
209 if ( !$this->headerDone
) {
210 $this->outputHeader();
212 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
213 echo $this->contents
;
215 $this->contents
= '';
222 public function getDir() {
225 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
231 public function getLanguageCode() {
234 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
240 public function getHeadAttribs() {
242 'dir' => $this->getDir(),
243 'lang' => $this->getLanguageCode(),
248 * Get whether the header has been output
251 public function headerDone() {
252 return $this->headerDone
;
255 public function outputHeader() {
256 $this->headerDone
= true;
257 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
259 if ( !$this->allowFrames
) {
260 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
263 if ( $this->redirectTarget
) {
264 $this->parent
->request
->response()->header( 'Location: ' . $this->redirectTarget
);
269 if ( $this->useShortHeader
) {
270 $this->outputShortHeader();
275 <?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( '../skins/common/config.js' ) . "\n"; ?
>
285 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
286 <div id
="mw-page-base"></div
>
287 <div id
="mw-head-base"></div
>
289 <div id
="bodyContent">
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 style
="background-image: url(../skins/common/images/mediawiki.png);"
308 href
="http://www.mediawiki.org/"
309 title
="Main Page"></a
>
311 <div
class="portal"><div
class="body">
313 echo $this->parent
->parse( wfMessage( 'config-sidebar' )->plain(), true );
319 echo Html
::closeElement( 'body' ) . Html
::closeElement( 'html' );
322 public function outputShortHeader() {
324 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
326 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
327 <meta name
="robots" content
="noindex, nofollow" />
328 <title
><?php
$this->outputTitle(); ?
></title
>
329 <?php
echo $this->getCssUrl() . "\n"; ?
>
330 <?php
echo $this->getJQuery(); ?
>
331 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
334 <body style
="background-image: none">
338 public function outputTitle() {
340 echo wfMessage( 'config-title', $wgVersion )->escaped();
343 public function getJQuery() {
344 return Html
::linkedScript( "../resources/jquery/jquery.js" );