diff options
author | Tim Starling <tstarling@wikimedia.org> | 2020-03-19 13:42:09 +1100 |
---|---|---|
committer | Reedy <reedy@wikimedia.org> | 2020-05-30 14:23:28 +0000 |
commit | 68c433bd23bd134883225f03626a94a16fc16bda (patch) | |
tree | 85bbc470ac4e40853bb012e04d7a4bda9f5be293 /includes/cache/localisation/LocalisationCache.php | |
parent | 2530009b8c1146716f23539925d9c86c620db918 (diff) | |
download | mediawikicore-68c433bd23bd134883225f03626a94a16fc16bda.tar.gz mediawikicore-68c433bd23bd134883225f03626a94a16fc16bda.zip |
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
Diffstat (limited to 'includes/cache/localisation/LocalisationCache.php')
-rw-r--r-- | includes/cache/localisation/LocalisationCache.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index 8d5642c97174..214cf7aab387 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -23,6 +23,8 @@ use CLDRPluralRuleParser\Error as CLDRPluralRuleError; use CLDRPluralRuleParser\Evaluator; use MediaWiki\Config\ServiceOptions; +use MediaWiki\HookContainer\HookContainer; +use MediaWiki\HookContainer\HookRunner; use MediaWiki\Languages\LanguageNameUtils; use Psr\Log\LoggerInterface; @@ -71,6 +73,9 @@ class LocalisationCache { */ private $logger; + /** @var HookRunner */ + private $hookRunner; + /** @var callable[] See comment for parameter in constructor */ private $clearStoreCallbacks; @@ -249,6 +254,7 @@ class LocalisationCache { * used to clear other caches that depend on this one, such as ResourceLoader's * MessageBlobStore. * @param LanguageNameUtils $langNameUtils + * @param HookContainer $hookContainer * @throws MWException */ public function __construct( @@ -256,7 +262,8 @@ class LocalisationCache { LCStore $store, LoggerInterface $logger, array $clearStoreCallbacks, - LanguageNameUtils $langNameUtils + LanguageNameUtils $langNameUtils, + HookContainer $hookContainer ) { $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); @@ -265,6 +272,7 @@ class LocalisationCache { $this->logger = $logger; $this->clearStoreCallbacks = $clearStoreCallbacks; $this->langNameUtils = $langNameUtils; + $this->hookRunner = new HookRunner( $hookContainer ); // Keep this separate from $this->options so it can be mutable $this->manualRecache = $options->get( 'manualRecache' ); @@ -957,7 +965,7 @@ class LocalisationCache { # Allow extensions an opportunity to adjust the data for this # fallback - Hooks::run( 'LocalisationCacheRecacheFallback', [ $this, $csCode, &$csData ] ); + $this->hookRunner->onLocalisationCacheRecacheFallback( $this, $csCode, $csData ); # Merge the data for this fallback into the final array if ( $csCode === $code ) { @@ -1014,7 +1022,7 @@ class LocalisationCache { } # Run hooks $unused = true; // Used to be $purgeBlobs, removed in 1.34 - Hooks::run( 'LocalisationCacheRecache', [ $this, $code, &$allData, &$unused ] ); + $this->hookRunner->onLocalisationCacheRecache( $this, $code, $allData, $unused ); if ( $allData['namespaceNames'] === null ) { throw new MWException( __METHOD__ . ': Localisation data failed sanity check! ' . |