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 * Whether to use the limited header (used during CC license callbacks)
46 private $useShortHeader = false;
51 * @param $parent WebInstaller
53 public function __construct( WebInstaller
$parent ) {
54 $this->parent
= $parent;
57 public function addHTML( $html ) {
58 $this->contents
.= $html;
62 public function addWikiText( $text ) {
63 $this->addHTML( $this->parent
->parse( $text ) );
66 public function addHTMLNoFlush( $html ) {
67 $this->contents
.= $html;
70 public function redirect( $url ) {
71 if ( $this->headerDone
) {
72 throw new MWException( __METHOD__
. ' called after sending headers' );
74 $this->redirectTarget
= $url;
77 public function output() {
79 $this->outputFooter();
83 * Get the raw vector CSS, flipping if needed
84 * @param $dir String 'ltr' or 'rtl'
87 public function getCSS( $dir ) {
88 $skinDir = dirname( dirname( dirname( __FILE__
) ) ) . '/skins';
89 $vectorCssFile = "$skinDir/vector/screen.css";
90 $configCssFile = "$skinDir/common/config.css";
93 $vectorCss = file_get_contents( $vectorCssFile );
94 $configCss = file_get_contents( $configCssFile );
96 if( !$vectorCss ||
!$configCss ) {
97 $css = "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
100 $css .= str_replace( 'images/', '../skins/vector/images/', $vectorCss ) . "\n" . str_replace( 'images/', '../skins/common/images/', $configCss );
101 if( $dir == 'rtl' ) {
102 $css = CSSJanus
::transform( $css, true );
108 * URL for index.php?css=foobar
111 private function getCssUrl( ) {
112 return $_SERVER['PHP_SELF'] . '?css=' . $this->getDir();
115 public function useShortHeader( $use = true ) {
116 $this->useShortHeader
= $use;
119 public function flush() {
120 if ( !$this->headerDone
) {
121 $this->outputHeader();
123 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
124 echo $this->contents
;
126 $this->contents
= '';
130 public function getDir() {
132 if( !is_object( $wgLang ) ||
!$wgLang->isRtl() )
138 public function getLanguageCode() {
140 if( !is_object( $wgLang ) )
143 return $wgLang->getCode();
146 public function getHeadAttribs() {
148 'dir' => $this->getDir(),
149 'lang' => $this->getLanguageCode(),
154 * Get whether the header has been output
157 public function headerDone() {
158 return $this->headerDone
;
161 public function outputHeader() {
162 $this->headerDone
= true;
163 $dbTypes = $this->parent
->getDBTypes();
165 $this->parent
->request
->response()->header("Content-Type: text/html; charset=utf-8");
166 if ( $this->redirectTarget
) {
167 $this->parent
->request
->response()->header( 'Location: '.$this->redirectTarget
);
171 if ( $this->useShortHeader
) {
172 $this->outputShortHeader();
177 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
179 <meta name
="robots" content
="noindex, nofollow" />
180 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
181 <title
><?php
$this->outputTitle(); ?
></title
>
182 <?php
echo Html
::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?
>
183 <?php
echo Html
::linkedStyle( $this->getCssUrl() ) . "\n"; ?
>
184 <?php
echo Html
::inlineScript( "var dbTypes = " . Xml
::encodeJsVar( $dbTypes ) ) . "\n"; ?
>
185 <?php
echo $this->getJQuery() . "\n"; ?
>
186 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
189 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
190 <div id
="mw-page-base"></div
>
191 <div id
="mw-head-base"></div
>
193 <div id
="bodyContent">
195 <h1
><?php
$this->outputTitle(); ?
></h1
>
199 public function outputFooter() {
200 if ( $this->useShortHeader
) {
212 <div
class="portal" id
="p-logo">
213 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
214 href
="http://www.mediawiki.org/"
215 title
="Main Page"></a
>
217 <script type
="text/javascript"> if (window
.isMSIE55
) fixalpha(); </script
>
218 <div
class="portal"><div
class="body">
220 echo $this->parent
->parse( wfMsgNoTrans( 'config-sidebar' ), true );
230 public function outputShortHeader() {
232 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
234 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
235 <meta name
="robots" content
="noindex, nofollow" />
236 <title
><?php
$this->outputTitle(); ?
></title
>
237 <?php
echo Html
::linkedStyle( $this->getCssUrl() ) . "\n"; ?
>
238 <?php
echo $this->getJQuery(); ?
>
239 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
242 <body style
="background-image: none">
246 public function outputTitle() {
248 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
251 public function getJQuery() {
252 return Html
::linkedScript( "../resources/jquery/jquery.js" );