Index: branches/new-installer/phase3/includes/installer/LocalSettings.php |
— | — | @@ -0,0 +1,239 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class LocalSettings { |
| 5 | + private $extensions, $values = array(); |
| 6 | + private $configPath, $dbSettings = ''; |
| 7 | + private $safeMode = false; |
| 8 | + |
| 9 | + /** |
| 10 | + * Construtor. |
| 11 | + * @param $installer Installer subclass |
| 12 | + */ |
| 13 | + public function __construct( Installer $installer ) { |
| 14 | + $this->configPath = $installer->getVar( 'IP' ) . '/config'; |
| 15 | + $this->extensions = $installer->getVar( '_Extensions' ); |
| 16 | + $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) ); |
| 17 | + |
| 18 | + $confItems = array_merge( array( 'wgScriptPath', 'wgScriptExtension', |
| 19 | + 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale', |
| 20 | + 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3', |
| 21 | + 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication', |
| 22 | + 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon', |
| 23 | + 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads', |
| 24 | + 'wgMainCacheType', '_MemCachedServers' ), $db->getGlobalNames() ); |
| 25 | + $boolItems = array( 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk', |
| 26 | + 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads' ); |
| 27 | + foreach( $confItems as $c ) { |
| 28 | + $val = $installer->getVar( $c ); |
| 29 | + if( in_array( $c, $boolItems ) ) { |
| 30 | + $val = wfBoolToStr( $val ); |
| 31 | + } |
| 32 | + $this->values[$c] = $val; |
| 33 | + } |
| 34 | + $this->dbSettings = $db->getLocalSettings(); |
| 35 | + $this->safeMode = $installer->getVar( '_SafeMode' ); |
| 36 | + $this->values['wgEmergencyContact'] = $this->values['wgPasswordSender']; |
| 37 | + $this->values = wfArrayMap( array( $this, 'escapePhpString' ), $this->values ); |
| 38 | + } |
| 39 | + |
| 40 | + function escapePhpString( $string ) { |
| 41 | + if ( is_array( $string ) || is_object( $string ) ) { |
| 42 | + return false; |
| 43 | + } |
| 44 | + return strtr( $string, |
| 45 | + array( |
| 46 | + "\n" => "\\n", |
| 47 | + "\r" => "\\r", |
| 48 | + "\t" => "\\t", |
| 49 | + "\\" => "\\\\", |
| 50 | + "\$" => "\\\$", |
| 51 | + "\"" => "\\\"" |
| 52 | + )); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Write the |
| 57 | + * @param $secretKey String A random string to |
| 58 | + * @return boolean On successful file write |
| 59 | + */ |
| 60 | + public function writeLocalSettings() { |
| 61 | + $localSettings = $this->getDefaultText(); |
| 62 | + if( count( $this->extensions ) ) { |
| 63 | + $localSettings .= "\n# The following extensions were automatically enabled:\n"; |
| 64 | + foreach( $this->extensions as $ext ) { |
| 65 | + $localSettings .= "require( '$ext/$ext.php' );\n"; |
| 66 | + } |
| 67 | + } |
| 68 | + return file_put_contents( $this->configPath . '/LocalSettings.php', $localSettings ); |
| 69 | + } |
| 70 | + |
| 71 | + private function buildMemcachedServerList() { |
| 72 | + $servers = $this->values['_MemCachedServers']; |
| 73 | + if( !$servers ) { |
| 74 | + return 'array()'; |
| 75 | + } else { |
| 76 | + $ret = 'array( '; |
| 77 | + $servers = explode( ',', $servers ); |
| 78 | + foreach( $servers as $srv ) { |
| 79 | + $srv = trim( $srv ); |
| 80 | + $ret .= "'$srv', "; |
| 81 | + } |
| 82 | + return rtrim( $ret, ', ' ) . ' )'; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + private function getDefaultText() { |
| 87 | + if( !$this->values['wgImageMagickConvertCommand'] ) { |
| 88 | + $this->values['wgImageMagickConvertCommand'] = '/usr/bin/convert'; |
| 89 | + $magic = '#'; |
| 90 | + } else { |
| 91 | + $magic = ''; |
| 92 | + } |
| 93 | + if( !$this->values['wgShellLocale'] ) { |
| 94 | + $this->values['wgShellLocale'] = 'en_US.UTF-8'; |
| 95 | + $locale = '#'; |
| 96 | + } else { |
| 97 | + $locale = ''; |
| 98 | + } |
| 99 | + $rights = $this->values['wgRightsUrl'] ? '' : '#'; |
| 100 | + $hashedUploads = $this->safeMode ? '#' : ''; |
| 101 | + switch( $this->values['wgMainCacheType'] ) { |
| 102 | + case 'anything': |
| 103 | + case 'db': |
| 104 | + case 'memcached': |
| 105 | + case 'accel': |
| 106 | + $cacheType = 'CACHE_' . strtoupper( $this->values['wgMainCacheType']); |
| 107 | + break; |
| 108 | + case 'none': |
| 109 | + default: |
| 110 | + $cacheType = 'CACHE_NONE'; |
| 111 | + } |
| 112 | + $mcservers = $this->buildMemcachedServerList(); |
| 113 | + return "<?php |
| 114 | +# This file was automatically generated by the MediaWiki installer. |
| 115 | +# If you make manual changes, please keep track in case you need to |
| 116 | +# recreate them later. |
| 117 | +# |
| 118 | +# See includes/DefaultSettings.php for all configurable settings |
| 119 | +# and their default values, but don't forget to make changes in _this_ |
| 120 | +# file, not there. |
| 121 | +# |
| 122 | +# Further documentation for configuration settings may be found at: |
| 123 | +# http://www.mediawiki.org/wiki/Manual:Configuration_settings |
| 124 | + |
| 125 | +# If you customize your file layout, set \$IP to the directory that contains |
| 126 | +# the other MediaWiki files. It will be used as a base to locate files. |
| 127 | +if( defined( 'MW_INSTALL_PATH' ) ) { |
| 128 | + \$IP = MW_INSTALL_PATH; |
| 129 | +} else { |
| 130 | + \$IP = dirname( __FILE__ ); |
| 131 | +} |
| 132 | + |
| 133 | +\$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" ); |
| 134 | +set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() ); |
| 135 | + |
| 136 | +require_once( \"\$IP/includes/DefaultSettings.php\" ); |
| 137 | + |
| 138 | +if ( \$wgCommandLineMode ) { |
| 139 | + if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) { |
| 140 | + die( \"This script must be run from the command line\\n\" ); |
| 141 | + } |
| 142 | +} |
| 143 | +## Uncomment this to disable output compression |
| 144 | +# \$wgDisableOutputCompression = true; |
| 145 | + |
| 146 | +\$wgSitename = \"{$this->values['wgSitename']}\"; |
| 147 | + |
| 148 | +## The URL base path to the directory containing the wiki; |
| 149 | +## defaults for all runtime URL paths are based off of this. |
| 150 | +## For more information on customizing the URLs please see: |
| 151 | +## http://www.mediawiki.org/wiki/Manual:Short_URL |
| 152 | +\$wgScriptPath = \"{$this->values['wgScriptPath']}\"; |
| 153 | +\$wgScriptExtension = \"{$this->values['wgScriptExtension']}\"; |
| 154 | + |
| 155 | +## The relative URL path to the skins directory |
| 156 | +\$wgStylePath = \"\$wgScriptPath/skins\"; |
| 157 | + |
| 158 | +## The relative URL path to the logo. Make sure you change this from the default, |
| 159 | +## or else you'll overwrite your logo when you upgrade! |
| 160 | +\$wgLogo = \"\$wgStylePath/common/images/wiki.png\"; |
| 161 | + |
| 162 | +## UPO means: this is also a user preference option |
| 163 | + |
| 164 | +\$wgEnableEmail = {$this->values['wgEnableEmail']}; |
| 165 | +\$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO |
| 166 | + |
| 167 | +\$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\"; |
| 168 | +\$wgPasswordSender = \"{$this->values['wgPasswordSender']}\"; |
| 169 | + |
| 170 | +\$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO |
| 171 | +\$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO |
| 172 | +\$wgEmailAuthentication = {$this->values['wgEmailAuthentication']}; |
| 173 | + |
| 174 | +## Database settings |
| 175 | +\$wgDBtype = \"{$this->values['wgDBtype']}\"; |
| 176 | +\$wgDBserver = \"{$this->values['wgDBserver']}\"; |
| 177 | +\$wgDBname = \"{$this->values['wgDBname']}\"; |
| 178 | +\$wgDBuser = \"{$this->values['wgDBuser']}\"; |
| 179 | +\$wgDBpassword = \"{$this->values['wgDBpassword']}\"; |
| 180 | + |
| 181 | +{$this->dbSettings} |
| 182 | + |
| 183 | +## Shared memory settings |
| 184 | +\$wgMainCacheType = $cacheType; |
| 185 | +\$wgMemCachedServers = $mcservers; |
| 186 | + |
| 187 | +## To enable image uploads, make sure the 'images' directory |
| 188 | +## is writable, then set this to true: |
| 189 | +\$wgEnableUploads = {$this->values['wgEnableUploads']}; |
| 190 | +{$magic}\$wgUseImageMagick = true; |
| 191 | +{$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\"; |
| 192 | + |
| 193 | +## If you use ImageMagick (or any other shell command) on a |
| 194 | +## Linux server, this will need to be set to the name of an |
| 195 | +## available UTF-8 locale |
| 196 | +{$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\"; |
| 197 | + |
| 198 | +## If you want to use image uploads under safe mode, |
| 199 | +## create the directories images/archive, images/thumb and |
| 200 | +## images/temp, and make them all writable. Then uncomment |
| 201 | +## this, if it's not already uncommented: |
| 202 | +{$hashedUploads}\$wgHashedUploadDirectory = false; |
| 203 | + |
| 204 | +## If you have the appropriate support software installed |
| 205 | +## you can enable inline LaTeX equations: |
| 206 | +\$wgUseTeX = false; |
| 207 | + |
| 208 | +## Set \$wgCacheDirectory to a writable directory on the web server |
| 209 | +## to make your wiki go slightly faster. The directory should not |
| 210 | +## be publically accessible from the web. |
| 211 | +#\$wgCacheDirectory = \"\$IP/cache\"; |
| 212 | + |
| 213 | +\$wgLocalInterwiki = strtolower( \$wgSitename ); |
| 214 | + |
| 215 | +\$wgLanguageCode = \"{$this->values['wgLanguageCode']}\"; |
| 216 | + |
| 217 | +\$wgSecretKey = \"{$this->values['wgSecretKey']}\"; |
| 218 | + |
| 219 | +## Default skin: you can change the default skin. Use the internal symbolic |
| 220 | +## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook': |
| 221 | +\$wgDefaultSkin = 'monobook'; |
| 222 | + |
| 223 | +## For attaching licensing metadata to pages, and displaying an |
| 224 | +## appropriate copyright notice / icon. GNU Free Documentation |
| 225 | +## License and Creative Commons licenses are supported so far. |
| 226 | +{$rights}\$wgEnableCreativeCommonsRdf = true; |
| 227 | +\$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright |
| 228 | +\$wgRightsUrl = \"{$this->values['wgRightsUrl']}\"; |
| 229 | +\$wgRightsText = \"{$this->values['wgRightsText']}\"; |
| 230 | +\$wgRightsIcon = \"{$this->values['wgRightsIcon']}\"; |
| 231 | +# \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used |
| 232 | + |
| 233 | +\$wgDiff3 = \"{$this->values['wgDiff3']}\"; |
| 234 | + |
| 235 | +# When you make changes to this configuration file, this will make |
| 236 | +# sure that cached pages are cleared. |
| 237 | +\$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); |
| 238 | +"; |
| 239 | + } |
| 240 | +} |
\ No newline at end of file |
Property changes on: branches/new-installer/phase3/includes/installer/LocalSettings.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 241 | + native |
Index: branches/new-installer/phase3/includes/installer/WebInstaller.php |
— | — | @@ -1520,7 +1520,12 @@ |
1521 | 1521 | } |
1522 | 1522 | $this->setVar( 'wgSecretKey', $secretKey ); |
1523 | 1523 | |
1524 | | - // @TODO Write LocalSettings, create admin account |
| 1524 | + // @TODO create admin account |
| 1525 | + |
| 1526 | + $this->startStage( 'config-install-localsettings' ); |
| 1527 | + $localSettings = new LocalSettings( $this->parent ); |
| 1528 | + $localSettings->writeLocalSettings(); |
| 1529 | + $this->endStage(); |
1525 | 1530 | } |
1526 | 1531 | |
1527 | 1532 | private function startStage( $msg ) { |
Index: branches/new-installer/phase3/includes/installer/SqliteInstaller.php |
— | — | @@ -107,4 +107,11 @@ |
108 | 108 | |
109 | 109 | function setupDatabase() { |
110 | 110 | } |
| 111 | + |
| 112 | + function getLocalSettings() { |
| 113 | + $dir = $this->getVar( 'wgSQLiteDataDir' ); |
| 114 | + return |
| 115 | +"# SQLite-specific settings |
| 116 | +\$wgSQLiteDataDir = \"{$dir}\";"; |
| 117 | + } |
111 | 118 | } |
Index: branches/new-installer/phase3/includes/installer/MysqlInstaller.php |
— | — | @@ -390,4 +390,20 @@ |
391 | 391 | return array( 'engine' => $this->getVar( '_MysqlEngine' ), |
392 | 392 | 'default charset' => $this->getVar( '_MysqlCharset' ) ); |
393 | 393 | } |
| 394 | + |
| 395 | + function getLocalSettings() { |
| 396 | + $dbmysql5 = wfBoolToStr( $this->getVar( 'wgDBmysql5', true ) ); |
| 397 | + $prefix = $this->getVar( 'wgDBprefix' ); |
| 398 | + $opts = $this->getTableOptions(); |
| 399 | + $tblOpts = "ENGINE=" . $opts['engine'] . ', DEFAULT CHARSET=' . $opts['default charset']; |
| 400 | + return |
| 401 | +"# MySQL specific settings |
| 402 | +\$wgDBprefix = \"{$prefix}\"; |
| 403 | + |
| 404 | +# MySQL table options to use during installation or update |
| 405 | +\$wgDBTableOptions = \"{$tblOpts}\"; |
| 406 | + |
| 407 | +# Experimental charset support for MySQL 4.1/5.0. |
| 408 | +\$wgDBmysql5 = {$dbmysql5};"; |
| 409 | + } |
394 | 410 | } |
Index: branches/new-installer/phase3/includes/installer/OracleInstaller.php |
— | — | @@ -92,5 +92,11 @@ |
93 | 93 | function getConnection() {} |
94 | 94 | |
95 | 95 | function setupDatabase() {} |
96 | | - |
| 96 | + |
| 97 | + function getLocalSettings() { |
| 98 | + $prefix = $this->getVar( 'wgDBprefix' ); |
| 99 | + return |
| 100 | +"# Oracle specific settings |
| 101 | +\$wgDBprefix = \"{$prefix}\";"; |
| 102 | + } |
97 | 103 | } |
Index: branches/new-installer/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -126,4 +126,15 @@ |
127 | 127 | |
128 | 128 | function setupDatabase() { |
129 | 129 | } |
| 130 | + |
| 131 | + function getLocalSettings() { |
| 132 | + $port = $this->getVar( 'wgDBport' ); |
| 133 | + $schema = $this->getVar( 'wgDBmwschema' ); |
| 134 | + $ts2 = $this->getVar( 'wgDBts2schema' ); |
| 135 | + return |
| 136 | +"# Postgres specific settings |
| 137 | +\$wgDBport = \"{$port}\"; |
| 138 | +\$wgDBmwschema = \"{$schema}\"; |
| 139 | +\$wgDBts2schema = \"{$ts2}\";"; |
| 140 | + } |
130 | 141 | } |
Index: branches/new-installer/phase3/includes/installer/InstallerDBType.php |
— | — | @@ -80,6 +80,12 @@ |
81 | 81 | return array(); |
82 | 82 | } |
83 | 83 | |
| 84 | + /** |
| 85 | + * Get the DBMS-specific options for LocalSettings.php generation. |
| 86 | + * @return String |
| 87 | + */ |
| 88 | + abstract function getLocalSettings(); |
| 89 | + |
84 | 90 | /** |
85 | 91 | * Construct and initialise parent. |
86 | 92 | * This is typically only called from Installer::getDBInstaller() |
Index: branches/new-installer/phase3/includes/AutoLoader.php |
— | — | @@ -431,6 +431,7 @@ |
432 | 432 | 'Installer' => 'includes/installer/Installer.php', |
433 | 433 | 'InstallerDBType' => 'includes/installer/InstallerDBType.php', |
434 | 434 | 'LBFactory_InstallerFake' => 'includes/installer/Installer.php', |
| 435 | + 'LocalSettings' => 'includes/installer/LocalSettings.php', |
435 | 436 | 'WebInstaller' => 'includes/installer/WebInstaller.php', |
436 | 437 | 'WebInstallerOutput' => 'includes/installer/WebInstallerOutput.php', |
437 | 438 | 'MysqlInstaller' => 'includes/installer/MysqlInstaller.php', |