Style and doc improvements
authorJeroen De Dauw <jeroendedauw@users.mediawiki.org>
Wed, 21 Jul 2010 10:56:35 +0000 (10:56 +0000)
committerJeroen De Dauw <jeroendedauw@users.mediawiki.org>
Wed, 21 Jul 2010 10:56:35 +0000 (10:56 +0000)
includes/installer/LocalSettingsGenerator.php

index fc47f0f..f5b268f 100644 (file)
@@ -1,42 +1,64 @@
 <?php
 
 class LocalSettingsGenerator {
-       private $extensions, $values = array();
-       private $configPath, $dbSettings = '';
+       private $extensions = array();
+       private $values = array();
+       private $configPath = '';
+       private $dbSettings = '';
        private $safeMode = false;
+       
+       /**
+        * @var Installer
+        */
        private $installer;
 
        /**
         * Constructor.
+        * 
         * @param $installer Installer subclass
         */
        public function __construct( Installer $installer ) {
                $this->installer = $installer;
+               
                $this->configPath = $installer->getVar( 'IP' ) . '/config';
                $this->extensions = $installer->getVar( '_Extensions' );
+               
                $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
 
-               $confItems = array_merge( array( 'wgScriptPath', 'wgScriptExtension',
-                       'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
-                       'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
-                       'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
-                       'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
-                       'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
-                       'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
-                       'wgDBpassword', 'wgUseInstantCommons' ), $db->getGlobalNames() );
+               $confItems = array_merge(
+                       array(
+                               'wgScriptPath', 'wgScriptExtension',
+                               'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
+                               'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
+                               'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
+                               'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
+                               'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
+                               'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
+                               'wgDBpassword', 'wgUseInstantCommons'
+                       ),
+                       $db->getGlobalNames()
+               );
+               
                $unescaped = array( 'wgRightsIcon' );
-               $boolItems = array( 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
-                       'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons' );
+               $boolItems = array( 
+                       'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
+                       'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons'
+               );
+               
                foreach( $confItems as $c ) {
                        $val = $installer->getVar( $c );
+                       
                        if( in_array( $c, $boolItems ) ) {
                                $val = wfBoolToStr( $val );
                        }
+                       
                        if ( !in_array( $c, $unescaped ) ) {
                                $val = self::escapePhpString( $val );
                        }
+                       
                        $this->values[$c] = $val;
                }
+               
                $this->dbSettings = $db->getLocalSettings();
                $this->safeMode = $installer->getVar( '_SafeMode' );
                $this->values['wgEmergencyContact'] = $this->values['wgPasswordSender'];
@@ -46,7 +68,9 @@ class LocalSettingsGenerator {
                if ( is_array( $string ) || is_object( $string ) ) {
                        return false;
                }
-               return strtr( $string,
+               
+               return strtr(
+                       $string,
                        array(
                                "\n" => "\\n",
                                "\r" => "\\r",
@@ -54,7 +78,8 @@ class LocalSettingsGenerator {
                                "\\" => "\\\\",
                                "\$" => "\\\$",
                                "\"" => "\\\""
-                       ));
+                       )
+               );
        }
 
        /**
@@ -64,8 +89,10 @@ class LocalSettingsGenerator {
         */
        public function getText() {
                $localSettings = $this->getDefaultText();
+               
                if( count( $this->extensions ) ) {
                        $localSettings .= "\n# The following extensions were automatically enabled:\n";
+                       
                        foreach( $this->extensions as $ext ) {
                                $localSettings .= "require( 'extensions/$ext/$ext.php' );\n";
                        }
@@ -76,15 +103,18 @@ class LocalSettingsGenerator {
 
        private function buildMemcachedServerList() {
                $servers = $this->values['_MemCachedServers'];
+               
                if( !$servers ) {
                        return 'array()';
                } else {
                        $ret = 'array( ';
                        $servers = explode( ',', $servers );
+                       
                        foreach( $servers as $srv ) {
                                $srv = trim( $srv );
                                $ret .= "'$srv', ";
                        }
+                       
                        return rtrim( $ret, ', ' ) . ' )';
                }
        }
@@ -96,14 +126,17 @@ class LocalSettingsGenerator {
                } else {
                        $magic = '';
                }
+               
                if( !$this->values['wgShellLocale'] ) {
                        $this->values['wgShellLocale'] = 'en_US.UTF-8';
                        $locale = '#';
                } else {
                        $locale = '';
                }
+               
                $rights = $this->values['wgRightsUrl'] ? '' : '#';
                $hashedUploads = $this->safeMode ? '#' : '';
+               
                switch( $this->values['wgMainCacheType'] ) {
                        case 'anything':
                        case 'db':
@@ -115,6 +148,7 @@ class LocalSettingsGenerator {
                        default:
                                $cacheType = 'CACHE_NONE';
                }
+               
                $mcservers = $this->buildMemcachedServerList();
                return "<?php
 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
@@ -248,4 +282,5 @@ if ( \$wgCommandLineMode ) {
 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
 ";
        }
-}
+       
+}
\ No newline at end of file