Merge new-installer branch to trunk
[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 headerDone() {
83 return $this->headerDone;
84 }
85
86 function outputHeader() {
87 $this->headerDone = true;
88 $dbTypes = $this->parent->getDBTypes();
89
90 $this->parent->request->response()->header("Content-Type: text/html; charset=utf-8");
91 if ( $this->redirectTarget ) {
92 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
93 return;
94 }
95
96 if ( $this->useShortHeader ) {
97 $this->outputShortHeader();
98 return;
99 }
100
101 ?>
102 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
103 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
104 <head>
105 <meta name="robots" content="noindex, nofollow" />
106 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
107 <title><?php $this->outputTitle(); ?></title>
108 <link rel="stylesheet" type="text/css" href="../skins/common/shared.css"/>
109 <link rel="stylesheet" type="text/css" href="../skins/monobook/main.css"/>
110 <link rel="stylesheet" type="text/css" href="../skins/common/config.css"/>
111 <script type="text/javascript"><!--
112 <?php echo "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) . ";\n"; ?>
113 // -->
114 </script>
115 <script type="text/javascript" src="../skins/common/jquery.min.js"></script>
116 <script type="text/javascript" src="../skins/common/config.js"></script>
117 </head>
118
119 <body class="<?php print $this->getDir(); ?>">
120 <noscript>
121 <style type="text/css">
122 .config-help-message { display: block; }
123 .config-show-help { display: none; }
124 </style>
125 </noscript>
126 <div id="globalWrapper">
127 <div id="column-content">
128 <div id="content">
129 <div id="bodyContent">
130
131 <h1><?php $this->outputTitle(); ?></h1>
132 <?php
133 }
134
135 function outputFooter() {
136 $this->outputWarnings();
137
138 if ( $this->useShortHeader ) {
139 ?>
140 </body></html>
141 <?php
142 return;
143 }
144 ?>
145
146 </div></div></div>
147
148
149 <div id="column-one">
150 <div class="portlet" id="p-logo">
151 <a style="background-image: url(../skins/common/images/mediawiki.png);"
152 href="http://www.mediawiki.org/"
153 title="Main Page"></a>
154 </div>
155 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
156 <div class='portlet'><div class='pBody'>
157 <?php
158 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
159 ?>
160 </div></div>
161 </div>
162
163 </div>
164
165 </body>
166 </html>
167 <?php
168 }
169
170 function outputShortHeader() {
171 ?>
172 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
173 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
174 <head>
175 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
176 <meta name="robots" content="noindex, nofollow" />
177 <title><?php $this->outputTitle(); ?></title>
178 <link rel="stylesheet" type="text/css" href="../skins/monobook/main.css"/>
179 <link rel="stylesheet" type="text/css" href="../skins/common/config.css"/>
180 <script type="text/javascript" src="../skins/common/jquery.min.js"></script>
181 <script type="text/javascript" src="../skins/common/config.js"></script>
182 </head>
183
184 <body style="background-image: none">
185 <?php
186 }
187
188 function outputTitle() {
189 global $wgVersion;
190 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
191 }
192
193 function outputWarnings() {
194 $this->addHTML( $this->warnings );
195 $this->warnings = '';
196 }
197 }