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 $dbSettings = '';
20 private $safeMode = false;
30 * @param $installer Installer subclass
32 public function __construct( Installer
$installer ) {
33 $this->installer
= $installer;
35 $this->extensions
= $installer->getVar( '_Extensions' );
37 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
39 $confItems = array_merge(
41 'wgScriptPath', 'wgScriptExtension',
42 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
43 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
44 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
45 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
46 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
47 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
48 'wgDBpassword', 'wgUseInstantCommons', 'wgUpgradeKey'
53 $unescaped = array( 'wgRightsIcon' );
55 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
56 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons'
59 foreach( $confItems as $c ) {
60 $val = $installer->getVar( $c );
62 if( in_array( $c, $boolItems ) ) {
63 $val = wfBoolToStr( $val );
66 if ( !in_array( $c, $unescaped ) ) {
67 $val = self
::escapePhpString( $val );
70 $this->values
[$c] = $val;
73 $this->dbSettings
= $db->getLocalSettings();
74 $this->safeMode
= $installer->getVar( '_SafeMode' );
75 $this->values
['wgEmergencyContact'] = $this->values
['wgPasswordSender'];
79 * Returns the escaped version of a string of php code.
81 * @param $string String
85 public static function escapePhpString( $string ) {
86 if ( is_array( $string ) ||
is_object( $string ) ) {
104 * Return the full text of the generated LocalSettings.php file,
105 * including the extensions
109 public function getText() {
110 $localSettings = $this->getDefaultText();
112 if( count( $this->extensions
) ) {
113 $localSettings .= "\n# The following extensions were automatically enabled:\n";
115 foreach( $this->extensions
as $extName ) {
116 $encExtName = self
::escapePhpString( $extName );
117 $localSettings .= "require( \"extensions/$encExtName/$encExtName.php\" );\n";
121 return $localSettings;
125 * Write the generated LocalSettings to a file
127 * @param $fileName String Full path to filename to write to
129 public function writeFile( $fileName ) {
130 file_put_contents( $fileName, $this->getText() );
136 private function buildMemcachedServerList() {
137 $servers = $this->values
['_MemCachedServers'];
143 $servers = explode( ',', $servers );
145 foreach( $servers as $srv ) {
150 return rtrim( $ret, ', ' ) . ' )';
157 private function getDefaultText() {
158 if( !$this->values
['wgImageMagickConvertCommand'] ) {
159 $this->values
['wgImageMagickConvertCommand'] = '/usr/bin/convert';
165 if( !$this->values
['wgShellLocale'] ) {
166 $this->values
['wgShellLocale'] = 'en_US.UTF-8';
172 $rights = $this->values
['wgRightsUrl'] ?
'' : '#';
173 $hashedUploads = $this->safeMode ?
'' : '#';
175 switch( $this->values
['wgMainCacheType'] ) {
180 $cacheType = 'CACHE_' . strtoupper( $this->values
['wgMainCacheType']);
184 $cacheType = 'CACHE_NONE';
187 $mcservers = $this->buildMemcachedServerList();
189 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
190 # installer. If you make manual changes, please keep track in case you
191 # need to recreate them later.
193 # See includes/DefaultSettings.php for all configurable settings
194 # and their default values, but don't forget to make changes in _this_
197 # Further documentation for configuration settings may be found at:
198 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
200 # If you customize your file layout, set \$IP to the directory that contains
201 # the other MediaWiki files. It will be used as a base to locate files.
202 if( defined( 'MW_INSTALL_PATH' ) ) {
203 \$IP = MW_INSTALL_PATH;
205 \$IP = dirname( __FILE__ );
208 require_once( \"\$IP/includes/DefaultSettings.php\" );
210 if ( \$wgCommandLineMode ) {
211 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
212 die( \"This script must be run from the command line\\n\" );
215 ## Uncomment this to disable output compression
216 # \$wgDisableOutputCompression = true;
218 \$wgSitename = \"{$this->values['wgSitename']}\";
220 ## The URL base path to the directory containing the wiki;
221 ## defaults for all runtime URL paths are based off of this.
222 ## For more information on customizing the URLs please see:
223 ## http://www.mediawiki.org/wiki/Manual:Short_URL
224 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
225 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
227 ## The relative URL path to the skins directory
228 \$wgStylePath = \"\$wgScriptPath/skins\";
230 ## The relative URL path to the logo. Make sure you change this from the default,
231 ## or else you'll overwrite your logo when you upgrade!
232 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
234 ## UPO means: this is also a user preference option
236 \$wgEnableEmail = {$this->values['wgEnableEmail']};
237 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
239 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
240 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
242 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
243 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
244 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
247 \$wgDBtype = \"{$this->values['wgDBtype']}\";
248 \$wgDBserver = \"{$this->values['wgDBserver']}\";
249 \$wgDBname = \"{$this->values['wgDBname']}\";
250 \$wgDBuser = \"{$this->values['wgDBuser']}\";
251 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
255 ## Shared memory settings
256 \$wgMainCacheType = $cacheType;
257 \$wgMemCachedServers = $mcservers;
259 ## To enable image uploads, make sure the 'images' directory
260 ## is writable, then set this to true:
261 \$wgEnableUploads = {$this->values['wgEnableUploads']};
262 {$magic}\$wgUseImageMagick = true;
263 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
265 # InstantCommons allows wiki to use images from http://commons.wikimedia.org
266 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
268 ## If you use ImageMagick (or any other shell command) on a
269 ## Linux server, this will need to be set to the name of an
270 ## available UTF-8 locale
271 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
273 ## If you want to use image uploads under safe mode,
274 ## create the directories images/archive, images/thumb and
275 ## images/temp, and make them all writable. Then uncomment
276 ## this, if it's not already uncommented:
277 {$hashedUploads}\$wgHashedUploadDirectory = false;
279 ## If you have the appropriate support software installed
280 ## you can enable inline LaTeX equations:
283 ## Set \$wgCacheDirectory to a writable directory on the web server
284 ## to make your wiki go slightly faster. The directory should not
285 ## be publically accessible from the web.
286 #\$wgCacheDirectory = \"\$IP/cache\";
288 \$wgLocalInterwiki = strtolower( \$wgSitename );
290 # Site language code, should be one of ./languages/Language(.*).php
291 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
293 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
295 # Site upgrade key. Must be set to a string (default provided) to turn on the
296 # web installer while LocalSettings.php is in place
297 #\$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\";
299 ## Default skin: you can change the default skin. Use the internal symbolic
300 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
301 \$wgDefaultSkin = 'vector';
303 ## For attaching licensing metadata to pages, and displaying an
304 ## appropriate copyright notice / icon. GNU Free Documentation
305 ## License and Creative Commons licenses are supported so far.
306 {$rights}\$wgEnableCreativeCommonsRdf = true;
307 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
308 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
309 \$wgRightsText = \"{$this->values['wgRightsText']}\";
310 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
311 # \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used
313 # Path to the GNU diff3 utility. Used for conflict resolution.
314 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
316 # When you make changes to this configuration file, this will make
317 # sure that cached pages are cleared.
318 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
320 # Enabled Extensions. Most extensions are enabled by including the base extension file here
321 # but check specific extension documentation for more details