diff --git a/extension.json b/extension.json index e72129cc..9d19c5bd 100644 --- a/extension.json +++ b/extension.json @@ -15,6 +15,7 @@ "CategoryTree": { "class": "MediaWiki\\Extension\\CategoryTree\\CategoryTreePage", "services": [ + "DBLoadBalancerFactory", "SearchEngineFactory" ] } @@ -97,6 +98,7 @@ "services": [ "CategoryTree.CategoryCache", "MainConfig", + "DBLoadBalancerFactory", "LinkRenderer" ] }, diff --git a/includes/ApiCategoryTree.php b/includes/ApiCategoryTree.php index 8e202545..177f7041 100644 --- a/includes/ApiCategoryTree.php +++ b/includes/ApiCategoryTree.php @@ -88,7 +88,7 @@ class ApiCategoryTree extends ApiBase { $depth = isset( $options['depth'] ) ? (int)$options['depth'] : 1; - $ct = new CategoryTree( $options, $this->getConfig(), $this->linkRenderer ); + $ct = new CategoryTree( $options, $this->getConfig(), $this->dbProvider, $this->linkRenderer ); $depth = $ct->optionManager->capDepth( $depth ); $ctConfig = $this->configFactory->makeConfig( 'categorytree' ); $html = $this->getHTML( $ct, $title, $depth, $ctConfig ); diff --git a/includes/CategoryTree.php b/includes/CategoryTree.php index dea3f2dd..dfae29a5 100644 --- a/includes/CategoryTree.php +++ b/includes/CategoryTree.php @@ -36,6 +36,7 @@ use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Title\Title; use Parser; use RequestContext; +use Wikimedia\Rdbms\IConnectionProvider; /** * Core functions for the CategoryTree extension, an AJAX based gadget @@ -48,21 +49,27 @@ class CategoryTree { /** @var Config */ private $config; + /** @var IConnectionProvider */ + private $dbProvider; + /** @var LinkRenderer */ private $linkRenderer; /** * @param array $options * @param Config $config + * @param IConnectionProvider $dbProvider * @param LinkRenderer $linkRenderer */ public function __construct( array $options, Config $config, + IConnectionProvider $dbProvider, LinkRenderer $linkRenderer ) { $this->optionManager = new OptionManager( $options, $config ); $this->config = $config; + $this->dbProvider = $dbProvider; $this->linkRenderer = $linkRenderer; } @@ -150,7 +157,7 @@ class CategoryTree { return ''; } - $dbr = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase(); + $dbr = $this->dbProvider->getReplicaDatabase(); $inverse = $this->optionManager->isInverse(); $mode = $this->optionManager->getOption( 'mode' ); @@ -272,7 +279,7 @@ class CategoryTree { * @return string */ public function renderParents( Title $title ) { - $dbr = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase(); + $dbr = $this->dbProvider->getReplicaDatabase(); $res = $dbr->select( 'categorylinks', diff --git a/includes/CategoryTreePage.php b/includes/CategoryTreePage.php index f7c9f803..ce4e903d 100644 --- a/includes/CategoryTreePage.php +++ b/includes/CategoryTreePage.php @@ -29,6 +29,7 @@ use MediaWiki\Html\Html; use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\Title\Title; use SearchEngineFactory; +use Wikimedia\Rdbms\IConnectionProvider; /** * Special page for the CategoryTree extension, an AJAX based gadget @@ -38,6 +39,9 @@ class CategoryTreePage extends SpecialPage { /** @var string */ public $target = ''; + /** @var IConnectionProvider */ + private $dbProvider; + /** @var SearchEngineFactory */ private $searchEngineFactory; @@ -45,12 +49,15 @@ class CategoryTreePage extends SpecialPage { public $tree = null; /** + * @param IConnectionProvider $dbProvider * @param SearchEngineFactory $searchEngineFactory */ public function __construct( + IConnectionProvider $dbProvider, SearchEngineFactory $searchEngineFactory ) { parent::__construct( 'CategoryTree' ); + $this->dbProvider = $dbProvider; $this->searchEngineFactory = $searchEngineFactory; } @@ -100,7 +107,7 @@ class CategoryTreePage extends SpecialPage { $options[$option] = $request->getVal( $option, $default ); } - $this->tree = new CategoryTree( $options, $config, $this->getLinkRenderer() ); + $this->tree = new CategoryTree( $options, $config, $this->dbProvider, $this->getLinkRenderer() ); $this->getOutput()->addWikiMsg( 'categorytree-header' ); diff --git a/includes/Hooks.php b/includes/Hooks.php index 3f4ef52a..e4f38df7 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -44,6 +44,7 @@ use Parser; use PPFrame; use RequestContext; use Skin; +use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\Rdbms\IResultWrapper; /** @@ -68,21 +69,27 @@ class Hooks implements /** @var Config */ private $config; + /** @var IConnectionProvider */ + private IConnectionProvider $dbProvider; + /** @var LinkRenderer */ private $linkRenderer; /** * @param CategoryCache $categoryCache * @param Config $config + * @param IConnectionProvider $dbProvider * @param LinkRenderer $linkRenderer */ public function __construct( CategoryCache $categoryCache, Config $config, + IConnectionProvider $dbProvider, LinkRenderer $linkRenderer ) { $this->categoryCache = $categoryCache; $this->config = $config; + $this->dbProvider = $dbProvider; $this->linkRenderer = $linkRenderer; } @@ -203,7 +210,7 @@ class Hooks implements $parserOutput->addModules( [ 'ext.categoryTree' ] ); } - $ct = new CategoryTree( $argv, $this->config, $this->linkRenderer ); + $ct = new CategoryTree( $argv, $this->config, $this->dbProvider, $this->linkRenderer ); $attr = Sanitizer::validateTagAttributes( $argv, 'div' ); @@ -326,7 +333,7 @@ class Hooks implements if ( $mode !== null ) { $options['mode'] = $mode; } - $tree = new CategoryTree( $options, $this->config, $this->linkRenderer ); + $tree = new CategoryTree( $options, $this->config, $this->dbProvider, $this->linkRenderer ); $cat = $this->categoryCache->getCategory( $title );