* For every service that MediaWiki core requires, an instantiator must be defined in
* this file.
*
+ * Note that, ideally, all information used to instantiate service objects should come
+ * from configuration. Information derived from the current request is acceptable, but
+ * only where there is no feasible alternative. It is preferred that such information
+ * (like the client IP, the acting user's identity, requested title, etc) be passed to
+ * the service object's methods as parameters. This makes the flow of information more
+ * obvious, and makes it easier to understand the behavior of services.
+ *
* @note As of version 1.27, MediaWiki is only beginning to use dependency injection.
* The services defined here do not yet fully represent all services used by core,
* much of the code still relies on global state for this accessing services.
$services->getDBLoadBalancerFactory(),
$services->getExternalStoreAccess(),
$services->getMainWANObjectCache(),
- new ServiceOptions( BlobStoreFactory::$constructorOptions,
+ new ServiceOptions( BlobStoreFactory::CONSTRUCTOR_OPTIONS,
$services->getMainConfig() ),
$services->getContentLanguage()
);
'BlockManager' => function ( MediaWikiServices $services ) : BlockManager {
return new BlockManager(
new ServiceOptions(
- BlockManager::$constructorOptions, $services->getMainConfig()
+ BlockManager::CONSTRUCTOR_OPTIONS, $services->getMainConfig()
),
$services->getPermissionManager(),
LoggerFactory::getInstance( 'BlockManager' )
);
$class = MWLBFactory::getLBFactoryClass( $lbConf );
- $instance = new $class( $lbConf );
- MWLBFactory::setSchemaAliases( $instance, $mainConfig->get( 'DBtype' ) );
-
- return $instance;
+ return new $class( $lbConf );
},
'EventRelayerGroup' => function ( MediaWikiServices $services ) : EventRelayerGroup {
if ( defined( 'MW_NO_SESSION' ) ) {
return $services->getLinkRendererFactory()->create();
} else {
+ // Normally information from the current request would not be passed in here;
+ // this is an exception. (See also the class documentation.)
return $services->getLinkRendererFactory()->createForUser(
RequestContext::getMain()->getUser()
);
);
},
+ 'LocalisationCache' => function ( MediaWikiServices $services ) : LocalisationCache {
+ $conf = $services->getMainConfig()->get( 'LocalisationCacheConf' );
+
+ $logger = LoggerFactory::getInstance( 'localisation' );
+
+ $store = LocalisationCache::getStoreFromConf(
+ $conf, $services->getMainConfig()->get( 'CacheDirectory' ) );
+ $logger->debug( 'LocalisationCache: using store ' . get_class( $store ) );
+
+ return new $conf['class'](
+ new ServiceOptions(
+ LocalisationCache::CONSTRUCTOR_OPTIONS,
+ // Two of the options are stored in $wgLocalisationCacheConf
+ $conf,
+ // In case someone set that config variable and didn't reset all keys, set defaults.
+ [
+ 'forceRecache' => false,
+ 'manualRecache' => false,
+ ],
+ // Some other options come from config itself
+ $services->getMainConfig()
+ ),
+ $store,
+ $logger,
+ [ function () use ( $services ) {
+ $services->getResourceLoader()->getMessageBlobStore()->clear();
+ } ]
+ );
+ },
+
'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff {
$config = $services->getMainConfig();
$cacheId = ObjectCache::detectLocalServerCache();
);
},
+ 'PasswordReset' => function ( MediaWikiServices $services ) : PasswordReset {
+ $options = new ServiceOptions( PasswordReset::CONSTRUCTOR_OPTIONS, $services->getMainConfig() );
+ return new PasswordReset(
+ $options,
+ AuthManager::singleton(),
+ $services->getPermissionManager(),
+ $services->getDBLoadBalancer(),
+ LoggerFactory::getInstance( 'authentication' )
+ );
+ },
+
'PerDbNameStatsdDataFactory' =>
function ( MediaWikiServices $services ) : StatsdDataFactoryInterface {
$config = $services->getMainConfig();
'PermissionManager' => function ( MediaWikiServices $services ) : PermissionManager {
return new PermissionManager(
new ServiceOptions(
- PermissionManager::$constructorOptions, $services->getMainConfig()
+ PermissionManager::CONSTRUCTOR_OPTIONS, $services->getMainConfig()
),
$services->getSpecialPageFactory(),
$services->getRevisionLookup(),
$services->getDBLoadBalancer(),
$services->getCommentStore(),
$services->getActorMigration(),
- $services->getWatchedItemStore()
+ $services->getWatchedItemStore(),
+ $services->getPermissionManager()
);
},