X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMediaWikiServices.php;h=6613db160222cfe62f4d7e61ee8f3203e66cca28;hb=903613ea74f764bc95421059eed61f0d4df92956;hp=891f426d7421508cbfbeee35579a4519c1d83914;hpb=5ffbb247aeb517bd72d8e53dd601eabd3a68b01b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index 891f426d74..6613db1602 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -11,9 +11,12 @@ use LBFactory; use LinkCache; use Liuggio\StatsdClient\Factory\StatsdDataFactory; use LoadBalancer; +use MediaWiki\Linker\LinkRenderer; +use MediaWiki\Linker\LinkRendererFactory; +use MediaWiki\Services\SalvageableService; use MediaWiki\Services\ServiceContainer; use MWException; -use ResourceLoader; +use ObjectCache; use SearchEngine; use SearchEngineConfig; use SearchEngineFactory; @@ -23,6 +26,7 @@ use WatchedItemStore; use SkinFactory; use TitleFormatter; use TitleParser; +use MediaWiki\Interwiki\InterwikiLookup; /** * Service locator for MediaWiki core services. @@ -88,7 +92,7 @@ class MediaWikiServices extends ServiceContainer { // even if it's just a file name or database credentials to load // configuration from. $bootstrapConfig = new GlobalVarConfig(); - self::$instance = self::newInstance( $bootstrapConfig ); + self::$instance = self::newInstance( $bootstrapConfig, 'load' ); } return self::$instance; @@ -121,7 +125,7 @@ class MediaWikiServices extends ServiceContainer { /** * 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 resetGlobalServiceLocator(). + * after every call to resetGlobalInstance(). * * @since 1.28 * @@ -129,7 +133,7 @@ class MediaWikiServices extends ServiceContainer { * when the configuration has changed significantly since bootstrap time, e.g. * during the installation process or during testing. * - * @warning Calling resetGlobalServiceLocator() may leave the application in an inconsistent + * @warning 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 @@ -150,11 +154,14 @@ class MediaWikiServices extends ServiceContainer { * was no previous instance, a new GlobalVarConfig object will be used to * bootstrap the services. * + * @param string $quick Set this to "quick" to allow expensive resources to be re-used. + * See SalvageableService for details. + * * @throws MWException If 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). */ - public static function resetGlobalInstance( Config $bootstrapConfig = null ) { + public static function resetGlobalInstance( Config $bootstrapConfig = null, $quick = '' ) { if ( self::$instance === null ) { // no global instance yet, nothing to reset return; @@ -166,9 +173,38 @@ class MediaWikiServices extends ServiceContainer { $bootstrapConfig = self::$instance->getBootstrapConfig(); } - self::$instance->destroy(); + $oldInstance = self::$instance; self::$instance = self::newInstance( $bootstrapConfig ); + self::$instance->importWiring( $oldInstance, [ 'BootstrapConfig' ] ); + + if ( $quick === 'quick' ) { + self::$instance->salvage( $oldInstance ); + } else { + $oldInstance->destroy(); + } + + } + + /** + * Salvages the state of any salvageable service instances in $other. + * + * @note $other will have been destroyed when salvage() returns. + * + * @param MediaWikiServices $other + */ + private function salvage( self $other ) { + foreach ( $this->getServiceNames() as $name ) { + $oldService = $other->peekService( $name ); + + if ( $oldService instanceof SalvageableService ) { + /** @var SalvageableService $newService */ + $newService = $this->getService( $name ); + $newService->salvage( $oldService ); + } + } + + $other->destroy(); } /** @@ -177,21 +213,23 @@ class MediaWikiServices extends ServiceContainer { * ServiceWiringFiles setting are loaded, and the MediaWikiServices hook is called. * * @param Config|null $bootstrapConfig The 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 provided, any call - * to getBootstrapConfig(), getConfigFactory, or getMainConfig will fail. - * A MediaWikiServices instance without access to configuration is called - * "primordial". + * 'BootstrapConfig' service. + * + * @param string $loadWiring set this to 'load' to load the wiring files specified + * in the 'ServiceWiringFiles' setting in $bootstrapConfig. * * @return MediaWikiServices * @throws MWException + * @throws \FatalError */ - private static function newInstance( Config $bootstrapConfig ) { + private static function newInstance( Config $bootstrapConfig, $loadWiring = '' ) { $instance = new self( $bootstrapConfig ); // Load the default wiring from the specified files. - $wiringFiles = $bootstrapConfig->get( 'ServiceWiringFiles' ); - $instance->loadWiringFiles( $wiringFiles ); + if ( $loadWiring === 'load' ) { + $wiringFiles = $bootstrapConfig->get( 'ServiceWiringFiles' ); + $instance->loadWiringFiles( $wiringFiles ); + } // Provide a traditional hook point to allow extensions to configure services. Hooks::run( 'MediaWikiServices', [ $instance ] ); @@ -222,6 +260,8 @@ class MediaWikiServices extends ServiceContainer { foreach ( $destroy as $name ) { $services->disableService( $name ); } + + ObjectCache::clear(); } /** @@ -261,7 +301,7 @@ class MediaWikiServices extends ServiceContainer { * instances to clean up. * * @param string $name - * @param string $destroy Whether the service instance should be destroyed if it exists. + * @param bool $destroy Whether the service instance should be destroyed if it exists. * When set to false, any existing service instance will effectively be detached * from the container. * @@ -381,6 +421,14 @@ class MediaWikiServices extends ServiceContainer { return $this->getService( 'SiteStore' ); } + /** + * @since 1.28 + * @return InterwikiLookup + */ + public function getInterwikiLookup() { + return $this->getService( 'InterwikiLookup' ); + } + /** * @since 1.27 * @return StatsdDataFactory @@ -470,6 +518,25 @@ class MediaWikiServices extends ServiceContainer { return $this->getService( 'LinkCache' ); } + /** + * @since 1.28 + * @return LinkRendererFactory + */ + public function getLinkRendererFactory() { + return $this->getService( 'LinkRendererFactory' ); + } + + /** + * LinkRenderer instance that can be used + * if no custom options are needed + * + * @since 1.28 + * @return LinkRenderer + */ + public function getLinkRenderer() { + return $this->getService( 'LinkRenderer' ); + } + /** * @since 1.28 * @return TitleFormatter