3 * Generator for LocalSettings.php file.
10 * Class for generating LocalSettings.php file.
15 class LocalSettingsGenerator
{
17 private $extensions = array();
18 private $values = array();
19 private $configPath = '';
20 private $dbSettings = '';
21 private $safeMode = false;
31 * @param $installer Installer subclass
33 public function __construct( Installer
$installer ) {
34 $this->installer
= $installer;
36 $this->configPath
= $installer->getVar( 'IP' ) . '/config';
37 $this->extensions
= $installer->getVar( '_Extensions' );
39 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
41 $confItems = array_merge(
43 'wgScriptPath', 'wgScriptExtension',
44 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
45 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
46 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
47 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
48 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
49 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
50 'wgDBpassword', 'wgUseInstantCommons'
55 $unescaped = array( 'wgRightsIcon' );
57 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
58 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons'
61 foreach( $confItems as $c ) {
62 $val = $installer->getVar( $c );
64 if( in_array( $c, $boolItems ) ) {
65 $val = wfBoolToStr( $val );
68 if ( !in_array( $c, $unescaped ) ) {
69 $val = self
::escapePhpString( $val );
72 $this->values
[$c] = $val;
75 $this->dbSettings
= $db->getLocalSettings();
76 $this->safeMode
= $installer->getVar( '_SafeMode' );
77 $this->values
['wgEmergencyContact'] = $this->values
['wgPasswordSender'];
81 * Returns the escaped version of a string of php code.
83 * @param $string String
87 public static function escapePhpString( $string ) {
88 if ( is_array( $string ) ||
is_object( $string ) ) {
106 * Return the full text of the generated LocalSettings.php file,
107 * including the extensions
111 public function getText() {
112 $localSettings = $this->getDefaultText();
114 if( count( $this->extensions
) ) {
115 $localSettings .= "\n# The following extensions were automatically enabled:\n";
117 foreach( $this->extensions
as $ext ) {
118 $localSettings .= "require( 'extensions/$ext/$ext.php' );\n";
122 return $localSettings;
128 private function buildMemcachedServerList() {
129 $servers = $this->values
['_MemCachedServers'];
135 $servers = explode( ',', $servers );
137 foreach( $servers as $srv ) {
142 return rtrim( $ret, ', ' ) . ' )';
149 private function getDefaultText() {
150 if( !$this->values
['wgImageMagickConvertCommand'] ) {
151 $this->values
['wgImageMagickConvertCommand'] = '/usr/bin/convert';
157 if( !$this->values
['wgShellLocale'] ) {
158 $this->values
['wgShellLocale'] = 'en_US.UTF-8';
164 $rights = $this->values
['wgRightsUrl'] ?
'' : '#';
165 $hashedUploads = $this->safeMode ?
'' : '#';
167 switch( $this->values
['wgMainCacheType'] ) {
172 $cacheType = 'CACHE_' . strtoupper( $this->values
['wgMainCacheType']);
176 $cacheType = 'CACHE_NONE';
179 $mcservers = $this->buildMemcachedServerList();
181 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
182 # installer. If you make manual changes, please keep track in case you
183 # need to recreate them later.
185 # See includes/DefaultSettings.php for all configurable settings
186 # and their default values, but don't forget to make changes in _this_
189 # Further documentation for configuration settings may be found at:
190 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
192 # If you customize your file layout, set \$IP to the directory that contains
193 # the other MediaWiki files. It will be used as a base to locate files.
194 if( defined( 'MW_INSTALL_PATH' ) ) {
195 \$IP = MW_INSTALL_PATH;
197 \$IP = dirname( __FILE__ );
200 require_once( \"\$IP/includes/DefaultSettings.php\" );
202 if ( \$wgCommandLineMode ) {
203 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
204 die( \"This script must be run from the command line\\n\" );
207 ## Uncomment this to disable output compression
208 # \$wgDisableOutputCompression = true;
210 \$wgSitename = \"{$this->values['wgSitename']}\";
212 ## The URL base path to the directory containing the wiki;
213 ## defaults for all runtime URL paths are based off of this.
214 ## For more information on customizing the URLs please see:
215 ## http://www.mediawiki.org/wiki/Manual:Short_URL
216 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
217 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
219 ## The relative URL path to the skins directory
220 \$wgStylePath = \"\$wgScriptPath/skins\";
222 ## The relative URL path to the logo. Make sure you change this from the default,
223 ## or else you'll overwrite your logo when you upgrade!
224 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
226 ## UPO means: this is also a user preference option
228 \$wgEnableEmail = {$this->values['wgEnableEmail']};
229 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
231 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
232 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
234 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
235 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
236 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
239 \$wgDBtype = \"{$this->values['wgDBtype']}\";
240 \$wgDBserver = \"{$this->values['wgDBserver']}\";
241 \$wgDBname = \"{$this->values['wgDBname']}\";
242 \$wgDBuser = \"{$this->values['wgDBuser']}\";
243 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
247 ## Shared memory settings
248 \$wgMainCacheType = $cacheType;
249 \$wgMemCachedServers = $mcservers;
251 ## To enable image uploads, make sure the 'images' directory
252 ## is writable, then set this to true:
253 \$wgEnableUploads = {$this->values['wgEnableUploads']};
254 {$magic}\$wgUseImageMagick = true;
255 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
257 # InstantCommons allows wiki to use images from http://commons.wikimedia.org
258 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
260 ## If you use ImageMagick (or any other shell command) on a
261 ## Linux server, this will need to be set to the name of an
262 ## available UTF-8 locale
263 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
265 ## If you want to use image uploads under safe mode,
266 ## create the directories images/archive, images/thumb and
267 ## images/temp, and make them all writable. Then uncomment
268 ## this, if it's not already uncommented:
269 {$hashedUploads}\$wgHashedUploadDirectory = false;
271 ## If you have the appropriate support software installed
272 ## you can enable inline LaTeX equations:
275 ## Set \$wgCacheDirectory to a writable directory on the web server
276 ## to make your wiki go slightly faster. The directory should not
277 ## be publically accessible from the web.
278 #\$wgCacheDirectory = \"\$IP/cache\";
280 \$wgLocalInterwiki = strtolower( \$wgSitename );
282 # Site language code, should be one of ./languages/Language(.*).php
283 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
285 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
287 ## Default skin: you can change the default skin. Use the internal symbolic
288 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
289 \$wgDefaultSkin = 'vector';
291 ## For attaching licensing metadata to pages, and displaying an
292 ## appropriate copyright notice / icon. GNU Free Documentation
293 ## License and Creative Commons licenses are supported so far.
294 {$rights}\$wgEnableCreativeCommonsRdf = true;
295 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
296 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
297 \$wgRightsText = \"{$this->values['wgRightsText']}\";
298 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
299 # \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used
301 # Path to the GNU diff3 utility. Used for conflict resolution.
302 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
304 # When you make changes to this configuration file, this will make
305 # sure that cached pages are cleared.
306 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
308 # Enabled Extensions. Most extensions are enabled by including the base extension file here
309 # but check specific extension documentation for more details