r83414 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83413‎ | r83414 | r83415 >
Date:22:41, 6 March 2011
Author:demon
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/REL1_17/phase3/includes/db/Database.php (modified) (history)
  • /branches/REL1_17/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /branches/REL1_17/phase3/includes/extauth/MediaWiki.php (modified) (history)
  • /branches/REL1_17/phase3/includes/filerepo/ForeignDBRepo.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/WebInstallerPage.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/db/Database.php
@@ -529,11 +529,7 @@
530530
531531 /**
532532 * 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
538534 */
539535 static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
540536 wfDeprecated( __METHOD__ );
@@ -546,16 +542,36 @@
547543 * $class = 'Database' . ucfirst( strtolower( $type ) );
548544 * as well as validate against the canonical list of DB types we have
549545 *
 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+ *
550555 * @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
551558 * @return DatabaseBase subclass or null
552559 */
553 - public final static function classFromType( $dbType ) {
 560+ public final static function newFromType( $dbType, $p = array() ) {
554561 $canonicalDBTypes = array(
555562 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2'
556563 );
557564 $dbType = strtolower( $dbType );
 565+
558566 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+ );
560576 } else {
561577 return null;
562578 }
Property changes on: branches/REL1_17/phase3/includes/db/Database.php
___________________________________________________________________
Modified: svn:mergeinfo
563579 Merged /trunk/phase3/includes/db/Database.php:r80864
Index: branches/REL1_17/phase3/includes/db/LoadBalancer.php
@@ -619,17 +619,16 @@
620620 throw new MWException( 'You must update your load-balancing configuration. See DefaultSettings.php entry for $wgDBservers.' );
621621 }
622622
623 - extract( $server );
 623+ $host = $server['host'];
 624+ $dbname = $server['dbname'];
 625+
624626 if ( $dbNameOverride !== false ) {
625 - $dbname = $dbNameOverride;
 627+ $server['dbname'] = $dbname = $dbNameOverride;
626628 }
627629
628 - # Get class for this database type
629 - $class = DatabaseBase::classFromType( $type );
630 -
631630 # Create object
632631 wfDebug( "Connecting to $host $dbname...\n" );
633 - $db = new $class( $host, $user, $password, $dbname, $flags );
 632+ $db = DatabaseBase::newFromType( $server['type'], $server );
634633 if ( $db->isOpen() ) {
635634 wfDebug( "Connected to $host $dbname.\n" );
636635 } else {
Property changes on: branches/REL1_17/phase3/includes/db/LoadBalancer.php
___________________________________________________________________
Added: svn:mergeinfo
637636 Merged /branches/new-installer/phase3/includes/db/LoadBalancer.php:r43664-66004
638637 Merged /branches/wmf-deployment/includes/db/LoadBalancer.php:r53381
639638 Merged /branches/REL1_15/phase3/includes/db/LoadBalancer.php:r51646
640639 Merged /branches/sqlite/includes/db/LoadBalancer.php:r58211-58321
641640 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 @@
3636
3737 function getMasterDB() {
3838 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+ );
4349 }
4450 return $this->dbConn;
4551 }
Property changes on: branches/REL1_17/phase3/includes/filerepo/ForeignDBRepo.php
___________________________________________________________________
Modified: svn:mergeinfo
4652 Merged /trunk/phase3/includes/filerepo/ForeignDBRepo.php:r80864
Index: branches/REL1_17/phase3/includes/installer/WebInstallerPage.php
@@ -384,9 +384,8 @@
385385
386386 $dbSupport = '';
387387 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";
391390 }
392391 $this->addHTML( $this->parent->getInfoBox(
393392 wfMsg( 'config-support-info', $dbSupport ) ) );
Property changes on: branches/REL1_17/phase3/includes/installer/WebInstallerPage.php
___________________________________________________________________
Modified: svn:mergeinfo
394393 Merged /trunk/phase3/includes/installer/WebInstallerPage.php:r80864
Index: branches/REL1_17/phase3/includes/extauth/MediaWiki.php
@@ -72,14 +72,14 @@
7373 private function initFromCond( $cond ) {
7474 global $wgExternalAuthConf;
7575
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+ )
8484 );
8585
8686 $row = $this->mDb->selectRow(
Property changes on: branches/REL1_17/phase3/includes/extauth/MediaWiki.php
___________________________________________________________________
Modified: svn:mergeinfo
8787 Merged /trunk/phase3/includes/extauth/MediaWiki.php:r80864

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80864Followup to r79848 (and really, make it useful...)...demon16:31, 24 January 2011
r80895Fix for r80864: the $dbname variable was not there only to make pretty debug ...ialex18:45, 24 January 2011

Status & tagging log