2010-05-07 12:25:01 +00:00
|
|
|
<?php
|
2010-08-21 18:20:09 +00:00
|
|
|
/**
|
|
|
|
|
* Output handler for the web installer.
|
|
|
|
|
*
|
2012-05-06 05:50:15 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-08-21 18:20:09 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Deployment
|
|
|
|
|
*/
|
2010-05-07 12:25:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Output class modelled on OutputPage.
|
|
|
|
|
*
|
2010-12-06 20:04:28 +00:00
|
|
|
* I've opted to use a distinct class rather than derive from OutputPage here in
|
|
|
|
|
* the interests of separation of concerns: if we used a subclass, there would be
|
|
|
|
|
* quite a lot of things you could do in OutputPage that would break the installer,
|
|
|
|
|
* that wouldn't be immediately obvious.
|
|
|
|
|
*
|
2010-07-29 18:36:39 +00:00
|
|
|
* @ingroup Deployment
|
|
|
|
|
* @since 1.17
|
2010-05-07 12:25:01 +00:00
|
|
|
*/
|
|
|
|
|
class WebInstallerOutput {
|
2014-04-08 10:22:43 +00:00
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
/**
|
|
|
|
|
* The WebInstaller object this WebInstallerOutput is used by.
|
2010-12-06 20:04:28 +00:00
|
|
|
*
|
2010-07-21 09:42:07 +00:00
|
|
|
* @var WebInstaller
|
2010-12-06 20:04:28 +00:00
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public $parent;
|
2010-11-05 12:48:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Buffered contents that haven't been output yet
|
2014-04-19 11:55:27 +00:00
|
|
|
* @var string
|
2010-11-05 12:48:13 +00:00
|
|
|
*/
|
|
|
|
|
private $contents = '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Has the header (or short header) been output?
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $headerDone = false;
|
|
|
|
|
|
2014-04-08 10:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public $redirectTarget;
|
2010-11-05 12:48:13 +00:00
|
|
|
|
2011-03-27 20:13:30 +00:00
|
|
|
/**
|
|
|
|
|
* Does the current page need to allow being used as a frame?
|
|
|
|
|
* If not, X-Frame-Options will be output to forbid it.
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
public $allowFrames = false;
|
|
|
|
|
|
2010-11-05 12:48:13 +00:00
|
|
|
/**
|
|
|
|
|
* Whether to use the limited header (used during CC license callbacks)
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
private $useShortHeader = false;
|
2010-07-21 09:42:07 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-04-08 10:22:43 +00:00
|
|
|
* @param WebInstaller $parent
|
2010-07-21 09:42:07 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( WebInstaller $parent ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->parent = $parent;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $html
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function addHTML( $html ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->contents .= $html;
|
|
|
|
|
$this->flush();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $text
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function addWikiText( $text ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->addHTML( $this->parent->parse( $text ) );
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $html
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function addHTMLNoFlush( $html ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->contents .= $html;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $url
|
|
|
|
|
*
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function redirect( $url ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $this->headerDone ) {
|
|
|
|
|
throw new MWException( __METHOD__ . ' called after sending headers' );
|
|
|
|
|
}
|
|
|
|
|
$this->redirectTarget = $url;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function output() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->flush();
|
|
|
|
|
$this->outputFooter();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 13:14:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get the raw vector CSS, flipping if needed
|
2013-10-14 01:34:58 +00:00
|
|
|
*
|
|
|
|
|
* @todo Possibly get rid of this function and use ResourceLoader in the manner it was
|
|
|
|
|
* designed to be used in, rather than just grabbing a list of filenames from it,
|
|
|
|
|
* and not properly handling such details as media types in module definitions.
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return string
|
2010-11-05 13:14:24 +00:00
|
|
|
*/
|
2014-06-04 19:25:55 +00:00
|
|
|
public function getCSS() {
|
2013-10-14 01:34:58 +00:00
|
|
|
// All CSS files these modules reference will be concatenated in sequence
|
|
|
|
|
// and loaded as one file.
|
|
|
|
|
$moduleNames = array(
|
|
|
|
|
'mediawiki.legacy.shared',
|
2014-04-29 08:37:46 +00:00
|
|
|
'mediawiki.skinning.interface',
|
2013-12-05 01:53:18 +00:00
|
|
|
'skins.vector.styles',
|
2013-10-14 01:34:58 +00:00
|
|
|
'mediawiki.legacy.config',
|
2012-03-28 14:18:38 +00:00
|
|
|
);
|
|
|
|
|
|
2013-10-14 01:34:58 +00:00
|
|
|
$prepend = '';
|
2010-12-07 01:42:38 +00:00
|
|
|
$css = '';
|
2012-03-28 14:18:38 +00:00
|
|
|
|
2013-10-14 01:34:58 +00:00
|
|
|
$resourceLoader = new ResourceLoader();
|
|
|
|
|
foreach ( $moduleNames as $moduleName ) {
|
2013-11-25 13:42:34 +00:00
|
|
|
/** @var ResourceLoaderFileModule $module */
|
2013-10-14 01:34:58 +00:00
|
|
|
$module = $resourceLoader->getModule( $moduleName );
|
|
|
|
|
$cssFileNames = $module->getAllStyleFiles();
|
|
|
|
|
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
foreach ( $cssFileNames as $cssFileName ) {
|
|
|
|
|
if ( !file_exists( $cssFileName ) ) {
|
|
|
|
|
$prepend .= ResourceLoader::makeComment( "Unable to find $cssFileName." );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_readable( $cssFileName ) ) {
|
2013-11-25 13:42:34 +00:00
|
|
|
$prepend .= ResourceLoader::makeComment( "Unable to read $cssFileName. " .
|
|
|
|
|
"Please check file permissions." );
|
2013-10-14 01:34:58 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
if ( preg_match( '/\.less$/', $cssFileName ) ) {
|
|
|
|
|
// Run the LESS compiler for *.less files (bug 55589)
|
|
|
|
|
$compiler = ResourceLoader::getLessCompiler();
|
|
|
|
|
$cssFileContents = $compiler->compileFile( $cssFileName );
|
|
|
|
|
} else {
|
|
|
|
|
// Regular CSS file
|
|
|
|
|
$cssFileContents = file_get_contents( $cssFileName );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $cssFileContents ) {
|
|
|
|
|
// Rewrite URLs, though don't bother embedding images. While static image
|
|
|
|
|
// files may be cached, CSS returned by this function is definitely not.
|
|
|
|
|
$cssDirName = dirname( $cssFileName );
|
|
|
|
|
$css .= CSSMin::remap(
|
|
|
|
|
/* source */ $cssFileContents,
|
|
|
|
|
/* local */ $cssDirName,
|
|
|
|
|
/* remote */ '..' . str_replace(
|
|
|
|
|
array( $GLOBALS['IP'], DIRECTORY_SEPARATOR ),
|
|
|
|
|
array( '', '/' ),
|
|
|
|
|
$cssDirName
|
|
|
|
|
),
|
|
|
|
|
/* embedData */ false
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$prepend .= ResourceLoader::makeComment( "Unable to read $cssFileName." );
|
|
|
|
|
}
|
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
|
$prepend .= ResourceLoader::formatException( $e );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$css .= "\n";
|
2012-03-28 14:18:38 +00:00
|
|
|
}
|
2013-10-14 01:34:58 +00:00
|
|
|
wfRestoreWarnings();
|
2010-12-03 13:46:21 +00:00
|
|
|
}
|
2013-10-14 01:34:58 +00:00
|
|
|
|
|
|
|
|
$css = $prepend . $css;
|
2010-12-03 13:46:21 +00:00
|
|
|
|
2014-06-04 19:25:55 +00:00
|
|
|
if ( $this->getDir() == 'rtl' ) {
|
2010-11-08 16:19:08 +00:00
|
|
|
$css = CSSJanus::transform( $css, true );
|
2010-11-05 13:14:24 +00:00
|
|
|
}
|
2012-03-28 14:18:38 +00:00
|
|
|
|
2010-11-20 20:24:48 +00:00
|
|
|
return $css;
|
2010-11-05 13:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-04 19:25:55 +00:00
|
|
|
* "<link>" to index.php?css=1 for the "<head>"
|
2014-04-08 10:22:43 +00:00
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return string
|
2010-11-05 13:14:24 +00:00
|
|
|
*/
|
2013-03-17 15:13:22 +00:00
|
|
|
private function getCssUrl() {
|
2014-06-04 19:25:55 +00:00
|
|
|
return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
|
2010-11-05 13:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function useShortHeader( $use = true ) {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->useShortHeader = $use;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-27 20:13:30 +00:00
|
|
|
public function allowFrames( $allow = true ) {
|
|
|
|
|
$this->allowFrames = $allow;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function flush() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( !$this->headerDone ) {
|
|
|
|
|
$this->outputHeader();
|
|
|
|
|
}
|
|
|
|
|
if ( !$this->redirectTarget && strlen( $this->contents ) ) {
|
|
|
|
|
echo $this->contents;
|
|
|
|
|
flush();
|
|
|
|
|
$this->contents = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:58:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function getDir() {
|
2010-05-07 12:25:01 +00:00
|
|
|
global $wgLang;
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2011-12-12 21:56:26 +00:00
|
|
|
return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:58:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function getLanguageCode() {
|
2010-05-08 13:45:14 +00:00
|
|
|
global $wgLang;
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2011-12-12 21:56:26 +00:00
|
|
|
return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
|
2010-05-08 13:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:58:29 +00:00
|
|
|
/**
|
2014-04-08 10:22:43 +00:00
|
|
|
* @return string[]
|
2011-05-02 16:58:29 +00:00
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function getHeadAttribs() {
|
2010-05-08 13:45:14 +00:00
|
|
|
return array(
|
|
|
|
|
'dir' => $this->getDir(),
|
|
|
|
|
'lang' => $this->getLanguageCode(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 12:48:13 +00:00
|
|
|
/**
|
|
|
|
|
* Get whether the header has been output
|
2014-04-08 10:22:43 +00:00
|
|
|
*
|
2010-11-05 12:48:13 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2010-07-21 09:42:07 +00:00
|
|
|
public function headerDone() {
|
2010-05-07 12:25:01 +00:00
|
|
|
return $this->headerDone;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function outputHeader() {
|
2010-05-07 12:25:01 +00:00
|
|
|
$this->headerDone = true;
|
2011-01-04 06:12:33 +00:00
|
|
|
$this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
|
2013-10-08 16:08:00 +00:00
|
|
|
|
2013-02-03 19:28:43 +00:00
|
|
|
if ( !$this->allowFrames ) {
|
2011-03-27 20:13:30 +00:00
|
|
|
$this->parent->request->response()->header( 'X-Frame-Options: DENY' );
|
|
|
|
|
}
|
2013-10-08 16:08:00 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $this->redirectTarget ) {
|
2013-04-13 11:36:24 +00:00
|
|
|
$this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->useShortHeader ) {
|
|
|
|
|
$this->outputShortHeader();
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
?>
|
2010-05-08 13:45:14 +00:00
|
|
|
<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
|
2010-05-07 12:25:01 +00:00
|
|
|
<head>
|
|
|
|
|
<meta name="robots" content="noindex, nofollow" />
|
|
|
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
|
|
|
|
<title><?php $this->outputTitle(); ?></title>
|
2011-07-07 16:52:47 +00:00
|
|
|
<?php echo $this->getCssUrl() . "\n"; ?>
|
2010-09-09 22:11:19 +00:00
|
|
|
<?php echo $this->getJQuery() . "\n"; ?>
|
2010-05-08 13:45:14 +00:00
|
|
|
<?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
|
2010-05-07 12:25:01 +00:00
|
|
|
</head>
|
|
|
|
|
|
2010-05-08 13:45:14 +00:00
|
|
|
<?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
|
2010-11-17 11:43:57 +00:00
|
|
|
<div id="mw-page-base"></div>
|
|
|
|
|
<div id="mw-head-base"></div>
|
2010-05-07 12:25:01 +00:00
|
|
|
<div id="content">
|
|
|
|
|
<div id="bodyContent">
|
|
|
|
|
|
|
|
|
|
<h1><?php $this->outputTitle(); ?></h1>
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function outputFooter() {
|
2010-05-07 12:25:01 +00:00
|
|
|
if ( $this->useShortHeader ) {
|
2013-10-08 16:33:06 +00:00
|
|
|
echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
|
|
|
|
|
|
2010-05-07 12:25:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
2010-11-17 11:43:57 +00:00
|
|
|
</div></div>
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2010-11-17 11:43:57 +00:00
|
|
|
<div id="mw-panel">
|
2010-11-20 21:07:34 +00:00
|
|
|
<div class="portal" id="p-logo">
|
2010-05-07 12:25:01 +00:00
|
|
|
<a style="background-image: url(../skins/common/images/mediawiki.png);"
|
2014-03-12 22:30:35 +00:00
|
|
|
href="https://www.mediawiki.org/"
|
2010-12-19 04:31:15 +00:00
|
|
|
title="Main Page"></a>
|
2010-05-07 12:25:01 +00:00
|
|
|
</div>
|
2010-11-20 21:07:34 +00:00
|
|
|
<div class="portal"><div class="body">
|
2010-05-07 12:25:01 +00:00
|
|
|
<?php
|
2012-08-21 19:58:47 +00:00
|
|
|
echo $this->parent->parse( wfMessage( 'config-sidebar' )->plain(), true );
|
2010-05-07 12:25:01 +00:00
|
|
|
?>
|
|
|
|
|
</div></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<?php
|
2013-10-08 16:33:06 +00:00
|
|
|
echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function outputShortHeader() {
|
2010-05-07 12:25:01 +00:00
|
|
|
?>
|
2010-05-08 13:45:14 +00:00
|
|
|
<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
|
2010-05-07 12:25:01 +00:00
|
|
|
<head>
|
|
|
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
|
|
|
|
<meta name="robots" content="noindex, nofollow" />
|
|
|
|
|
<title><?php $this->outputTitle(); ?></title>
|
2011-07-07 16:52:47 +00:00
|
|
|
<?php echo $this->getCssUrl() . "\n"; ?>
|
2010-09-09 22:11:19 +00:00
|
|
|
<?php echo $this->getJQuery(); ?>
|
2010-05-08 13:45:14 +00:00
|
|
|
<?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
|
2010-05-07 12:25:01 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
|
|
<body style="background-image: none">
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-21 09:42:07 +00:00
|
|
|
public function outputTitle() {
|
2011-05-15 13:21:16 +00:00
|
|
|
global $wgVersion;
|
2012-08-21 19:58:47 +00:00
|
|
|
echo wfMessage( 'config-title', $wgVersion )->escaped();
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:22:43 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-09-09 22:11:19 +00:00
|
|
|
public function getJQuery() {
|
2014-04-18 14:39:37 +00:00
|
|
|
return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
|
2010-05-07 13:28:29 +00:00
|
|
|
}
|
2014-04-08 10:22:43 +00:00
|
|
|
|
2010-11-05 12:48:13 +00:00
|
|
|
}
|