3 class LocalSettingsGenerator
{
5 private $extensions = array();
6 private $values = array();
7 private $configPath = '';
8 private $dbSettings = '';
9 private $safeMode = false;
19 * @param $installer Installer subclass
21 public function __construct( Installer
$installer ) {
22 $this->installer
= $installer;
24 $this->configPath
= $installer->getVar( 'IP' ) . '/config';
25 $this->extensions
= $installer->getVar( '_Extensions' );
27 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
29 $confItems = array_merge(
31 'wgScriptPath', 'wgScriptExtension',
32 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
33 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
34 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
35 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
36 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
37 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
38 'wgDBpassword', 'wgUseInstantCommons'
43 $unescaped = array( 'wgRightsIcon' );
45 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
46 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons'
49 foreach( $confItems as $c ) {
50 $val = $installer->getVar( $c );
52 if( in_array( $c, $boolItems ) ) {
53 $val = wfBoolToStr( $val );
56 if ( !in_array( $c, $unescaped ) ) {
57 $val = self
::escapePhpString( $val );
60 $this->values
[$c] = $val;
63 $this->dbSettings
= $db->getLocalSettings();
64 $this->safeMode
= $installer->getVar( '_SafeMode' );
65 $this->values
['wgEmergencyContact'] = $this->values
['wgPasswordSender'];
69 * Returns the escaped version of a string of php code.
71 * @param $string String
75 public static function escapePhpString( $string ) {
76 if ( is_array( $string ) ||
is_object( $string ) ) {
94 * Return the full text of the generated LocalSettings.php file,
95 * including the extensions
99 public function getText() {
100 $localSettings = $this->getDefaultText();
102 if( count( $this->extensions
) ) {
103 $localSettings .= "\n# The following extensions were automatically enabled:\n";
105 foreach( $this->extensions
as $ext ) {
106 $localSettings .= "require( 'extensions/$ext/$ext.php' );\n";
110 return $localSettings;
116 private function buildMemcachedServerList() {
117 $servers = $this->values
['_MemCachedServers'];
123 $servers = explode( ',', $servers );
125 foreach( $servers as $srv ) {
130 return rtrim( $ret, ', ' ) . ' )';
137 private function getDefaultText() {
138 if( !$this->values
['wgImageMagickConvertCommand'] ) {
139 $this->values
['wgImageMagickConvertCommand'] = '/usr/bin/convert';
145 if( !$this->values
['wgShellLocale'] ) {
146 $this->values
['wgShellLocale'] = 'en_US.UTF-8';
152 $rights = $this->values
['wgRightsUrl'] ?
'' : '#';
153 $hashedUploads = $this->safeMode ?
'#' : '';
155 switch( $this->values
['wgMainCacheType'] ) {
160 $cacheType = 'CACHE_' . strtoupper( $this->values
['wgMainCacheType']);
164 $cacheType = 'CACHE_NONE';
167 $mcservers = $this->buildMemcachedServerList();
169 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
170 # installer. If you make manual changes, please keep track in case you
171 # need to recreate them later.
173 # See includes/DefaultSettings.php for all configurable settings
174 # and their default values, but don't forget to make changes in _this_
177 # Further documentation for configuration settings may be found at:
178 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
180 # If you customize your file layout, set \$IP to the directory that contains
181 # the other MediaWiki files. It will be used as a base to locate files.
182 if( defined( 'MW_INSTALL_PATH' ) ) {
183 \$IP = MW_INSTALL_PATH;
185 \$IP = dirname( __FILE__ );
188 \$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
189 set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() );
191 require_once( \"\$IP/includes/DefaultSettings.php\" );
193 if ( \$wgCommandLineMode ) {
194 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
195 die( \"This script must be run from the command line\\n\" );
198 ## Uncomment this to disable output compression
199 # \$wgDisableOutputCompression = true;
201 \$wgSitename = \"{$this->values['wgSitename']}\";
203 ## The URL base path to the directory containing the wiki;
204 ## defaults for all runtime URL paths are based off of this.
205 ## For more information on customizing the URLs please see:
206 ## http://www.mediawiki.org/wiki/Manual:Short_URL
207 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
208 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
210 ## The relative URL path to the skins directory
211 \$wgStylePath = \"\$wgScriptPath/skins\";
213 ## The relative URL path to the logo. Make sure you change this from the default,
214 ## or else you'll overwrite your logo when you upgrade!
215 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
217 ## UPO means: this is also a user preference option
219 \$wgEnableEmail = {$this->values['wgEnableEmail']};
220 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
222 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
223 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
225 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
226 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
227 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
230 \$wgDBtype = \"{$this->values['wgDBtype']}\";
231 \$wgDBserver = \"{$this->values['wgDBserver']}\";
232 \$wgDBname = \"{$this->values['wgDBname']}\";
233 \$wgDBuser = \"{$this->values['wgDBuser']}\";
234 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
238 ## Shared memory settings
239 \$wgMainCacheType = $cacheType;
240 \$wgMemCachedServers = $mcservers;
242 ## To enable image uploads, make sure the 'images' directory
243 ## is writable, then set this to true:
244 \$wgEnableUploads = {$this->values['wgEnableUploads']};
245 {$magic}\$wgUseImageMagick = true;
246 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
248 # InstantCommons allows wiki to use images from http://commons.wikimedia.org
249 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
251 ## If you use ImageMagick (or any other shell command) on a
252 ## Linux server, this will need to be set to the name of an
253 ## available UTF-8 locale
254 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
256 ## If you want to use image uploads under safe mode,
257 ## create the directories images/archive, images/thumb and
258 ## images/temp, and make them all writable. Then uncomment
259 ## this, if it's not already uncommented:
260 {$hashedUploads}\$wgHashedUploadDirectory = false;
262 ## If you have the appropriate support software installed
263 ## you can enable inline LaTeX equations:
266 ## Set \$wgCacheDirectory to a writable directory on the web server
267 ## to make your wiki go slightly faster. The directory should not
268 ## be publically accessible from the web.
269 #\$wgCacheDirectory = \"\$IP/cache\";
271 \$wgLocalInterwiki = strtolower( \$wgSitename );
273 # Site language code, should be one of ./languages/Language(.*).php
274 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
276 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
278 ## Default skin: you can change the default skin. Use the internal symbolic
279 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
280 \$wgDefaultSkin = 'vector';
282 ## For attaching licensing metadata to pages, and displaying an
283 ## appropriate copyright notice / icon. GNU Free Documentation
284 ## License and Creative Commons licenses are supported so far.
285 {$rights}\$wgEnableCreativeCommonsRdf = true;
286 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
287 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
288 \$wgRightsText = \"{$this->values['wgRightsText']}\";
289 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
290 # \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used
292 # Path to the GNU diff3 utility. Used for conflict resolution.
293 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
295 # When you make changes to this configuration file, this will make
296 # sure that cached pages are cleared.
297 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );