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";
92 $css = file_get_contents( $vectorCssFile ) . "\n" . file_get_contents( $configCssFile );
95 return "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
96 } elseif( $dir == 'rtl' ) {
97 $css = CSSJanus
::transform( $css, true );
99 return str_replace( 'images/', '../skins/vector/images/', $css );
103 * URL for index.php?css=foobar
106 private function getCssUrl( ) {
107 return $_SERVER['PHP_SELF'] . '?css=' . $this->getDir();
110 public function useShortHeader( $use = true ) {
111 $this->useShortHeader
= $use;
114 public function flush() {
115 if ( !$this->headerDone
) {
116 $this->outputHeader();
118 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
119 echo $this->contents
;
121 $this->contents
= '';
125 public function getDir() {
127 if( !is_object( $wgLang ) ||
!$wgLang->isRtl() )
133 public function getLanguageCode() {
135 if( !is_object( $wgLang ) )
138 return $wgLang->getCode();
141 public function getHeadAttribs() {
143 'dir' => $this->getDir(),
144 'lang' => $this->getLanguageCode(),
149 * Get whether the header has been output
152 public function headerDone() {
153 return $this->headerDone
;
156 public function outputHeader() {
157 $this->headerDone
= true;
158 $dbTypes = $this->parent
->getDBTypes();
160 $this->parent
->request
->response()->header("Content-Type: text/html; charset=utf-8");
161 if ( $this->redirectTarget
) {
162 $this->parent
->request
->response()->header( 'Location: '.$this->redirectTarget
);
166 if ( $this->useShortHeader
) {
167 $this->outputShortHeader();
172 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
174 <meta name
="robots" content
="noindex, nofollow" />
175 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
176 <title
><?php
$this->outputTitle(); ?
></title
>
177 <?php
echo Html
::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?
>
178 <?php
echo Html
::linkedStyle( $this->getCssUrl() ) . "\n"; ?
>
179 <?php
echo Html
::inlineScript( "var dbTypes = " . Xml
::encodeJsVar( $dbTypes ) ) . "\n"; ?
>
180 <?php
echo $this->getJQuery() . "\n"; ?
>
181 <?php
echo $this->getJQueryTipsy() . "\n"; ?
>
182 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
185 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
186 <div id
="mw-page-base"></div
>
187 <div id
="mw-head-base"></div
>
189 <div id
="bodyContent">
191 <h1
><?php
$this->outputTitle(); ?
></h1
>
195 public function outputFooter() {
196 if ( $this->useShortHeader
) {
208 <div
class="portlet" id
="p-logo">
209 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
210 href
="http://www.mediawiki.org/"
211 title
="Main Page"></a
>
213 <script type
="text/javascript"> if (window
.isMSIE55
) fixalpha(); </script
>
214 <div
class='portlet'><div
class='pBody'>
216 echo $this->parent
->parse( wfMsgNoTrans( 'config-sidebar' ), true );
228 public function outputShortHeader() {
230 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
232 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
233 <meta name
="robots" content
="noindex, nofollow" />
234 <title
><?php
$this->outputTitle(); ?
></title
>
235 <?php
echo Html
::linkedStyle( $this->getCssUrl() ) . "\n"; ?
>
236 <?php
echo $this->getJQuery(); ?
>
237 <?php
echo $this->getJQueryTipsy() . "\n"; ?
>
238 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
241 <body style
="background-image: none">
245 public function outputTitle() {
247 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
250 public function getJQuery() {
251 return Html
::linkedScript( "../resources/jquery/jquery.js" );
253 public function getJQueryTipsy() {
254 return Html
::linkedScript( "../resources/jquery/jquery.tipsy.js" );