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',
60 'wgLanguageCode',
'wgLocaltimezone',
'wgEnableEmail',
'wgEnableUserEmail',
61 'wgDiff3',
'wgEnotifUserTalk',
'wgEnotifWatchlist',
'wgEmailAuthentication',
62 'wgDBtype',
'wgSecretKey',
'wgRightsUrl',
'wgSitename',
'wgRightsIcon',
63 'wgRightsText',
'_MainCacheType',
'wgEnableUploads',
64 '_MemCachedServers',
'wgDBserver',
'wgDBuser',
65 'wgDBpassword',
'wgUseInstantCommons',
'wgUpgradeKey',
'wgDefaultSkin',
66 'wgMetaNamespace',
'wgAuthenticationTokenVersion',
'wgPingback',
67 '_Logo1x',
'_LogoTagline',
'_LogoWordmark',
'_LogoIcon',
68 '_LogoWordmarkWidth',
'_LogoWordmarkHeight',
69 '_LogoTaglineWidth',
'_LogoTaglineHeight'
77 $unescaped = [
'wgRightsIcon',
'_Caches',
78 '_Logo1x',
'_LogoWordmark',
'_LogoTagline',
'_LogoIcon',
81 'wgEnableEmail',
'wgEnableUserEmail',
'wgEnotifUserTalk',
82 'wgEnotifWatchlist',
'wgEmailAuthentication',
'wgEnableUploads',
'wgUseInstantCommons',
86 foreach ( $confItems as $c ) {
87 $val = $installer->
getVar( $c );
89 if ( in_array( $c, $boolItems ) ) {
93 if ( !in_array( $c, $unescaped ) && $val !==
null ) {
94 $val = self::escapePhpString( $val );
97 $this->values[$c] = $val;
100 $this->dbSettings = $db->getLocalSettings();
101 $this->values[
'wgEmergencyContact'] = $this->values[
'wgPasswordSender'];
110 public function setGroupRights( $group, $rightsArr ) {
111 $this->groupPermissions[$group] = $rightsArr;
121 public static function escapePhpString( $string ) {
122 if ( is_array( $string ) || is_object( $string ) ) {
145 public function getText() {
146 $localSettings = $this->getDefaultText();
148 if ( count( $this->skins ) ) {
151# The following skins were automatically enabled:\n";
153 foreach ( $this->skins as $skinName ) {
154 $localSettings .= $this->generateExtEnableLine(
'skins', $skinName );
157 $localSettings .=
"\n";
160 if ( count( $this->extensions ) ) {
162# Enabled extensions. Most of the extensions are enabled by adding
163# wfLoadExtension( 'ExtensionName' );
164# to LocalSettings.php. Check specific extension documentation for more details.
165# The following extensions were automatically enabled:\n";
167 foreach ( $this->extensions as $extName ) {
168 $localSettings .= $this->generateExtEnableLine(
'extensions', $extName );
171 $localSettings .=
"\n";
175# End of automatically generated settings.
176# Add more configuration options below.\n\n";
178 return $localSettings;
189 private function generateExtEnableLine( $dir, $name ) {
190 if ( $dir ===
'extensions' ) {
191 $jsonFile =
'extension.json';
192 $function =
'wfLoadExtension';
193 } elseif ( $dir ===
'skins' ) {
194 $jsonFile =
'skin.json';
195 $function =
'wfLoadSkin';
197 throw new InvalidArgumentException(
'$dir was not "extensions" or "skins"' );
200 $encName = self::escapePhpString( $name );
202 if ( file_exists(
"{$this->IP}/$dir/$encName/$jsonFile" ) ) {
203 return "$function( '$encName' );\n";
205 return "require_once \"\$IP/$dir/$encName/$encName.php\";\n";
214 public function writeFile( $fileName ) {
215 file_put_contents( $fileName, $this->getText() );
221 protected function buildMemcachedServerList() {
222 $servers = $this->values[
'_MemCachedServers'];
228 $servers = explode(
',', $servers );
230 foreach ( $servers as $srv ) {
235 return rtrim( $ret,
', ' ) .
' ]';
242 protected function getDefaultText() {
243 if ( !$this->values[
'wgImageMagickConvertCommand'] ) {
244 $this->values[
'wgImageMagickConvertCommand'] =
'/usr/bin/convert';
251 if ( $this->values[
'wgMetaNamespace'] !== $this->values[
'wgSitename'] ) {
252 $metaNamespace =
"\$wgMetaNamespace = \"{$this->values['wgMetaNamespace']}\";\n";
257 if ( $this->groupPermissions ) {
258 $groupRights .=
"# The following permissions were set based on your choice in the installer\n";
259 foreach ( $this->groupPermissions as $group => $rightArr ) {
260 $group = self::escapePhpString( $group );
261 foreach ( $rightArr as $right => $perm ) {
262 $right = self::escapePhpString( $right );
263 $groupRights .=
"\$wgGroupPermissions[\"$group\"][\"$right\"] = " .
267 $groupRights .=
"\n";
269 if ( ( isset( $this->groupPermissions[
'*'][
'edit'] ) &&
270 $this->groupPermissions[
'*'][
'edit'] ===
false )
271 && ( isset( $this->groupPermissions[
'*'][
'createaccount'] ) &&
272 $this->groupPermissions[
'*'][
'createaccount'] ===
false )
273 && ( isset( $this->groupPermissions[
'*'][
'read'] ) &&
274 $this->groupPermissions[
'*'][
'read'] !==
false )
276 $noFollow =
"# Set \$wgNoFollowLinks to true if you open up your wiki to editing by\n"
277 .
"# the general public and wish to apply nofollow to external links as a\n"
278 .
"# deterrent to spammers. Nofollow is not a comprehensive anti-spam solution\n"
279 .
"# and open wikis will generally require other anti-spam measures; for more\n"
280 .
"# information, see https://www.mediawiki.org/wiki/Manual:Combating_spam\n"
281 .
"\$wgNoFollowLinks = false;\n\n";
286 if ( array_key_exists(
'wgServer', $this->values ) && $this->values[
'wgServer'] !==
null ) {
287 $serverSetting =
"\n## The protocol and server name to use in fully-qualified URLs\n";
288 $serverSetting .=
"\$wgServer = \"{$this->values['wgServer']}\";";
291 switch ( $this->values[
'_MainCacheType'] ) {
296 $cacheType =
'CACHE_' . strtoupper( $this->values[
'_MainCacheType'] );
300 $cacheType =
'CACHE_NONE';
303 $mcservers = $this->buildMemcachedServerList();
304 if ( file_exists( dirname( __DIR__ ) .
'/PlatformSettings.php' ) ) {
305 $platformSettings =
"\n## Include platform/distribution defaults";
306 $platformSettings .=
"\nrequire_once \"\$IP/includes/PlatformSettings.php\";";
308 $platformSettings =
'';
311 $this->values[
'taglineConfig'] = $this->values[
'_LogoTagline'] ?
"\n\t'tagline' => [
312 \"src\" => \"{$this->values['_LogoTagline']}\",
313 \"width\" => {$this->values['_LogoTaglineWidth']},
314 \"height\" => {$this->values['_LogoTaglineHeight']}
317 $this->values[
'wordmarkConfig'] = $this->values[
'_LogoWordmark'] ?
"\n\t'wordmark' => [
318 \"src\" => \"{$this->values['_LogoWordmark']}\",
319 \"width\" => {$this->values['_LogoWordmarkWidth']},
320 \"height\" => {$this->values['_LogoWordmarkHeight']},
323 $this->values[
'sidebarLogo'] = $this->values[
'_Logo1x'] ?: $this->values[
'_LogoIcon'];
327# This file was automatically generated by the MediaWiki {$version}
328# installer. If you make manual changes, please keep track in case you
329# need to recreate them later.
331# See docs/Configuration.md for all configurable settings
332# and their default values, but don't forget to make changes in _this_
335# Further documentation for configuration settings may be found at:
336# https://www.mediawiki.org/wiki/Manual:Configuration_settings
338# Protect against web entry
339if ( !defined( 'MEDIAWIKI' ) ) {
344## Uncomment this to disable output compression
345# \$wgDisableOutputCompression = true;
347\$wgSitename = \"{$this->values['wgSitename']}\";
349## The URL base path to the directory containing the wiki;
350## defaults for all runtime URL paths are based off of this.
351## For more information on customizing the URLs
352## (like /w/index.php/Page_title to /wiki/Page_title) please see:
353## https://www.mediawiki.org/wiki/Manual:Short_URL
354\$wgScriptPath = \"{$this->values['wgScriptPath']}\";
357## The URL path to static resources (images, scripts, etc.)
358\$wgResourceBasePath = \$wgScriptPath;
360## The URL paths to the logo. Make sure you change this from the default,
361## or else you'll overwrite your logo when you upgrade!
363 '1x' => \"{$this->values['sidebarLogo']}\",{$this->values['wordmarkConfig']}{$this->values['taglineConfig']}
364 'icon' => \"{$this->values['_LogoIcon']}\",
367## UPO means: this is also a user preference option
369\$wgEnableEmail = {$this->values['wgEnableEmail']};
370\$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
372\$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
373\$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
375\$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
376\$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
377\$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
380\$wgDBtype = \"{$this->values['wgDBtype']}\";
381\$wgDBserver = \"{$this->values['wgDBserver']}\";
382\$wgDBname = \"{$this->values['wgDBname']}\";
383\$wgDBuser = \"{$this->values['wgDBuser']}\";
384\$wgDBpassword = \"{$this->values['wgDBpassword']}\";
388# Shared database table
389# This has no effect unless \$wgSharedDB is also set.
390\$wgSharedTables[] = \"actor\";
392## Shared memory settings
393\$wgMainCacheType = $cacheType;
394\$wgMemCachedServers = $mcservers;
396## To enable image uploads, make sure the 'images' directory
397## is writable, then set this to true:
398\$wgEnableUploads = {$this->values['wgEnableUploads']};
399{$magic}\$wgUseImageMagick = true;
400{$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
402# InstantCommons allows wiki to use images from https://commons.wikimedia.org
403\$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
405# Periodically send a pingback to https://www.mediawiki.org/ with basic data
406# about this MediaWiki instance. The Wikimedia Foundation shares this data
407# with MediaWiki developers to help guide future development efforts.
408\$wgPingback = {$this->values['wgPingback']};
410# Site language code, should be one of the list in ./includes/languages/data/Names.php
411\$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
414\$wgLocaltimezone = \"{$this->values['wgLocaltimezone']}\";
416## Set \$wgCacheDirectory to a writable directory on the web server
417## to make your wiki go slightly faster. The directory should not
418## be publicly accessible from the web.
419#\$wgCacheDirectory = \"\$IP/cache\";
421\$wgSecretKey = \"{$this->values['wgSecretKey']}\";
423# Changing this will log out all existing sessions.
424\$wgAuthenticationTokenVersion = \"{$this->values['wgAuthenticationTokenVersion']}\";
426# Site upgrade key. Must be set to a string (default provided) to turn on the
427# web installer while LocalSettings.php is in place
428\$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\";
430## For attaching licensing metadata to pages, and displaying an
431## appropriate copyright notice / icon. GNU Free Documentation
432## License and Creative Commons licenses are supported so far.
433\$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
434\$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
435\$wgRightsText = \"{$this->values['wgRightsText']}\";
436\$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
438# Path to the GNU diff3 utility. Used for conflict resolution.
439\$wgDiff3 = \"{$this->values['wgDiff3']}\";
441{$groupRights}{$noFollow}## Default skin: you can change the default skin. Use the internal symbolic
442## names, e.g. 'vector' or 'monobook':
443\$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.
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
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.