properly capitalize the word "MediaWiki"
[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 /**
23 * The WebInstaller object this WebInstallerOutput is used by.
24 *
25 * @var WebInstaller
26 */
27 public $parent;
28
29 public $contents = '';
30 public $warnings = '';
31 public $headerDone = false;
32 public $redirectTarget;
33 public $debug = true;
34 public $useShortHeader = false;
35
36 /**
37 * Constructor.
38 *
39 * @param $parent WebInstaller
40 */
41 public function __construct( WebInstaller $parent ) {
42 $this->parent = $parent;
43 }
44
45 public function addHTML( $html ) {
46 $this->contents .= $html;
47 $this->flush();
48 }
49
50 public function addWikiText( $text ) {
51 $this->addHTML( $this->parent->parse( $text ) );
52 }
53
54 public function addHTMLNoFlush( $html ) {
55 $this->contents .= $html;
56 }
57
58 public function addWarning( $msg ) {
59 $this->warnings .= "<p>$msg</p>\n";
60 }
61
62 public function addWarningMsg( $msg /*, ... */ ) {
63 $params = func_get_args();
64 array_shift( $params );
65 $this->addWarning( wfMsg( $msg, $params ) );
66 }
67
68 public function redirect( $url ) {
69 if ( $this->headerDone ) {
70 throw new MWException( __METHOD__ . ' called after sending headers' );
71 }
72 $this->redirectTarget = $url;
73 }
74
75 public function output() {
76 $this->flush();
77 $this->outputFooter();
78 }
79
80 public function useShortHeader( $use = true ) {
81 $this->useShortHeader = $use;
82 }
83
84 public function flush() {
85 if ( !$this->headerDone ) {
86 $this->outputHeader();
87 }
88 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
89 echo $this->contents;
90 ob_flush();
91 flush();
92 $this->contents = '';
93 }
94 }
95
96 public function getDir() {
97 global $wgLang;
98 if( !is_object( $wgLang ) || !$wgLang->isRtl() )
99 return 'ltr';
100 else
101 return 'rtl';
102 }
103
104 public function getLanguageCode() {
105 global $wgLang;
106 if( !is_object( $wgLang ) )
107 return 'en';
108 else
109 return $wgLang->getCode();
110 }
111
112 public function getHeadAttribs() {
113 return array(
114 'dir' => $this->getDir(),
115 'lang' => $this->getLanguageCode(),
116 );
117 }
118
119 public function headerDone() {
120 return $this->headerDone;
121 }
122
123 public function outputHeader() {
124 $this->headerDone = true;
125 $dbTypes = $this->parent->getDBTypes();
126
127 $this->parent->request->response()->header("Content-Type: text/html; charset=utf-8");
128 if ( $this->redirectTarget ) {
129 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
130 return;
131 }
132
133 if ( $this->useShortHeader ) {
134 $this->outputShortHeader();
135 return;
136 }
137
138 ?>
139 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
140 <head>
141 <meta name="robots" content="noindex, nofollow" />
142 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
143 <title><?php $this->outputTitle(); ?></title>
144 <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
145 <?php echo Html::linkedStyle( '../skins/monobook/main.css' ) . "\n"; ?>
146 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
147 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
148 <?php $this->outputJQuery() . "\n"; ?>
149 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
150 </head>
151
152 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
153 <noscript>
154 <style type="text/css">
155 .config-help-message { display: block; }
156 .config-show-help { display: none; }
157 </style>
158 </noscript>
159 <div id="globalWrapper">
160 <div id="column-content">
161 <div id="content">
162 <div id="bodyContent">
163
164 <h1><?php $this->outputTitle(); ?></h1>
165 <?php
166 }
167
168 public function outputFooter() {
169 $this->outputWarnings();
170
171 if ( $this->useShortHeader ) {
172 ?>
173 </body></html>
174 <?php
175 return;
176 }
177 ?>
178
179 </div></div></div>
180
181
182 <div id="column-one">
183 <div class="portlet" id="p-logo">
184 <a style="background-image: url(../skins/common/images/mediawiki.png);"
185 href="http://www.mediawiki.org/"
186 title="Main Page"></a>
187 </div>
188 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
189 <div class='portlet'><div class='pBody'>
190 <?php
191 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
192 ?>
193 </div></div>
194 </div>
195
196 </div>
197
198 </body>
199 </html>
200 <?php
201 }
202
203 public function outputShortHeader() {
204 ?>
205 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
206 <head>
207 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
208 <meta name="robots" content="noindex, nofollow" />
209 <title><?php $this->outputTitle(); ?></title>
210 <?php echo Html::linkedStyle( '../skins/monobook/main.css' ) . "\n"; ?>
211 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
212 <?php $this->outputJQuery(); ?>
213 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
214 </head>
215
216 <body style="background-image: none">
217 <?php
218 }
219
220 public function outputTitle() {
221 global $wgVersion;
222 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
223 }
224
225 public function outputJQuery() {
226 global $wgJQueryVersion;
227 echo Html::linkedScript( "../skins/common/jquery-$wgJQueryVersion.min.js" );
228 }
229
230 public function outputWarnings() {
231 $this->addHTML( $this->warnings );
232 $this->warnings = '';
233 }
234
235 }