Do not assume that the current working dir is phase3/config
[lhc/web/wiklou.git] / includes / installer / WebInstallerOutput.php
1 <?php
2 /**
3 * Output handler for the web installer.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Output class modelled on OutputPage.
11 *
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.
16 *
17 * @ingroup Deployment
18 * @since 1.17
19 */
20 class WebInstallerOutput {
21 /**
22 * The WebInstaller object this WebInstallerOutput is used by.
23 *
24 * @var WebInstaller
25 */
26 public $parent;
27
28 /**
29 * Buffered contents that haven't been output yet
30 * @var String
31 */
32 private $contents = '';
33
34 /**
35 * Has the header (or short header) been output?
36 * @var bool
37 */
38 private $headerDone = false;
39
40 public $redirectTarget;
41
42 /**
43 * Whether to use the limited header (used during CC license callbacks)
44 * @var bool
45 */
46 private $useShortHeader = false;
47
48 /**
49 * Constructor.
50 *
51 * @param $parent WebInstaller
52 */
53 public function __construct( WebInstaller $parent ) {
54 $this->parent = $parent;
55 }
56
57 public function addHTML( $html ) {
58 $this->contents .= $html;
59 $this->flush();
60 }
61
62 public function addWikiText( $text ) {
63 $this->addHTML( $this->parent->parse( $text ) );
64 }
65
66 public function addHTMLNoFlush( $html ) {
67 $this->contents .= $html;
68 }
69
70 public function redirect( $url ) {
71 if ( $this->headerDone ) {
72 throw new MWException( __METHOD__ . ' called after sending headers' );
73 }
74 $this->redirectTarget = $url;
75 }
76
77 public function output() {
78 $this->flush();
79 $this->outputFooter();
80 }
81
82 /**
83 * Get the raw vector CSS, flipping if needed
84 * @param $dir String 'ltr' or 'rtl'
85 * @return String
86 */
87 public function getCSS( $dir ) {
88 $skinDir = dirname( dirname( dirname( __FILE__ ) ) ) . '/skins';
89 $vectorCssFile = "$skinDir/vector/screen.css";
90 $configCssFile = "$skinDir/common/config.css";
91 $css = '';
92 wfSuppressWarnings();
93 $vectorCss = file_get_contents( $vectorCssFile );
94 $configCss = file_get_contents( $configCssFile );
95 wfRestoreWarnings();
96 if( !$vectorCss || !$configCss ) {
97 $css = "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
98 }
99
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 );
103 }
104 return $css;
105 }
106
107 /**
108 * URL for index.php?css=foobar
109 * @return String
110 */
111 private function getCssUrl( ) {
112 return $_SERVER['PHP_SELF'] . '?css=' . $this->getDir();
113 }
114
115 public function useShortHeader( $use = true ) {
116 $this->useShortHeader = $use;
117 }
118
119 public function flush() {
120 if ( !$this->headerDone ) {
121 $this->outputHeader();
122 }
123 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
124 echo $this->contents;
125 flush();
126 $this->contents = '';
127 }
128 }
129
130 public function getDir() {
131 global $wgLang;
132 if( !is_object( $wgLang ) || !$wgLang->isRtl() )
133 return 'ltr';
134 else
135 return 'rtl';
136 }
137
138 public function getLanguageCode() {
139 global $wgLang;
140 if( !is_object( $wgLang ) )
141 return 'en';
142 else
143 return $wgLang->getCode();
144 }
145
146 public function getHeadAttribs() {
147 return array(
148 'dir' => $this->getDir(),
149 'lang' => $this->getLanguageCode(),
150 );
151 }
152
153 /**
154 * Get whether the header has been output
155 * @return bool
156 */
157 public function headerDone() {
158 return $this->headerDone;
159 }
160
161 public function outputHeader() {
162 $this->headerDone = true;
163 $dbTypes = $this->parent->getDBTypes();
164
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 );
168 return;
169 }
170
171 if ( $this->useShortHeader ) {
172 $this->outputShortHeader();
173 return;
174 }
175
176 ?>
177 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
178 <head>
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"; ?>
187 </head>
188
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>
192 <div id="content">
193 <div id="bodyContent">
194
195 <h1><?php $this->outputTitle(); ?></h1>
196 <?php
197 }
198
199 public function outputFooter() {
200 if ( $this->useShortHeader ) {
201 ?>
202 </body></html>
203 <?php
204 return;
205 }
206 ?>
207
208 </div></div>
209
210
211 <div id="mw-panel">
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>
216 </div>
217 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
218 <div class="portal"><div class="body">
219 <?php
220 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
221 ?>
222 </div></div>
223 </div>
224
225 </body>
226 </html>
227 <?php
228 }
229
230 public function outputShortHeader() {
231 ?>
232 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
233 <head>
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' ); ?>
240 </head>
241
242 <body style="background-image: none">
243 <?php
244 }
245
246 public function outputTitle() {
247 global $wgVersion;
248 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
249 }
250
251 public function getJQuery() {
252 return Html::linkedScript( "../resources/jquery/jquery.js" );
253 }
254 }