]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/installer/WebInstallerOutput.php
MediaWiki 1.17.0-scripts
[autoinstallsdev/mediawiki.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          * Does the current page need to allow being used as a frame?
44          * If not, X-Frame-Options will be output to forbid it.
45          *
46          * @var bool
47          */
48         public $allowFrames = false;
49
50         /**
51          * Whether to use the limited header (used during CC license callbacks)
52          * @var bool
53          */
54         private $useShortHeader = false;
55
56         /**
57          * Constructor.
58          *
59          * @param $parent WebInstaller
60          */
61         public function __construct( WebInstaller $parent ) {
62                 $this->parent = $parent;
63         }
64
65         public function addHTML( $html ) {
66                 $this->contents .= $html;
67                 $this->flush();
68         }
69
70         public function addWikiText( $text ) {
71                 $this->addHTML( $this->parent->parse( $text ) );
72         }
73
74         public function addHTMLNoFlush( $html ) {
75                 $this->contents .= $html;
76         }
77
78         public function redirect( $url ) {
79                 if ( $this->headerDone ) {
80                         throw new MWException( __METHOD__ . ' called after sending headers' );
81                 }
82                 $this->redirectTarget = $url;
83         }
84
85         public function output() {
86                 $this->flush();
87                 $this->outputFooter();
88         }
89
90         /**
91          * Get the raw vector CSS, flipping if needed
92          * @param $dir String 'ltr' or 'rtl'
93          * @return String
94          */
95         public function getCSS( $dir ) {
96                 $skinDir = dirname( dirname( dirname( __FILE__ ) ) ) . '/skins';
97                 $vectorCssFile = "$skinDir/vector/screen.css";
98                 $configCssFile = "$skinDir/common/config.css";
99                 $css = '';
100                 wfSuppressWarnings();
101                 $vectorCss = file_get_contents( $vectorCssFile );
102                 $configCss = file_get_contents( $configCssFile );
103                 wfRestoreWarnings();
104                 if( !$vectorCss || !$configCss ) {
105                         $css = "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
106                 }
107
108                 $css .= str_replace( 'images/', '../skins/vector/images/', $vectorCss ) . "\n" . str_replace( 'images/', '../skins/common/images/', $configCss );
109                 if( $dir == 'rtl' ) {
110                         $css = CSSJanus::transform( $css, true );
111                 }
112                 return $css;
113         }
114
115         /**
116          * URL for index.php?css=foobar
117          * @return String
118          */
119         private function getCssUrl( ) {
120                 return $_SERVER['PHP_SELF'] . '?css=' . $this->getDir();
121         }
122
123         public function useShortHeader( $use = true ) {
124                 $this->useShortHeader = $use;
125         }
126
127         public function allowFrames( $allow = true ) {
128                 $this->allowFrames = $allow;
129         }
130
131         public function flush() {
132                 if ( !$this->headerDone ) {
133                         $this->outputHeader();
134                 }
135                 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
136                         echo $this->contents;
137                         flush();
138                         $this->contents = '';
139                 }
140         }
141
142         public function getDir() {
143                 global $wgLang;
144                 if( !is_object( $wgLang ) || !$wgLang->isRtl() )
145                         return 'ltr';
146                 else
147                         return 'rtl';
148         }
149
150         public function getLanguageCode() {
151                 global $wgLang;
152                 if( !is_object( $wgLang ) )
153                         return 'en';
154                 else
155                         return $wgLang->getCode();
156         }
157
158         public function getHeadAttribs() {
159                 return array(
160                         'dir' => $this->getDir(),
161                         'lang' => $this->getLanguageCode(),
162                 );
163         }
164
165         /**
166          * Get whether the header has been output
167          * @return bool
168          */
169         public function headerDone() {
170                 return $this->headerDone;
171         }
172
173         public function outputHeader() {
174                 $this->headerDone = true;
175                 $dbTypes = $this->parent->getDBTypes();
176
177                 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
178                 if (!$this->allowFrames) {
179                         $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
180                 }
181                 if ( $this->redirectTarget ) {
182                         $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
183                         return;
184                 }
185
186                 if ( $this->useShortHeader ) {
187                         $this->outputShortHeader();
188                         return;
189                 }
190
191 ?>
192 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
193 <head>
194         <meta name="robots" content="noindex, nofollow" />
195         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
196         <title><?php $this->outputTitle(); ?></title>
197         <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
198         <?php echo Html::linkedStyle( $this->getCssUrl() ) . "\n"; ?>
199         <?php echo Html::inlineScript(  "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
200         <?php echo $this->getJQuery() . "\n"; ?>
201         <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
202 </head>
203
204 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
205 <div id="mw-page-base"></div>
206 <div id="mw-head-base"></div>
207 <div id="content">
208 <div id="bodyContent">
209
210 <h1><?php $this->outputTitle(); ?></h1>
211 <?php
212         }
213
214         public function outputFooter() {
215                 if ( $this->useShortHeader ) {
216 ?>
217 </body></html>
218 <?php
219                         return;
220                 }
221 ?>
222
223 </div></div>
224
225
226 <div id="mw-panel">
227         <div class="portal" id="p-logo">
228           <a style="background-image: url(../skins/common/images/mediawiki.png);"
229                 href="http://www.mediawiki.org/"
230                 title="Main Page"></a>
231         </div>
232         <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
233         <div class="portal"><div class="body">
234 <?php
235         echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
236 ?>
237         </div></div>
238 </div>
239
240 </body>
241 </html>
242 <?php
243         }
244
245         public function outputShortHeader() {
246 ?>
247 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
248 <head>
249         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
250         <meta name="robots" content="noindex, nofollow" />
251         <title><?php $this->outputTitle(); ?></title>
252         <?php echo Html::linkedStyle( $this->getCssUrl() ) . "\n"; ?>
253         <?php echo $this->getJQuery(); ?>
254         <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
255 </head>
256
257 <body style="background-image: none">
258 <?php
259         }
260
261         public function outputTitle() {
262                 global $wgVersion;
263                 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
264         }
265
266         public function getJQuery() {
267                 return Html::linkedScript( "../resources/jquery/jquery.js" );
268         }
269 }