MediaWiki
REL1_20
|
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' 00066 ), 00067 $db->getGlobalNames() 00068 ); 00069 00070 $unescaped = array( 'wgRightsIcon' ); 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 ) ) { 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 $localSettings .= " 00141 # Enabled Extensions. Most extensions are enabled by including the base extension file here 00142 # but check specific extension documentation for more details 00143 # The following extensions were automatically enabled:\n"; 00144 00145 foreach( $this->extensions as $extName ) { 00146 $encExtName = self::escapePhpString( $extName ); 00147 $localSettings .= "require_once( \"\$IP/extensions/$encExtName/$encExtName.php\" );\n"; 00148 } 00149 } 00150 00151 $localSettings .= "\n\n# End of automatically generated settings. 00152 # Add more configuration options below.\n\n"; 00153 00154 return $localSettings; 00155 } 00156 00162 public function writeFile( $fileName ) { 00163 file_put_contents( $fileName, $this->getText() ); 00164 } 00165 00169 protected function buildMemcachedServerList() { 00170 $servers = $this->values['_MemCachedServers']; 00171 00172 if( !$servers ) { 00173 return 'array()'; 00174 } else { 00175 $ret = 'array( '; 00176 $servers = explode( ',', $servers ); 00177 00178 foreach( $servers as $srv ) { 00179 $srv = trim( $srv ); 00180 $ret .= "'$srv', "; 00181 } 00182 00183 return rtrim( $ret, ', ' ) . ' )'; 00184 } 00185 } 00186 00190 protected function getDefaultText() { 00191 if( !$this->values['wgImageMagickConvertCommand'] ) { 00192 $this->values['wgImageMagickConvertCommand'] = '/usr/bin/convert'; 00193 $magic = '#'; 00194 } else { 00195 $magic = ''; 00196 } 00197 00198 if( !$this->values['wgShellLocale'] ) { 00199 $this->values['wgShellLocale'] = 'en_US.UTF-8'; 00200 $locale = '#'; 00201 } else { 00202 $locale = ''; 00203 } 00204 00205 //$rightsUrl = $this->values['wgRightsUrl'] ? '' : '#'; // TODO: Fixme, I'm unused! 00206 $hashedUploads = $this->safeMode ? '' : '#'; 00207 $metaNamespace = ''; 00208 if( $this->values['wgMetaNamespace'] !== $this->values['wgSitename'] ) { 00209 $metaNamespace = "\$wgMetaNamespace = \"{$this->values['wgMetaNamespace']}\";\n"; 00210 } 00211 00212 $groupRights = ''; 00213 if( $this->groupPermissions ) { 00214 $groupRights .= "# The following permissions were set based on your choice in the installer\n"; 00215 foreach( $this->groupPermissions as $group => $rightArr ) { 00216 $group = self::escapePhpString( $group ); 00217 foreach( $rightArr as $right => $perm ) { 00218 $right = self::escapePhpString( $right ); 00219 $groupRights .= "\$wgGroupPermissions['$group']['$right'] = " . 00220 wfBoolToStr( $perm ) . ";\n"; 00221 } 00222 } 00223 } 00224 00225 switch( $this->values['wgMainCacheType'] ) { 00226 case 'anything': 00227 case 'db': 00228 case 'memcached': 00229 case 'accel': 00230 $cacheType = 'CACHE_' . strtoupper( $this->values['wgMainCacheType']); 00231 break; 00232 case 'none': 00233 default: 00234 $cacheType = 'CACHE_NONE'; 00235 } 00236 00237 $mcservers = $this->buildMemcachedServerList(); 00238 return "<?php 00239 # This file was automatically generated by the MediaWiki {$GLOBALS['wgVersion']} 00240 # installer. If you make manual changes, please keep track in case you 00241 # need to recreate them later. 00242 # 00243 # See includes/DefaultSettings.php for all configurable settings 00244 # and their default values, but don't forget to make changes in _this_ 00245 # file, not there. 00246 # 00247 # Further documentation for configuration settings may be found at: 00248 # http://www.mediawiki.org/wiki/Manual:Configuration_settings 00249 00250 # Protect against web entry 00251 if ( !defined( 'MEDIAWIKI' ) ) { 00252 exit; 00253 } 00254 00255 ## Uncomment this to disable output compression 00256 # \$wgDisableOutputCompression = true; 00257 00258 \$wgSitename = \"{$this->values['wgSitename']}\"; 00259 {$metaNamespace} 00260 ## The URL base path to the directory containing the wiki; 00261 ## defaults for all runtime URL paths are based off of this. 00262 ## For more information on customizing the URLs 00263 ## (like /w/index.php/Page_title to /wiki/Page_title) please see: 00264 ## http://www.mediawiki.org/wiki/Manual:Short_URL 00265 \$wgScriptPath = \"{$this->values['wgScriptPath']}\"; 00266 \$wgScriptExtension = \"{$this->values['wgScriptExtension']}\"; 00267 00268 ## The protocol and server name to use in fully-qualified URLs 00269 \$wgServer = \"{$this->values['wgServer']}\"; 00270 00271 ## The relative URL path to the skins directory 00272 \$wgStylePath = \"\$wgScriptPath/skins\"; 00273 00274 ## The relative URL path to the logo. Make sure you change this from the default, 00275 ## or else you'll overwrite your logo when you upgrade! 00276 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\"; 00277 00278 ## UPO means: this is also a user preference option 00279 00280 \$wgEnableEmail = {$this->values['wgEnableEmail']}; 00281 \$wgEnableUserEmail = {$this->values['wgEnableUserEmail']}; # UPO 00282 00283 \$wgEmergencyContact = \"{$this->values['wgEmergencyContact']}\"; 00284 \$wgPasswordSender = \"{$this->values['wgPasswordSender']}\"; 00285 00286 \$wgEnotifUserTalk = {$this->values['wgEnotifUserTalk']}; # UPO 00287 \$wgEnotifWatchlist = {$this->values['wgEnotifWatchlist']}; # UPO 00288 \$wgEmailAuthentication = {$this->values['wgEmailAuthentication']}; 00289 00290 ## Database settings 00291 \$wgDBtype = \"{$this->values['wgDBtype']}\"; 00292 \$wgDBserver = \"{$this->values['wgDBserver']}\"; 00293 \$wgDBname = \"{$this->values['wgDBname']}\"; 00294 \$wgDBuser = \"{$this->values['wgDBuser']}\"; 00295 \$wgDBpassword = \"{$this->values['wgDBpassword']}\"; 00296 00297 {$this->dbSettings} 00298 00299 ## Shared memory settings 00300 \$wgMainCacheType = $cacheType; 00301 \$wgMemCachedServers = $mcservers; 00302 00303 ## To enable image uploads, make sure the 'images' directory 00304 ## is writable, then set this to true: 00305 \$wgEnableUploads = {$this->values['wgEnableUploads']}; 00306 {$magic}\$wgUseImageMagick = true; 00307 {$magic}\$wgImageMagickConvertCommand = \"{$this->values['wgImageMagickConvertCommand']}\"; 00308 00309 # InstantCommons allows wiki to use images from http://commons.wikimedia.org 00310 \$wgUseInstantCommons = {$this->values['wgUseInstantCommons']}; 00311 00312 ## If you use ImageMagick (or any other shell command) on a 00313 ## Linux server, this will need to be set to the name of an 00314 ## available UTF-8 locale 00315 {$locale}\$wgShellLocale = \"{$this->values['wgShellLocale']}\"; 00316 00317 ## If you want to use image uploads under safe mode, 00318 ## create the directories images/archive, images/thumb and 00319 ## images/temp, and make them all writable. Then uncomment 00320 ## this, if it's not already uncommented: 00321 {$hashedUploads}\$wgHashedUploadDirectory = false; 00322 00323 ## Set \$wgCacheDirectory to a writable directory on the web server 00324 ## to make your wiki go slightly faster. The directory should not 00325 ## be publically accessible from the web. 00326 #\$wgCacheDirectory = \"\$IP/cache\"; 00327 00328 # Site language code, should be one of the list in ./languages/Names.php 00329 \$wgLanguageCode = \"{$this->values['wgLanguageCode']}\"; 00330 00331 \$wgSecretKey = \"{$this->values['wgSecretKey']}\"; 00332 00333 # Site upgrade key. Must be set to a string (default provided) to turn on the 00334 # web installer while LocalSettings.php is in place 00335 \$wgUpgradeKey = \"{$this->values['wgUpgradeKey']}\"; 00336 00337 ## Default skin: you can change the default skin. Use the internal symbolic 00338 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector': 00339 \$wgDefaultSkin = \"{$this->values['wgDefaultSkin']}\"; 00340 00341 ## For attaching licensing metadata to pages, and displaying an 00342 ## appropriate copyright notice / icon. GNU Free Documentation 00343 ## License and Creative Commons licenses are supported so far. 00344 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright 00345 \$wgRightsUrl = \"{$this->values['wgRightsUrl']}\"; 00346 \$wgRightsText = \"{$this->values['wgRightsText']}\"; 00347 \$wgRightsIcon = \"{$this->values['wgRightsIcon']}\"; 00348 00349 # Path to the GNU diff3 utility. Used for conflict resolution. 00350 \$wgDiff3 = \"{$this->values['wgDiff3']}\"; 00351 00352 # Query string length limit for ResourceLoader. You should only set this if 00353 # your web server has a query string length limit (then set it to that limit), 00354 # or if you have suhosin.get.max_value_length set in php.ini (then set it to 00355 # that value) 00356 \$wgResourceLoaderMaxQueryLength = {$this->values['wgResourceLoaderMaxQueryLength']}; 00357 00358 {$groupRights}"; 00359 } 00360 00361 }