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