Skip to content

Commit

Permalink
Migrate to use DatabaseVirtualDomains (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Nov 19, 2024
1 parent 092074e commit cb84173
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';

$cfg['suppress_issue_types'] = [
'PhanAccessMethodInternal',
'PhanPluginMixedKeyNoKey',
'SecurityCheck-LikelyFalsePositive',
'PhanPluginMixedKeyNoKey'
];

return $cfg;
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ChangeLog for IncidentReporting


### 1.3.0 (19-11-2024)
* Require MediaWiki 1.42.0
* Add support for virtual database domains
* Remove support for $wgIncidentReportingDatabase

### 1.2.0 (01-01-2024)
* Add configuration variable, $wgIncidentReportingInactiveServices

Expand Down
14 changes: 5 additions & 9 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"Universal Omega"
],
"url": "https://github.com/miraheze/IncidentReporting",
"version": "1.2.0",
"version": "1.3.0",
"descriptionmsg": "incidentreporting-desc",
"license-name": "GPL-3.0-or-later",
"type": "specialpage",
"requires": {
"MediaWiki": ">= 1.38.0"
"MediaWiki": ">= 1.42.0"
},
"AvailableRights": [
"viewincidents",
Expand Down Expand Up @@ -43,14 +43,12 @@
"ResourceModules": {
"ext.incidentreporting.oouiform": {
"scripts": "ext.incidentreporting.oouiform.ooui.js",
"targets": [ "desktop", "mobile" ],
"dependencies": [
"mediawiki.storage",
"oojs-ui-widgets"
]
},
"ext.incidentreporting.oouiform.styles": {
"targets": [ "desktop", "mobile" ],
"styles": "ext.incidentreporting.oouiform.ooui.less"
}
},
Expand All @@ -59,11 +57,6 @@
"remoteExtPath": "IncidentReporting/modules"
},
"config": {
"IncidentReportingDatabase": {
"description": "Database name where all data is stored.",
"public": true,
"value": false
},
"IncidentReportingServices": {
"description": "Human readable list of service components with page URLs. Set to false for no link. Format: 'name' => 'url'.",
"public": true,
Expand All @@ -88,5 +81,8 @@
"ConfigRegistry": {
"incidentreporting": "GlobalVarConfig::newInstance"
},
"DatabaseVirtualDomains": [
"virtual-incidentreporting"
],
"manifest_version": 2
}
8 changes: 4 additions & 4 deletions includes/IncidentReportingFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use Wikimedia\Rdbms\DBConnRef;
use Wikimedia\Rdbms\IDatabase;

class IncidentReportingFormFactory {
/** @var Config */
Expand All @@ -18,7 +18,7 @@ public function __construct() {
}

public function getFormDescriptor(
DBConnRef $dbw,
IDatabase $dbw,
int $id,
bool $edit,
IContextSource $context
Expand Down Expand Up @@ -482,7 +482,7 @@ public function getFormDescriptor(
public function getForm(
int $id,
bool $edit,
DBConnRef $dbw,
IDatabase $dbw,
IContextSource $context,
$formClass = IncidentReportingOOUIForm::class
) {
Expand Down Expand Up @@ -529,7 +529,7 @@ protected function submitForm(
array $formData,
HTMLForm $form,
int $id,
DBConnRef $dbw,
IDatabase $dbw,
IContextSource $context
) {
if ( isset( $formData['view'] ) && $formData['view'] ) {
Expand Down
28 changes: 22 additions & 6 deletions includes/IncidentReportingHooks.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
<?php

class IncidentReportingHooks {

public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
$updater->addExtensionTable( 'incidents',
__DIR__ . '/../sql/incidents.sql' );
$updater->addExtensionUpdateOnVirtualDomain( [
'virtual-incidentreporting',
'addTable',
'incidents',
__DIR__ . '/../sql/incidents.sql',
true,
] );

$updater->addExtensionTable( 'incidents_log',
__DIR__ . '/../sql/incidents_log.sql' );
$updater->addExtensionUpdateOnVirtualDomain( [
'virtual-incidentreporting',
'addTable',
'incidents_log',
__DIR__ . '/../sql/incidents_log.sql',
true,
] );

$updater->addExtensionTable( 'incidents_reviewer',
__DIR__ . '/../sql/incidents_reviewer.sql' );
$updater->addExtensionUpdateOnVirtualDomain( [
'virtual-incidentreporting',
'addTable',
'incidents_reviewer',
__DIR__ . '/../sql/incidents_reviewer.sql',
true,
] );
}
}
9 changes: 2 additions & 7 deletions includes/IncidentReportingPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ class IncidentReportingPager extends TablePager {
/** @var string */
private $type;

/** @var Config */
private $config;

public function __construct( $type, $component, $services ) {
parent::__construct( $this->getContext() );
$this->type = $type;
$this->component = $component;
$this->config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'incidentreporting' );

$this->mDb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()
->getMainLB( $this->config->get( 'IncidentReportingDatabase' ) )
->getMaintenanceConnectionRef( DB_REPLICA, [], $this->config->get( 'IncidentReportingDatabase' ) );
$this->mDb = MediaWikiServices::getInstance()->getConnectionProvider()
->getReplicaDatabase( 'virtual-incidentreporting' );

$irServices = [];
foreach ( $services as $service => $url ) {
Expand Down
11 changes: 5 additions & 6 deletions includes/SpecialIncidentReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use Wikimedia\Rdbms\DBConnRef;
use Wikimedia\Rdbms\IDatabase;

class SpecialIncidentReports extends SpecialPage {
/** @var Config */
Expand All @@ -23,9 +23,8 @@ public function execute( $par ) {

$par = explode( '/', $par );

$dbw = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()
->getMainLB( $this->config->get( 'IncidentReportingDatabase' ) )
->getMaintenanceConnectionRef( DB_PRIMARY, [], $this->config->get( 'IncidentReportingDatabase' ) );
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()
->getPrimaryDatabase( 'virtual-incidentreporting' );

$inc = $dbw->selectRow(
'incidents',
Expand All @@ -48,7 +47,7 @@ public function execute( $par ) {
public function showForm(
int $id,
bool $edit,
DBConnRef $dbw,
IDatabase $dbw,
bool $isPublished
) {
if ( !$isPublished && !$this->permissionManager->userHasRight( $this->getContext()->getUser(), 'editincidents' ) ) {
Expand All @@ -72,7 +71,7 @@ public function showForm(
$htmlForm->show();
}

public function showLanding( DBConnRef $dbw ) {
public function showLanding( IDatabase $dbw ) {
$type = $this->getRequest()->getText( 'type' );
$component = $this->getRequest()->getText( 'component' );
$published = $this->getRequest()->getText( 'published' );
Expand Down

0 comments on commit cb84173

Please sign in to comment.