From b2ef67d9c892f612e6d42641d8170c8a7254eb8a Mon Sep 17 00:00:00 2001 From: Fomafix Date: Wed, 20 Sep 2023 20:36:37 +0000 Subject: [PATCH] Replace deprecated wfGetDB( DB_REPLICA ) Bug: T330641 Change-Id: Ic2dc694bbb29c3ff315f2be32c24ee6995f9b964 --- extension.json | 1 + includes/ApiCategoryTree.php | 9 ++++++++- includes/CategoryTree.php | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extension.json b/extension.json index d5c344e5..49a45ed6 100644 --- a/extension.json +++ b/extension.json @@ -24,6 +24,7 @@ "class": "MediaWiki\\Extension\\CategoryTree\\ApiCategoryTree", "services": [ "ConfigFactory", + "DBLoadBalancerFactory", "LanguageConverterFactory", "MainWANObjectCache" ] diff --git a/includes/ApiCategoryTree.php b/includes/ApiCategoryTree.php index 7de277fd..66d6e762 100644 --- a/includes/ApiCategoryTree.php +++ b/includes/ApiCategoryTree.php @@ -11,6 +11,7 @@ use MediaWiki\Languages\LanguageConverterFactory; use MediaWiki\Title\Title; use WANObjectCache; use Wikimedia\ParamValidator\ParamValidator; +use Wikimedia\Rdbms\IConnectionProvider; /** * This program is free software; you can redistribute it and/or modify @@ -36,6 +37,9 @@ class ApiCategoryTree extends ApiBase { /** @var LanguageConverterFactory */ private $languageConverterFactory; + /** @var IConnectionProvider */ + private $dbProvider; + /** @var WANObjectCache */ private $wanCache; @@ -43,6 +47,7 @@ class ApiCategoryTree extends ApiBase { * @param ApiMain $main * @param string $action * @param ConfigFactory $configFactory + * @param IConnectionProvider $dbProvider * @param LanguageConverterFactory $languageConverterFactory * @param WANObjectCache $wanCache */ @@ -50,12 +55,14 @@ class ApiCategoryTree extends ApiBase { ApiMain $main, $action, ConfigFactory $configFactory, + IConnectionProvider $dbProvider, LanguageConverterFactory $languageConverterFactory, WANObjectCache $wanCache ) { parent::__construct( $main, $action ); $this->configFactory = $configFactory; $this->languageConverterFactory = $languageConverterFactory; + $this->dbProvider = $dbProvider; $this->wanCache = $wanCache; } @@ -122,7 +129,7 @@ class ApiCategoryTree extends ApiBase { if ( $condition === 'last-modified' ) { $params = $this->extractRequestParams(); $title = CategoryTree::makeTitle( $params['category'] ); - return wfGetDB( DB_REPLICA )->selectField( 'page', 'page_touched', + return $this->dbProvider->getReplicaDatabase()->selectField( 'page', 'page_touched', [ 'page_namespace' => NS_CATEGORY, 'page_title' => $title->getDBkey(), diff --git a/includes/CategoryTree.php b/includes/CategoryTree.php index 4bfa6757..71e4c839 100644 --- a/includes/CategoryTree.php +++ b/includes/CategoryTree.php @@ -401,7 +401,7 @@ class CategoryTree { return ''; } - $dbr = wfGetDB( DB_REPLICA ); + $dbr = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase(); $inverse = $this->isInverse(); $mode = $this->getOption( 'mode' ); @@ -522,7 +522,7 @@ class CategoryTree { public function renderParents( Title $title ) { global $wgCategoryTreeMaxChildren; - $dbr = wfGetDB( DB_REPLICA ); + $dbr = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase(); $res = $dbr->select( 'categorylinks',