3 class LocalSettingsGenerator
{
4 private $extensions, $values = array();
5 private $configPath, $dbSettings = '';
6 private $safeMode = false;
11 * @param $installer Installer subclass
13 public function __construct( Installer
$installer ) {
14 $this->installer
= $installer;
15 $this->configPath
= $installer->getVar( 'IP' ) . '/config';
16 $this->extensions
= $installer->getVar( '_Extensions' );
17 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
19 $confItems = array_merge( array( 'wgScriptPath', 'wgScriptExtension',
20 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
21 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
22 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
23 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
24 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
25 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
26 'wgDBpassword' ), $db->getGlobalNames() );
27 $boolItems = array( 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
28 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads' );
29 foreach( $confItems as $c ) {
30 $val = $installer->getVar( $c );
31 if( in_array( $c, $boolItems ) ) {
32 $val = wfBoolToStr( $val );
34 $this->values
[$c] = $val;
36 $this->dbSettings
= $db->getLocalSettings();
37 $this->safeMode
= $installer->getVar( '_SafeMode' );
38 $this->values
['wgEmergencyContact'] = $this->values
['wgPasswordSender'];
39 $this->values
= wfArrayMap( array( 'LocalSettingsGenerator', 'escapePhpString' ), $this->values
);
42 public static function escapePhpString( $string ) {
43 if ( is_array( $string ) ||
is_object( $string ) ) {
46 return strtr( $string,
59 * @param $secretKey String A random string to
60 * @return boolean On successful file write
62 public function writeLocalSettings() {
63 $localSettings = $this->getDefaultText();
64 if( count( $this->extensions
) ) {
65 $localSettings .= "\n# The following extensions were automatically enabled:\n";
66 foreach( $this->extensions
as $ext ) {
67 $localSettings .= "require( 'extensions/$ext/$ext.php' );\n";
71 $ret = file_put_contents( $this->configPath
. '/LocalSettings.php', $localSettings );
74 $warn = wfMsg( 'config-install-localsettings-unwritable' ) . '
75 <textarea name="LocalSettings" id="LocalSettings" cols="80" rows="25" readonly="readonly">'
76 . htmlspecialchars( $localSettings ) . '</textarea>';
77 $this->installer
->output
->addWarning( $warn );
82 private function buildMemcachedServerList() {
83 $servers = $this->values
['_MemCachedServers'];
88 $servers = explode( ',', $servers );
89 foreach( $servers as $srv ) {
93 return rtrim( $ret, ', ' ) . ' )';
97 private function getDefaultText() {
98 if( !$this->values
['wgImageMagickConvertCommand'] ) {
99 $this->values
['wgImageMagickConvertCommand'] = '/usr/bin/convert';
104 if( !$this->values
['wgShellLocale'] ) {
105 $this->values
['wgShellLocale'] = 'en_US.UTF-8';
110 $rights = $this->values
['wgRightsUrl'] ?
'' : '#';
111 $hashedUploads = $this->safeMode ?
'#' : '';
112 switch( $this->values
['wgMainCacheType'] ) {
117 $cacheType = 'CACHE_' . strtoupper( $this->values
['wgMainCacheType']);
121 $cacheType = 'CACHE_NONE';
123 $mcservers = $this->buildMemcachedServerList();
125 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
126 # installer. If you make manual changes, please keep track in case you
127 # need to recreate them later.
129 # See includes/DefaultSettings.php for all configurable settings
130 # and their default values, but don't forget to make changes in _this_
133 # Further documentation for configuration settings may be found at:
134 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
136 # If you customize your file layout, set \$IP to the directory that contains
137 # the other MediaWiki files. It will be used as a base to locate files.
138 if( defined( 'MW_INSTALL_PATH' ) ) {
139 \$IP = MW_INSTALL_PATH;
141 \$IP = dirname( __FILE__ );
144 \$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
145 set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() );
147 require_once( \"\$IP/includes/DefaultSettings.php\" );
149 if ( \$wgCommandLineMode ) {
150 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
151 die( \"This script must be run from the command line\\n\" );
154 ## Uncomment this to disable output compression
155 # \$wgDisableOutputCompression = true;
157 \$wgSitename = \"{$this->values['wgSitename']}\";
159 ## The URL base path to the directory containing the wiki;
160 ## defaults for all runtime URL paths are based off of this.
161 ## For more information on customizing the URLs please see:
162 ## http://www.mediawiki.org/wiki/Manual:Short_URL
163 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
164 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
166 ## The relative URL path to the skins directory
167 \$wgStylePath = \"\$wgScriptPath/skins\";
169 ## The relative URL path to the logo. Make sure you change this from the default,
170 ## or else you'll overwrite your logo when you upgrade!
171 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
173 ## UPO means: this is also a user preference option
175 \$wgEnableEmail = {$this->values['wgEnableEmail']};
176 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
178 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
179 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
181 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
182 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
183 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
186 \$wgDBtype = \"{$this->values['wgDBtype']}\";
187 \$wgDBserver = \"{$this->values['wgDBserver']}\";
188 \$wgDBname = \"{$this->values['wgDBname']}\";
189 \$wgDBuser = \"{$this->values['wgDBuser']}\";
190 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
194 ## Shared memory settings
195 \$wgMainCacheType = $cacheType;
196 \$wgMemCachedServers = $mcservers;
198 ## To enable image uploads, make sure the 'images' directory
199 ## is writable, then set this to true:
200 \$wgEnableUploads = {$this->values['wgEnableUploads']};
201 {$magic}\$wgUseImageMagick = true;
202 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
204 ## If you use ImageMagick (or any other shell command) on a
205 ## Linux server, this will need to be set to the name of an
206 ## available UTF-8 locale
207 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
209 ## If you want to use image uploads under safe mode,
210 ## create the directories images/archive, images/thumb and
211 ## images/temp, and make them all writable. Then uncomment
212 ## this, if it's not already uncommented:
213 {$hashedUploads}\$wgHashedUploadDirectory = false;
215 ## If you have the appropriate support software installed
216 ## you can enable inline LaTeX equations:
219 ## Set \$wgCacheDirectory to a writable directory on the web server
220 ## to make your wiki go slightly faster. The directory should not
221 ## be publically accessible from the web.
222 #\$wgCacheDirectory = \"\$IP/cache\";
224 \$wgLocalInterwiki = strtolower( \$wgSitename );
226 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
228 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
230 ## Default skin: you can change the default skin. Use the internal symbolic
231 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
232 \$wgDefaultSkin = 'monobook';
234 ## For attaching licensing metadata to pages, and displaying an
235 ## appropriate copyright notice / icon. GNU Free Documentation
236 ## License and Creative Commons licenses are supported so far.
237 {$rights}\$wgEnableCreativeCommonsRdf = true;
238 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
239 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
240 \$wgRightsText = \"{$this->values['wgRightsText']}\";
241 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
242 # \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used
244 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
246 # When you make changes to this configuration file, this will make
247 # sure that cached pages are cleared.
248 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );