3 class LocalSettingsGenerator
{
4 private $extensions = array();
5 private $values = array();
6 private $configPath = '';
7 private $dbSettings = '';
8 private $safeMode = false;
18 * @param $installer Installer subclass
20 public function __construct( Installer
$installer ) {
21 $this->installer
= $installer;
23 $this->configPath
= $installer->getVar( 'IP' ) . '/config';
24 $this->extensions
= $installer->getVar( '_Extensions' );
26 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
28 $confItems = array_merge(
30 'wgScriptPath', 'wgScriptExtension',
31 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
32 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
33 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
34 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
35 'wgRightsText', 'wgRightsCode', 'wgMainCacheType', 'wgEnableUploads',
36 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
37 'wgDBpassword', 'wgUseInstantCommons'
42 $unescaped = array( 'wgRightsIcon' );
44 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
45 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons'
48 foreach( $confItems as $c ) {
49 $val = $installer->getVar( $c );
51 if( in_array( $c, $boolItems ) ) {
52 $val = wfBoolToStr( $val );
55 if ( !in_array( $c, $unescaped ) ) {
56 $val = self
::escapePhpString( $val );
59 $this->values
[$c] = $val;
62 $this->dbSettings
= $db->getLocalSettings();
63 $this->safeMode
= $installer->getVar( '_SafeMode' );
64 $this->values
['wgEmergencyContact'] = $this->values
['wgPasswordSender'];
67 public static function escapePhpString( $string ) {
68 if ( is_array( $string ) ||
is_object( $string ) ) {
86 * Return the full text of the generated LocalSettings.php file,
87 * including the extensions
90 public function getText() {
91 $localSettings = $this->getDefaultText();
93 if( count( $this->extensions
) ) {
94 $localSettings .= "\n# The following extensions were automatically enabled:\n";
96 foreach( $this->extensions
as $ext ) {
97 $localSettings .= "require( 'extensions/$ext/$ext.php' );\n";
101 return $localSettings;
104 private function buildMemcachedServerList() {
105 $servers = $this->values
['_MemCachedServers'];
111 $servers = explode( ',', $servers );
113 foreach( $servers as $srv ) {
118 return rtrim( $ret, ', ' ) . ' )';
122 private function getDefaultText() {
123 if( !$this->values
['wgImageMagickConvertCommand'] ) {
124 $this->values
['wgImageMagickConvertCommand'] = '/usr/bin/convert';
130 if( !$this->values
['wgShellLocale'] ) {
131 $this->values
['wgShellLocale'] = 'en_US.UTF-8';
137 $rights = $this->values
['wgRightsUrl'] ?
'' : '#';
138 $hashedUploads = $this->safeMode ?
'#' : '';
140 switch( $this->values
['wgMainCacheType'] ) {
145 $cacheType = 'CACHE_' . strtoupper( $this->values
['wgMainCacheType']);
149 $cacheType = 'CACHE_NONE';
152 $mcservers = $this->buildMemcachedServerList();
154 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
155 # installer. If you make manual changes, please keep track in case you
156 # need to recreate them later.
158 # See includes/DefaultSettings.php for all configurable settings
159 # and their default values, but don't forget to make changes in _this_
162 # Further documentation for configuration settings may be found at:
163 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
165 # If you customize your file layout, set \$IP to the directory that contains
166 # the other MediaWiki files. It will be used as a base to locate files.
167 if( defined( 'MW_INSTALL_PATH' ) ) {
168 \$IP = MW_INSTALL_PATH;
170 \$IP = dirname( __FILE__ );
173 \$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
174 set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() );
176 require_once( \"\$IP/includes/DefaultSettings.php\" );
178 if ( \$wgCommandLineMode ) {
179 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
180 die( \"This script must be run from the command line\\n\" );
183 ## Uncomment this to disable output compression
184 # \$wgDisableOutputCompression = true;
186 \$wgSitename = \"{$this->values['wgSitename']}\";
188 ## The URL base path to the directory containing the wiki;
189 ## defaults for all runtime URL paths are based off of this.
190 ## For more information on customizing the URLs please see:
191 ## http://www.mediawiki.org/wiki/Manual:Short_URL
192 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
193 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
195 ## The relative URL path to the skins directory
196 \$wgStylePath = \"\$wgScriptPath/skins\";
198 ## The relative URL path to the logo. Make sure you change this from the default,
199 ## or else you'll overwrite your logo when you upgrade!
200 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
202 ## UPO means: this is also a user preference option
204 \$wgEnableEmail = {$this->values['wgEnableEmail']};
205 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
207 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
208 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
210 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
211 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
212 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
215 \$wgDBtype = \"{$this->values['wgDBtype']}\";
216 \$wgDBserver = \"{$this->values['wgDBserver']}\";
217 \$wgDBname = \"{$this->values['wgDBname']}\";
218 \$wgDBuser = \"{$this->values['wgDBuser']}\";
219 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
223 ## Shared memory settings
224 \$wgMainCacheType = $cacheType;
225 \$wgMemCachedServers = $mcservers;
227 ## To enable image uploads, make sure the 'images' directory
228 ## is writable, then set this to true:
229 \$wgEnableUploads = {$this->values['wgEnableUploads']};
230 {$magic}\$wgUseImageMagick = true;
231 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
233 # InstantCommons allows wiki to use images from http://commons.wikimedia.org
234 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
236 ## If you use ImageMagick (or any other shell command) on a
237 ## Linux server, this will need to be set to the name of an
238 ## available UTF-8 locale
239 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
241 ## If you want to use image uploads under safe mode,
242 ## create the directories images/archive, images/thumb and
243 ## images/temp, and make them all writable. Then uncomment
244 ## this, if it's not already uncommented:
245 {$hashedUploads}\$wgHashedUploadDirectory = false;
247 ## If you have the appropriate support software installed
248 ## you can enable inline LaTeX equations:
251 ## Set \$wgCacheDirectory to a writable directory on the web server
252 ## to make your wiki go slightly faster. The directory should not
253 ## be publically accessible from the web.
254 #\$wgCacheDirectory = \"\$IP/cache\";
256 \$wgLocalInterwiki = strtolower( \$wgSitename );
258 # Site language code, should be one of ./languages/Language(.*).php
259 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
261 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
263 ## Default skin: you can change the default skin. Use the internal symbolic
264 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
265 \$wgDefaultSkin = 'vector';
267 ## For attaching licensing metadata to pages, and displaying an
268 ## appropriate copyright notice / icon. GNU Free Documentation
269 ## License and Creative Commons licenses are supported so far.
270 {$rights}\$wgEnableCreativeCommonsRdf = true;
271 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
272 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
273 \$wgRightsText = \"{$this->values['wgRightsText']}\";
274 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
275 # \$wgRightsCode = \"{$this->values['wgRightsCode']}\"; # Not yet used
277 # Path to the GNU diff3 utility. Used for conflict resolution.
278 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
280 # When you make changes to this configuration file, this will make
281 # sure that cached pages are cleared.
282 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );