Skip to content

Commit ac5917c

Browse files
authored
Replace wfGetDB with MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef (#89)
* Replace wfGetDB with MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef * Update SqlProvider.php * Update PageSchemas.php * Update SqlProvider.php * Update AppliedFilter.php * Update psalm.xml * Update PageSchemas.php * Update SqlProvider.php * Update PageSchemas.php * Update AppliedFilter.php
1 parent 80e1a3e commit ac5917c

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

includes/AppliedFilter.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ public function checkSQL( $value_field ) {
152152
}
153153

154154
$sql = "(";
155-
$dbr = wfGetDB( DB_REPLICA );
155+
$dbr = MediaWikiServices::getInstance()
156+
->getDBLoadBalancer()
157+
->getMaintenanceConnectionRef( DB_REPLICA );
156158
if ( $this->search_terms != null ) {
157159
$quoteReplace = ( $wgDBtype == 'postgres' ? "''" : "\'" );
158160
foreach ( $this->search_terms as $i => $search_term ) {

includes/Filter.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SD;
44

5+
use MediaWiki\MediaWikiServices;
56
use SD\Sql\PropertyTypeDbInfo;
67
use SD\Sql\SqlProvider;
78
use SMWDIProperty;
@@ -106,7 +107,9 @@ public function getTimePeriodValues(): PossibleFilterValues {
106107
$possible_dates = [];
107108
$property_value = $this->escapedProperty();
108109
$date_field = PropertyTypeDbInfo::dateField( $this->propertyType() );
109-
$dbw = wfGetDB( DB_PRIMARY );
110+
$dbw = MediaWikiServices::getInstance()
111+
->getDBLoadBalancer()
112+
->getMaintenanceConnectionRef( DB_PRIMARY );
110113
list( $yearValue, $monthValue, $dayValue ) = SqlProvider::getDateFunctions( $date_field );
111114
$fields = "$yearValue, $monthValue, $dayValue";
112115
$datesTable = $dbw->tableName( PropertyTypeDbInfo::tableName( $this->propertyType() ) );
@@ -234,7 +237,9 @@ public function getTimePeriodValues(): PossibleFilterValues {
234237
public function getAllValues(): PossibleFilterValues {
235238
$possible_values = [];
236239
$property_value = $this->escapedProperty();
237-
$dbw = wfGetDB( DB_PRIMARY );
240+
$dbw = MediaWikiServices::getInstance()
241+
->getDBLoadBalancer()
242+
->getMaintenanceConnectionRef( DB_PRIMARY );
238243
$property_table_name = $dbw->tableName( PropertyTypeDbInfo::tableName( $this->propertyType() ) );
239244
$revision_table_name = $dbw->tableName( 'revision' );
240245
$page_props_table_name = $dbw->tableName( 'page_props' );
@@ -277,7 +282,9 @@ public function getAllValues(): PossibleFilterValues {
277282
}
278283

279284
private function getTimePeriod() {
280-
$dbw = wfGetDB( DB_PRIMARY );
285+
$dbw = MediaWikiServices::getInstance()
286+
->getDBLoadBalancer()
287+
->getMaintenanceConnectionRef( DB_PRIMARY );
281288
$property_value = $this->escapedProperty();
282289
$date_field = PropertyTypeDbInfo::dateField( $this->propertyType() );
283290
$datesTable = $dbw->tableName( PropertyTypeDbInfo::tableName( $this->propertyType() ) );

includes/PageSchemas.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SD;
44

55
use Html;
6+
use MediaWiki\MediaWikiServices;
67

78
/**
89
* Static functions for Semantic Drilldown, for use by the Page Schemas
@@ -105,7 +106,10 @@ public static function getFieldEditingHTML( $psField ) {
105106
$html_text .= wfMessage( 'sd_createfilter_usepropertyvalues' )->text() . "\n";
106107
$html_text .= Html::input( 'sd_values_source_num', 'category', 'radio', $fromCategoryAttrs ) . "\n";
107108
$html_text .= "\t" . wfMessage( 'sd_createfilter_usecategoryvalues' )->text() . "\n";
108-
$categories = ( new DbService( null, wfGetDB( DB_REPLICA ) ) )->getTopLevelCategories();
109+
$dbr = MediaWikiServices::getInstance()
110+
->getDBLoadBalancer()
111+
->getMaintenanceConnectionRef( DB_REPLICA );
112+
$categories = ( new DbService( null, $dbr ) )->getTopLevelCategories();
109113
$categoriesHTML = "";
110114
foreach ( $categories as $category ) {
111115
$categoryOptionAttrs = [];

includes/Sql/SqlProvider.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SD\Sql;
44

5+
use MediaWiki\MediaWikiServices;
56
use SD\AppliedFilter;
67
use SD\Utils;
78

@@ -47,7 +48,9 @@ public static function getSQLFromClauseForField( $new_filter ) {
4748
* @return string
4849
*/
4950
public static function getSQLFromClauseForCategory( $subcategory, $child_subcategories ) {
50-
$dbr = wfGetDB( DB_REPLICA );
51+
$dbr = MediaWikiServices::getInstance()
52+
->getDBLoadBalancer()
53+
->getMaintenanceConnectionRef( DB_REPLICA );
5154
$smwIDs = $dbr->tableName( Utils::getIDsTableName() );
5255
$smwCategoryInstances = $dbr->tableName( Utils::getCategoryInstancesTableName() );
5356
$ns_cat = NS_CATEGORY;
@@ -78,7 +81,9 @@ public static function getSQLFromClauseForCategory( $subcategory, $child_subcate
7881
* @return string
7982
*/
8083
public static function getSQLFromClause( string $category, string $subcategory, array $subcategories, array $applied_filters ) {
81-
$dbr = wfGetDB( DB_REPLICA );
84+
$dbr = MediaWikiServices::getInstance()
85+
->getDBLoadBalancer()
86+
->getMaintenanceConnectionRef( DB_REPLICA );
8287
$smwIDs = $dbr->tableName( Utils::getIDsTableName() );
8388
$smwCategoryInstances = $dbr->tableName( Utils::getCategoryInstancesTableName() );
8489
$cat_ns = NS_CATEGORY;

psalm.xml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<UndefinedFunction>
2828
<errorLevel type="suppress">
2929
<referencedFunction name="wfMessage" />
30-
<referencedFunction name="wfGetDB" />
3130
</errorLevel>
3231
</UndefinedFunction>
3332
</issueHandlers>

0 commit comments

Comments
 (0)