Pass the result of the database queries in Title::getPreviousRevisionID() and Title...
[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
98 // All these files will be concatenated in sequence and loaded
99 // as one file.
100 // The string 'images/' in the files' contents will be replaced
101 // by '../skins/$skinName/images/', where $skinName is what appears
102 // before the last '/' in each of the strings.
103 $cssFileNames = array(
104 "common/shared.css",
105 "vector/screen.css",
106 "common/config.css",
107 );
108
109 $css = '';
110
111 wfSuppressWarnings();
112 foreach ( $cssFileNames as $cssFileName ) {
113 $fullCssFileName = "$skinDir/$cssFileName";
114 $cssFileContents = file_get_contents( $fullCssFileName );
115 if ( $cssFileContents ) {
116 preg_match( "/^(\w+)\//", $cssFileName, $match );
117 $skinName = $match[1];
118 $css .= str_replace( 'images/', "../skins/$skinName/images/", $cssFileContents );
119 } else {
120 $css .= "/** Your webserver cannot read $fullCssFileName. Please check file permissions. */";
121 }
122
123 $css .= "\n";
124 }
125 wfRestoreWarnings();
126
127 if( $dir == 'rtl' ) {
128 $css = CSSJanus::transform( $css, true );
129 }
130
131 return $css;
132 }
133
134 /**
135 * <link> to index.php?css=foobar for the <head>
136 * @return String
137 */
138 private function getCssUrl( ) {
139 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
140 }
141
142 public function useShortHeader( $use = true ) {
143 $this->useShortHeader = $use;
144 }
145
146 public function allowFrames( $allow = true ) {
147 $this->allowFrames = $allow;
148 }
149
150 public function flush() {
151 if ( !$this->headerDone ) {
152 $this->outputHeader();
153 }
154 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
155 echo $this->contents;
156 flush();
157 $this->contents = '';
158 }
159 }
160
161 /**
162 * @return string
163 */
164 public function getDir() {
165 global $wgLang;
166 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
167 }
168
169 /**
170 * @return string
171 */
172 public function getLanguageCode() {
173 global $wgLang;
174 return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
175 }
176
177 /**
178 * @return array
179 */
180 public function getHeadAttribs() {
181 return array(
182 'dir' => $this->getDir(),
183 'lang' => $this->getLanguageCode(),
184 );
185 }
186
187 /**
188 * Get whether the header has been output
189 * @return bool
190 */
191 public function headerDone() {
192 return $this->headerDone;
193 }
194
195 public function outputHeader() {
196 $this->headerDone = true;
197 $dbTypes = $this->parent->getDBTypes();
198
199 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
200 if (!$this->allowFrames) {
201 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
202 }
203 if ( $this->redirectTarget ) {
204 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
205 return;
206 }
207
208 if ( $this->useShortHeader ) {
209 $this->outputShortHeader();
210 return;
211 }
212
213 ?>
214 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
215 <head>
216 <meta name="robots" content="noindex, nofollow" />
217 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
218 <title><?php $this->outputTitle(); ?></title>
219 <?php echo $this->getCssUrl() . "\n"; ?>
220 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
221 <?php echo $this->getJQuery() . "\n"; ?>
222 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
223 </head>
224
225 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
226 <div id="mw-page-base"></div>
227 <div id="mw-head-base"></div>
228 <div id="content">
229 <div id="bodyContent">
230
231 <h1><?php $this->outputTitle(); ?></h1>
232 <?php
233 }
234
235 public function outputFooter() {
236 if ( $this->useShortHeader ) {
237 ?>
238 </body></html>
239 <?php
240 return;
241 }
242 ?>
243
244 </div></div>
245
246
247 <div id="mw-panel">
248 <div class="portal" id="p-logo">
249 <a style="background-image: url(../skins/common/images/mediawiki.png);"
250 href="http://www.mediawiki.org/"
251 title="Main Page"></a>
252 </div>
253 <div class="portal"><div class="body">
254 <?php
255 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
256 ?>
257 </div></div>
258 </div>
259
260 </body>
261 </html>
262 <?php
263 }
264
265 public function outputShortHeader() {
266 ?>
267 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
268 <head>
269 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
270 <meta name="robots" content="noindex, nofollow" />
271 <title><?php $this->outputTitle(); ?></title>
272 <?php echo $this->getCssUrl() . "\n"; ?>
273 <?php echo $this->getJQuery(); ?>
274 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
275 </head>
276
277 <body style="background-image: none">
278 <?php
279 }
280
281 public function outputTitle() {
282 global $wgVersion;
283 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
284 }
285
286 public function getJQuery() {
287 return Html::linkedScript( "../resources/jquery/jquery.js" );
288 }
289 }