BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
MediaWiki\MediaWikiServices Class Reference
Inheritance diagram for MediaWiki\MediaWikiServices:
Collaboration diagram for MediaWiki\MediaWikiServices:

Public Member Functions

 resetServiceForTesting ($name, $destroy=true)
 
 __construct (Config $config)
 
 getBootstrapConfig ()
 
 getConfigFactory ()
 
 getMainConfig ()
 
 getSiteLookup ()
 
 getSiteStore ()
 
 getInterwikiLookup ()
 
 getStatsdDataFactory ()
 
 getEventRelayerGroup ()
 
 newSearchEngine ()
 
 getSearchEngineFactory ()
 
 getSearchEngineConfig ()
 
 getSkinFactory ()
 
 getDBLoadBalancerFactory ()
 
 getDBLoadBalancer ()
 
 getWatchedItemStore ()
 
 getWatchedItemQueryService ()
 
 getCryptRand ()
 
 getCryptHKDF ()
 
 getMediaHandlerFactory ()
 
 getMimeAnalyzer ()
 
 getProxyLookup ()
 
 getParser ()
 
 getParserCache ()
 
 getGenderCache ()
 
 getLinkCache ()
 
 getLinkRendererFactory ()
 
 getLinkRenderer ()
 
 getTitleFormatter ()
 
 getTitleParser ()
 
 getMainObjectStash ()
 
 getMainWANObjectCache ()
 
 getLocalServerObjectCache ()
 
 getVirtualRESTServiceClient ()
 
 getConfiguredReadOnlyMode ()
 
 getReadOnlyMode ()
 
 getWikiRevisionUploadImporter ()
 
 getWikiRevisionOldRevisionImporter ()
 
 getWikiRevisionOldRevisionImporterNoUpdates ()
 
 getShellCommandFactory ()
 
 getExternalStoreFactory ()
 
 getBlobStoreFactory ()
 
 getBlobStore ()
 
 getRevisionStore ()
 
 getRevisionLookup ()
 
 getRevisionFactory ()
 
 getContentModelStore ()
 
 getSlotRoleStore ()
 
 getPreferencesFactory ()
 
 getHttpRequestFactory ()
 
 getCommentStore ()
 
 getActorMigration ()
 
- Public Member Functions inherited from MediaWiki\Services\ServiceContainer
 __construct (array $extraInstantiationParams=[])
 
 destroy ()
 
 loadWiringFiles (array $wiringFiles)
 
 applyWiring (array $serviceInstantiators)
 
 importWiring (ServiceContainer $container, $skip=[])
 
 hasService ($name)
 
 peekService ($name)
 
 getServiceNames ()
 
 defineService ($name, callable $instantiator)
 
 redefineService ($name, callable $instantiator)
 
 disableService ($name)
 
 getService ($name)
 
 isServiceDisabled ($name)
 

Static Public Member Functions

static getInstance ()
 
static forceGlobalInstance (MediaWikiServices $services)
 
static resetGlobalInstance (Config $bootstrapConfig=null, $quick= '')
 
static disableStorageBackend ()
 
static resetChildProcessServices ()
 
static failIfResetNotAllowed ($method)
 

Additional Inherited Members

- Protected Member Functions inherited from MediaWiki\Services\ServiceContainer
 resetService ($name, $destroy=true)
 

Detailed Description

MediaWikiServices is the service locator for the application scope of MediaWiki. Its implemented as a simple configurable DI container. MediaWikiServices acts as a top level factory/registry for top level services, and builds the network of service objects that defines MediaWiki's application logic. It acts as an entry point to MediaWiki's dependency injection mechanism.

Services are defined in the "wiring" array passed to the constructor, or by calling defineService().

See Also
docs/injection.txt for an overview of using dependency injection in the MediaWiki code base.

Constructor & Destructor Documentation

