# capitalize the first letter of the filename before
# looking it up in the shared repository.
$name = $wgContLang->ucfirst($this->name);
- $dbc = wfGetDB( DB_SLAVE, 'commons' );
+ $dbc = Image::getCommonsDB();
$row = $dbc->selectRow( "`$wgSharedUploadDBname`.{$wgSharedUploadDBprefix}image",
array(
// Write to the other DB using selectDB, not database selectors
// This avoids breaking replication in MySQL
- $dbw = wfGetDB( DB_MASTER, 'commons' );
- $dbw->selectDB( $wgSharedUploadDBname );
+ $dbw = Image::getCommonsDB();
} else {
$dbw = wfGetDB( DB_MASTER );
}
}
}
+ static function getCommonsDB() {
+ static $dbc;
+ global $wgLoadBalancer;
+ if ( !isset( $dbc ) ) {
+ $i = $wgLoadBalancer->getGroupIndex( 'commons' );
+ $dbinfo = $wgLoadBalancer->mServers[$i];
+ $dbc = new Database( $dbinfo['host'], $dbinfo['user'],
+ $dbinfo['password'], $wgSharedUploadDBname );
+ }
+ return $dbc;
+ }
+
} //class
/**