30class LocalSettingsGenerator {
32 protected $extensions = [];
33 protected $skins = [];
34 protected $values = [];
35 protected $groupPermissions = [];
36 protected $dbSettings =
'';
47 public function __construct(
Installer $installer ) {
48 $this->installer = $installer;
50 $this->extensions = $installer->
getVar(
'_Extensions' );
51 $this->skins = $installer->
getVar(
'_Skins' );
52 $this->
IP = $installer->
getVar(
'IP' );
56 $confItems = array_merge(
58 'wgServer',
'wgScriptPath',
59 'wgPasswordSender',
'wgImageMagickConvertCommand',
'wgShellLocale',
60 'wgLanguageCode',
'wgEnableEmail',
'wgEnableUserEmail',
'wgDiff3',
61 'wgEnotifUserTalk',
'wgEnotifWatchlist',
'wgEmailAuthentication',
62 'wgDBtype',
'wgSecretKey',
'wgRightsUrl',
'wgSitename',
'wgRightsIcon',
63 'wgRightsText',
'_MainCacheType',
'wgEnableUploads',
64 '_MemCachedServers',
'wgDBserver',
'wgDBuser',
65 'wgDBpassword',
'wgUseInstantCommons',
'wgUpgradeKey',
'wgDefaultSkin',
66 'wgMetaNamespace',
'_Logo',
'wgAuthenticationTokenVersion',
'wgPingback',
74 $unescaped = [
'wgRightsIcon',
'_Logo',
'_Caches' ];
76 'wgEnableEmail',
'wgEnableUserEmail',
'wgEnotifUserTalk',
77 'wgEnotifWatchlist',
'wgEmailAuthentication',
'wgEnableUploads',
'wgUseInstantCommons',
81 foreach ( $confItems as $c ) {
82 $val = $installer->
getVar( $c );
84 if ( in_array( $c, $boolItems ) ) {
88 if ( !in_array( $c, $unescaped ) && $val !==
null ) {
89 $val = self::escapePhpString( $val );
92 $this->values[$c] = $val;
95 $this->dbSettings = $db->getLocalSettings();
96 $this->values[
'wgEmergencyContact'] = $this->values[
'wgPasswordSender'];
105 public function setGroupRights( $group, $rightsArr ) {
106 $this->groupPermissions[$group] = $rightsArr;
116 public static function escapePhpString( $string ) {
117 if ( is_array( $string ) || is_object( $string ) ) {
140 public function getText() {
141 $localSettings = $this->getDefaultText();
143 if ( count( $this->skins ) ) {
146# The following skins were automatically enabled:\n";
148 foreach ( $this->skins as $skinName ) {
149 $localSettings .= $this->generateExtEnableLine(
'skins', $skinName );
152 $localSettings .=
"\n";
155 if ( count( $this->extensions ) ) {
157# Enabled extensions. Most of the extensions are enabled by adding
158# wfLoadExtension( 'ExtensionName' );
159# to LocalSettings.php. Check specific extension documentation for more details.
160# The following extensions were automatically enabled:\n";
162 foreach ( $this->extensions as $extName ) {
163 $localSettings .= $this->generateExtEnableLine(
'extensions', $extName );
166 $localSettings .=
"\n";
170# End of automatically generated settings.
171# Add more configuration options below.\n\n";
173 return $localSettings;
184 private function generateExtEnableLine( $dir, $name ) {
185 if ( $dir ===
'extensions' ) {
186 $jsonFile =
'extension.json';
187 $function =
'wfLoadExtension';
188 } elseif ( $dir ===
'skins' ) {
189 $jsonFile =
'skin.json';
190 $function =
'wfLoadSkin';
192 throw new InvalidArgumentException(
'$dir was not "extensions" or "skins"' );
195 $encName = self::escapePhpString( $name );
197 if ( file_exists(
"{$this->IP}/$dir/$encName/$jsonFile" ) ) {
198 return "$function( '$encName' );\n";
200 return "require_once \"\$IP/$dir/$encName/$encName.php\";\n";
209 public function writeFile( $fileName ) {
210 file_put_contents( $fileName, $this->getText() );
216 protected function buildMemcachedServerList() {
217 $servers = $this->values[
'_MemCachedServers'];
223 $servers = explode(
',', $servers );
225 foreach ( $servers as $srv ) {
230 return rtrim( $ret,
', ' ) .
' ]';
237 protected function getDefaultText() {
238 if ( !$this->values[
'wgImageMagickConvertCommand'] ) {
239 $this->values[
'wgImageMagickConvertCommand'] =
'/usr/bin/convert';
245 if ( !$this->values[
'wgShellLocale'] ) {
246 $this->values[
'wgShellLocale'] =
'C.UTF-8';
253 if ( $this->values[
'wgMetaNamespace'] !== $this->values[
'wgSitename'] ) {
254 $metaNamespace =
"\$wgMetaNamespace = \"{$this->values['wgMetaNamespace']}\";\n";
259 if ( $this->groupPermissions ) {
260 $groupRights .=
"# The following permissions were set based on your choice in the installer\n";
261 foreach ( $this->groupPermissions as $group => $rightArr ) {
262 $group = self::escapePhpString( $group );
263 foreach ( $rightArr as $right => $perm ) {
264 $right = self::escapePhpString( $right );
265 $groupRights .=
"\$wgGroupPermissions['$group']['$right'] = " .
269 $groupRights .=
"\n";
271 if ( ( isset( $this->groupPermissions[
'*'][
'edit'] ) &&
272 $this->groupPermissions[
'*'][
'edit'] ===
false )
273 && ( isset( $this->groupPermissions[
'*'][
'createaccount'] ) &&
274 $this->groupPermissions[
'*'][
'createaccount'] ===
false )
275 && ( isset( $this->groupPermissions[
'*'][
'read'] ) &&
276 $this->groupPermissions[
'*'][
'read'] !==
false )
278 $noFollow =
"# Set \$wgNoFollowLinks to true if you open up your wiki to editing by\n"
279 .
"# the general public and wish to apply nofollow to external links as a\n"
280 .
"# deterrent to spammers. Nofollow is not a comprehensive anti-spam solution\n"
281 .
"# and open wikis will generally require other anti-spam measures; for more\n"
282 .
"# information, see https://www.mediawiki.org/wiki/Manual:Combating_spam\n"
283 .
"\$wgNoFollowLinks = false;\n\n";
288 if ( array_key_exists(
'wgServer', $this->values ) && $this->values[
'wgServer'] !==
null ) {
289 $serverSetting =
"\n## The protocol and server name to use in fully-qualified URLs\n";
290 $serverSetting .=
"\$wgServer = \"{$this->values['wgServer']}\";";
293 switch ( $this->values[
'_MainCacheType'] ) {
298 $cacheType =
'CACHE_' . strtoupper( $this->values[
'_MainCacheType'] );
302 $cacheType =
'CACHE_NONE';
305 $mcservers = $this->buildMemcachedServerList();
306 if ( file_exists( dirname( __DIR__ ) .
'/PlatformSettings.php' ) ) {
307 $platformSettings =
"\n## Include platform/distribution defaults";
308 $platformSettings .=
"\nrequire_once \"\$IP/includes/PlatformSettings.php\";";
310 $platformSettings =
'';
315# This file was automatically generated by the MediaWiki {$version}
316# installer. If you make manual changes, please keep track in case you
317# need to recreate them later.
319# See includes/DefaultSettings.php for all configurable settings
320# and their default values, but don't forget to make changes in _this_
323# Further documentation for configuration settings may be found at:
324# https://www.mediawiki.org/wiki/Manual:Configuration_settings
326# Protect against web entry
327if ( !defined( 'MEDIAWIKI' ) ) {
332## Uncomment this to disable output compression
333# \$wgDisableOutputCompression = true;
335\$wgSitename = \"{$this->values['wgSitename']}\";
337## The URL base path to the directory containing the wiki;
338## defaults for all runtime URL paths are based off of this.
339## For more information on customizing the URLs
340## (like /w/index.php/Page_title to /wiki/Page_title) please see:
341## https://www.mediawiki.org/wiki/Manual:Short_URL
342\$wgScriptPath = \"{$this->values['wgScriptPath']}\";
345## The URL path to static resources (images, scripts, etc.)
346\$wgResourceBasePath = \$wgScriptPath;
348## The URL paths to the logo. Make sure you change this from the default,
349## or else you'll overwrite your logo when you upgrade!
350\$wgLogos = [ '1x' => \"{$this->values['_Logo']}\" ];
352## UPO means: this is also a user preference option
354\$wgEnableEmail = {$this->values['wgEnableEmail']};
355\$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
357\$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
358\$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
360\$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
361\$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
362\$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
365\$wgDBtype = \"{$this->values['wgDBtype']}\";
366\$wgDBserver = \"{$this->values['wgDBserver']}\";
367\$wgDBname = \"{$this->values['wgDBname']}\";
368\$wgDBuser = \"{$this->values['wgDBuser']}\";
369\$wgDBpassword = \"{$this->values['wgDBpassword']}\";
373# Shared database table
374# This has no effect unless \$wgSharedDB is also set.
375\$wgSharedTables[] = \"actor\";
377## Shared memory settings
378\$wgMainCacheType = $cacheType;
379\$wgMemCachedServers = $mcservers;
381## To enable image uploads, make sure the 'images' directory
382## is writable, then set this to true:
383\$wgEnableUploads = {$this->values['wgEnableUploads']};
384{$magic}\$wgUseImageMagick = true;
385{$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
387# InstantCommons allows wiki to use images from https://commons.wikimedia.org
388\$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
390# Periodically send a pingback to https://www.mediawiki.org/ with basic data
391# about this MediaWiki instance. The Wikimedia Foundation shares this data
392# with MediaWiki developers to help guide future development efforts.
393\$wgPingback = {$this->values['wgPingback']};
395## If you use ImageMagick (or any other shell command) on a
396## Linux server, this will need to be set to the name of an
397## available UTF-8 locale. This should ideally be set to an English
398## language locale so that the behaviour of C library functions will
399## be consistent with typical installations. Use \$wgLanguageCode to
401{$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
403## Set \$wgCacheDirectory to a writable directory on the web server
404## to make your wiki go slightly faster. The directory should not
405## be publicly accessible from the web.
406#\$wgCacheDirectory = \"\$IP/cache\";
408# Site language code, should be one of the list in ./languages/data/Names.php
409\$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
411\$wgSecretKey = \"{$this->values['wgSecretKey']}\";
413# Changing this will log out all existing sessions.
414\$wgAuthenticationTokenVersion = \"{$this->values['wgAuthenticationTokenVersion']}\";
416# Site upgrade key. Must be set to a string (default provided) to turn on the
417# web installer while LocalSettings.php is in place
418\$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\";
420## For attaching licensing metadata to pages, and displaying an
421## appropriate copyright notice / icon. GNU Free Documentation
422## License and Creative Commons licenses are supported so far.
423\$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
424\$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
425\$wgRightsText = \"{$this->values['wgRightsText']}\";
426\$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
428# Path to the GNU diff3 utility. Used for conflict resolution.
429\$wgDiff3 = \"{$this->values['wgDiff3']}\";
431{$groupRights}{$noFollow}## Default skin: you can change the default skin. Use the internal symbolic
432## names, ie 'vector', 'monobook':
433\$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\";
const MW_VERSION
The running version of MediaWiki.
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
Pre-librarized class name for IPUtils.
getDBInstaller( $type=false)
Get an instance of DatabaseInstaller for the specified DB type.
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.