Index: branches/REL1_17/phase3/includes/db/Database.php |
— | — | @@ -529,11 +529,7 @@ |
530 | 530 | |
531 | 531 | /** |
532 | 532 | * Same as new DatabaseMysql( ... ), kept for backward compatibility |
533 | | - * @param $server String: database server host |
534 | | - * @param $user String: database user name |
535 | | - * @param $password String: database user password |
536 | | - * @param $dbName String: database name |
537 | | - * @param $flags |
| 533 | + * @deprecated |
538 | 534 | */ |
539 | 535 | static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) { |
540 | 536 | wfDeprecated( __METHOD__ ); |
— | — | @@ -546,16 +542,36 @@ |
547 | 543 | * $class = 'Database' . ucfirst( strtolower( $type ) ); |
548 | 544 | * as well as validate against the canonical list of DB types we have |
549 | 545 | * |
| 546 | + * This factory function is mostly useful for when you need to connect to a |
| 547 | + * database other than the MediaWiki default (such as for external auth, |
| 548 | + * an extension, et cetera). Do not use this to connect to the MediaWiki |
| 549 | + * database. Example uses in core: |
| 550 | + * @see LoadBalancer::reallyOpenConnection() |
| 551 | + * @see ExternalUser_MediaWiki::initFromCond() |
| 552 | + * @see ForeignDBRepo::getMasterDB() |
| 553 | + * @see WebInstaller_DBConnect::execute() |
| 554 | + * |
550 | 555 | * @param $dbType String A possible DB type |
| 556 | + * @param $p Array An array of options to pass to the constructor. |
| 557 | + * Valid options are: host, user, password, dbname, flags, tableprefix |
551 | 558 | * @return DatabaseBase subclass or null |
552 | 559 | */ |
553 | | - public final static function classFromType( $dbType ) { |
| 560 | + public final static function newFromType( $dbType, $p = array() ) { |
554 | 561 | $canonicalDBTypes = array( |
555 | 562 | 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2' |
556 | 563 | ); |
557 | 564 | $dbType = strtolower( $dbType ); |
| 565 | + |
558 | 566 | if( in_array( $dbType, $canonicalDBTypes ) ) { |
559 | | - return 'Database' . ucfirst( $dbType ); |
| 567 | + $class = 'Database' . ucfirst( $dbType ); |
| 568 | + return new $class( |
| 569 | + isset( $p['host'] ) ? $p['host'] : false, |
| 570 | + isset( $p['user'] ) ? $p['user'] : false, |
| 571 | + isset( $p['password'] ) ? $p['password'] : false, |
| 572 | + isset( $p['dbname'] ) ? $p['dbname'] : false, |
| 573 | + isset( $p['flags'] ) ? $p['flags'] : 0, |
| 574 | + isset( $p['tableprefix'] ) ? $p['tableprefix'] : 'get from global' |
| 575 | + ); |
560 | 576 | } else { |
561 | 577 | return null; |
562 | 578 | } |
Property changes on: branches/REL1_17/phase3/includes/db/Database.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
563 | 579 | Merged /trunk/phase3/includes/db/Database.php:r80864 |
Index: branches/REL1_17/phase3/includes/db/LoadBalancer.php |
— | — | @@ -619,17 +619,16 @@ |
620 | 620 | throw new MWException( 'You must update your load-balancing configuration. See DefaultSettings.php entry for $wgDBservers.' ); |
621 | 621 | } |
622 | 622 | |
623 | | - extract( $server ); |
| 623 | + $host = $server['host']; |
| 624 | + $dbname = $server['dbname']; |
| 625 | + |
624 | 626 | if ( $dbNameOverride !== false ) { |
625 | | - $dbname = $dbNameOverride; |
| 627 | + $server['dbname'] = $dbname = $dbNameOverride; |
626 | 628 | } |
627 | 629 | |
628 | | - # Get class for this database type |
629 | | - $class = DatabaseBase::classFromType( $type ); |
630 | | - |
631 | 630 | # Create object |
632 | 631 | wfDebug( "Connecting to $host $dbname...\n" ); |
633 | | - $db = new $class( $host, $user, $password, $dbname, $flags ); |
| 632 | + $db = DatabaseBase::newFromType( $server['type'], $server ); |
634 | 633 | if ( $db->isOpen() ) { |
635 | 634 | wfDebug( "Connected to $host $dbname.\n" ); |
636 | 635 | } else { |
Property changes on: branches/REL1_17/phase3/includes/db/LoadBalancer.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
637 | 636 | Merged /branches/new-installer/phase3/includes/db/LoadBalancer.php:r43664-66004 |
638 | 637 | Merged /branches/wmf-deployment/includes/db/LoadBalancer.php:r53381 |
639 | 638 | Merged /branches/REL1_15/phase3/includes/db/LoadBalancer.php:r51646 |
640 | 639 | Merged /branches/sqlite/includes/db/LoadBalancer.php:r58211-58321 |
641 | 640 | Merged /trunk/phase3/includes/db/LoadBalancer.php:r80841,80864,80895,82845,82847-82848 |
Index: branches/REL1_17/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 | } |
Property changes on: branches/REL1_17/phase3/includes/filerepo/ForeignDBRepo.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
46 | 52 | Merged /trunk/phase3/includes/filerepo/ForeignDBRepo.php:r80864 |
Index: branches/REL1_17/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 ) ) ); |
Property changes on: branches/REL1_17/phase3/includes/installer/WebInstallerPage.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
394 | 393 | Merged /trunk/phase3/includes/installer/WebInstallerPage.php:r80864 |
Index: branches/REL1_17/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( |
Property changes on: branches/REL1_17/phase3/includes/extauth/MediaWiki.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
87 | 87 | Merged /trunk/phase3/includes/extauth/MediaWiki.php:r80864 |