Merge "Refactor Watchlist code so mobile can be more consistent"
[lhc/web/wiklou.git] / includes / installer / WebInstallerPage.php
index 677af4f..9fdee76 100644 (file)
@@ -145,11 +145,12 @@ abstract class WebInstallerPage {
 
        /**
         * @param string $var
+        * @param mixed $default
         *
         * @return mixed
         */
-       public function getVar( $var ) {
-               return $this->parent->getVar( $var );
+       public function getVar( $var, $default = null ) {
+               return $this->parent->getVar( $var, $default );
        }
 
        /**
@@ -163,7 +164,7 @@ abstract class WebInstallerPage {
        /**
         * Get the starting tags of a fieldset.
         *
-        * @param string $legend message name
+        * @param string $legend Message name
         *
         * @return string
         */
@@ -948,6 +949,7 @@ class WebInstallerOptions extends WebInstallerPage {
         */
        public function execute() {
                if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
+                       $this->submitSkins();
                        return 'skip';
                }
                if ( $this->parent->request->wasPosted() ) {
@@ -1025,6 +1027,38 @@ class WebInstallerOptions extends WebInstallerPage {
                        $this->getFieldSetEnd()
                );
 
+               $skins = $this->parent->findExtensions( 'skins' );
+               $skinHtml = $this->getFieldSetStart( 'config-skins' );
+
+               if ( $skins ) {
+                       $skinNames = array_map( 'strtolower', $skins );
+
+                       $radioButtons = $this->parent->getRadioElements( array(
+                               'var' => 'wgDefaultSkin',
+                               'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
+                               'values' => $skinNames,
+                               'value' => $this->getVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) ),
+                       ) );
+
+                       foreach ( $skins as $skin ) {
+                               $skinHtml .=
+                                       '<div class="config-skins-item">' .
+                                       $this->parent->getCheckBox( array(
+                                               'var' => "skin-$skin",
+                                               'rawtext' => $skin,
+                                               'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
+                                       ) ) .
+                                       '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
+                                       '</div>';
+                       }
+               } else {
+                       $skinHtml .= $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() );
+               }
+
+               $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
+                       $this->getFieldSetEnd();
+               $this->addHTML( $skinHtml );
+
                $extensions = $this->parent->findExtensions();
 
                if ( $extensions ) {
@@ -1220,6 +1254,40 @@ class WebInstallerOptions extends WebInstallerPage {
                $this->addHTML( $this->getCCDoneBox() );
        }
 
+       /**
+        * Returns a default value to be used for $wgDefaultSkin: the preferred skin, if available among
+        * the installed skins, or any other one otherwise.
+        *
+        * @param string[] $skinNames Names of installed skins.
+        * @return string
+        */
+       public function getDefaultSkin( array $skinNames ) {
+               $defaultSkin = $GLOBALS['wgDefaultSkin'];
+               if ( in_array( $defaultSkin, $skinNames ) ) {
+                       return $defaultSkin;
+               } else {
+                       return $skinNames[0];
+               }
+       }
+
+       /**
+        * If the user skips this installer page, we still need to set up the default skins, but ignore
+        * everything else.
+        *
+        * @return bool
+        */
+       public function submitSkins() {
+               $skins = $this->parent->findExtensions( 'skins' );
+               $this->parent->setVar( '_Skins', $skins );
+
+               if ( $skins ) {
+                       $skinNames = array_map( 'strtolower', $skins );
+                       $this->parent->setVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) );
+               }
+
+               return true;
+       }
+
        /**
         * @return bool
         */
@@ -1228,7 +1296,7 @@ class WebInstallerOptions extends WebInstallerPage {
                        'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
                        'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
                        'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers',
-                       'wgUseInstantCommons' ) );
+                       'wgUseInstantCommons', 'wgDefaultSkin' ) );
 
                $retVal = true;
 
@@ -1263,6 +1331,27 @@ class WebInstallerOptions extends WebInstallerPage {
                        $this->setVar( 'wgRightsIcon', '' );
                }
 
+               $skinsAvailable = $this->parent->findExtensions( 'skins' );
+               $skinsToInstall = array();
+               foreach ( $skinsAvailable as $skin ) {
+                       $this->parent->setVarsFromRequest( array( "skin-$skin" ) );
+                       if ( $this->getVar( "skin-$skin" ) ) {
+                               $skinsToInstall[] = $skin;
+                       }
+               }
+               $this->parent->setVar( '_Skins', $skinsToInstall );
+
+               if ( !$skinsToInstall && $skinsAvailable ) {
+                       $this->parent->showError( 'config-skins-must-enable-some' );
+                       $retVal = false;
+               }
+               $defaultSkin = $this->getVar( 'wgDefaultSkin' );
+               $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
+               if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
+                       $this->parent->showError( 'config-skins-must-enable-default' );
+                       $retVal = false;
+               }
+
                $extsAvailable = $this->parent->findExtensions();
                $extsToInstall = array();
                foreach ( $extsAvailable as $ext ) {