MediaWiki\MediaWikiServices::__construct ( Config  $config)
Parameters
Config$configThe Config object to be registered as the 'BootstrapConfig' service. This has to contain at least the information needed to set up the 'ConfigFactory' service.

Member Function Documentation

static MediaWiki\MediaWikiServices::disableStorageBackend ( )
static

Disables all storage layer services. After calling this, any attempt to access the storage layer will result in an error. Use resetGlobalInstance() to restore normal operation.

Since
1.28
Warning
This is intended for extreme situations only and should never be used while serving normal web requests. Legitimate use cases for this method include the installation process. Test fixtures may also use this, if the fixture relies on globalState.
See Also
resetGlobalInstance()
resetChildProcessServices()
static MediaWiki\MediaWikiServices::failIfResetNotAllowed (   $method)
static

Convenience method that throws an exception unless it is called during a phase in which resetting of global services is allowed. In general, services should not be reset individually, since that may introduce inconsistencies.

Since
1.28

This method will throw an exception if:

  • self::$resetInProgress is false (to allow all services to be reset together via resetGlobalInstance)
  • and MEDIAWIKI_INSTALL is not defined (to allow services to be reset during installation)
  • and MW_PHPUNIT_TEST is not defined (to allow services to be reset during testing)

This method is intended to be used to safeguard against accidentally resetting global service instances that are not yet managed by MediaWikiServices. It is defined here in the MediaWikiServices services class to have a central place for managing service bootstrapping and resetting.

Parameters
string$methodthe name of the caller method, as given by METHOD.
Exceptions
MWExceptionif called outside bootstrap mode.
See Also
resetGlobalInstance()
forceGlobalInstance()
disableStorageBackend()
static MediaWiki\MediaWikiServices::forceGlobalInstance ( MediaWikiServices  $services)
static

Replaces the global MediaWikiServices instance.

Since
1.28
Note
This is for use in PHPUnit tests only!
Exceptions
MWExceptionif called outside of PHPUnit tests.
Parameters
MediaWikiServices$servicesThe new MediaWikiServices object.
Returns
MediaWikiServices The old MediaWikiServices object, so it can be restored later.
MediaWiki\MediaWikiServices::getActorMigration ( )
Since
1.31
Returns
ActorMigration
MediaWiki\MediaWikiServices::getBlobStore ( )
Since
1.31
Returns
BlobStore
MediaWiki\MediaWikiServices::getBlobStoreFactory ( )
Since
1.31
Returns
BlobStoreFactory
MediaWiki\MediaWikiServices::getBootstrapConfig ( )

Returns the Config object containing the bootstrap configuration. Bootstrap configuration would typically include database credentials and other information that may be needed before the ConfigFactory service can be instantiated.

Note
This should only be used during bootstrapping, in particular when creating the MainConfig service. Application logic should use getMainConfig() to get a Config instances.
Since
1.27
Returns
Config
MediaWiki\MediaWikiServices::getCommentStore ( )
Since
1.31
Returns
CommentStore
MediaWiki\MediaWikiServices::getConfigFactory ( )
Since
1.27
Returns
ConfigFactory
MediaWiki\MediaWikiServices::getConfiguredReadOnlyMode ( )
Since
1.29
Returns
MediaWiki\MediaWikiServices::getContentModelStore ( )
Since
1.31
Returns
NameTableStore
MediaWiki\MediaWikiServices::getCryptHKDF ( )
Since
1.28
Returns
CryptHKDF
MediaWiki\MediaWikiServices::getCryptRand ( )
Since
1.28
Returns
CryptRand
MediaWiki\MediaWikiServices::getDBLoadBalancer ( )
Since
1.28
Returns
LoadBalancer The main DB load balancer for the local wiki.
MediaWiki\MediaWikiServices::getDBLoadBalancerFactory ( )
Since
1.28
Returns
LBFactory
MediaWiki\MediaWikiServices::getEventRelayerGroup ( )
Since
1.27
Returns
EventRelayerGroup
MediaWiki\MediaWikiServices::getExternalStoreFactory ( )
Since
1.31
Returns
MediaWiki\MediaWikiServices::getGenderCache ( )
Since
1.28
Returns
GenderCache
MediaWiki\MediaWikiServices::getHttpRequestFactory ( )
Since
1.31
Returns
HttpRequestFactory
static MediaWiki\MediaWikiServices::getInstance ( )
static

