3 * Output handler for the web installer.
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.
20 class WebInstallerOutput
{
22 * The WebInstaller object this WebInstallerOutput is used by.
29 * Buffered contents that haven't been output yet
32 private $contents = '';
35 * Has the header (or short header) been output?
38 private $headerDone = false;
40 public $redirectTarget;
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.
48 public $allowFrames = false;
51 * Whether to use the limited header (used during CC license callbacks)
54 private $useShortHeader = false;
59 * @param $parent WebInstaller
61 public function __construct( WebInstaller
$parent ) {
62 $this->parent
= $parent;
65 public function addHTML( $html ) {
66 $this->contents
.= $html;
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() {
87 $this->outputFooter();
91 * Get the raw vector CSS, flipping if needed
92 * @param $dir String 'ltr' or 'rtl'
95 public function getCSS( $dir ) {
96 $skinDir = dirname( dirname( dirname( __FILE__
) ) ) . '/skins';
98 // All these files will be concatenated in sequence and loaded
100 // The string 'images/' in the files' contents will be replaced
101 // by '../skins/$skinName/images/', where $skinName is what appears
102 // before the last '/' in each of the strings.
103 $cssFileNames = array(
111 wfSuppressWarnings();
112 foreach ( $cssFileNames as $cssFileName ) {
113 $fullCssFileName = "$skinDir/$cssFileName";
114 $cssFileContents = file_get_contents( $fullCssFileName );
115 if ( $cssFileContents ) {
116 preg_match( "/^(\w+)\//", $cssFileName, $match );
117 $skinName = $match[1];
118 $css .= str_replace( 'images/', "../skins/$skinName/images/", $cssFileContents );
120 $css .= "/** Your webserver cannot read $fullCssFileName. Please check file permissions. */";
127 if( $dir == 'rtl' ) {
128 $css = CSSJanus
::transform( $css, true );
135 * <link> to index.php?css=foobar for the <head>
138 private function getCssUrl( ) {
139 return Html
::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
142 public function useShortHeader( $use = true ) {
143 $this->useShortHeader
= $use;
146 public function allowFrames( $allow = true ) {
147 $this->allowFrames
= $allow;
150 public function flush() {
151 if ( !$this->headerDone
) {
152 $this->outputHeader();
154 if ( !$this->redirectTarget
&& strlen( $this->contents
) ) {
155 echo $this->contents
;
157 $this->contents
= '';
164 public function getDir() {
166 return is_object( $wgLang ) ?
$wgLang->getDir() : 'ltr';
172 public function getLanguageCode() {
174 return is_object( $wgLang ) ?
$wgLang->getCode() : 'en';
180 public function getHeadAttribs() {
182 'dir' => $this->getDir(),
183 'lang' => $this->getLanguageCode(),
188 * Get whether the header has been output
191 public function headerDone() {
192 return $this->headerDone
;
195 public function outputHeader() {
196 $this->headerDone
= true;
197 $dbTypes = $this->parent
->getDBTypes();
199 $this->parent
->request
->response()->header( 'Content-Type: text/html; charset=utf-8' );
200 if (!$this->allowFrames
) {
201 $this->parent
->request
->response()->header( 'X-Frame-Options: DENY' );
203 if ( $this->redirectTarget
) {
204 $this->parent
->request
->response()->header( 'Location: '.$this->redirectTarget
);
208 if ( $this->useShortHeader
) {
209 $this->outputShortHeader();
214 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
216 <meta name
="robots" content
="noindex, nofollow" />
217 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
218 <title
><?php
$this->outputTitle(); ?
></title
>
219 <?php
echo $this->getCssUrl() . "\n"; ?
>
220 <?php
echo Html
::inlineScript( "var dbTypes = " . Xml
::encodeJsVar( $dbTypes ) ) . "\n"; ?
>
221 <?php
echo $this->getJQuery() . "\n"; ?
>
222 <?php
echo Html
::linkedScript( '../skins/common/config.js' ) . "\n"; ?
>
225 <?php
echo Html
::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?
>
226 <div id
="mw-page-base"></div
>
227 <div id
="mw-head-base"></div
>
229 <div id
="bodyContent">
231 <h1
><?php
$this->outputTitle(); ?
></h1
>
235 public function outputFooter() {
236 if ( $this->useShortHeader
) {
248 <div
class="portal" id
="p-logo">
249 <a style
="background-image: url(../skins/common/images/mediawiki.png);"
250 href
="http://www.mediawiki.org/"
251 title
="Main Page"></a
>
253 <div
class="portal"><div
class="body">
255 echo $this->parent
->parse( wfMsgNoTrans( 'config-sidebar' ), true );
265 public function outputShortHeader() {
267 <?php
echo Html
::htmlHeader( $this->getHeadAttribs() ); ?
>
269 <meta http
-equiv
="Content-type" content
="text/html; charset=utf-8" />
270 <meta name
="robots" content
="noindex, nofollow" />
271 <title
><?php
$this->outputTitle(); ?
></title
>
272 <?php
echo $this->getCssUrl() . "\n"; ?
>
273 <?php
echo $this->getJQuery(); ?
>
274 <?php
echo Html
::linkedScript( '../skins/common/config.js' ); ?
>
277 <body style
="background-image: none">
281 public function outputTitle() {
283 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
286 public function getJQuery() {
287 return Html
::linkedScript( "../resources/jquery/jquery.js" );