Nikerabbit wanted "
[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 $vectorCssFile = dirname( dirname( dirname( __FILE__ ) ) ) .
89 '/skins/vector/screen.css';
90 wfSuppressWarnings();
91 $css = file_get_contents( $vectorCssFile );
92 wfRestoreWarnings();
93 if( !$css ) {
94 return "/** Your webserver cannot read $vectorCssFile, please check file permissions */";
95 } elseif( $dir == 'rtl' ) {
96 return CSSJanus::transform( $css, true );
97 } else {
98 return $css;
99 }
100 }
101
102 /**
103 * URL for index.php?css=foobar
104 * @return String
105 */
106 private function getCssUrl( ) {
107 return $_SERVER['PHP_SELF'] . '?css=' . $this->getDir();
108 }
109
110 public function useShortHeader( $use = true ) {
111 $this->useShortHeader = $use;
112 }
113
114 public function flush() {
115 if ( !$this->headerDone ) {
116 $this->outputHeader();
117 }
118 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
119 echo $this->contents;
120 flush();
121 $this->contents = '';
122 }
123 }
124
125 public function getDir() {
126 global $wgLang;
127 if( !is_object( $wgLang ) || !$wgLang->isRtl() )
128 return 'ltr';
129 else
130 return 'rtl';
131 }
132
133 public function getLanguageCode() {
134 global $wgLang;
135 if( !is_object( $wgLang ) )
136 return 'en';
137 else
138 return $wgLang->getCode();
139 }
140
141 public function getHeadAttribs() {
142 return array(
143 'dir' => $this->getDir(),
144 'lang' => $this->getLanguageCode(),
145 );
146 }
147
148 /**
149 * Get whether the header has been output
150 * @return bool
151 */
152 public function headerDone() {
153 return $this->headerDone;
154 }
155
156 public function outputHeader() {
157 $this->headerDone = true;
158 $dbTypes = $this->parent->getDBTypes();
159
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 );
163 return;
164 }
165
166 if ( $this->useShortHeader ) {
167 $this->outputShortHeader();
168 return;
169 }
170
171 ?>
172 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
173 <head>
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::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
180 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
181 <?php echo $this->getJQuery() . "\n"; ?>
182 <?php echo $this->getJQueryTipsy() . "\n"; ?>
183 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
184 </head>
185
186 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
187 <noscript>
188 <style type="text/css">
189 .config-help-message { display: block; }
190 .config-show-help { display: none; }
191 </style>
192 </noscript>
193 <div id="mw-page-base">
194 <div id="mw-head-base">
195 <div id="content">
196 <div id="bodyContent">
197
198 <h1><?php $this->outputTitle(); ?></h1>
199 <?php
200 }
201
202 public function outputFooter() {
203 if ( $this->useShortHeader ) {
204 ?>
205 </body></html>
206 <?php
207 return;
208 }
209 ?>
210
211 </div></div></div>
212
213
214 <div id="column-one">
215 <div class="portlet" id="p-logo">
216 <a style="background-image: url(../skins/common/images/mediawiki.png);"
217 href="http://www.mediawiki.org/"
218 title="Main Page"></a>
219 </div>
220 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
221 <div class='portlet'><div class='pBody'>
222 <?php
223 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
224 ?>
225 </div></div>
226 </div>
227
228 </div>
229
230 </body>
231 </html>
232 <?php
233 }
234
235 public function outputShortHeader() {
236 ?>
237 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
238 <head>
239 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
240 <meta name="robots" content="noindex, nofollow" />
241 <title><?php $this->outputTitle(); ?></title>
242 <?php echo Html::linkedStyle( $this->getCssUrl() ) . "\n"; ?>
243 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
244 <?php echo $this->getJQuery(); ?>
245 <?php echo $this->getJQueryTipsy() . "\n"; ?>
246 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
247 </head>
248
249 <body style="background-image: none">
250 <?php
251 }
252
253 public function outputTitle() {
254 global $wgVersion;
255 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
256 }
257
258 public function getJQuery() {
259 return Html::linkedScript( "../resources/jquery/jquery.js" );
260 }
261 public function getJQueryTipsy() {
262 return Html::linkedScript( "../resources/jquery/jquery.tipsy.js" );
263 }
264 }