Replace deprecated global function wfGetDB()

Bug: T330641
Change-Id: If0427da7a6d2de9d1ec00bf1ff7e5b8a495617e9
This commit is contained in:
Fomafix 2023-10-15 18:48:50 +00:00
parent 029af825a9
commit 318407932c
4 changed files with 13 additions and 2 deletions

View file

@ -37,6 +37,7 @@
"main": {
"class": "PageImages\\PageImages",
"services": [
"DBLoadBalancerFactory",
"RepoGroup",
"UserOptionsLookup"
]

View file

@ -18,6 +18,7 @@ use MediaWiki\User\UserOptionsLookup;
use OutputPage;
use RepoGroup;
use Skin;
use Wikimedia\Rdbms\IConnectionProvider;
/**
* @license WTFPL
@ -59,6 +60,9 @@ class PageImages implements
*/
public const PROP_NAME_FREE = 'page_image_free';
/** @var IConnectionProvider */
private $dbProvider;
/** @var RepoGroup */
private $repoGroup;
@ -74,19 +78,23 @@ class PageImages implements
private static function factory() {
$services = MediaWikiServices::getInstance();
return new self(
$services->getDBLoadBalancerFactory(),
$services->getRepoGroup(),
$services->getUserOptionsLookup()
);
}
/**
* @param IConnectionProvider $dbProvider
* @param RepoGroup $repoGroup
* @param UserOptionsLookup $userOptionsLookup
*/
public function __construct(
IConnectionProvider $dbProvider,
RepoGroup $repoGroup,
UserOptionsLookup $userOptionsLookup
) {
$this->dbProvider = $dbProvider;
$this->repoGroup = $repoGroup;
$this->userOptionsLookup = $userOptionsLookup;
}
@ -170,7 +178,7 @@ class PageImages implements
return null;
}
$dbr = wfGetDB( DB_REPLICA );
$dbr = $this->dbProvider->getReplicaDatabase();
$fileName = $dbr->selectField( 'page_props',
'pp_value',
[

View file

@ -58,7 +58,8 @@ class InitImageData extends Maintenance {
'LEFT JOIN', 'page_id = il_from',
] ];
$dbr = wfGetDB( DB_REPLICA );
$dbr = $this->getServiceContainer()->getDBLoadBalancerFactory()
->getReplicaDatabase();
if ( $this->hasOption( 'namespaces' ) ) {
$ns = explode( ',', $this->getOption( 'namespaces' ) );
$conds['page_namespace'] = $ns;

View file

@ -24,6 +24,7 @@ class PageImagesTest extends MediaWikiIntegrationTestCase {
private function newPageImages() {
$services = $this->getServiceContainer();
return new PageImages(
$services->getDBLoadBalancerFactory(),
$services->getRepoGroup(),
$services->getUserOptionsLookup()
);