42 public const APPLY_DEFAULT_CONFIG_OPTIONS = [
89 $options->
get(
'DBname' ),
90 $options->
get(
'DBmwschema' ),
91 $options->
get(
'DBprefix' )
93 'profiler' =>
function ( $section ) {
94 return Profiler::instance()->scopedProfileIn( $section );
96 'trxProfiler' => Profiler::instance()->getTransactionProfiler(),
97 'replLogger' => LoggerFactory::getInstance(
'DBReplication' ),
98 'queryLogger' => LoggerFactory::getInstance(
'DBQuery' ),
99 'connLogger' => LoggerFactory::getInstance(
'DBConnection' ),
100 'perfLogger' => LoggerFactory::getInstance(
'DBPerformance' ),
101 'errorLogger' => [ MWExceptionHandler::class,
'logException' ],
102 'deprecationLogger' => [ static::class,
'logDeprecation' ],
105 'readOnlyReason' => $readOnlyMode->
getReason(),
106 'defaultGroup' => $options->
get(
'DBDefaultGroup' ),
113 if ( $lbConf[
'class'] ===
Wikimedia\Rdbms\LBFactorySimple::class ) {
114 if ( isset( $lbConf[
'servers'] ) ) {
116 } elseif ( is_array( $options->
get(
'DBservers' ) ) ) {
117 $lbConf[
'servers'] = [];
118 foreach ( $options->
get(
'DBservers' ) as $i => $server ) {
124 'host' => $options->
get(
'DBserver' ),
125 'user' => $options->
get(
'DBuser' ),
126 'password' => $options->
get(
'DBpassword' ),
127 'dbname' => $options->
get(
'DBname' ),
128 'type' => $options->
get(
'DBtype' ),
134 $server[
'flags'] |= $options->
get(
'DBssl' ) ?
DBO_SSL : 0;
137 $lbConf[
'servers'] = [ $server ];
139 if ( !isset( $lbConf[
'externalClusters'] ) ) {
140 $lbConf[
'externalClusters'] = $options->
get(
'ExternalServers' );
143 $serversCheck = $lbConf[
'servers'];
144 } elseif ( $lbConf[
'class'] ===
Wikimedia\Rdbms\LBFactoryMulti::class ) {
145 if ( isset( $lbConf[
'serverTemplate'] ) ) {
146 if ( in_array( $lbConf[
'serverTemplate'][
'type'], $typesWithSchema,
true ) ) {
147 $lbConf[
'serverTemplate'][
'schema'] = $options->
get(
'DBmwschema' );
149 $lbConf[
'serverTemplate'][
'sqlMode'] = $options->
get(
'SQLMode' );
150 $serversCheck = [ $lbConf[
'serverTemplate'] ];
156 $options->
get(
'DBname' ),
157 $options->
get(
'DBprefix' )
160 $lbConf[
'srvCache'] = $srvCache;
161 $lbConf[
'memStash'] = $mainStash;
162 $lbConf[
'wanCache'] = $wanCache;
171 return [
'postgres' ];
180 if ( $server[
'type'] ===
'sqlite' ) {
181 $httpMethod = $_SERVER[
'REQUEST_METHOD'] ??
null;
185 $isHttpRead = in_array( $httpMethod, [
'GET',
'HEAD',
'OPTIONS',
'TRACE' ] );
189 $request = \MediaWiki\Rest\EntryPoint::getMainRequest();
190 if ( $request->hasHeader(
'Promise-Non-Write-API-Action' ) ) {
195 'dbDirectory' => $options->
get(
'SQLiteDataDir' ),
196 'trxMode' => $isHttpRead ?
'DEFERRED' :
'IMMEDIATE'
198 } elseif ( $server[
'type'] ===
'postgres' ) {
200 'port' => $options->
get(
'DBport' ),
202 'keywordTableMap' => [
'user' =>
'mwuser',
'text' =>
'pagecontent' ]
206 if ( in_array( $server[
'type'], self::getDbTypesWithSchemas(),
true ) ) {
207 $server += [
'schema' => $options->
get(
'DBmwschema' ) ];
211 if ( $options->
get(
'DebugDumpSql' )
212 || $options->
get(
'DebugLogFile' )
213 || $options->
get(
'DebugToolbar' )
217 $server[
'flags'] = $flags;
220 'tablePrefix' => $options->
get(
'DBprefix' ),
221 'sqlMode' => $options->
get(
'SQLMode' ),
233 foreach ( $servers as $server ) {
234 $type = $server[
'type'] ??
null;
235 $srvDB = $server[
'dbname'] ??
null;
236 $srvTP = $server[
'tablePrefix'] ??
'';
238 if (
$type ===
'mysql' ) {
241 if ( $srvDB !==
null && $srvDB !== $ldDB ) {
244 } elseif (
$type ===
'postgres' ) {
245 if ( $srvTP !==
'' ) {
250 if ( $srvTP !==
'' && $srvTP !== $ldTP ) {
261 $e =
new UnexpectedValueException(
262 "\$wgDBprefix is set to '$prefix' but the database type is '$dbType'. " .
263 "MediaWiki does not support using a table prefix with this RDBMS type."
274 $e =
new UnexpectedValueException(
275 "\$wgDBservers has dbname='$srvDB' but \$wgDBname='$ldDB'. " .
276 "Set \$wgDBname to the database used by this wiki project. " .
277 "There is rarely a need to set 'dbname' in \$wgDBservers. " .
278 "Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
279 "use of Database::getDomainId(), and other features are not reliable when " .
280 "\$wgDBservers does not match the local wiki database/prefix."
291 $e =
new UnexpectedValueException(
292 "\$wgDBservers has tablePrefix='$srvTP' but \$wgDBprefix='$ldTP'. " .
293 "Set \$wgDBprefix to the table prefix used by this wiki project. " .
294 "There is rarely a need to set 'tablePrefix' in \$wgDBservers. " .
295 "Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
296 "use of Database::getDomainId(), and other features are not reliable when " .
297 "\$wgDBservers does not match the local wiki database/prefix."
313 'LBFactory_Single' => Wikimedia\Rdbms\LBFactorySingle::class,
314 'LBFactory_Simple' => Wikimedia\Rdbms\LBFactorySimple::class,
315 'LBFactory_Multi' => Wikimedia\Rdbms\LBFactoryMulti::class,
317 'LBFactorySingle' => Wikimedia\Rdbms\LBFactorySingle::class,
318 'LBFactorySimple' => Wikimedia\Rdbms\LBFactorySimple::class,
319 'LBFactoryMulti' => Wikimedia\Rdbms\LBFactoryMulti::class
322 $class = $config[
'class'];
323 return $compat[$class] ?? $class;
333 $rawLocalDomain = strlen( $domain->getTablePrefix() )
334 ?
"{$domain->getDatabase()}-{$domain->getTablePrefix()}"
335 : (string)$domain->getDatabase();
346 if ( isset( self::$loggedDeprecations[$msg] ) ) {
349 self::$loggedDeprecations[$msg] =
true;
350 MWDebug::sendRawDeprecated( $msg,
true,
wfGetCaller() );
global $wgCommandLineMode
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
wfHostname()
Get host name of the current machine, for use in error reporting.
Class representing a cache/ephemeral data store.
static output(Throwable $e, $mode, Throwable $eNew=null)
MediaWiki-specific class for generating database load balancers.
static setDomainAliases(ILBFactory $lbFactory)
static logDeprecation( $msg)
Log a database deprecation warning.
static assertValidServerConfigs(array $servers, $ldDB, $ldTP)
static getDbTypesWithSchemas()
static initServerInfo(array $server, ServiceOptions $options)
static array $loggedDeprecations
Cache of already-logged deprecation messages.
static reportMismatchedPrefixes( $srvTP, $ldTP)
static getLBFactoryClass(array $config)
Decide which LBFactory class to use.
static reportMismatchedDBs( $srvDB, $ldDB)
static reportIfPrefixSet( $prefix, $dbType)
static applyDefaultConfig(array $lbConf, ServiceOptions $options, ConfiguredReadOnlyMode $readOnlyMode, BagOStuff $srvCache, BagOStuff $mainStash, WANObjectCache $wanCache)
Multi-datacenter aware caching interface.
Class to handle database/schema/prefix specifications for IDatabase.