Page MenuHomeWickedGov Phorge

GlobalPreferencesConnectionProvider.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

GlobalPreferencesConnectionProvider.php

<?php
namespace GlobalPreferences\Services;
use MediaWiki\Config\ServiceOptions;
use Wikimedia\Rdbms\IConnectionProvider;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\IReadableDatabase;
/**
* A service used to fetch a database connection to the GlobalPreferences database.
*/
class GlobalPreferencesConnectionProvider {
public const CONSTRUCTOR_OPTIONS = [
'GlobalPreferencesDB',
'SharedDB',
];
private ServiceOptions $options;
private IConnectionProvider $dbProvider;
public function __construct( ServiceOptions $options, IConnectionProvider $dbProvider ) {
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->options = $options;
$this->dbProvider = $dbProvider;
}
/**
* @return false|string The domain ID of the GlobalPreferences database
*/
private function getDomainId() {
$globalPreferencesDB = (string)$this->options->get( 'GlobalPreferencesDB' );
$sharedDB = (string)$this->options->get( 'SharedDB' );
if ( $globalPreferencesDB ) {
return $globalPreferencesDB;
} elseif ( $sharedDB ) {
return $sharedDB;
}
// local wiki
return false;
}
/**
* Get a replica GlobalPreferences database connection.
*
* @since 1.44
*
* @return IReadableDatabase
*/
public function getReplicaDatabase(): IReadableDatabase {
return $this->dbProvider->getReplicaDatabase( $this->getDomainId() );
}
/**
* Get a primary GlobalPreferences database connection.
*
* @since 1.44
*
* @return IDatabase
* @internal You should probably be using the API or special page to update a user's global preference value.
*/
public function getPrimaryDatabase(): IDatabase {
return $this->dbProvider->getPrimaryDatabase( $this->getDomainId() );
}
}

File Metadata

Mime Type
text/x-php
Expires
Aug 17 2026, 02:21 (11 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e2/e4/3dcc73a1c4bd35fafb745946a2c6
Default Alt Text
GlobalPreferencesConnectionProvider.php (1 KB)

Event Timeline