Commit 946ca9a6 authored by Alexia's avatar Alexia

Just bring that back.

parent 5ea3ee56
......@@ -110,6 +110,7 @@
"AutoloadClasses": {
"AbuseFilter": "includes/AbuseFilter.php",
"AbuseFilterCachingParser" : "includes/parser/AbuseFilterCachingParser.php",
"AbuseFilterCentralDb" : "includes/AbuseFilterCentralDb.php",
"AbuseFilterParser": "includes/parser/AbuseFilterParser.php",
"AbuseFilterTokenizer": "includes/parser/AbuseFilterTokenizer.php",
"AbuseFilterHooks": "includes/AbuseFilterHooks.php",
......
......@@ -362,7 +362,7 @@ class AbuseFilter {
if ( !$wgAbuseFilterCentralDB ) {
return false;
}
$dbr = wfGetDB( DB_REPLICA, [], $wgAbuseFilterCentralDB );
$dbr = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_REPLICA );
$filter = $globalIndex;
} else {
$dbr = wfGetDB( DB_REPLICA );
......@@ -861,7 +861,7 @@ class AbuseFilter {
}
if ( count( $globalFilters ) ) {
$fdb = wfGetDB( DB_REPLICA, [], $wgAbuseFilterCentralDB );
$fdb = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_REPLICA );
$consequences = $consequences + self::loadConsequencesFromDB(
$fdb,
$globalFilters,
......@@ -1489,7 +1489,7 @@ class AbuseFilter {
}
global $wgAbuseFilterCentralDB;
$fdb = wfGetDB( DB_MASTER, [], $wgAbuseFilterCentralDB );
$fdb = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_MASTER );
foreach ( $central_log_rows as $row ) {
$fdb->insert( 'abuse_filter_log', $row, __METHOD__ );
......@@ -1556,7 +1556,7 @@ class AbuseFilter {
// Store to text table
if ( $global ) {
$dbw = wfGetDB( DB_MASTER, [], $wgAbuseFilterCentralDB );
$dbw = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_MASTER );
} else {
$dbw = wfGetDB( DB_MASTER );
}
......@@ -3223,7 +3223,7 @@ class AbuseFilter {
return $cache[$filterID];
}
$fdb = wfGetDB( DB_REPLICA, [], $wgAbuseFilterCentralDB );
$fdb = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_REPLICA );
$cache[$filterID] = $fdb->selectField(
'abuse_filter',
......
<?php
use MediaWiki\MediaWikiServices;
/**
* Database factory class, this will determine whether to use the main database
* or an external database defined in configuration file
*/
class AbuseFilterCentralDb {
/**
* Singleton instance of this class.
*
* @var object
*/
static private $instance = null;
/**
* Central database connection.
* This will get set to false if a central database is not configured.
*
* @var array
*/
private $dbs = [];
/**
* Central cluster.
*
* @var string
*/
private $cluster = null;
/**
* Central database.
*
* @var string
*/
private $database = null;
/**
* Main Constructor
*
* @access public
* @param string Cluster name from $wgExternalClusters.
* @param string Database name for the central database.
* @return void
*/
public function __construct( $cluster, $database ) {
$this->cluster = $cluster;
$this->database = $database;
}
/**
* Return a singleton instance of this class.
*
* @access public
* @return object AbuseFilterDbFactory
*/
static public function getInstance() {
if ( self::$instance === null ) {
$config = MediaWikiServices::getInstance()->getConfigFactory()::getDefaultInstance()->makeConfig( 'main' );
$abuseFilterCentralCluster = $config->get( 'AbuseFilterCentralCluster' );
$abuseFilterCentralDB = $config->get( 'AbuseFilterCentralDB' );
self::$instance = new self( $abuseFilterCentralCluster, $abuseFilterCentralDB );
}
return self::$instance;
}
/**
* Get the central database filter store.
*
* @access public
* @param integer $dbtype either DB_MASTER or DB_REPLICA.
* @return DatabaseBase|false DatabaseBase or false on connection error.
*/
public function getCentralDb( $dbtype = DB_MASTER ) {
if ( isset( $this->dbs[$dbtype] ) && $this->dbs[$dbtype] !== null ) {
return $this->dbs[$dbtype];
}
$db = false;
if ( $this->isUsingCentralDb() ) {
if ( $this->isUsingCentralCluster() ) {
$db = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getExternalLB( $this->cluster )->getConnection( $dbtype, false, $this->database );
} else {
$db = wfGetDB( $dbtype, [], $this->database );
}
}
$this->dbs[$dbtype] = $db;
return $this->dbs[$dbtype];
}
/**
* Are we using a central cluster?
*
* @access public
* @return boolean
*/
public function isUsingCentralCluster() {
return $this->cluster !== null;
}
/**
* Are we using a central database?
*
* @access public
* @return boolean
*/
public function isUsingCentralDb() {
return $this->database !== null;
}
}
......@@ -289,7 +289,7 @@ class AbuseFilterHooks {
if ( $log_ids !== null && count( $log_ids ) ) {
global $wgAbuseFilterCentralDB;
$fdb = wfGetDB( DB_MASTER, [], $wgAbuseFilterCentralDB );
$fdb = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_MASTER );
$fdb->update( 'abuse_filter_log',
[ 'afl_rev_id' => $revision->getId() ],
......@@ -482,7 +482,7 @@ class AbuseFilterHooks {
}
if ( $wgAbuseFilterCentralDB && !$wgAbuseFilterIsCentral ) {
$dbr = wfGetDB( DB_REPLICA, [], $wgAbuseFilterCentralDB );
$dbr = AbuseFilterCentralDb::getInstance()->getCentralDb( DB_REPLICA );
$where['af_global'] = 1;
$res = $dbr->select(
[ 'abuse_filter_action', 'abuse_filter' ],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment