Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -522,11 +522,7 @@ |
523 | 523 | |
524 | 524 | /** |
525 | 525 | * Same as new DatabaseMysql( ... ), kept for backward compatibility |
526 | | - * @param $server String: database server host |
527 | | - * @param $user String: database user name |
528 | | - * @param $password String: database user password |
529 | | - * @param $dbName String: database name |
530 | | - * @param $flags |
| 526 | + * @deprecated |
531 | 527 | */ |
532 | 528 | static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) { |
533 | 529 | wfDeprecated( __METHOD__ ); |
— | — | @@ -539,16 +535,36 @@ |
540 | 536 | * $class = 'Database' . ucfirst( strtolower( $type ) ); |
541 | 537 | * as well as validate against the canonical list of DB types we have |
542 | 538 | * |
| 539 | + * This factory function is mostly useful for when you need to connect to a |
| 540 | + * database other than the MediaWiki default (such as for external auth, |
| 541 | + * an extension, et cetera). Do not use this to connect to the MediaWiki |
| 542 | + * database. Example uses in core: |
| 543 | + * @see LoadBalancer::reallyOpenConnection() |
| 544 | + * @see ExternalUser_MediaWiki::initFromCond() |
| 545 | + * @see ForeignDBRepo::getMasterDB() |
| 546 | + * @see WebInstaller_DBConnect::execute() |
| 547 | + * |
543 | 548 | * @param $dbType String A possible DB type |
| 549 | + * @param $p Array An array of options to pass to the constructor. |
| 550 | + * Valid options are: host, user, password, dbname, flags, tableprefix |
544 | 551 | * @return DatabaseBase subclass or null |
545 | 552 | */ |
546 | | - public final static function classFromType( $dbType ) { |
| 553 | + public final static function newFromType( $dbType, $p = array() ) { |
547 | 554 | $canonicalDBTypes = array( |
548 | 555 | 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2' |
549 | 556 | ); |
550 | 557 | $dbType = strtolower( $dbType ); |
| 558 | + |
551 | 559 | if( in_array( $dbType, $canonicalDBTypes ) ) { |
552 | | - return 'Database' . ucfirst( $dbType ); |
| 560 | + $class = 'Database' . ucfirst( $dbType ); |
| 561 | + return new $class( |
| 562 | + isset( $p['host'] ) ? $p['host'] : false, |
| 563 | + isset( $p['user'] ) ? $p['user'] : false, |
| 564 | + isset( $p['password'] ) ? $p['password'] : false, |
| 565 | + isset( $p['dbname'] ) ? $p['dbname'] : false, |
| 566 | + isset( $p['flags'] ) ? $p['flags'] : 0, |
| 567 | + isset( $p['tableprefix'] ) ? $p['tableprefix'] : 'get from global' |
| 568 | + ); |
553 | 569 | } else { |
554 | 570 | return null; |
555 | 571 | } |
Index: trunk/phase3/includes/db/LoadBalancer.php |
— | — | @@ -620,23 +620,16 @@ |
621 | 621 | 'See DefaultSettings.php entry for $wgDBservers.' ); |
622 | 622 | } |
623 | 623 | |
624 | | - $type = $server['type']; |
625 | 624 | $host = $server['host']; |
626 | | - $user = $server['user']; |
627 | | - $password = $server['password']; |
628 | | - $flags = $server['flags']; |
629 | 625 | $dbname = $server['dbname']; |
630 | 626 | |
631 | 627 | if ( $dbNameOverride !== false ) { |
632 | 628 | $dbname = $dbNameOverride; |
633 | 629 | } |
634 | 630 | |
635 | | - # Get class for this database type |
636 | | - $class = DatabaseBase::classFromType( $type ); |
637 | | - |
638 | 631 | # Create object |
639 | 632 | wfDebug( "Connecting to $host $dbname...\n" ); |
640 | | - $db = new $class( $host, $user, $password, $dbname, $flags ); |
| 633 | + $db = DatabaseBase::newFromType( $server['type'], $server ); |
641 | 634 | if ( $db->isOpen() ) { |
642 | 635 | wfDebug( "Connected to $host $dbname.\n" ); |
643 | 636 | } else { |
Index: trunk/phase3/includes/filerepo/ForeignDBRepo.php |
— | — | @@ -35,10 +35,16 @@ |
36 | 36 | |
37 | 37 | function getMasterDB() { |
38 | 38 | if ( !isset( $this->dbConn ) ) { |
39 | | - $class = DatabaseBase::classFromType( $this->dbType ); |
40 | | - $this->dbConn = new $class( $this->dbServer, $this->dbUser, |
41 | | - $this->dbPassword, $this->dbName, $this->dbFlags, |
42 | | - $this->tablePrefix ); |
| 39 | + $this->dbConn = DatabaseBase::newFromType( $this->dbType, |
| 40 | + array( |
| 41 | + 'server' => $this->dbServer, |
| 42 | + 'user' => $this->dbUser, |
| 43 | + 'password' => $this->dbPassword, |
| 44 | + 'dbname' => $this->dbName, |
| 45 | + 'flags' => $this->dbFlags, |
| 46 | + 'tableprefix' => $this->tablePrefix |
| 47 | + ) |
| 48 | + ); |
43 | 49 | } |
44 | 50 | return $this->dbConn; |
45 | 51 | } |
Index: trunk/phase3/includes/installer/WebInstallerPage.php |
— | — | @@ -384,9 +384,8 @@ |
385 | 385 | |
386 | 386 | $dbSupport = ''; |
387 | 387 | foreach( $this->parent->getDBTypes() as $type ) { |
388 | | - $db = DatabaseBase::classFromType( $type ); |
389 | | - $dbSupport .= wfMsgNoTrans( "config-support-$type", |
390 | | - call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n"; |
| 388 | + $link = DatabaseBase::newFromType( $type )->getSoftwareLink(); |
| 389 | + $dbSupport .= wfMsgNoTrans( "config-support-$type", $link ) . "\n"; |
391 | 390 | } |
392 | 391 | $this->addHTML( $this->parent->getInfoBox( |
393 | 392 | wfMsg( 'config-support-info', $dbSupport ) ) ); |
Index: trunk/phase3/includes/extauth/MediaWiki.php |
— | — | @@ -72,14 +72,14 @@ |
73 | 73 | private function initFromCond( $cond ) { |
74 | 74 | global $wgExternalAuthConf; |
75 | 75 | |
76 | | - $class = DatabaseBase::classFromType( $wgExternalAuthConf['DBtype'] ); |
77 | | - $this->mDb = new $class( |
78 | | - $wgExternalAuthConf['DBserver'], |
79 | | - $wgExternalAuthConf['DBuser'], |
80 | | - $wgExternalAuthConf['DBpassword'], |
81 | | - $wgExternalAuthConf['DBname'], |
82 | | - 0, |
83 | | - $wgExternalAuthConf['DBprefix'] |
| 76 | + $this->mDb = DatabaseBase::newFromType( $wgExternalAuthConf['DBtype'], |
| 77 | + array( |
| 78 | + 'server' => $wgExternalAuthConf['DBserver'], |
| 79 | + 'user' => $wgExternalAuthConf['DBuser'], |
| 80 | + 'password' => $wgExternalAuthConf['DBpassword'], |
| 81 | + 'dbname' => $wgExternalAuthConf['DBname'], |
| 82 | + 'tableprefix' => $wgExternalAuthConf['DBprefix'], |
| 83 | + ) |
84 | 84 | ); |
85 | 85 | |
86 | 86 | $row = $this->mDb->selectRow( |