Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -540,6 +540,27 @@ |
541 | 541 | return new DatabaseMysql( $server, $user, $password, $dbName, $flags ); |
542 | 542 | } |
543 | 543 | |
| 544 | + /** |
| 545 | + * Given a DB type, construct the name of the appropriate child class of |
| 546 | + * DatabaseBase. This is designed to replace all of the manual stuff like: |
| 547 | + * $class = 'Database' . ucfirst( strtolower( $type ) ); |
| 548 | + * as well as validate against the canonical list of DB types we have |
| 549 | + * |
| 550 | + * @param $dbType String A possible DB type |
| 551 | + * @return DatabaseBase subclass or null |
| 552 | + */ |
| 553 | + public final static function classFromType( $dbType ) { |
| 554 | + $canonicalDBTypes = array( |
| 555 | + 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2' |
| 556 | + ); |
| 557 | + $dbType = strtolower( $dbType ); |
| 558 | + if( in_array( $dbType, $canonicalDBTypes ) ) { |
| 559 | + return 'Database' . ucfirst( $dbType ); |
| 560 | + } else { |
| 561 | + return null; |
| 562 | + } |
| 563 | + } |
| 564 | + |
544 | 565 | protected function installErrorHandler() { |
545 | 566 | $this->mPHPError = false; |
546 | 567 | $this->htmlErrors = ini_set( 'html_errors', '0' ); |
Index: trunk/phase3/includes/db/LoadBalancer.php |
— | — | @@ -632,7 +632,7 @@ |
633 | 633 | } |
634 | 634 | |
635 | 635 | # Get class for this database type |
636 | | - $class = 'Database' . ucfirst( $type ); |
| 636 | + $class = DatabaseBase::classFromType( $type ); |
637 | 637 | |
638 | 638 | # Create object |
639 | 639 | wfDebug( "Connecting to $host $dbname...\n" ); |
Index: trunk/phase3/includes/filerepo/ForeignDBRepo.php |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | |
37 | 37 | function getMasterDB() { |
38 | 38 | if ( !isset( $this->dbConn ) ) { |
39 | | - $class = 'Database' . ucfirst( $this->dbType ); |
| 39 | + $class = DatabaseBase::classFromType( $this->dbType ); |
40 | 40 | $this->dbConn = new $class( $this->dbServer, $this->dbUser, |
41 | 41 | $this->dbPassword, $this->dbName, $this->dbFlags, |
42 | 42 | $this->tablePrefix ); |
Index: trunk/phase3/includes/installer/WebInstallerPage.php |
— | — | @@ -384,7 +384,7 @@ |
385 | 385 | |
386 | 386 | $dbSupport = ''; |
387 | 387 | foreach( $this->parent->getDBTypes() as $type ) { |
388 | | - $db = 'Database' . ucfirst( $type ); |
| 388 | + $db = DatabaseBase::classFromType( $type ); |
389 | 389 | $dbSupport .= wfMsgNoTrans( "config-support-$type", |
390 | 390 | call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n"; |
391 | 391 | } |
Index: trunk/phase3/includes/extauth/MediaWiki.php |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | private function initFromCond( $cond ) { |
74 | 74 | global $wgExternalAuthConf; |
75 | 75 | |
76 | | - $class = 'Database' . $wgExternalAuthConf['DBtype']; |
| 76 | + $class = DatabaseBase::classFromType( $wgExternalAuthConf['DBtype'] ) |
77 | 77 | $this->mDb = new $class( |
78 | 78 | $wgExternalAuthConf['DBserver'], |
79 | 79 | $wgExternalAuthConf['DBuser'], |