23use InvalidArgumentException;
31class LocalSettingsGenerator {
33 protected $extensions = [];
34 protected $skins = [];
35 protected $values = [];
36 protected $groupPermissions = [];
37 protected $dbSettings =
'';
48 public function __construct( Installer $installer ) {
49 $this->installer = $installer;
51 $this->extensions = $installer->getVar(
'_Extensions' );
52 $this->skins = $installer->getVar(
'_Skins' );
53 $this->IP = $installer->getVar(
'IP' );
55 $db = $installer->getDBInstaller( $installer->getVar(
'wgDBtype' ) );
57 $confItems = array_merge(
59 'wgServer',
'wgScriptPath',
60 'wgPasswordSender',
'wgImageMagickConvertCommand',
61 'wgLanguageCode',
'wgLocaltimezone',
'wgEnableEmail',
'wgEnableUserEmail',
62 'wgDiff3',
'wgEnotifUserTalk',
'wgEnotifWatchlist',
'wgEmailAuthentication',
63 'wgDBtype',
'wgSecretKey',
'wgRightsUrl',
'wgSitename',
'wgRightsIcon',
64 'wgRightsText',
'_MainCacheType',
'wgEnableUploads',
65 '_MemCachedServers',
'wgDBserver',
'wgDBuser',
66 'wgDBpassword',
'wgUseInstantCommons',
'wgUpgradeKey',
'wgDefaultSkin',
67 'wgMetaNamespace',
'wgAuthenticationTokenVersion',
'wgPingback',
68 '_Logo1x',
'_LogoTagline',
'_LogoWordmark',
'_LogoIcon',
69 '_LogoWordmarkWidth',
'_LogoWordmarkHeight',
70 '_LogoTaglineWidth',
'_LogoTaglineHeight',
'_WithDevelopmentSettings'
78 $unescaped = [
'wgRightsIcon',
'_Caches',
79 '_Logo1x',
'_LogoWordmark',
'_LogoTagline',
'_LogoIcon',
82 'wgEnableEmail',
'wgEnableUserEmail',
'wgEnotifUserTalk',
83 'wgEnotifWatchlist',
'wgEmailAuthentication',
'wgEnableUploads',
'wgUseInstantCommons',
87 foreach ( $confItems as $c ) {
88 $val = $installer->getVar( $c );
90 if ( in_array( $c, $boolItems ) ) {
94 if ( !in_array( $c, $unescaped ) && $val !==
null ) {
95 $val = self::escapePhpString( $val );
98 $this->values[$c] = $val;
101 $this->dbSettings = $db->getLocalSettings();
102 $this->values[
'wgEmergencyContact'] = $this->values[
'wgPasswordSender'];
111 public function setGroupRights( $group, $rightsArr ) {
112 $this->groupPermissions[$group] = $rightsArr;
122 public static function escapePhpString( $string ) {
123 if ( is_array( $string ) || is_object( $string ) ) {
146 public function getText() {
147 $localSettings = $this->getDefaultText();
149 if ( count( $this->skins ) ) {
152# The following skins were automatically enabled:\n";
154 foreach ( $this->skins as $skinName ) {
155 $localSettings .= $this->generateExtEnableLine(
'skins', $skinName );
158 $localSettings .=
"\n";
161 if ( count( $this->extensions ) ) {
163# Enabled extensions. Most of the extensions are enabled by adding
164# wfLoadExtension( 'ExtensionName' );
165# to LocalSettings.php. Check specific extension documentation for more details.
166# The following extensions were automatically enabled:\n";
168 foreach ( $this->extensions as $extName ) {
169 $localSettings .= $this->generateExtEnableLine(
'extensions', $extName );
172 $localSettings .=
"\n";
176# End of automatically generated settings.
177# Add more configuration options below.\n\n";
179 return $localSettings;
190 private function generateExtEnableLine( $dir, $name ) {
191 if ( $dir ===
'extensions' ) {
192 $jsonFile =
'extension.json';
193 $function =
'wfLoadExtension';
194 } elseif ( $dir ===
'skins' ) {
195 $jsonFile =
'skin.json';
196 $function =
'wfLoadSkin';
198 throw new InvalidArgumentException(
'$dir was not "extensions" or "skins"' );
201 $encName = self::escapePhpString( $name );
203 if ( file_exists(
"{$this->IP}/$dir/$encName/$jsonFile" ) ) {
204 return "$function( '$encName' );\n";
206 return "require_once \"\$IP/$dir/$encName/$encName.php\";\n";
215 public function writeFile( $fileName ) {
216 file_put_contents( $fileName, $this->getText() );
222 protected function buildMemcachedServerList() {
223 $servers = $this->values[
'_MemCachedServers'];
229 $servers = explode(
',', $servers );
231 foreach ( $servers as $srv ) {
236 return rtrim( $ret,
', ' ) .
' ]';
243 protected function getDefaultText() {
244 if ( !$this->values[
'wgImageMagickConvertCommand'] ) {
245 $this->values[
'wgImageMagickConvertCommand'] =
'/usr/bin/convert';
252 if ( $this->values[
'wgMetaNamespace'] !== $this->values[
'wgSitename'] ) {
253 $metaNamespace =
"\$wgMetaNamespace = '{$this->values['wgMetaNamespace']}';\n";
258 if ( $this->groupPermissions ) {
259 $groupRights .=
"# The following permissions were set based on your choice in the installer\n";
260 foreach ( $this->groupPermissions as $group => $rightArr ) {
261 $group = self::escapePhpString( $group );
262 foreach ( $rightArr as $right => $perm ) {
263 $right = self::escapePhpString( $right );
264 $groupRights .=
"\$wgGroupPermissions['$group']['$right'] = " .
268 $groupRights .=
"\n";
270 if ( ( isset( $this->groupPermissions[
'*'][
'edit'] ) &&
271 $this->groupPermissions[
'*'][
'edit'] ===
false )
272 && ( isset( $this->groupPermissions[
'*'][
'createaccount'] ) &&
273 $this->groupPermissions[
'*'][
'createaccount'] ===
false )
274 && ( isset( $this->groupPermissions[
'*'][
'read'] ) &&
275 $this->groupPermissions[
'*'][
'read'] !==
false )
277 $noFollow =
"# Set \$wgNoFollowLinks to true if you open up your wiki to editing by\n"
278 .
"# the general public and wish to apply nofollow to external links as a\n"
279 .
"# deterrent to spammers. Nofollow is not a comprehensive anti-spam solution\n"
280 .
"# and open wikis will generally require other anti-spam measures; for more\n"
281 .
"# information, see https://www.mediawiki.org/wiki/Manual:Combating_spam\n"
282 .
"\$wgNoFollowLinks = false;\n\n";
287 if ( array_key_exists(
'wgServer', $this->values ) && $this->values[
'wgServer'] !==
null ) {
288 $serverSetting =
"\n## The protocol and server name to use in fully-qualified URLs\n";
289 $serverSetting .=
"\$wgServer = '{$this->values['wgServer']}';";
292 switch ( $this->values[
'_MainCacheType'] ) {
297 $cacheType =
'CACHE_' . strtoupper( $this->values[
'_MainCacheType'] );
301 $cacheType =
'CACHE_NONE';
304 $mcservers = $this->buildMemcachedServerList();
305 if ( file_exists( dirname( __DIR__ ) .
'/PlatformSettings.php' ) ) {
306 $platformSettings =
"\n## Include platform/distribution defaults";
307 $platformSettings .=
"\nrequire_once \"\$IP/includes/PlatformSettings.php\";";
309 $platformSettings =
'';
312 $developmentSettings =
'';
313 if ( isset( $this->values[
'_WithDevelopmentSettings'] ) && $this->values[
'_WithDevelopmentSettings'] ) {
314 $developmentSettings =
"\n## Include DevelopmentSettings.php";
315 $developmentSettings .=
"\nrequire_once \"\$IP/includes/DevelopmentSettings.php\";";
318 $this->values[
'taglineConfig'] = $this->values[
'_LogoTagline'] ?
"\n\t'tagline' => [
319 \"src\" => \"{$this->values['_LogoTagline']}\",
320 \"width\" => {$this->values['_LogoTaglineWidth']},
321 \"height\" => {$this->values['_LogoTaglineHeight']}
324 $this->values[
'wordmarkConfig'] = $this->values[
'_LogoWordmark'] ?
"\n\t'wordmark' => [
325 \"src\" => \"{$this->values['_LogoWordmark']}\",
326 \"width\" => {$this->values['_LogoWordmarkWidth']},
327 \"height\" => {$this->values['_LogoWordmarkHeight']},
330 $this->values[
'sidebarLogo'] = $this->values[
'_Logo1x'] ?: $this->values[
'_LogoIcon'];
334# This file was automatically generated by the MediaWiki {$version}
335# installer. If you make manual changes, please keep track in case you
336# need to recreate them later.
338# See includes/MainConfigSchema.php for all configurable settings
339# and their default values, but don't forget to make changes in _this_
342# Further documentation for configuration settings may be found at:
343# https://www.mediawiki.org/wiki/Manual:Configuration_settings
345# Protect against web entry
346if ( !defined( 'MEDIAWIKI' ) ) {
349{$developmentSettings}
353## Uncomment this to disable output compression
354# \$wgDisableOutputCompression = true;
356\$wgSitename = '{$this->values['wgSitename']}';
358## The URL base path to the directory containing the wiki;
359## defaults for all runtime URL paths are based off of this.
360## For more information on customizing the URLs
361## (like /w/index.php/Page_title to /wiki/Page_title) please see:
362## https://www.mediawiki.org/wiki/Manual:Short_URL
363\$wgScriptPath = '{$this->values['wgScriptPath']}';
366## The URL path to static resources (images, scripts, etc.)
367\$wgResourceBasePath = \$wgScriptPath;
369## The URL paths to the logo. Make sure you change this from the default,
370## or else you'll overwrite your logo when you upgrade!
372 '1x' => \"{$this->values['sidebarLogo']}\",{$this->values['wordmarkConfig']}{$this->values['taglineConfig']}
373 'icon' => \"{$this->values['_LogoIcon']}\",
376## UPO means: this is also a user preference option
378\$wgEnableEmail = {$this->values['wgEnableEmail']};
379\$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
381\$wgEmergencyContact = '{$this->values['wgEmergencyContact']}';
382\$wgPasswordSender = '{$this->values['wgPasswordSender']}';
384\$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
385\$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
386\$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
389\$wgDBtype = '{$this->values['wgDBtype']}';
390\$wgDBserver = '{$this->values['wgDBserver']}';
391\$wgDBname = '{$this->values['wgDBname']}';
392\$wgDBuser = '{$this->values['wgDBuser']}';
393\$wgDBpassword = '{$this->values['wgDBpassword']}';
397# Shared database table
398# This has no effect unless \$wgSharedDB is also set.
399\$wgSharedTables[] = \"actor\";
401## Shared memory settings
402\$wgMainCacheType = $cacheType;
403\$wgMemCachedServers = $mcservers;
405## To enable image uploads, make sure the 'images' directory
406## is writable, then set this to true:
407\$wgEnableUploads = {$this->values['wgEnableUploads']};
408{$magic}\$wgUseImageMagick = true;
409{$magic}\$wgImageMagickConvertCommand = '{$this->values['wgImageMagickConvertCommand']}';
411# InstantCommons allows wiki to use images from https://commons.wikimedia.org
412\$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
414# Periodically send a pingback to https://www.mediawiki.org/ with basic data
415# about this MediaWiki instance. The Wikimedia Foundation shares this data
416# with MediaWiki developers to help guide future development efforts.
417\$wgPingback = {$this->values['wgPingback']};
419# Site language code, should be one of the list in ./includes/languages/data/Names.php
420\$wgLanguageCode = '{$this->values['wgLanguageCode']}';
423\$wgLocaltimezone = '{$this->values['wgLocaltimezone']}';
425## Set \$wgCacheDirectory to a writable directory on the web server
426## to make your wiki go slightly faster. The directory should not
427## be publicly accessible from the web.
428#\$wgCacheDirectory = \"\$IP/cache\";
430\$wgSecretKey = '{$this->values['wgSecretKey']}';
432# Changing this will log out all existing sessions.
433\$wgAuthenticationTokenVersion = '{$this->values['wgAuthenticationTokenVersion']}';
435# Site upgrade key. Must be set to a string (default provided) to turn on the
436# web installer while LocalSettings.php is in place
437\$wgUpgradeKey = '{$this->values['wgUpgradeKey']}';
439## For attaching licensing metadata to pages, and displaying an
440## appropriate copyright notice / icon. GNU Free Documentation
441## License and Creative Commons licenses are supported so far.
442\$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
443\$wgRightsUrl = '{$this->values['wgRightsUrl']}';
444\$wgRightsText = '{$this->values['wgRightsText']}';
445\$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
447# Path to the GNU diff3 utility. Used for conflict resolution.
448\$wgDiff3 = '{$this->values['wgDiff3']}';
450{$groupRights}{$noFollow}## Default skin: you can change the default skin. Use the internal symbolic
451## names, e.g. 'vector' or 'monobook':
452\$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.