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
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.
35 class WebInstallerOutput
{
37 * The WebInstaller object this WebInstallerOutput is used by.
44 * Buffered contents that haven't been output yet
47 private $contents = '';
50 * Has the header (or short header) been output?
53 private $headerDone = false;
55 public $redirectTarget;
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.
63 public $allowFrames = false;
66 * Whether to use the limited header (used during CC license callbacks)
69 private $useShortHeader = false;
74 * @param $parent WebInstaller
76 public function __construct( WebInstaller
$parent ) {
77 $this->parent
= $parent;
80 public function addHTML( $html ) {
81 $this->contents
.= $html;
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() {
102 $this->outputFooter();
106 * Get the raw vector CSS, flipping if needed
107 * @param $dir String 'ltr' or 'rtl'
110 public function getCSS( $dir ) {
111 $skinDir = dirname( dirname( dirname( __FILE__
) ) ) . '/skins';
113 // All these files will be concatenated in sequence and loaded
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(
126 wfSuppressWarnings();
127 foreach ( $cssFileNames as $cssFileName ) {
128 $fullCssFileName = "$skinDir/$cssFileName";
129 $cssFileContents = file_get_contents( $fullCssFileName );
130 if ( $cssFileContents ) {
131 preg_match( "/^(\w+)\//", $cssFileName, $match );
132 $skinName = $match[1];
133 $css .= str_replace( 'images/', "../skins/$skinName/images/", $cssFileContents );
135 $css .= "/** Your webserver cannot read $fullCssFileName. Please check file permissions. */";
142 if( $dir == 'rtl' ) {
143 $css = CSSJanus
::transform( $css, true );
150 * <link> to index.php?css=foobar for the <head>
153 private function getCssUrl( ) {
154 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
157 public function useShortHeader( $use = true ) {
158 $this->useShortHeader
= $use;
161 public function allowFrames( $allow = true ) {
162 $this->allowFrames
= $allow;
165 public function flush() {
166 if ( !$this->headerDone
) {
167 $this->outputHeader();
169 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
170 echo $this->contents
;
172 $this->contents
= '';
179 public function getDir() {
181 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
187 public function getLanguageCode() {
189 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
195 public function getHeadAttribs() {
197 'dir' => $this->getDir(),
198 'lang' => $this->getLanguageCode(),
203 * Get whether the header has been output
206 public function headerDone() {
207 return $this->headerDone
;
210 public function outputHeader() {
211 $this->headerDone
= true;
212 $dbTypes = $this->parent
->getDBTypes();
214 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
215 if (!$this->allowFrames
) {
216 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
218 if ( $this->redirectTarget
) {
219 $this->parent
->request
->response()->header( 'Location: '.$this->redirectTarget
);
223 if ( $this->useShortHeader
) {
224 $this->outputShortHeader();
229 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
231 <meta name
="robots" content
="noindex, nofollow" />
232 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
233 <title
><?php
$this->outputTitle(); ?
></title
>
234 <?php
echo $this->getCssUrl() . "\n"; ?
>
235 <?php
echo Html
::inlineScript( "var dbTypes = " . Xml
::encodeJsVar( $dbTypes ) ) . "\n"; ?
>
236 <?php
echo $this->getJQuery() . "\n"; ?
>
237 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
240 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
241 <div id
="mw-page-base"></div
>
242 <div id
="mw-head-base"></div
>
244 <div id
="bodyContent">
246 <h1
><?php
$this->outputTitle(); ?
></h1
>
250 public function outputFooter() {
251 if ( $this->useShortHeader
) {
263 <div
class="portal" id
="p-logo">
264 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
265 href
="http://www.mediawiki.org/"
266 title
="Main Page"></a
>
268 <div
class="portal"><div
class="body">
270 echo $this->parent
->parse( wfMsgNoTrans( 'config-sidebar' ), true );
280 public function outputShortHeader() {
282 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
284 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
285 <meta name
="robots" content
="noindex, nofollow" />
286 <title
><?php
$this->outputTitle(); ?
></title
>
287 <?php
echo $this->getCssUrl() . "\n"; ?
>
288 <?php
echo $this->getJQuery(); ?
>
289 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
292 <body style
="background-image: none">
296 public function outputTitle() {
298 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
301 public function getJQuery() {
302 return Html
::linkedScript( "../resources/jquery/jquery.js" );