Code style fixes in Language::isValidCode()
[mediawiki.git] / includes / installer / WebInstallerOutput.php
blob3e65eae350a97afc035b662dab2c60e7e9c28558
1 <?php
2 /**
3 * Output handler for the web installer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Deployment
24 /**
25 * Output class modelled on OutputPage.
27 * I've opted to use a distinct class rather than derive from OutputPage here in
28 * the interests of separation of concerns: if we used a subclass, there would be
29 * quite a lot of things you could do in OutputPage that would break the installer,
30 * that wouldn't be immediately obvious.
32 * @ingroup Deployment
33 * @since 1.17
35 class WebInstallerOutput {
36 /**
37 * The WebInstaller object this WebInstallerOutput is used by.
39 * @var WebInstaller
41 public $parent;
43 /**
44 * Buffered contents that haven't been output yet
45 * @var String
47 private $contents = '';
49 /**
50 * Has the header (or short header) been output?
51 * @var bool
53 private $headerDone = false;
55 public $redirectTarget;
57 /**
58 * Does the current page need to allow being used as a frame?
59 * If not, X-Frame-Options will be output to forbid it.
61 * @var bool
63 public $allowFrames = false;
65 /**
66 * Whether to use the limited header (used during CC license callbacks)
67 * @var bool
69 private $useShortHeader = false;
71 /**
72 * Constructor.
74 * @param $parent WebInstaller
76 public function __construct( WebInstaller $parent ) {
77 $this->parent = $parent;
80 public function addHTML( $html ) {
81 $this->contents .= $html;
82 $this->flush();
85 public function addWikiText( $text ) {
86 $this->addHTML( $this->parent->parse( $text ) );
89 public function addHTMLNoFlush( $html ) {
90 $this->contents .= $html;
93 public function redirect( $url ) {
94 if ( $this->headerDone ) {
95 throw new MWException( __METHOD__ . ' called after sending headers' );
97 $this->redirectTarget = $url;
100 public function output() {
101 $this->flush();
102 $this->outputFooter();
106 * Get the raw vector CSS, flipping if needed
107 * @param string $dir 'ltr' or 'rtl'
108 * @return String
110 public function getCSS( $dir ) {
111 $skinDir = dirname( dirname( __DIR__ ) ) . '/skins';
113 // All these files will be concatenated in sequence and loaded
114 // as one file.
115 // The string 'images/' in the files' contents will be replaced
116 // by '../skins/$skinName/images/', where $skinName is what appears
117 // before the last '/' in each of the strings.
118 $cssFileNames = array(
120 // Basically the "skins.vector" ResourceLoader module styles
121 'common/shared.css',
122 'common/commonElements.css',
123 'common/commonContent.css',
124 'common/commonInterface.css',
125 'vector/screen.css',
127 // mw-config specific
128 'common/config.css',
131 $css = '';
133 wfSuppressWarnings();
134 foreach ( $cssFileNames as $cssFileName ) {
135 $fullCssFileName = "$skinDir/$cssFileName";
136 $cssFileContents = file_get_contents( $fullCssFileName );
137 if ( $cssFileContents ) {
138 preg_match( "/^(\w+)\//", $cssFileName, $match );
139 $skinName = $match[1];
140 $css .= str_replace( 'images/', "../skins/$skinName/images/", $cssFileContents );
141 } else {
142 $css .= "/** Your webserver cannot read $fullCssFileName. Please check file permissions. */";
145 $css .= "\n";
147 wfRestoreWarnings();
149 if ( $dir == 'rtl' ) {
150 $css = CSSJanus::transform( $css, true );
153 return $css;
157 * "<link>" to index.php?css=foobar for the "<head>"
158 * @return String
160 private function getCssUrl() {
161 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
164 public function useShortHeader( $use = true ) {
165 $this->useShortHeader = $use;
168 public function allowFrames( $allow = true ) {
169 $this->allowFrames = $allow;
172 public function flush() {
173 if ( !$this->headerDone ) {
174 $this->outputHeader();
176 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
177 echo $this->contents;
178 flush();
179 $this->contents = '';
184 * @return string
186 public function getDir() {
187 global $wgLang;
188 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
192 * @return string
194 public function getLanguageCode() {
195 global $wgLang;
196 return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
200 * @return array
202 public function getHeadAttribs() {
203 return array(
204 'dir' => $this->getDir(),
205 'lang' => $this->getLanguageCode(),
210 * Get whether the header has been output
211 * @return bool
213 public function headerDone() {
214 return $this->headerDone;
217 public function outputHeader() {
218 $this->headerDone = true;
219 $dbTypes = $this->parent->getDBTypes();
221 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
222 if ( !$this->allowFrames ) {
223 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
225 if ( $this->redirectTarget ) {
226 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
227 return;
230 if ( $this->useShortHeader ) {
231 $this->outputShortHeader();
232 return;
236 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
237 <head>
238 <meta name="robots" content="noindex, nofollow" />
239 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
240 <title><?php $this->outputTitle(); ?></title>
241 <?php echo $this->getCssUrl() . "\n"; ?>
242 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
243 <?php echo $this->getJQuery() . "\n"; ?>
244 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
245 </head>
247 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
248 <div id="mw-page-base"></div>
249 <div id="mw-head-base"></div>
250 <div id="content">
251 <div id="bodyContent">
253 <h1><?php $this->outputTitle(); ?></h1>
254 <?php
257 public function outputFooter() {
258 if ( $this->useShortHeader ) {
260 </body></html>
261 <?php
262 return;
266 </div></div>
269 <div id="mw-panel">
270 <div class="portal" id="p-logo">
271 <a style="background-image: url(../skins/common/images/mediawiki.png);"
272 href="http://www.mediawiki.org/"
273 title="Main Page"></a>
274 </div>
275 <div class="portal"><div class="body">
276 <?php
277 echo $this->parent->parse( wfMessage( 'config-sidebar' )->plain(), true );
279 </div></div>
280 </div>
282 </body>
283 </html>
284 <?php
287 public function outputShortHeader() {
289 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
290 <head>
291 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
292 <meta name="robots" content="noindex, nofollow" />
293 <title><?php $this->outputTitle(); ?></title>
294 <?php echo $this->getCssUrl() . "\n"; ?>
295 <?php echo $this->getJQuery(); ?>
296 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
297 </head>
299 <body style="background-image: none">
300 <?php
303 public function outputTitle() {
304 global $wgVersion;
305 echo wfMessage( 'config-title', $wgVersion )->escaped();
308 public function getJQuery() {
309 return Html::linkedScript( "../resources/jquery/jquery.js" );