Merge "registration: Make it easier for other code to get extension metadata"
[lhc/web/wiklou.git] / includes / installer / LocalSettingsGenerator.php
index 5e89ca4..737c996 100644 (file)
@@ -34,6 +34,7 @@ class LocalSettingsGenerator {
        protected $groupPermissions = array();
        protected $dbSettings = '';
        protected $safeMode = false;
+       protected $IP;
 
        /**
         * @var Installer
@@ -49,6 +50,8 @@ class LocalSettingsGenerator {
                $this->installer = $installer;
 
                $this->extensions = $installer->getVar( '_Extensions' );
+               $this->skins = $installer->getVar( '_Skins' );
+               $this->IP = $installer->getVar( 'IP' );
 
                $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
 
@@ -62,7 +65,7 @@ class LocalSettingsGenerator {
                                'wgRightsText', 'wgMainCacheType', 'wgEnableUploads',
                                'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
                                'wgDBpassword', 'wgUseInstantCommons', 'wgUpgradeKey', 'wgDefaultSkin',
-                               'wgMetaNamespace', 'wgResourceLoaderMaxQueryLength', 'wgLogo',
+                               'wgMetaNamespace', 'wgLogo',
                        ),
                        $db->getGlobalNames()
                );
@@ -129,13 +132,25 @@ class LocalSettingsGenerator {
 
        /**
         * Return the full text of the generated LocalSettings.php file,
-        * including the extensions
+        * including the extensions and skins.
         *
         * @return string
         */
        public function getText() {
                $localSettings = $this->getDefaultText();
 
+               if ( count( $this->skins ) ) {
+                       $localSettings .= "
+# Enabled skins.
+# The following skins were automatically enabled:\n";
+
+                       foreach ( $this->skins as $skinName ) {
+                               $localSettings .= $this->generateExtEnableLine( 'skins', $skinName );
+                       }
+
+                       $localSettings .= "\n";
+               }
+
                if ( count( $this->extensions ) ) {
                        $localSettings .= "
 # Enabled Extensions. Most extensions are enabled by including the base extension file here
@@ -143,17 +158,47 @@ class LocalSettingsGenerator {
 # The following extensions were automatically enabled:\n";
 
                        foreach ( $this->extensions as $extName ) {
-                               $encExtName = self::escapePhpString( $extName );
-                               $localSettings .= "require_once \"\$IP/extensions/$encExtName/$encExtName.php\";\n";
+                               $localSettings .= $this->generateExtEnableLine( 'extensions', $extName );
                        }
+
+                       $localSettings .= "\n";
                }
 
-               $localSettings .= "\n\n# End of automatically generated settings.
+               $localSettings .= "
+# End of automatically generated settings.
 # Add more configuration options below.\n\n";
 
                return $localSettings;
        }
 
+       /**
+        * Generate the appropriate line to enable the given extension or skin
+        *
+        * @param string $dir Either "extensions" or "skins"
+        * @param string $name Name of extension/skin
+        * @throws InvalidArgumentException
+        * @return string
+        */
+       private function generateExtEnableLine( $dir, $name ) {
+               if ( $dir === 'extensions' ) {
+                       $jsonFile = 'extension.json';
+                       $function = 'wfLoadExtension';
+               } elseif ( $dir === 'skins' ) {
+                       $jsonFile = 'skin.json';
+                       $function = 'wfLoadSkin';
+               } else {
+                       throw new InvalidArgumentException( '$dir was not "extensions" or "skins' );
+               }
+
+               $encName = self::escapePhpString( $name );
+
+               if ( file_exists( "{$this->IP}/$dir/$encName/$jsonFile" ) ) {
+                       return "$function( '$encName' );\n";
+               } else {
+                       return "require_once \"\$IP/$dir/$encName/$encName.php\";\n";
+               }
+       }
+
        /**
         * Write the generated LocalSettings to a file
         *
@@ -202,7 +247,6 @@ class LocalSettingsGenerator {
                        $locale = '';
                }
 
-               //$rightsUrl = $this->values['wgRightsUrl'] ? '' : '#'; // @todo FIXME: I'm unused!
                $hashedUploads = $this->safeMode ? '' : '#';
                $metaNamespace = '';
                if ( $this->values['wgMetaNamespace'] !== $this->values['wgSitename'] ) {
@@ -221,16 +265,21 @@ class LocalSettingsGenerator {
                                                wfBoolToStr( $perm ) . ";\n";
                                }
                        }
-                       if ( $this->groupPermissions['*']['edit'] === false
-                               && $this->groupPermissions['*']['createaccount'] === false
-                               && $this->groupPermissions['*']['read'] !== false
+                       $groupRights .= "\n";
+
+                       if ( ( isset( $this->groupPermissions['*']['edit'] ) &&
+                                       $this->groupPermissions['*']['edit'] === false )
+                               && ( isset( $this->groupPermissions['*']['createaccount'] ) &&
+                                       $this->groupPermissions['*']['createaccount'] === false )
+                               && ( isset( $this->groupPermissions['*']['read'] ) &&
+                                       $this->groupPermissions['*']['read'] !== false )
                        ) {
-                               $noFollow = "\n# Set \$wgNoFollowLinks to true if you open up your wiki to editing by\n"
+                               $noFollow = "# Set \$wgNoFollowLinks to true if you open up your wiki to editing by\n"
                                        . "# the general public and wish to apply nofollow to external links as a\n"
                                        . "# deterrent to spammers. Nofollow is not a comprehensive anti-spam solution\n"
                                        . "# and open wikis will generally require other anti-spam measures; for more\n"
                                        . "# information, see https://www.mediawiki.org/wiki/Manual:Combating_spam\n"
-                                       . "\$wgNoFollowLinks = false;";
+                                       . "\$wgNoFollowLinks = false;\n\n";
                        }
                }
 
@@ -350,10 +399,6 @@ ${serverSetting}
 # web installer while LocalSettings.php is in place
 \$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\";
 
-## Default skin: you can change the default skin. Use the internal symbolic
-## names, ie 'vector', 'monobook':
-\$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\";
-
 ## For attaching licensing metadata to pages, and displaying an
 ## appropriate copyright notice / icon. GNU Free Documentation
 ## License and Creative Commons licenses are supported so far.
@@ -365,6 +410,9 @@ ${serverSetting}
 # Path to the GNU diff3 utility. Used for conflict resolution.
 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
 
-{$groupRights}{$noFollow}";
+{$groupRights}{$noFollow}## Default skin: you can change the default skin. Use the internal symbolic
+## names, ie 'vector', 'monobook':
+\$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\";
+";
        }
 }