3 * Output handler for the web installer.
10 * Output class modelled on OutputPage.
12 * I've opted to use a distinct class rather than derive from OutputPage here in
13 * the interests of separation of concerns: if we used a subclass, there would be
14 * quite a lot of things you could do in OutputPage that would break the installer,
15 * that wouldn't be immediately obvious.
20 class WebInstallerOutput
{
22 * The WebInstaller object this WebInstallerOutput is used by.
29 * Buffered contents that haven't been output yet
32 private $contents = '';
35 * Has the header (or short header) been output?
38 private $headerDone = false;
40 public $redirectTarget;
43 * Does the current page need to allow being used as a frame?
44 * If not, X-Frame-Options will be output to forbid it.
48 public $allowFrames = false;
51 * Whether to use the limited header (used during CC license callbacks)
54 private $useShortHeader = false;
59 * @param $parent WebInstaller
61 public function __construct( WebInstaller
$parent ) {
62 $this->parent
= $parent;
65 public function addHTML( $html ) {
66 $this->contents
.= $html;
70 public function addWikiText( $text ) {
71 $this->addHTML( $this->parent
->parse( $text ) );
74 public function addHTMLNoFlush( $html ) {
75 $this->contents
.= $html;
78 public function redirect( $url ) {
79 if ( $this->headerDone
) {
80 throw new MWException( __METHOD__
. ' called after sending headers' );
82 $this->redirectTarget
= $url;
85 public function output() {
87 $this->outputFooter();
91 * Get the raw vector CSS, flipping if needed
92 * @param $dir String 'ltr' or 'rtl'
95 public function getCSS( $dir ) {
96 $skinDir = dirname( dirname( dirname( __FILE__
) ) ) . '/skins';
97 $vectorCssFile = "$skinDir/vector/screen.css";
98 $configCssFile = "$skinDir/common/config.css";
100 wfSuppressWarnings();
101 $vectorCss = file_get_contents( $vectorCssFile );
102 $configCss = file_get_contents( $configCssFile );
104 if( !$vectorCss ||
!$configCss ) {
105 $css = "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
108 $css .= str_replace( 'images/', '../skins/vector/images/', $vectorCss ) . "\n" . str_replace( 'images/', '../skins/common/images/', $configCss );
109 if( $dir == 'rtl' ) {
110 $css = CSSJanus
::transform( $css, true );
116 * <link> to index.php?css=foobar for the <head>
119 private function getCssUrl( ) {
120 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
123 public function useShortHeader( $use = true ) {
124 $this->useShortHeader
= $use;
127 public function allowFrames( $allow = true ) {
128 $this->allowFrames
= $allow;
131 public function flush() {
132 if ( !$this->headerDone
) {
133 $this->outputHeader();
135 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
136 echo $this->contents
;
138 $this->contents
= '';
145 public function getDir() {
147 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
153 public function getLanguageCode() {
155 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
161 public function getHeadAttribs() {
163 'dir' => $this->getDir(),
164 'lang' => $this->getLanguageCode(),
169 * Get whether the header has been output
172 public function headerDone() {
173 return $this->headerDone
;
176 public function outputHeader() {
177 $this->headerDone
= true;
178 $dbTypes = $this->parent
->getDBTypes();
180 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
181 if (!$this->allowFrames
) {
182 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
184 if ( $this->redirectTarget
) {
185 $this->parent
->request
->response()->header( 'Location: '.$this->redirectTarget
);
189 if ( $this->useShortHeader
) {
190 $this->outputShortHeader();
195 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
197 <meta name
="robots" content
="noindex, nofollow" />
198 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
199 <title
><?php
$this->outputTitle(); ?
></title
>
200 <?php
echo Html
::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?
>
201 <?php
echo $this->getCssUrl() . "\n"; ?
>
202 <?php
echo Html
::inlineScript( "var dbTypes = " . Xml
::encodeJsVar( $dbTypes ) ) . "\n"; ?
>
203 <?php
echo $this->getJQuery() . "\n"; ?
>
204 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
207 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
208 <div id
="mw-page-base"></div
>
209 <div id
="mw-head-base"></div
>
211 <div id
="bodyContent">
213 <h1
><?php
$this->outputTitle(); ?
></h1
>
217 public function outputFooter() {
218 if ( $this->useShortHeader
) {
230 <div
class="portal" id
="p-logo">
231 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
232 href
="http://www.mediawiki.org/"
233 title
="Main Page"></a
>
235 <div
class="portal"><div
class="body">
237 echo $this->parent
->parse( wfMsgNoTrans( 'config-sidebar' ), true );
247 public function outputShortHeader() {
249 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
251 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
252 <meta name
="robots" content
="noindex, nofollow" />
253 <title
><?php
$this->outputTitle(); ?
></title
>
254 <?php
echo $this->getCssUrl() . "\n"; ?
>
255 <?php
echo $this->getJQuery(); ?
>
256 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
259 <body style
="background-image: none">
263 public function outputTitle() {
265 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
268 public function getJQuery() {
269 return Html
::linkedScript( "../resources/jquery/jquery.js" );