Returns the global default instance of the top level service locator.

Since
1.27

The default instance is initialized using the service instantiator functions defined in ServiceWiring.php.

Note
This should only be called by static functions! The instance returned here should not be passed around! Objects that need access to a service should have that service injected into the constructor, never a service locator!
Returns
MediaWikiServices
MediaWiki\MediaWikiServices::getInterwikiLookup ( )
Since
1.28
Returns
InterwikiLookup
MediaWiki\MediaWikiServices::getLinkCache ( )
Since
1.28
Returns
LinkCache
MediaWiki\MediaWikiServices::getLinkRenderer ( )

LinkRenderer instance that can be used if no custom options are needed

Since
1.28
Returns
LinkRenderer
MediaWiki\MediaWikiServices::getLinkRendererFactory ( )
Since
1.28
Returns
LinkRendererFactory
MediaWiki\MediaWikiServices::getLocalServerObjectCache ( )
Since
1.28
Returns
MediaWiki\MediaWikiServices::getMainConfig ( )

Returns the Config object that provides configuration for MediaWiki core. This may or may not be the same object that is returned by getBootstrapConfig().

Since
1.27
Returns
Config
MediaWiki\MediaWikiServices::getMainObjectStash ( )
Since
1.28
Returns
MediaWiki\MediaWikiServices::getMainWANObjectCache ( )
Since
1.28
Returns
MediaWiki\MediaWikiServices::getMediaHandlerFactory ( )
Since
1.28
Returns
MediaHandlerFactory
MediaWiki\MediaWikiServices::getMimeAnalyzer ( )
Since
1.28
Returns
MimeAnalyzer
MediaWiki\MediaWikiServices::getParser ( )
Since
1.29
Returns
Parser
MediaWiki\MediaWikiServices::getParserCache ( )
Since
1.30
Returns
ParserCache
MediaWiki\MediaWikiServices::getPreferencesFactory ( )
Since
1.31
Returns
PreferencesFactory
MediaWiki\MediaWikiServices::getProxyLookup ( )
Since
1.28
Returns
ProxyLookup
MediaWiki\MediaWikiServices::getReadOnlyMode ( )
Since
1.29
Returns
MediaWiki\MediaWikiServices::getRevisionFactory ( )
Since
1.31
Returns
RevisionFactory
MediaWiki\MediaWikiServices::getRevisionLookup ( )
Since
1.31
Returns
RevisionLookup
MediaWiki\MediaWikiServices::getRevisionStore ( )
Since
1.31
Returns
RevisionStore
MediaWiki\MediaWikiServices::getSearchEngineConfig ( )
Since
1.27
Returns
SearchEngineConfig
MediaWiki\MediaWikiServices::getSearchEngineFactory ( )
Since
1.27
Returns
SearchEngineFactory
MediaWiki\MediaWikiServices::getShellCommandFactory ( )
Since
1.30
Returns
CommandFactory
MediaWiki\MediaWikiServices::getSiteLookup ( )
Since
1.27
Returns
SiteLookup
MediaWiki\MediaWikiServices::getSiteStore ( )
Since
1.27
Returns
SiteStore
MediaWiki\MediaWikiServices::getSkinFactory ( )
Since
1.27
Returns
SkinFactory
MediaWiki\MediaWikiServices::getSlotRoleStore ( )
Since
1.31
Returns
NameTableStore
MediaWiki\MediaWikiServices::getStatsdDataFactory ( )
Since
1.27
Returns
IBufferingStatsdDataFactory
MediaWiki\MediaWikiServices::getTitleFormatter ( )
Since
1.28
Returns
TitleFormatter
MediaWiki\MediaWikiServices::getTitleParser ( )
Since
1.28
Returns
TitleParser
MediaWiki\MediaWikiServices::getVirtualRESTServiceClient ( )
Since
1.28
Returns
VirtualRESTServiceClient
MediaWiki\MediaWikiServices::getWatchedItemQueryService ( )
Since
1.28
Returns
WatchedItemQueryService
MediaWiki\MediaWikiServices::getWatchedItemStore ( )
Since
1.28
Returns
WatchedItemStoreInterface
MediaWiki\MediaWikiServices::getWikiRevisionOldRevisionImporter ( )
Since
1.31
Returns
MediaWiki\MediaWikiServices::getWikiRevisionOldRevisionImporterNoUpdates ( )
Since
1.31
Returns
MediaWiki\MediaWikiServices::getWikiRevisionUploadImporter ( )
Since
1.31
Returns
MediaWiki\MediaWikiServices::newSearchEngine ( )
Since
1.27
Returns
SearchEngine
static MediaWiki\MediaWikiServices::resetChildProcessServices ( )
static

