diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 559d0219025..fe34e1330b5 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -267,7 +267,10 @@ return [ }, 'BacklinkCacheFactory' => static function ( MediaWikiServices $services ): BacklinkCacheFactory { - return new BacklinkCacheFactory( $services->getMainWANObjectCache() ); + return new BacklinkCacheFactory( + $services->getMainWANObjectCache(), + $services->getHookContainer() + ); }, 'BadFileLookup' => static function ( MediaWikiServices $services ): BadFileLookup { diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php index e150e249fd5..21d46d1ea2e 100644 --- a/includes/cache/BacklinkCache.php +++ b/includes/cache/BacklinkCache.php @@ -26,7 +26,8 @@ */ use MediaWiki\Cache\CacheKeyHelper; -use MediaWiki\HookContainer\ProtectedHookAccessorTrait; +use MediaWiki\HookContainer\HookContainer; +use MediaWiki\HookContainer\HookRunner; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageIdentity; @@ -53,7 +54,6 @@ use Wikimedia\Rdbms\SelectQueryBuilder; * Introduced by r47317 */ class BacklinkCache { - use ProtectedHookAccessorTrait; /** @var BacklinkCache */ protected static $instance; @@ -85,6 +85,9 @@ class BacklinkCache { /** @var WANObjectCache */ protected $wanCache; + /** @var HookRunner */ + private $hookRunner; + /** * Local copy of a database object. * @@ -106,11 +109,17 @@ class BacklinkCache { * Create a new BacklinkCache * * @param WANObjectCache $wanCache + * @param HookContainer $hookContainer * @param PageReference $page Page to create a backlink cache for */ - public function __construct( WANObjectCache $wanCache, PageReference $page ) { + public function __construct( + WANObjectCache $wanCache, + HookContainer $hookContainer, + PageReference $page + ) { $this->page = $page; $this->wanCache = $wanCache; + $this->hookRunner = new HookRunner( $hookContainer ); } /** @@ -271,7 +280,7 @@ class BacklinkCache { } else { $prefix = null; // @phan-suppress-next-line PhanTypeMismatchArgument Type mismatch on pass-by-ref args - $this->getHookRunner()->onBacklinkCacheGetPrefix( $table, $prefix ); + $this->hookRunner->onBacklinkCacheGetPrefix( $table, $prefix ); if ( $prefix ) { return $prefix; } else { @@ -342,7 +351,7 @@ class BacklinkCache { default: $knownTable = false; $conds = null; - $this->getHookRunner()->onBacklinkCacheGetConditions( $table, + $this->hookRunner->onBacklinkCacheGetConditions( $table, // @phan-suppress-next-line PhanTypeMismatchArgumentNullable castFrom does not return null here Title::castFromPageReference( $this->page ), // @phan-suppress-next-line PhanTypeMismatchArgument Type mismatch on pass-by-ref args diff --git a/includes/cache/BacklinkCacheFactory.php b/includes/cache/BacklinkCacheFactory.php index 7ac0e28f074..c032e300b86 100644 --- a/includes/cache/BacklinkCacheFactory.php +++ b/includes/cache/BacklinkCacheFactory.php @@ -24,6 +24,7 @@ namespace MediaWiki\Cache; use BacklinkCache; +use MediaWiki\HookContainer\HookContainer; use MediaWiki\Page\PageReference; use WANObjectCache; @@ -37,11 +38,19 @@ class BacklinkCacheFactory { /** @var WANObjectCache */ private $wanCache; + /** @var HookContainer */ + private $hookContainer; + /** * @param WANObjectCache $wanCache + * @param HookContainer $hookContainer */ - public function __construct( WANObjectCache $wanCache ) { + public function __construct( + WANObjectCache $wanCache, + HookContainer $hookContainer + ) { $this->wanCache = $wanCache; + $this->hookContainer = $hookContainer; } /** @@ -56,7 +65,11 @@ class BacklinkCacheFactory { */ public function getBacklinkCache( PageReference $page ): BacklinkCache { if ( !$this->latestBacklinkCache || !$this->latestBacklinkCache->getPage()->isSamePageAs( $page ) ) { - $this->latestBacklinkCache = new BacklinkCache( $this->wanCache, $page ); + $this->latestBacklinkCache = new BacklinkCache( + $this->wanCache, + $this->hookContainer, + $page + ); } return $this->latestBacklinkCache; } diff --git a/tests/phpunit/unit/includes/cache/BacklinkCacheFactoryTest.php b/tests/phpunit/unit/includes/cache/BacklinkCacheFactoryTest.php index e6f782e8a67..1a0a4851f0b 100644 --- a/tests/phpunit/unit/includes/cache/BacklinkCacheFactoryTest.php +++ b/tests/phpunit/unit/includes/cache/BacklinkCacheFactoryTest.php @@ -14,7 +14,10 @@ class BacklinkCacheFactoryTest extends MediaWikiUnitTestCase { public function testGetBacklinkCache() { $wanCache = new WANObjectCache( [ 'cache' => new EmptyBagOStuff() ] ); $page = PageReferenceValue::localReference( NS_CATEGORY, "kittens" ); - $factory = new BacklinkCacheFactory( $wanCache ); + $factory = new BacklinkCacheFactory( + $wanCache, + $this->createHookContainer() + ); $cache = $factory->getBacklinkCache( $page ); $this->assertTrue( $cache->getPage()->isSamePageAs( $page ) );