[Core JS] wikibits.js / IEFixes clean up
[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 * Does the current page need to allow being used as a frame?
44 * If not, X-Frame-Options will be output to forbid it.
45 *
46 * @var bool
47 */
48 public $allowFrames = false;
49
50 /**
51 * Whether to use the limited header (used during CC license callbacks)
52 * @var bool
53 */
54 private $useShortHeader = false;
55
56 /**
57 * Constructor.
58 *
59 * @param $parent WebInstaller
60 */
61 public function __construct( WebInstaller $parent ) {
62 $this->parent = $parent;
63 }
64
65 public function addHTML( $html ) {
66 $this->contents .= $html;
67 $this->flush();
68 }
69
70 public function addWikiText( $text ) {
71 $this->addHTML( $this->parent->parse( $text ) );
72 }
73
74 public function addHTMLNoFlush( $html ) {
75 $this->contents .= $html;
76 }
77
78 public function redirect( $url ) {
79 if ( $this->headerDone ) {
80 throw new MWException( __METHOD__ . ' called after sending headers' );
81 }
82 $this->redirectTarget = $url;
83 }
84
85 public function output() {
86 $this->flush();
87 $this->outputFooter();
88 }
89
90 /**
91 * Get the raw vector CSS, flipping if needed
92 * @param $dir String 'ltr' or 'rtl'
93 * @return String
94 */
95 public function getCSS( $dir ) {
96 $skinDir = dirname( dirname( dirname( __FILE__ ) ) ) . '/skins';
97 $vectorCssFile = "$skinDir/vector/screen.css";
98 $configCssFile = "$skinDir/common/config.css";
99 $css = '';
100 wfSuppressWarnings();
101 $vectorCss = file_get_contents( $vectorCssFile );
102 $configCss = file_get_contents( $configCssFile );
103 wfRestoreWarnings();
104 if( !$vectorCss || !$configCss ) {
105 $css = "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
106 }
107
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 );
111 }
112 return $css;
113 }
114
115 /**
116 * <link> to index.php?css=foobar for the <head>
117 * @return String
118 */
119 private function getCssUrl( ) {
120 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
121 }
122
123 public function useShortHeader( $use = true ) {
124 $this->useShortHeader = $use;
125 }
126
127 public function allowFrames( $allow = true ) {
128 $this->allowFrames = $allow;
129 }
130
131 public function flush() {
132 if ( !$this->headerDone ) {
133 $this->outputHeader();
134 }
135 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
136 echo $this->contents;
137 flush();
138 $this->contents = '';
139 }
140 }
141
142 /**
143 * @return string
144 */
145 public function getDir() {
146 global $wgLang;
147 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
148 }
149
150 /**
151 * @return string
152 */
153 public function getLanguageCode() {
154 global $wgLang;
155 return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
156 }
157
158 /**
159 * @return array
160 */
161 public function getHeadAttribs() {
162 return array(
163 'dir' => $this->getDir(),
164 'lang' => $this->getLanguageCode(),
165 );
166 }
167
168 /**
169 * Get whether the header has been output
170 * @return bool
171 */
172 public function headerDone() {
173 return $this->headerDone;
174 }
175
176 public function outputHeader() {
177 $this->headerDone = true;
178 $dbTypes = $this->parent->getDBTypes();
179
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' );
183 }
184 if ( $this->redirectTarget ) {
185 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
186 return;
187 }
188
189 if ( $this->useShortHeader ) {
190 $this->outputShortHeader();
191 return;
192 }
193
194 ?>
195 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
196 <head>
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"; ?>
205 </head>
206
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>
210 <div id="content">
211 <div id="bodyContent">
212
213 <h1><?php $this->outputTitle(); ?></h1>
214 <?php
215 }
216
217 public function outputFooter() {
218 if ( $this->useShortHeader ) {
219 ?>
220 </body></html>
221 <?php
222 return;
223 }
224 ?>
225
226 </div></div>
227
228
229 <div id="mw-panel">
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>
234 </div>
235 <div class="portal"><div class="body">
236 <?php
237 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
238 ?>
239 </div></div>
240 </div>
241
242 </body>
243 </html>
244 <?php
245 }
246
247 public function outputShortHeader() {
248 ?>
249 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
250 <head>
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' ); ?>
257 </head>
258
259 <body style="background-image: none">
260 <?php
261 }
262
263 public function outputTitle() {
264 global $wgVersion;
265 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
266 }
267
268 public function getJQuery() {
269 return Html::linkedScript( "../resources/jquery/jquery.js" );
270 }
271 }