Resets any services that may have become stale after a child process returns from after pcntl_fork(). It's also safe, but generally unnecessary, to call this method from the parent process.

Since
1.28
Note
This is intended for use in the context of process forking only!
See Also
resetGlobalInstance()
disableStorageBackend()
static MediaWiki\MediaWikiServices::resetGlobalInstance ( Config  $bootstrapConfig = null,
  $quick = '' 
)
static

Creates a new instance of MediaWikiServices and sets it as the global default instance. getInstance() will return a different MediaWikiServices object after every call to resetGlobalInstance().

Since
1.28
Warning
This should not be used during normal operation. It is intended for use when the configuration has changed significantly since bootstrap time, e.g. during the installation process or during testing.
Calling resetGlobalInstance() may leave the application in an inconsistent state. Calling this is only safe under the ASSUMPTION that NO REFERENCE to any of the services managed by MediaWikiServices exist. If any service objects managed by the old MediaWikiServices instance remain in use, they may INTERFERE with the operation of the services managed by the new MediaWikiServices. Operating with a mix of services created by the old and the new MediaWikiServices instance may lead to INCONSISTENCIES and even DATA LOSS! Any class implementing LAZY LOADING is especially prone to this problem, since instances would typically retain a reference to a storage layer service.
See Also
forceGlobalInstance()
resetGlobalInstance()
resetBetweenTest()
Parameters
Config | null$bootstrapConfigThe Config object to be registered as the 'BootstrapConfig' service. This has to contain at least the information needed to set up the 'ConfigFactory' service. If not given, the bootstrap config of the old instance of MediaWikiServices will be re-used. If there was no previous instance, a new GlobalVarConfig object will be used to bootstrap the services.
string$quickSet this to "quick" to allow expensive resources to be re-used. See SalvageableService for details.
Exceptions
MWExceptionIf called after MW_SERVICE_BOOTSTRAP_COMPLETE has been defined in Setup.php (unless MW_PHPUNIT_TEST or MEDIAWIKI_INSTALL or RUN_MAINTENANCE_IF_MAIN is defined).
MediaWiki\MediaWikiServices::resetServiceForTesting (   $name,
  $destroy = true 
)

Resets the given service for testing purposes.

Since
1.28
Warning
This is generally unsafe! Other services may still retain references to the stale service instance, leading to failures and inconsistencies. Subclasses may use this method to reset specific services under specific instances, but it should not be exposed to application logic.
Note
With proper dependency injection used throughout the codebase, this method should not be needed. It is provided to allow tests that pollute global service instances to clean up.
Parameters
string$name
bool$destroyWhether the service instance should be destroyed if it exists. When set to false, any existing service instance will effectively be detached from the container.
Exceptions
MWExceptionif called outside of PHPUnit tests.

The documentation for this class was generated from the following file: