Add TitleIsMovable hook so extensions can create new namespaces in which pages can...
[mediawiki.git] / includes / installer / WebInstallerOutput.php
blob9eb2c2c6a5a104297daee6274d27102fc60f864d
1 <?php
2 /**
3 * Output handler for the web installer.
5 * @file
6 * @ingroup Deployment
7 */
9 /**
10 * Output class modelled on OutputPage.
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.
17 * @ingroup Deployment
18 * @since 1.17
20 class WebInstallerOutput {
21 /**
22 * The WebInstaller object this WebInstallerOutput is used by.
24 * @var WebInstaller
26 public $parent;
28 /**
29 * Buffered contents that haven't been output yet
30 * @var String
32 private $contents = '';
34 /**
35 * Has the header (or short header) been output?
36 * @var bool
38 private $headerDone = false;
40 public $redirectTarget;
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.
46 * @var bool
48 public $allowFrames = false;
50 /**
51 * Whether to use the limited header (used during CC license callbacks)
52 * @var bool
54 private $useShortHeader = false;
56 /**
57 * Constructor.
59 * @param $parent WebInstaller
61 public function __construct( WebInstaller $parent ) {
62 $this->parent = $parent;
65 public function addHTML( $html ) {
66 $this->contents .= $html;
67 $this->flush();
70 public function addWikiText( $text ) {
71 $this->addHTML( $this->parent->parse( $text ) );
74 public function addHTMLNoFlush( $html ) {
75 $this->contents .= $html;
78 public function redirect( $url ) {
79 if ( $this->headerDone ) {
80 throw new MWException( __METHOD__ . ' called after sending headers' );
82 $this->redirectTarget = $url;
85 public function output() {
86 $this->flush();
87 $this->outputFooter();
90 /**
91 * Get the raw vector CSS, flipping if needed
92 * @param $dir String 'ltr' or 'rtl'
93 * @return String
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 */";
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 );
112 return $css;
116 * <link> to index.php?css=foobar for the <head>
117 * @return String
119 private function getCssUrl( ) {
120 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
123 public function useShortHeader( $use = true ) {
124 $this->useShortHeader = $use;
127 public function allowFrames( $allow = true ) {
128 $this->allowFrames = $allow;
131 public function flush() {
132 if ( !$this->headerDone ) {
133 $this->outputHeader();
135 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
136 echo $this->contents;
137 flush();
138 $this->contents = '';
143 * @return string
145 public function getDir() {
146 global $wgLang;
147 if( !is_object( $wgLang ) || !$wgLang->isRtl() ) {
148 return 'ltr';
149 } else {
150 return 'rtl';
155 * @return string
157 public function getLanguageCode() {
158 global $wgLang;
159 if( !is_object( $wgLang ) ) {
160 return 'en';
161 } else {
162 return $wgLang->getCode();
167 * @return array
169 public function getHeadAttribs() {
170 return array(
171 'dir' => $this->getDir(),
172 'lang' => $this->getLanguageCode(),
177 * Get whether the header has been output
178 * @return bool
180 public function headerDone() {
181 return $this->headerDone;
184 public function outputHeader() {
185 $this->headerDone = true;
186 $dbTypes = $this->parent->getDBTypes();
188 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
189 if (!$this->allowFrames) {
190 $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
192 if ( $this->redirectTarget ) {
193 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
194 return;
197 if ( $this->useShortHeader ) {
198 $this->outputShortHeader();
199 return;
203 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
204 <head>
205 <meta name="robots" content="noindex, nofollow" />
206 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
207 <title><?php $this->outputTitle(); ?></title>
208 <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
209 <?php echo $this->getCssUrl() . "\n"; ?>
210 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
211 <?php echo $this->getJQuery() . "\n"; ?>
212 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
213 </head>
215 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
216 <div id="mw-page-base"></div>
217 <div id="mw-head-base"></div>
218 <div id="content">
219 <div id="bodyContent">
221 <h1><?php $this->outputTitle(); ?></h1>
222 <?php
225 public function outputFooter() {
226 if ( $this->useShortHeader ) {
228 </body></html>
229 <?php
230 return;
234 </div></div>
237 <div id="mw-panel">
238 <div class="portal" id="p-logo">
239 <a style="background-image: url(../skins/common/images/mediawiki.png);"
240 href="http://www.mediawiki.org/"
241 title="Main Page"></a>
242 </div>
243 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
244 <div class="portal"><div class="body">
245 <?php
246 echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
248 </div></div>
249 </div>
251 </body>
252 </html>
253 <?php
256 public function outputShortHeader() {
258 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
259 <head>
260 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
261 <meta name="robots" content="noindex, nofollow" />
262 <title><?php $this->outputTitle(); ?></title>
263 <?php echo $this->getCssUrl() . "\n"; ?>
264 <?php echo $this->getJQuery(); ?>
265 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
266 </head>
268 <body style="background-image: none">
269 <?php
272 public function outputTitle() {
273 global $wgVersion;
274 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
277 public function getJQuery() {
278 return Html::linkedScript( "../resources/jquery/jquery.js" );