MediaWiki  REL1_24
WebInstallerOutput.php
Go to the documentation of this file.
00001 <?php
00035 class WebInstallerOutput {
00036 
00042     public $parent;
00043 
00048     private $contents = '';
00049 
00054     private $headerDone = false;
00055 
00059     public $redirectTarget;
00060 
00067     public $allowFrames = false;
00068 
00073     private $useShortHeader = false;
00074 
00078     public function __construct( WebInstaller $parent ) {
00079         $this->parent = $parent;
00080     }
00081 
00085     public function addHTML( $html ) {
00086         $this->contents .= $html;
00087         $this->flush();
00088     }
00089 
00093     public function addWikiText( $text ) {
00094         $this->addHTML( $this->parent->parse( $text ) );
00095     }
00096 
00100     public function addHTMLNoFlush( $html ) {
00101         $this->contents .= $html;
00102     }
00103 
00109     public function redirect( $url ) {
00110         if ( $this->headerDone ) {
00111             throw new MWException( __METHOD__ . ' called after sending headers' );
00112         }
00113         $this->redirectTarget = $url;
00114     }
00115 
00116     public function output() {
00117         $this->flush();
00118         $this->outputFooter();
00119     }
00120 
00126     public function getCSS() {
00127         global $wgStyleDirectory;
00128 
00129         $moduleNames = array(
00130             // See SkinTemplate::setupSkinUserCss
00131             'mediawiki.legacy.shared',
00132             // See Vector::setupSkinUserCss
00133             'mediawiki.skinning.interface',
00134         );
00135 
00136         if ( file_exists( "$wgStyleDirectory/Vector/Vector.php" ) ) {
00137             // Force loading Vector skin if available as a fallback skin
00138             // for whatever ResourceLoader wants to have as the default.
00139 
00140             // Include instead of require, as this will work without it, it will just look bad.
00141             // We need the 'global' statement for $wgResourceModules because the Vector skin adds the
00142             // definitions for its RL modules there that we use implicitly below.
00143 
00144             // @codingStandardsIgnoreStart
00145             global $wgResourceModules; // This is NOT UNUSED!
00146             // @codingStandardsIgnoreEnd
00147 
00148             include_once "$wgStyleDirectory/Vector/Vector.php";
00149 
00150             $moduleNames[] = 'skins.vector.styles';
00151         }
00152 
00153         $moduleNames[] = 'mediawiki.legacy.config';
00154 
00155         $resourceLoader = new ResourceLoader();
00156         $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
00157                 'debug' => 'true',
00158                 'lang' => $this->getLanguageCode(),
00159                 'only' => 'styles',
00160         ) ) );
00161 
00162         $styles = array();
00163         foreach ( $moduleNames as $moduleName ) {
00165             $module = $resourceLoader->getModule( $moduleName );
00166 
00167             // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
00168             $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
00169                 $module->readStyleFiles(
00170                     $module->getStyleFiles( $rlContext ),
00171                     $module->getFlip( $rlContext )
00172             ) ) );
00173         }
00174 
00175         return implode( "\n", $styles );
00176     }
00177 
00183     private function getCssUrl() {
00184         return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
00185     }
00186 
00187     public function useShortHeader( $use = true ) {
00188         $this->useShortHeader = $use;
00189     }
00190 
00191     public function allowFrames( $allow = true ) {
00192         $this->allowFrames = $allow;
00193     }
00194 
00195     public function flush() {
00196         if ( !$this->headerDone ) {
00197             $this->outputHeader();
00198         }
00199         if ( !$this->redirectTarget && strlen( $this->contents ) ) {
00200             echo $this->contents;
00201             flush();
00202             $this->contents = '';
00203         }
00204     }
00205 
00209     public function getDir() {
00210         global $wgLang;
00211 
00212         return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
00213     }
00214 
00218     public function getLanguageCode() {
00219         global $wgLang;
00220 
00221         return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
00222     }
00223 
00227     public function getHeadAttribs() {
00228         return array(
00229             'dir' => $this->getDir(),
00230             'lang' => $this->getLanguageCode(),
00231         );
00232     }
00233 
00239     public function headerDone() {
00240         return $this->headerDone;
00241     }
00242 
00243     public function outputHeader() {
00244         $this->headerDone = true;
00245         $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
00246 
00247         if ( !$this->allowFrames ) {
00248             $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
00249         }
00250 
00251         if ( $this->redirectTarget ) {
00252             $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
00253 
00254             return;
00255         }
00256 
00257         if ( $this->useShortHeader ) {
00258             $this->outputShortHeader();
00259 
00260             return;
00261         }
00262 ?>
00263 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
00264 <head>
00265     <meta name="robots" content="noindex, nofollow" />
00266     <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
00267     <title><?php $this->outputTitle(); ?></title>
00268     <?php echo $this->getCssUrl() . "\n"; ?>
00269     <?php echo $this->getJQuery() . "\n"; ?>
00270     <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
00271 </head>
00272 
00273 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
00274 <div id="mw-page-base"></div>
00275 <div id="mw-head-base"></div>
00276 <div id="content" class="mw-body">
00277 <div id="bodyContent" class="mw-body-content">
00278 
00279 <h1><?php $this->outputTitle(); ?></h1>
00280 <?php
00281     }
00282 
00283     public function outputFooter() {
00284         if ( $this->useShortHeader ) {
00285             echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
00286 
00287             return;
00288         }
00289 ?>
00290 
00291 </div></div>
00292 
00293 <div id="mw-panel">
00294     <div class="portal" id="p-logo">
00295       <a style="background-image: url(images/installer-logo.png);"
00296         href="https://www.mediawiki.org/"
00297         title="Main Page"></a>
00298     </div>
00299     <div class="portal"><div class="body">
00300 <?php
00301     echo $this->parent->parse( wfMessage( 'config-sidebar' )->plain(), true );
00302 ?>
00303     </div></div>
00304 </div>
00305 
00306 <?php
00307         echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
00308     }
00309 
00310     public function outputShortHeader() {
00311 ?>
00312 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
00313 <head>
00314     <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
00315     <meta name="robots" content="noindex, nofollow" />
00316     <title><?php $this->outputTitle(); ?></title>
00317     <?php echo $this->getCssUrl() . "\n"; ?>
00318     <?php echo $this->getJQuery(); ?>
00319     <?php echo Html::linkedScript( 'config.js' ); ?>
00320 </head>
00321 
00322 <body style="background-image: none">
00323 <?php
00324     }
00325 
00326     public function outputTitle() {
00327         global $wgVersion;
00328         echo wfMessage( 'config-title', $wgVersion )->escaped();
00329     }
00330 
00334     public function getJQuery() {
00335         return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
00336     }
00337 
00338 }