MediaWiki  1.28.1
MWLBFactory.php
Go to the documentation of this file.
1 <?php
26 
31 abstract class MWLBFactory {
37  public static function applyDefaultConfig( array $lbConf, Config $mainConfig ) {
39 
40  static $typesWithSchema = [ 'postgres', 'msssql' ];
41 
42  $lbConf += [
43  'localDomain' => new DatabaseDomain(
44  $mainConfig->get( 'DBname' ),
45  null,
46  $mainConfig->get( 'DBprefix' )
47  ),
48  'profiler' => Profiler::instance(),
49  'trxProfiler' => Profiler::instance()->getTransactionProfiler(),
50  'replLogger' => LoggerFactory::getInstance( 'DBReplication' ),
51  'queryLogger' => LoggerFactory::getInstance( 'DBQuery' ),
52  'connLogger' => LoggerFactory::getInstance( 'DBConnection' ),
53  'perfLogger' => LoggerFactory::getInstance( 'DBPerformance' ),
54  'errorLogger' => [ MWExceptionHandler::class, 'logException' ],
55  'cliMode' => $wgCommandLineMode,
56  'hostname' => wfHostname(),
57  // TODO: replace the global wfConfiguredReadOnlyReason() with a service.
58  'readOnlyReason' => wfConfiguredReadOnlyReason(),
59  ];
60 
61  if ( $lbConf['class'] === 'LBFactorySimple' ) {
62  if ( isset( $lbConf['servers'] ) ) {
63  // Server array is already explicitly configured; leave alone
64  } elseif ( is_array( $mainConfig->get( 'DBservers' ) ) ) {
65  foreach ( $mainConfig->get( 'DBservers' ) as $i => $server ) {
66  if ( $server['type'] === 'sqlite' ) {
67  $server += [ 'dbDirectory' => $mainConfig->get( 'SQLiteDataDir' ) ];
68  } elseif ( $server['type'] === 'postgres' ) {
69  $server += [ 'port' => $mainConfig->get( 'DBport' ) ];
70  }
71  if ( in_array( $server['type'], $typesWithSchema, true ) ) {
72  $server += [ 'schema' => $mainConfig->get( 'DBmwschema' ) ];
73  }
74 
75  $server += [
76  'tablePrefix' => $mainConfig->get( 'DBprefix' ),
77  'flags' => DBO_DEFAULT,
78  'sqlMode' => $mainConfig->get( 'SQLMode' ),
79  'utf8Mode' => $mainConfig->get( 'DBmysql5' )
80  ];
81 
82  $lbConf['servers'][$i] = $server;
83  }
84  } else {
86  $flags |= $mainConfig->get( 'DebugDumpSql' ) ? DBO_DEBUG : 0;
87  $flags |= $mainConfig->get( 'DBssl' ) ? DBO_SSL : 0;
88  $flags |= $mainConfig->get( 'DBcompress' ) ? DBO_COMPRESS : 0;
89  $server = [
90  'host' => $mainConfig->get( 'DBserver' ),
91  'user' => $mainConfig->get( 'DBuser' ),
92  'password' => $mainConfig->get( 'DBpassword' ),
93  'dbname' => $mainConfig->get( 'DBname' ),
94  'tablePrefix' => $mainConfig->get( 'DBprefix' ),
95  'type' => $mainConfig->get( 'DBtype' ),
96  'load' => 1,
97  'flags' => $flags,
98  'sqlMode' => $mainConfig->get( 'SQLMode' ),
99  'utf8Mode' => $mainConfig->get( 'DBmysql5' )
100  ];
101  if ( in_array( $server['type'], $typesWithSchema, true ) ) {
102  $server += [ 'schema' => $mainConfig->get( 'DBmwschema' ) ];
103  }
104  if ( $server['type'] === 'sqlite' ) {
105  $server[ 'dbDirectory'] = $mainConfig->get( 'SQLiteDataDir' );
106  } elseif ( $server['type'] === 'postgres' ) {
107  $server['port'] = $mainConfig->get( 'DBport' );
108  }
109  $lbConf['servers'] = [ $server ];
110  }
111  if ( !isset( $lbConf['externalClusters'] ) ) {
112  $lbConf['externalClusters'] = $mainConfig->get( 'ExternalServers' );
113  }
114  } elseif ( $lbConf['class'] === 'LBFactoryMulti' ) {
115  if ( isset( $lbConf['serverTemplate'] ) ) {
116  if ( in_array( $lbConf['serverTemplate']['type'], $typesWithSchema, true ) ) {
117  $lbConf['serverTemplate']['schema'] = $mainConfig->get( 'DBmwschema' );
118  }
119  $lbConf['serverTemplate']['sqlMode'] = $mainConfig->get( 'SQLMode' );
120  $lbConf['serverTemplate']['utf8Mode'] = $mainConfig->get( 'DBmysql5' );
121  }
122  }
123 
124  // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
125  $sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
126  if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) {
127  $lbConf['srvCache'] = $sCache;
128  }
130  if ( $cCache->getQoS( $cCache::ATTR_EMULATION ) > $cCache::QOS_EMULATION_SQL ) {
131  $lbConf['memCache'] = $cCache;
132  }
133  $wCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
134  if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) {
135  $lbConf['wanCache'] = $wCache;
136  }
137 
138  return $lbConf;
139  }
140 
149  public static function getLBFactoryClass( array $config ) {
150  // For configuration backward compatibility after removing
151  // underscores from class names in MediaWiki 1.23.
152  $bcClasses = [
153  'LBFactory_Simple' => 'LBFactorySimple',
154  'LBFactory_Single' => 'LBFactorySingle',
155  'LBFactory_Multi' => 'LBFactoryMulti'
156  ];
157 
158  $class = $config['class'];
159 
160  if ( isset( $bcClasses[$class] ) ) {
161  $class = $bcClasses[$class];
162  wfDeprecated(
163  '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
164  '1.23'
165  );
166  }
167 
168  return $class;
169  }
170 }
the array() calling protocol came about after MediaWiki 1.4rc1.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static instance()
Singleton.
Definition: Profiler.php:61
wfHostname()
Fetch server name for use in error reporting etc.
static getLocalClusterInstance()
Get the main cluster-local cache object.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2703
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
get($name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
Class to handle database/prefix specification for IDatabase domains.
global $wgCommandLineMode
Definition: Setup.php:495
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
const DBO_DEBUG
Definition: defines.php:6
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
const DBO_DEFAULT
Definition: defines.php:10
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
MediaWiki-specific class for generating database load balancers.
Definition: MWLBFactory.php:31
const DBO_SSL
Definition: defines.php:14
const DBO_COMPRESS
Definition: defines.php:15
static applyDefaultConfig(array $lbConf, Config $mainConfig)
Definition: MWLBFactory.php:37