]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/installer/WebInstallerOutput.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / installer / WebInstallerOutput.php
index cb708d1392f0f814ddfaa9547ecae3c720c03169..e4eb255bbd52f79b1d6694b34e33bb9b5f36ad99 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Output handler for the web installer.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Deployment
  */
@@ -18,6 +33,7 @@
  * @since 1.17
  */
 class WebInstallerOutput {
+
        /**
         * The WebInstaller object this WebInstallerOutput is used by.
         *
@@ -27,7 +43,7 @@ class WebInstallerOutput {
 
        /**
         * Buffered contents that haven't been output yet
-        * @var String
+        * @var string
         */
        private $contents = '';
 
@@ -37,6 +53,9 @@ class WebInstallerOutput {
         */
        private $headerDone = false;
 
+       /**
+        * @var string
+        */
        public $redirectTarget;
 
        /**
@@ -54,27 +73,39 @@ class WebInstallerOutput {
        private $useShortHeader = false;
 
        /**
-        * Constructor.
-        *
-        * @param $parent WebInstaller
+        * @param WebInstaller $parent
         */
        public function __construct( WebInstaller $parent ) {
                $this->parent = $parent;
        }
 
+       /**
+        * @param string $html
+        */
        public function addHTML( $html ) {
                $this->contents .= $html;
                $this->flush();
        }
 
+       /**
+        * @param string $text
+        */
        public function addWikiText( $text ) {
                $this->addHTML( $this->parent->parse( $text ) );
        }
 
+       /**
+        * @param string $html
+        */
        public function addHTMLNoFlush( $html ) {
                $this->contents .= $html;
        }
 
+       /**
+        * @param string $url
+        *
+        * @throws MWException
+        */
        public function redirect( $url ) {
                if ( $this->headerDone ) {
                        throw new MWException( __METHOD__ . ' called after sending headers' );
@@ -84,40 +115,79 @@ class WebInstallerOutput {
 
        public function output() {
                $this->flush();
-               $this->outputFooter();
+
+               if ( !$this->redirectTarget ) {
+                       $this->outputFooter();
+               }
        }
 
        /**
-        * Get the raw vector CSS, flipping if needed
-        * @param $dir String 'ltr' or 'rtl'
-        * @return String
+        * Get the stylesheet of the MediaWiki skin.
+        *
+        * @return string
         */
-       public function getCSS( $dir ) {
-               $skinDir = dirname( dirname( dirname( __FILE__ ) ) ) . '/skins';
-               $vectorCssFile = "$skinDir/vector/screen.css";
-               $configCssFile = "$skinDir/common/config.css";
-               $css = '';
-               wfSuppressWarnings();
-               $vectorCss = file_get_contents( $vectorCssFile );
-               $configCss = file_get_contents( $configCssFile );
-               wfRestoreWarnings();
-               if( !$vectorCss || !$configCss ) {
-                       $css = "/** Your webserver cannot read $vectorCssFile or $configCssFile, please check file permissions */";
+       public function getCSS() {
+               global $wgStyleDirectory;
+
+               $moduleNames = [
+                       // See SkinTemplate::setupSkinUserCss
+                       'mediawiki.legacy.shared',
+                       // See Vector::setupSkinUserCss
+                       'mediawiki.skinning.interface',
+               ];
+
+               $resourceLoader = new ResourceLoader();
+
+               if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
+                       // Force loading Vector skin if available as a fallback skin
+                       // for whatever ResourceLoader wants to have as the default.
+                       $registry = new ExtensionRegistry();
+                       $data = $registry->readFromQueue( [
+                               "$wgStyleDirectory/Vector/skin.json" => 1,
+                       ] );
+                       if ( isset( $data['globals']['wgResourceModules'] ) ) {
+                               $resourceLoader->register( $data['globals']['wgResourceModules'] );
+                       }
+
+                       $moduleNames[] = 'skins.vector.styles';
                }
 
-               $css .= str_replace( 'images/', '../skins/vector/images/', $vectorCss ) . "\n" . str_replace( 'images/', '../skins/common/images/', $configCss );
-               if( $dir == 'rtl' ) {
-                       $css = CSSJanus::transform( $css, true );
+               $moduleNames[] = 'mediawiki.legacy.config';
+
+               $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
+                               'debug' => 'true',
+                               'lang' => $this->getLanguageCode(),
+                               'only' => 'styles',
+               ] ) );
+
+               $styles = [];
+               foreach ( $moduleNames as $moduleName ) {
+                       /** @var ResourceLoaderFileModule $module */
+                       $module = $resourceLoader->getModule( $moduleName );
+                       if ( !$module ) {
+                               // T98043: Don't fatal, but it won't look as pretty.
+                               continue;
+                       }
+
+                       // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
+                       $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
+                               $module->readStyleFiles(
+                                       $module->getStyleFiles( $rlContext ),
+                                       $module->getFlip( $rlContext ),
+                                       $rlContext
+                       ) ) );
                }
-               return $css;
+
+               return implode( "\n", $styles );
        }
 
        /**
-        * URL for index.php?css=foobar
-        * @return String
+        * "<link>" to index.php?css=1 for the "<head>"
+        *
+        * @return string
         */
-       private function getCssUrl( ) {
-               return $_SERVER['PHP_SELF'] . '?css=' . $this->getDir();
+       private function getCssUrl() {
+               return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
        }
 
        public function useShortHeader( $use = true ) {
@@ -139,31 +209,37 @@ class WebInstallerOutput {
                }
        }
 
+       /**
+        * @return string
+        */
        public function getDir() {
                global $wgLang;
-               if( !is_object( $wgLang ) || !$wgLang->isRtl() )
-                       return 'ltr';
-               else
-                       return 'rtl';
+
+               return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
        }
 
+       /**
+        * @return string
+        */
        public function getLanguageCode() {
                global $wgLang;
-               if( !is_object( $wgLang ) )
-                       return 'en';
-               else
-                       return $wgLang->getCode();
+
+               return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
        }
 
+       /**
+        * @return string[]
+        */
        public function getHeadAttribs() {
-               return array(
+               return [
                        'dir' => $this->getDir(),
-                       'lang' => $this->getLanguageCode(),
-               );
+                       'lang' => wfBCP47( $this->getLanguageCode() ),
+               ];
        }
 
        /**
         * Get whether the header has been output
+        *
         * @return bool
         */
        public function headerDone() {
@@ -172,40 +248,40 @@ class WebInstallerOutput {
 
        public function outputHeader() {
                $this->headerDone = true;
-               $dbTypes = $this->parent->getDBTypes();
-
                $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
-               if (!$this->allowFrames) {
+
+               if ( !$this->allowFrames ) {
                        $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
                }
+
                if ( $this->redirectTarget ) {
-                       $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
+                       $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
+
                        return;
                }
 
                if ( $this->useShortHeader ) {
                        $this->outputShortHeader();
+
                        return;
                }
-
 ?>
 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
+
 <head>
        <meta name="robots" content="noindex, nofollow" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title><?php $this->outputTitle(); ?></title>
-       <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
-       <?php echo Html::linkedStyle( $this->getCssUrl() ) . "\n"; ?>
-       <?php echo Html::inlineScript(  "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
+       <?php echo $this->getCssUrl() . "\n"; ?>
        <?php echo $this->getJQuery() . "\n"; ?>
-       <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
+       <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
 </head>
 
-<?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
+<?php echo Html::openElement( 'body', [ 'class' => $this->getDir() ] ) . "\n"; ?>
 <div id="mw-page-base"></div>
 <div id="mw-head-base"></div>
-<div id="content">
-<div id="bodyContent">
+<div id="content" class="mw-body">
+<div id="bodyContent" class="mw-body-content">
 
 <h1><?php $this->outputTitle(); ?></h1>
 <?php
@@ -213,33 +289,32 @@ class WebInstallerOutput {
 
        public function outputFooter() {
                if ( $this->useShortHeader ) {
-?>
-</body></html>
-<?php
+                       echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
+
                        return;
                }
 ?>
 
 </div></div>
 
-
 <div id="mw-panel">
        <div class="portal" id="p-logo">
-         <a style="background-image: url(../skins/common/images/mediawiki.png);"
-               href="http://www.mediawiki.org/"
-               title="Main Page"></a>
+               <a style="background-image: url(images/installer-logo.png);"
+                       href="https://www.mediawiki.org/"
+                       title="Main Page"></a>
        </div>
-       <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
-       <div class="portal"><div class="body">
 <?php
-       echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
+       $message = wfMessage( 'config-sidebar' )->plain();
+       foreach ( explode( '----', $message ) as $section ) {
+               echo '<div class="portal"><div class="body">';
+               echo $this->parent->parse( $section, true );
+               echo '</div></div>';
+       }
 ?>
-       </div></div>
 </div>
 
-</body>
-</html>
 <?php
+               echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
        }
 
        public function outputShortHeader() {
@@ -249,9 +324,9 @@ class WebInstallerOutput {
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta name="robots" content="noindex, nofollow" />
        <title><?php $this->outputTitle(); ?></title>
-       <?php echo Html::linkedStyle( $this->getCssUrl() ) . "\n"; ?>
+       <?php echo $this->getCssUrl() . "\n"; ?>
        <?php echo $this->getJQuery(); ?>
-       <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
+       <?php echo Html::linkedScript( 'config.js' ); ?>
 </head>
 
 <body style="background-image: none">
@@ -260,10 +335,14 @@ class WebInstallerOutput {
 
        public function outputTitle() {
                global $wgVersion;
-               echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
+               echo wfMessage( 'config-title', $wgVersion )->escaped();
        }
 
+       /**
+        * @return string
+        */
        public function getJQuery() {
-               return Html::linkedScript( "../resources/jquery/jquery.js" );
+               return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
        }
+
 }