Inject service DBLoadBalancerFactory

Change-Id: I50195f98c2ea130f9dba73e357977653c2fc1a37
This commit is contained in:
Fomafix 2023-11-01 14:11:34 +00:00 committed by James D. Forrester
parent 0fc8f3b24e
commit 9206c5368b
5 changed files with 29 additions and 6 deletions

View file

@ -15,6 +15,7 @@
"CategoryTree": {
"class": "MediaWiki\\Extension\\CategoryTree\\CategoryTreePage",
"services": [
"DBLoadBalancerFactory",
"SearchEngineFactory"
]
}
@ -97,6 +98,7 @@
"services": [
"CategoryTree.CategoryCache",
"MainConfig",
"DBLoadBalancerFactory",
"LinkRenderer"
]
},

View file

@ -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 );

View file

@ -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',

View file

@ -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' );

View file

@ -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 );