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 $groupPermissions = array();
20 private $dbSettings = '';
21 private $safeMode = false;
31 * @param $installer Installer subclass
33 public function __construct( Installer
$installer ) {
34 $this->installer
= $installer;
36 $this->extensions
= $installer->getVar( '_Extensions' );
38 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
40 $confItems = array_merge(
42 'wgScriptPath', 'wgScriptExtension',
43 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
44 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
45 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
46 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
47 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
48 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
49 'wgDBpassword', 'wgUseInstantCommons', 'wgUpgradeKey', 'wgDefaultSkin',
50 'wgMetaNamespace', 'wgResourceLoaderMaxQueryLength'
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 * For $wgGroupPermissions, set a given ['group']['permission'] value.
82 * @param $group String Group name
83 * @param $rightsArr Array An array of permissions, in the form of:
84 * array( 'right' => true, 'right2' => false )
86 public function setGroupRights( $group, $rightsArr ) {
87 $this->groupPermissions
[$group] = $rightsArr;
91 * Returns the escaped version of a string of php code.
93 * @param $string String
97 public static function escapePhpString( $string ) {
98 if ( is_array( $string ) ||
is_object( $string ) ) {
116 * Return the full text of the generated LocalSettings.php file,
117 * including the extensions
121 public function getText() {
122 $localSettings = $this->getDefaultText();
124 if( count( $this->extensions
) ) {
126 # Enabled Extensions. Most extensions are enabled by including the base extension file here
127 # but check specific extension documentation for more details
128 # The following extensions were automatically enabled:\n";
130 foreach( $this->extensions
as $extName ) {
131 $encExtName = self
::escapePhpString( $extName );
132 $localSettings .= "require( \"extensions/$encExtName/$encExtName.php\" );\n";
136 $localSettings .= "\n\n# End of automatically generated settings.
137 # Add more configuration options below.\n\n";
139 return $localSettings;
143 * Write the generated LocalSettings to a file
145 * @param $fileName String Full path to filename to write to
147 public function writeFile( $fileName ) {
148 file_put_contents( $fileName, $this->getText() );
154 private function buildMemcachedServerList() {
155 $servers = $this->values
['_MemCachedServers'];
161 $servers = explode( ',', $servers );
163 foreach( $servers as $srv ) {
168 return rtrim( $ret, ', ' ) . ' )';
175 private function getDefaultText() {
176 if( !$this->values
['wgImageMagickConvertCommand'] ) {
177 $this->values
['wgImageMagickConvertCommand'] = '/usr/bin/convert';
183 if( !$this->values
['wgShellLocale'] ) {
184 $this->values
['wgShellLocale'] = 'en_US.UTF-8';
190 $rightsUrl = $this->values
['wgRightsUrl'] ?
'' : '#';
191 $hashedUploads = $this->safeMode ?
'' : '#';
193 if( $this->values
['wgMetaNamespace'] !== $this->values
['wgSitename'] ) {
194 $metaNamespace = "\$wgMetaNamespace = \"{$this->values['wgMetaNamespace']}\";\n";
198 if( $this->groupPermissions
) {
199 $groupRights .= "# The following permissions were set based on your choice in the installer\n";
200 foreach( $this->groupPermissions
as $group => $rightArr ) {
201 $group = self
::escapePhpString( $group );
202 foreach( $rightArr as $right => $perm ) {
203 $right = self
::escapePhpString( $right );
204 $groupRights .= "\$wgGroupPermissions['$group']['$right'] = " .
205 wfBoolToStr( $perm ) . ";\n";
210 switch( $this->values
['wgMainCacheType'] ) {
215 $cacheType = 'CACHE_' . strtoupper( $this->values
['wgMainCacheType']);
219 $cacheType = 'CACHE_NONE';
222 $mcservers = $this->buildMemcachedServerList();
224 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
225 # installer. If you make manual changes, please keep track in case you
226 # need to recreate them later.
228 # See includes/DefaultSettings.php for all configurable settings
229 # and their default values, but don't forget to make changes in _this_
232 # Further documentation for configuration settings may be found at:
233 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
235 # Protect against web entry
236 if ( !defined( 'MEDIAWIKI' ) ) {
240 ## Uncomment this to disable output compression
241 # \$wgDisableOutputCompression = true;
243 \$wgSitename = \"{$this->values['wgSitename']}\";
245 ## The URL base path to the directory containing the wiki;
246 ## defaults for all runtime URL paths are based off of this.
247 ## For more information on customizing the URLs please see:
248 ## http://www.mediawiki.org/wiki/Manual:Short_URL
249 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
250 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
252 ## The relative URL path to the skins directory
253 \$wgStylePath = \"\$wgScriptPath/skins\";
255 ## The relative URL path to the logo. Make sure you change this from the default,
256 ## or else you'll overwrite your logo when you upgrade!
257 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
259 ## UPO means: this is also a user preference option
261 \$wgEnableEmail = {$this->values['wgEnableEmail']};
262 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
264 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
265 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
267 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
268 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
269 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
272 \$wgDBtype = \"{$this->values['wgDBtype']}\";
273 \$wgDBserver = \"{$this->values['wgDBserver']}\";
274 \$wgDBname = \"{$this->values['wgDBname']}\";
275 \$wgDBuser = \"{$this->values['wgDBuser']}\";
276 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
280 ## Shared memory settings
281 \$wgMainCacheType = $cacheType;
282 \$wgMemCachedServers = $mcservers;
284 ## To enable image uploads, make sure the 'images' directory
285 ## is writable, then set this to true:
286 \$wgEnableUploads = {$this->values['wgEnableUploads']};
287 {$magic}\$wgUseImageMagick = true;
288 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
290 # InstantCommons allows wiki to use images from http://commons.wikimedia.org
291 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
293 ## If you use ImageMagick (or any other shell command) on a
294 ## Linux server, this will need to be set to the name of an
295 ## available UTF-8 locale
296 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
298 ## If you want to use image uploads under safe mode,
299 ## create the directories images/archive, images/thumb and
300 ## images/temp, and make them all writable. Then uncomment
301 ## this, if it's not already uncommented:
302 {$hashedUploads}\$wgHashedUploadDirectory = false;
304 ## Set \$wgCacheDirectory to a writable directory on the web server
305 ## to make your wiki go slightly faster. The directory should not
306 ## be publically accessible from the web.
307 #\$wgCacheDirectory = \"\$IP/cache\";
309 # Site language code, should be one of ./languages/Language(.*).php
310 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
312 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
314 # Site upgrade key. Must be set to a string (default provided) to turn on the
315 # web installer while LocalSettings.php is in place
316 \$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\";
318 ## Default skin: you can change the default skin. Use the internal symbolic
319 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
320 \$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\";
322 ## For attaching licensing metadata to pages, and displaying an
323 ## appropriate copyright notice / icon. GNU Free Documentation
324 ## License and Creative Commons licenses are supported so far.
325 {$rightsUrl}\$wgEnableCreativeCommonsRdf = true;
326 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
327 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
328 \$wgRightsText = \"{$this->values['wgRightsText']}\";
329 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
330 # \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used
332 # Path to the GNU diff3 utility. Used for conflict resolution.
333 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
335 # Query string length limit for ResourceLoader. You should only set this if
336 # your web server has a query string length limit (then set it to that limit),
337 # or if you have suhosin.get.max_value_length set in php.ini (then set it to
339 \$wgResourceLoaderMaxQueryLength = {$this->values['wgResourceLoaderMaxQueryLength']};