e8f746f9b1d5622d0e9ae47521febbe7f6a41f41
[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 flush();
70 $this->contents = '';
71 }
72 }
73
74 function getDir() {
75 global $wgLang;
76 if( !is_object( $wgLang ) || !$wgLang->isRtl() )
77 return 'ltr';
78 else
79 return 'rtl';
80 }
81
82 function getLanguageCode() {
83 global $wgLang;
84 if( !is_object( $wgLang ) )
85 return 'en';
86 else
87 return $wgLang->getCode();
88 }
89
90 function getHeadAttribs() {
91 return array(
92 'dir' => $this->getDir(),
93 'lang' => $this->getLanguageCode(),
94 );
95 }
96
97 function headerDone() {
98 return $this->headerDone;
99 }
100
101 function outputHeader() {
102 $this->headerDone = true;
103 $dbTypes = $this->parent->getDBTypes();
104
105 $this->parent->request->response()->header("Content-Type: text/html; charset=utf-8");
106 if ( $this->redirectTarget ) {
107 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
108 return;
109 }
110
111 if ( $this->useShortHeader ) {
112 $this->outputShortHeader();
113 return;
114 }
115
116 ?>
117 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
118 <head>
119 <meta name="robots" content="noindex, nofollow" />
120 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
121 <title><?php $this->outputTitle(); ?></title>
122 <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
123 <?php echo Html::linkedStyle( '../skins/monobook/main.css' ) . "\n"; ?>
124 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
125 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
126 <?php $this->outputJQuery() . "\n"; ?>
127 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
128 </head>
129
130 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
131 <noscript>
132 <style type="text/css">
133 .config-help-message { display: block; }
134 .config-show-help { display: none; }
135 </style>
136 </noscript>
137 <div id="globalWrapper">
138 <div id="column-content">
139 <div id="content">
140 <div id="bodyContent">
141
142 <h1><?php $this->outputTitle(); ?></h1>
143 <?php
144 }
145
146 function outputFooter() {
147 $this->outputWarnings();
148
149 if ( $this->useShortHeader ) {
150 ?>
151 </body></html>
152 <?php
153 return;
154 }
155 ?>
156
157 </div></div></div>
158
159
160 <div id="column-one">
161 <div class="portlet" id="p-logo">
162 <a style="background-image: url(../skins/common/images/mediawiki.png);"
163 href="http://www.mediawiki.org/"
164 title="Main Page"></a>
165 </div>
166 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
167 <div class='portlet'><div class='pBody'>
168 <?php
169 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
170 ?>
171 </div></div>
172 </div>
173
174 </div>
175
176 </body>
177 </html>
178 <?php
179 }
180
181 function outputShortHeader() {
182 ?>
183 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
184 <head>
185 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
186 <meta name="robots" content="noindex, nofollow" />
187 <title><?php $this->outputTitle(); ?></title>
188 <?php echo Html::linkedStyle( '../skins/monobook/main.css' ) . "\n"; ?>
189 <?php echo Html::linkedStyle( '../skins/common/config.css' ) . "\n"; ?>
190 <?php $this->outputJQuery(); ?>
191 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
192 </head>
193
194 <body style="background-image: none">
195 <?php
196 }
197
198 function outputTitle() {
199 global $wgVersion;
200 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
201 }
202
203 function outputJQuery() {
204 global $wgJQueryVersion;
205 echo Html::linkedScript( "../skins/common/jquery-$wgJQueryVersion.min.js" );
206 }
207
208 function outputWarnings() {
209 $this->addHTML( $this->warnings );
210 $this->warnings = '';
211 }
212 }