MediaWiki
REL1_22
|
00001 <?php 00030 class LocalSettingsGenerator { 00031 00032 protected $extensions = array(); 00033 protected $values = array(); 00034 protected $groupPermissions = array(); 00035 protected $dbSettings = ''; 00036 protected $safeMode = false; 00037 00041 protected $installer; 00042 00048 public function __construct( Installer $installer ) { 00049 $this->installer = $installer; 00050 00051 $this->extensions = $installer->getVar( '_Extensions' ); 00052 00053 $db = $installer->getDBInstaller( $installer->getVar( 'wgDBtype' ) ); 00054 00055 $confItems = array_merge( 00056 array( 00057 'wgServer', 'wgScriptPath', 'wgScriptExtension', 00058 'wgPasswordSender', 'wgImageMagickConvertCommand', 'wgShellLocale', 00059 'wgLanguageCode', 'wgEnableEmail', 'wgEnableUserEmail', 'wgDiff3', 00060 'wgEnotifUserTalk', 'wgEnotifWatchlist', 'wgEmailAuthentication', 00061 'wgDBtype', 'wgSecretKey', 'wgRightsUrl', 'wgSitename', 'wgRightsIcon', 00062 'wgRightsText', 'wgMainCacheType', 'wgEnableUploads', 00063 'wgMainCacheType', '_MemCachedServers', 'wgDBserver', 'wgDBuser', 00064 'wgDBpassword', 'wgUseInstantCommons', 'wgUpgradeKey', 'wgDefaultSkin', 00065 'wgMetaNamespace', 'wgResourceLoaderMaxQueryLength', 'wgLogo', 00066 ), 00067 $db->getGlobalNames() 00068 ); 00069 00070 $unescaped = array( 'wgRightsIcon', 'wgLogo' ); 00071 $boolItems = array( 00072 'wgEnableEmail', 'wgEnableUserEmail', 'wgEnotifUserTalk', 00073 'wgEnotifWatchlist', 'wgEmailAuthentication', 'wgEnableUploads', 'wgUseInstantCommons' 00074 ); 00075 00076 foreach ( $confItems as $c ) { 00077 $val = $installer->getVar( $c ); 00078 00079 if ( in_array( $c, $boolItems ) ) { 00080 $val = wfBoolToStr( $val ); 00081 } 00082 00083 if ( !in_array( $c, $unescaped ) && $val !== null ) { 00084 $val = self::escapePhpString( $val ); 00085 } 00086 00087 $this->values[$c] = $val; 00088 } 00089 00090 $this->dbSettings = $db->getLocalSettings(); 00091 $this->safeMode = $installer->getVar( '_SafeMode' ); 00092 $this->values['wgEmergencyContact'] = $this->values['wgPasswordSender']; 00093 } 00094 00101 public function setGroupRights( $group, $rightsArr ) { 00102 $this->groupPermissions[$group] = $rightsArr; 00103 } 00104 00112 public static function escapePhpString( $string ) { 00113 if ( is_array( $string ) || is_object( $string ) ) { 00114 return false; 00115 } 00116 00117 return strtr( 00118 $string, 00119 array( 00120 "\n" => "\\n", 00121 "\r" => "\\r", 00122 "\t" => "\\t", 00123 "\\" => "\\\\", 00124 "\$" => "\\\$", 00125 "\"" => "\\\"" 00126 ) 00127 ); 00128 } 00129 00136 public function getText() { 00137 $localSettings = $this->getDefaultText(); 00138 00139 if ( count( $this->extensions ) ) { 00140 $extensions = $this->installer->findExtensions(); 00141 $localSettings .= " 00142 # Enabled Extensions. Most extensions are enabled by including the base extension file here 00143 # but check specific extension documentation for more details 00144 # The following extensions were automatically enabled:\n"; 00145 00146 $ip = $this->installer->getVar( 'IP' ); 00147 foreach ( $this->extensions as $ext) { 00148 $path = str_replace( $ip, '', $extensions[$ext]['path'] ); 00149 $prefix = ''; 00150 if ( $path !== $extensions[$ext]['path'] ) { 00151 $prefix = '$IP'; 00152 } 00153 $path = $prefix . self::escapePhpString( $path ); 00154 $localSettings .= "require_once \"$path\";\n"; 00155 } 00156 } 00157 00158 $localSettings .= "\n\n# End of automatically generated settings. 00159 # Add more configuration options below.\n\n"; 00160 00161 return $localSettings; 00162 } 00163 00169 public function writeFile( $fileName ) { 00170 file_put_contents( $fileName, $this->getText() ); 00171 } 00172 00176 protected function buildMemcachedServerList() { 00177 $servers = $this->values['_MemCachedServers']; 00178 00179 if ( !$servers ) { 00180 return 'array()'; 00181 } else { 00182 $ret = 'array( '; 00183 $servers = explode( ',', $servers ); 00184 00185 foreach ( $servers as $srv ) { 00186 $srv = trim( $srv ); 00187 $ret .= "'$srv', "; 00188 } 00189 00190 return rtrim( $ret, ', ' ) . ' )'; 00191 } 00192 } 00193 00197 protected function getDefaultText() { 00198 if ( !$this->values['wgImageMagickConvertCommand'] ) { 00199 $this->values['wgImageMagickConvertCommand'] = '/usr/bin/convert'; 00200 $magic = '#'; 00201 } else { 00202 $magic = ''; 00203 } 00204 00205 if ( !$this->values['wgShellLocale'] ) { 00206 $this->values['wgShellLocale'] = 'en_US.UTF-8'; 00207 $locale = '#'; 00208 } else { 00209 $locale = ''; 00210 } 00211 00212 //$rightsUrl = $this->values['wgRightsUrl'] ? '' : '#'; // @todo FIXME: I'm unused! 00213 $hashedUploads = $this->safeMode ? '' : '#'; 00214 $metaNamespace = ''; 00215 if ( $this->values['wgMetaNamespace'] !== $this->values['wgSitename'] ) { 00216 $metaNamespace = "\$wgMetaNamespace = \"{$this->values['wgMetaNamespace']}\";\n"; 00217 } 00218 00219 $groupRights = ''; 00220 if ( $this->groupPermissions ) { 00221 $groupRights .= "# The following permissions were set based on your choice in the installer\n"; 00222 foreach ( $this->groupPermissions as $group => $rightArr ) { 00223 $group = self::escapePhpString( $group ); 00224 foreach ( $rightArr as $right => $perm ) { 00225 $right = self::escapePhpString( $right ); 00226 $groupRights .= "\$wgGroupPermissions['$group']['$right'] = " . 00227 wfBoolToStr( $perm ) . ";\n"; 00228 } 00229 } 00230 } 00231 00232 $wgServerSetting = ""; 00233 if ( array_key_exists( 'wgServer', $this->values ) && $this->values['wgServer'] !== null ) { 00234 $wgServerSetting = "\n## The protocol and server name to use in fully-qualified URLs\n"; 00235 $wgServerSetting .= "\$wgServer = \"{$this->values['wgServer']}\";\n"; 00236 } 00237 00238 switch ( $this->values['wgMainCacheType'] ) { 00239 case 'anything': 00240 case 'db': 00241 case 'memcached': 00242 case 'accel': 00243 $cacheType = 'CACHE_' . strtoupper( $this->values['wgMainCacheType'] ); 00244 break; 00245 case 'none': 00246 default: 00247 $cacheType = 'CACHE_NONE'; 00248 } 00249 00250 $mcservers = $this->buildMemcachedServerList(); 00251 00252 return "<?php 00253 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']} 00254 # installer. If you make manual changes, please keep track in case you 00255 # need to recreate them later. 00256 # 00257 # See includes/DefaultSettings.php for all configurable settings 00258 # and their default values, but don't forget to make changes in _this_ 00259 # file, not there. 00260 # 00261 # Further documentation for configuration settings may be found at: 00262 # http://www.mediawiki.org/wiki/Manual:Configuration_settings 00263 00264 # Protect against web entry 00265 if ( !defined( 'MEDIAWIKI' ) ) { 00266 exit; 00267 } 00268 00269 ## Uncomment this to disable output compression 00270 # \$wgDisableOutputCompression = true; 00271 00272 \$wgSitename = \"{$this->values['wgSitename']}\"; 00273 {$metaNamespace} 00274 ## The URL base path to the directory containing the wiki; 00275 ## defaults for all runtime URL paths are based off of this. 00276 ## For more information on customizing the URLs 00277 ## (like /w/index.php/Page_title to /wiki/Page_title) please see: 00278 ## http://www.mediawiki.org/wiki/Manual:Short_URL 00279 \$wgScriptPath = \"{$this->values['wgScriptPath']}\"; 00280 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\"; 00281 ${wgServerSetting} 00282 ## The relative URL path to the skins directory 00283 \$wgStylePath = \"\$wgScriptPath/skins\"; 00284 00285 ## The relative URL path to the logo. Make sure you change this from the default, 00286 ## or else you'll overwrite your logo when you upgrade! 00287 \$wgLogo = \"{$this->values['wgLogo']}\"; 00288 00289 ## UPO means: this is also a user preference option 00290 00291 \$wgEnableEmail = {$this->values['wgEnableEmail']}; 00292 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO 00293 00294 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\"; 00295 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\"; 00296 00297 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO 00298 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO 00299 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']}; 00300 00301 ## Database settings 00302 \$wgDBtype = \"{$this->values['wgDBtype']}\"; 00303 \$wgDBserver = \"{$this->values['wgDBserver']}\"; 00304 \$wgDBname = \"{$this->values['wgDBname']}\"; 00305 \$wgDBuser = \"{$this->values['wgDBuser']}\"; 00306 \$wgDBpassword = \"{$this->values['wgDBpassword']}\"; 00307 00308 {$this->dbSettings} 00309 00310 ## Shared memory settings 00311 \$wgMainCacheType = $cacheType; 00312 \$wgMemCachedServers = $mcservers; 00313 00314 ## To enable image uploads, make sure the 'images' directory 00315 ## is writable, then set this to true: 00316 \$wgEnableUploads = {$this->values['wgEnableUploads']}; 00317 {$magic}\$wgUseImageMagick = true; 00318 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\"; 00319 00320 # InstantCommons allows wiki to use images from http://commons.wikimedia.org 00321 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']}; 00322 00323 ## If you use ImageMagick (or any other shell command) on a 00324 ## Linux server, this will need to be set to the name of an 00325 ## available UTF-8 locale 00326 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\"; 00327 00328 ## If you want to use image uploads under safe mode, 00329 ## create the directories images/archive, images/thumb and 00330 ## images/temp, and make them all writable. Then uncomment 00331 ## this, if it's not already uncommented: 00332 {$hashedUploads}\$wgHashedUploadDirectory = false; 00333 00334 ## Set \$wgCacheDirectory to a writable directory on the web server 00335 ## to make your wiki go slightly faster. The directory should not 00336 ## be publically accessible from the web. 00337 #\$wgCacheDirectory = \"\$IP/cache\"; 00338 00339 # Site language code, should be one of the list in ./languages/Names.php 00340 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\"; 00341 00342 \$wgSecretKey = \"{$this->values['wgSecretKey']}\"; 00343 00344 # Site upgrade key. Must be set to a string (default provided) to turn on the 00345 # web installer while LocalSettings.php is in place 00346 \$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\"; 00347 00348 ## Default skin: you can change the default skin. Use the internal symbolic 00349 ## names, ie 'cologneblue', 'monobook', 'vector': 00350 \$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\"; 00351 00352 ## For attaching licensing metadata to pages, and displaying an 00353 ## appropriate copyright notice / icon. GNU Free Documentation 00354 ## License and Creative Commons licenses are supported so far. 00355 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright 00356 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\"; 00357 \$wgRightsText = \"{$this->values['wgRightsText']}\"; 00358 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\"; 00359 00360 # Path to the GNU diff3 utility. Used for conflict resolution. 00361 \$wgDiff3 = \"{$this->values['wgDiff3']}\"; 00362 00363 {$groupRights}"; 00364 } 00365 }