r24578 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24577‎ | r24578 | r24579 >
Date:13:34, 4 August 2007
Author:brion
Status:old
Tags:
Comment:
Make use of $wgAlternateMaster for grabbing the remote dbs
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -11,6 +11,36 @@
1212
1313 */
1414
 15+class CentralAuthHelper {
 16+ private static $connections = array();
 17+
 18+ function get( $dbname ) {
 19+ global $wgDBname;
 20+ if( $dbname == $wgDBname ) {
 21+ return wfGetDB( DB_MASTER );
 22+ }
 23+ if( !isset( self::$connections[$dbname] ) ) {
 24+ self::$connections[$dbname] = self::openConnection( $dbname );
 25+ }
 26+ return self::$connections[$dbname];
 27+ }
 28+
 29+ private function getServer( $dbname ) {
 30+ global $wgAlternateMaster, $wgDBserver;
 31+ if( isset( $wgAlternateMaster[$dbname] ) ) {
 32+ return $wgAlternateMaster[$dbname];
 33+ } elseif( isset( $wgAlternateMaster['DEFAULT'] ) ) {
 34+ return $wgAlternateMaster['DEFAULT'];
 35+ }
 36+ return $wgDBserver;
 37+ }
 38+
 39+ private function openConnection( $dbname ) {
 40+ global $wgDBuser, $wgDBpassword;
 41+ $server = self::getServer( $dbname );
 42+ return new Database( $server, $wgDBuser, $wgDBpassword, $dbname );
 43+ }
 44+}
1545
1646 class CentralAuthUser {
1747
@@ -28,14 +58,14 @@
2959 * @fixme Make use of some info to get the appropriate master DB
3060 */
3161 public static function getCentralDB() {
32 - return wfGetDB( DB_MASTER, 'Central' );
 62+ return CentralAuthHelper::get( 'centralauth' );
3363 }
3464
3565 /**
3666 * @fixme Make use of some info to get the appropriate master DB
3767 */
3868 public static function getLocalDB( $dbname ) {
39 - return wfGetDB( DB_MASTER );
 69+ return CentralAuthHelper::get( $dbname );
4070 }
4171
4272 public static function tableName( $name ) {

Status & tagging log