MediaWiki  1.23.14
LocalSettingsGenerator.php
Go to the documentation of this file.
1 <?php
31 
32  protected $extensions = array();
33  protected $values = array();
34  protected $groupPermissions = array();
35  protected $dbSettings = '';
36  protected $safeMode = false;
37 
41  protected $installer;
42 
48  public function __construct( Installer $installer ) {
49  $this->installer = $installer;
50 
51  $this->extensions = $installer->getVar( '_Extensions' );
52 
53  $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) );
54 
55  $confItems = array_merge(
56  array(
57  'wgServer', 'wgScriptPath', 'wgScriptExtension',
58  'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale',
59  'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3',
60  'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication',
61  'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon',
62  'wgRightsText', 'wgMainCacheType', 'wgEnableUploads',
63  'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser',
64  'wgDBpassword', 'wgUseInstantCommons', 'wgUpgradeKey', 'wgDefaultSkin',
65  'wgMetaNamespace', 'wgResourceLoaderMaxQueryLength', 'wgLogo',
66  ),
67  $db->getGlobalNames()
68  );
69 
70  $unescaped = array( 'wgRightsIcon', 'wgLogo' );
71  $boolItems = array(
72  'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk',
73  'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons'
74  );
75 
76  foreach ( $confItems as $c ) {
77  $val = $installer->getVar( $c );
78 
79  if ( in_array( $c, $boolItems ) ) {
80  $val = wfBoolToStr( $val );
81  }
82 
83  if ( !in_array( $c, $unescaped ) && $val !== null ) {
84  $val = self::escapePhpString( $val );
85  }
86 
87  $this->values[$c] = $val;
88  }
89 
90  $this->dbSettings = $db->getLocalSettings();
91  $this->safeMode = $installer->getVar( '_SafeMode' );
92  $this->values['wgEmergencyContact'] = $this->values['wgPasswordSender'];
93  }
94 
101  public function setGroupRights( $group, $rightsArr ) {
102  $this->groupPermissions[$group] = $rightsArr;
103  }
104 
112  public static function escapePhpString( $string ) {
113  if ( is_array( $string ) || is_object( $string ) ) {
114  return false;
115  }
116 
117  return strtr(
118  $string,
119  array(
120  "\n" => "\\n",
121  "\r" => "\\r",
122  "\t" => "\\t",
123  "\\" => "\\\\",
124  "\$" => "\\\$",
125  "\"" => "\\\""
126  )
127  );
128  }
129 
136  public function getText() {
137  $localSettings = $this->getDefaultText();
138 
139  if ( count( $this->extensions ) ) {
140  $localSettings .= "
141 # Enabled Extensions. Most extensions are enabled by including the base extension file here
142 # but check specific extension documentation for more details
143 # The following extensions were automatically enabled:\n";
144 
145  foreach ( $this->extensions as $extName ) {
146  $encExtName = self::escapePhpString( $extName );
147  $localSettings .= "require_once \"\$IP/extensions/$encExtName/$encExtName.php\";\n";
148  }
149  }
150 
151  $localSettings .= "\n\n# End of automatically generated settings.
152 # Add more configuration options below.\n\n";
153 
154  return $localSettings;
155  }
156 
162  public function writeFile( $fileName ) {
163  file_put_contents( $fileName, $this->getText() );
164  }
165 
169  protected function buildMemcachedServerList() {
170  $servers = $this->values['_MemCachedServers'];
171 
172  if ( !$servers ) {
173  return 'array()';
174  } else {
175  $ret = 'array( ';
176  $servers = explode( ',', $servers );
177 
178  foreach ( $servers as $srv ) {
179  $srv = trim( $srv );
180  $ret .= "'$srv', ";
181  }
182 
183  return rtrim( $ret, ', ' ) . ' )';
184  }
185  }
186 
190  protected function getDefaultText() {
191  if ( !$this->values['wgImageMagickConvertCommand'] ) {
192  $this->values['wgImageMagickConvertCommand'] = '/usr/bin/convert';
193  $magic = '#';
194  } else {
195  $magic = '';
196  }
197 
198  if ( !$this->values['wgShellLocale'] ) {
199  $this->values['wgShellLocale'] = 'en_US.UTF-8';
200  $locale = '#';
201  } else {
202  $locale = '';
203  }
204 
205  //$rightsUrl = $this->values['wgRightsUrl'] ? '' : '#'; // @todo FIXME: I'm unused!
206  $hashedUploads = $this->safeMode ? '' : '#';
207  $metaNamespace = '';
208  if ( $this->values['wgMetaNamespace'] !== $this->values['wgSitename'] ) {
209  $metaNamespace = "\$wgMetaNamespace = \"{$this->values['wgMetaNamespace']}\";\n";
210  }
211 
212  $groupRights = '';
213  $noFollow = '';
214  if ( $this->groupPermissions ) {
215  $groupRights .= "# The following permissions were set based on your choice in the installer\n";
216  foreach ( $this->groupPermissions as $group => $rightArr ) {
217  $group = self::escapePhpString( $group );
218  foreach ( $rightArr as $right => $perm ) {
220  $groupRights .= "\$wgGroupPermissions['$group']['$right'] = " .
221  wfBoolToStr( $perm ) . ";\n";
222  }
223  }
224  if ( ( isset( $this->groupPermissions['*']['edit'] ) &&
225  $this->groupPermissions['*']['edit'] === false )
226  && ( isset( $this->groupPermissions['*']['createaccount'] ) &&
227  $this->groupPermissions['*']['createaccount'] === false )
228  && ( isset( $this->groupPermissions['*']['read'] ) &&
229  $this->groupPermissions['*']['read'] !== false )
230  ) {
231  $noFollow = "\n# Set \$wgNoFollowLinks to true if you open up your wiki to editing by\n"
232  . "# the general public and wish to apply nofollow to external links as a\n"
233  . "# deterrent to spammers. Nofollow is not a comprehensive anti-spam solution\n"
234  . "# and open wikis will generally require other anti-spam measures; for more\n"
235  . "# information, see https://www.mediawiki.org/wiki/Manual:Combating_spam\n"
236  . "\$wgNoFollowLinks = false;";
237  }
238  }
239 
240  $serverSetting = "";
241  if ( array_key_exists( 'wgServer', $this->values ) && $this->values['wgServer'] !== null ) {
242  $serverSetting = "\n## The protocol and server name to use in fully-qualified URLs\n";
243  $serverSetting .= "\$wgServer = \"{$this->values['wgServer']}\";\n";
244  }
245 
246  switch ( $this->values['wgMainCacheType'] ) {
247  case 'anything':
248  case 'db':
249  case 'memcached':
250  case 'accel':
251  $cacheType = 'CACHE_' . strtoupper( $this->values['wgMainCacheType'] );
252  break;
253  case 'none':
254  default:
255  $cacheType = 'CACHE_NONE';
256  }
257 
258  $mcservers = $this->buildMemcachedServerList();
259 
260  return "<?php
261 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']}
262 # installer. If you make manual changes, please keep track in case you
263 # need to recreate them later.
264 #
265 # See includes/DefaultSettings.php for all configurable settings
266 # and their default values, but don't forget to make changes in _this_
267 # file, not there.
268 #
269 # Further documentation for configuration settings may be found at:
270 # https://www.mediawiki.org/wiki/Manual:Configuration_settings
271 
272 # Protect against web entry
273 if ( !defined( 'MEDIAWIKI' ) ) {
274  exit;
275 }
276 
277 ## Uncomment this to disable output compression
278 # \$wgDisableOutputCompression = true;
279 
280 \$wgSitename = \"{$this->values['wgSitename']}\";
281 {$metaNamespace}
282 ## The URL base path to the directory containing the wiki;
283 ## defaults for all runtime URL paths are based off of this.
284 ## For more information on customizing the URLs
285 ## (like /w/index.php/Page_title to /wiki/Page_title) please see:
286 ## https://www.mediawiki.org/wiki/Manual:Short_URL
287 \$wgScriptPath = \"{$this->values['wgScriptPath']}\";
288 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\";
289 ${serverSetting}
290 ## The relative URL path to the skins directory
291 \$wgStylePath = \"\$wgScriptPath/skins\";
292 
293 ## The relative URL path to the logo. Make sure you change this from the default,
294 ## or else you'll overwrite your logo when you upgrade!
295 \$wgLogo = \"{$this->values['wgLogo']}\";
296 
297 ## UPO means: this is also a user preference option
298 
299 \$wgEnableEmail = {$this->values['wgEnableEmail']};
300 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO
301 
302 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\";
303 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\";
304 
305 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO
306 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO
307 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']};
308 
309 ## Database settings
310 \$wgDBtype = \"{$this->values['wgDBtype']}\";
311 \$wgDBserver = \"{$this->values['wgDBserver']}\";
312 \$wgDBname = \"{$this->values['wgDBname']}\";
313 \$wgDBuser = \"{$this->values['wgDBuser']}\";
314 \$wgDBpassword = \"{$this->values['wgDBpassword']}\";
315 
316 {$this->dbSettings}
317 
318 ## Shared memory settings
319 \$wgMainCacheType = $cacheType;
320 \$wgMemCachedServers = $mcservers;
321 
322 ## To enable image uploads, make sure the 'images' directory
323 ## is writable, then set this to true:
324 \$wgEnableUploads = {$this->values['wgEnableUploads']};
325 {$magic}\$wgUseImageMagick = true;
326 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\";
327 
328 # InstantCommons allows wiki to use images from http://commons.wikimedia.org
329 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']};
330 
331 ## If you use ImageMagick (or any other shell command) on a
332 ## Linux server, this will need to be set to the name of an
333 ## available UTF-8 locale
334 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\";
335 
336 ## If you want to use image uploads under safe mode,
337 ## create the directories images/archive, images/thumb and
338 ## images/temp, and make them all writable. Then uncomment
339 ## this, if it's not already uncommented:
340 {$hashedUploads}\$wgHashedUploadDirectory = false;
341 
342 ## Set \$wgCacheDirectory to a writable directory on the web server
343 ## to make your wiki go slightly faster. The directory should not
344 ## be publically accessible from the web.
345 #\$wgCacheDirectory = \"\$IP/cache\";
346 
347 # Site language code, should be one of the list in ./languages/Names.php
348 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\";
349 
350 \$wgSecretKey = \"{$this->values['wgSecretKey']}\";
351 
352 # Site upgrade key. Must be set to a string (default provided) to turn on the
353 # web installer while LocalSettings.php is in place
354 \$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\";
355 
356 ## Default skin: you can change the default skin. Use the internal symbolic
357 ## names, ie 'cologneblue', 'monobook', 'vector':
358 \$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\";
359 
360 ## For attaching licensing metadata to pages, and displaying an
361 ## appropriate copyright notice / icon. GNU Free Documentation
362 ## License and Creative Commons licenses are supported so far.
363 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
364 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\";
365 \$wgRightsText = \"{$this->values['wgRightsText']}\";
366 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\";
367 
368 # Path to the GNU diff3 utility. Used for conflict resolution.
369 \$wgDiff3 = \"{$this->values['wgDiff3']}\";
370 
371 {$groupRights}{$noFollow}";
372  }
373 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LocalSettingsGenerator\$dbSettings
$dbSettings
Definition: LocalSettingsGenerator.php:35
LocalSettingsGenerator\writeFile
writeFile( $fileName)
Write the generated LocalSettings to a file.
Definition: LocalSettingsGenerator.php:161
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
$right
return false if a UserGetRights hook might remove the named right $right
Definition: hooks.txt:2809
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
Definition: GlobalFunctions.php:3835
LocalSettingsGenerator\buildMemcachedServerList
buildMemcachedServerList()
Definition: LocalSettingsGenerator.php:168
LocalSettingsGenerator\$installer
Installer $installer
Definition: LocalSettingsGenerator.php:40
LocalSettingsGenerator\$safeMode
$safeMode
Definition: LocalSettingsGenerator.php:36
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
LocalSettingsGenerator\__construct
__construct(Installer $installer)
Constructor.
Definition: LocalSettingsGenerator.php:47
LocalSettingsGenerator\getText
getText()
Return the full text of the generated LocalSettings.php file, including the extensions.
Definition: LocalSettingsGenerator.php:135
Installer\getVar
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
Definition: Installer.php:457
Installer\getDBInstaller
getDBInstaller( $type=false)
Get an instance of DatabaseInstaller for the specified DB type.
Definition: Installer.php:481
LocalSettingsGenerator\$extensions
$extensions
Definition: LocalSettingsGenerator.php:32
LocalSettingsGenerator
Class for generating LocalSettings.php file.
Definition: LocalSettingsGenerator.php:30
LocalSettingsGenerator\$groupPermissions
$groupPermissions
Definition: LocalSettingsGenerator.php:34
LocalSettingsGenerator\getDefaultText
getDefaultText()
Definition: LocalSettingsGenerator.php:189
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LocalSettingsGenerator\$values
$values
Definition: LocalSettingsGenerator.php:33
LocalSettingsGenerator\escapePhpString
static escapePhpString( $string)
Returns the escaped version of a string of php code.
Definition: LocalSettingsGenerator.php:111
Installer
Base installer class.
Definition: Installer.php:39
LocalSettingsGenerator\setGroupRights
setGroupRights( $group, $rightsArr)
For $wgGroupPermissions, set a given ['group']['permission'] value.
Definition: LocalSettingsGenerator.php:100
values
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition: hooks.txt:177