Renamed InstallerDBType to DatabaseInstaller
[lhc/web/wiklou.git] / includes / installer / WebInstallerOutput.php
1 <?php
2
3 /**
4 * Output class modelled on OutputPage.
5 *
6 * I've opted to use a distinct class rather than derive from OutputPage here in
7 * the interests of separation of concerns: if we used a subclass, there would be
8 * quite a lot of things you could do in OutputPage that would break the installer,
9 * that wouldn't be immediately obvious.
10 */
11 class WebInstallerOutput {
12 var $parent;
13 var $contents = '';
14 var $warnings = '';
15 var $headerDone = false;
16 var $redirectTarget;
17 var $debug = true;
18 var $useShortHeader = false;
19
20 function __construct( $parent ) {
21 $this->parent = $parent;
22 }
23
24 function addHTML( $html ) {
25 $this->contents .= $html;
26 $this->flush();
27 }
28
29 function addWikiText( $text ) {
30 $this->addHTML( $this->parent->parse( $text ) );
31 }
32
33 function addHTMLNoFlush( $html ) {
34 $this->contents .= $html;
35 }
36
37 function addWarning( $msg ) {
38 $this->warnings .= "<p>$msg</p>\n";
39 }
40
41 function addWarningMsg( $msg /*, ... */ ) {
42 $params = func_get_args();
43 array_shift( $params );
44 $this->addWarning( wfMsg( $msg, $params ) );
45 }
46
47 function redirect( $url ) {
48 if ( $this->headerDone ) {
49 throw new MWException( __METHOD__ . ' called after sending headers' );
50 }
51 $this->redirectTarget = $url;
52 }
53
54 function output() {
55 $this->flush();
56 $this->outputFooter();
57 }
58
59 function useShortHeader( $use = true ) {
60 $this->useShortHeader = $use;
61 }
62
63 function flush() {
64 if ( !$this->headerDone ) {
65 $this->outputHeader();
66 }
67 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
68 echo $this->contents;
69 ob_flush();
70 flush();
71 $this->contents = '';
72 }
73 }
74
75 function getDir() {
76 global $wgLang;
77 if( !is_object( $wgLang ) || !$wgLang->isRtl() )
78 return 'ltr';
79 else
80 return 'rtl';
81 }
82
83 function getLanguageCode() {
84 global $wgLang;
85 if( !is_object( $wgLang ) )
86 return 'en';
87 else
88 return $wgLang->getCode();
89 }
90
91 function getHeadAttribs() {
92 return array(
93 'dir' => $this->getDir(),
94 'lang' => $this->getLanguageCode(),
95 );
96 }
97
98 function headerDone() {
99 return $this->headerDone;
100 }
101
102 function outputHeader() {
103 $this->headerDone = true;
104 $dbTypes = $this->parent->getDBTypes();
105
106 $this->parent->request->response()->header("Content-Type: text/html; charset=utf-8");
107 if ( $this->redirectTarget ) {
108 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
109 return;
110 }
111
112 if ( $this->useShortHeader ) {
113 $this->outputShortHeader();
114 return;
115 }
116
117 ?>
118 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
119 <head>
120 <meta name="robots" content="noindex, nofollow" />
121 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
122 <title><?php $this->outputTitle(); ?></title>
123 <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
124 <?php echo Html::linkedStyle( '../skins/monobook/main.css' ) . "\n"; ?>
125 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
126 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
127 <?php $this->outputJQuery() . "\n"; ?>
128 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
129 </head>
130
131 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
132 <noscript>
133 <style type="text/css">
134 .config-help-message { display: block; }
135 .config-show-help { display: none; }
136 </style>
137 </noscript>
138 <div id="globalWrapper">
139 <div id="column-content">
140 <div id="content">
141 <div id="bodyContent">
142
143 <h1><?php $this->outputTitle(); ?></h1>
144 <?php
145 }
146
147 function outputFooter() {
148 $this->outputWarnings();
149
150 if ( $this->useShortHeader ) {
151 ?>
152 </body></html>
153 <?php
154 return;
155 }
156 ?>
157
158 </div></div></div>
159
160
161 <div id="column-one">
162 <div class="portlet" id="p-logo">
163 <a style="background-image: url(../skins/common/images/mediawiki.png);"
164 href="http://www.mediawiki.org/"
165 title="Main Page"></a>
166 </div>
167 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
168 <div class='portlet'><div class='pBody'>
169 <?php
170 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
171 ?>
172 </div></div>
173 </div>
174
175 </div>
176
177 </body>
178 </html>
179 <?php
180 }
181
182 function outputShortHeader() {
183 ?>
184 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
185 <head>
186 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
187 <meta name="robots" content="noindex, nofollow" />
188 <title><?php $this->outputTitle(); ?></title>
189 <?php echo Html::linkedStyle( '../skins/monobook/main.css' ) . "\n"; ?>
190 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
191 <?php $this->outputJQuery(); ?>
192 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
193 </head>
194
195 <body style="background-image: none">
196 <?php
197 }
198
199 function outputTitle() {
200 global $wgVersion;
201 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
202 }
203
204 function outputJQuery() {
205 global $wgJQueryVersion;
206 echo Html::linkedScript( "../skins/common/jquery-$wgJQueryVersion.min.js" );
207 }
208
209 function outputWarnings() {
210 $this->addHTML( $this->warnings );
211 $this->warnings = '';
212 }
213 }