MediaWiki
REL1_22
|
00001 <?php 00029 class ForeignDBRepo extends LocalRepo { 00030 # Settings 00031 var $dbType, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags, 00032 $tablePrefix, $hasSharedCache; 00033 00034 # Other stuff 00035 var $dbConn; 00036 var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' ); 00037 var $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' ); 00038 00042 function __construct( $info ) { 00043 parent::__construct( $info ); 00044 $this->dbType = $info['dbType']; 00045 $this->dbServer = $info['dbServer']; 00046 $this->dbUser = $info['dbUser']; 00047 $this->dbPassword = $info['dbPassword']; 00048 $this->dbName = $info['dbName']; 00049 $this->dbFlags = $info['dbFlags']; 00050 $this->tablePrefix = $info['tablePrefix']; 00051 $this->hasSharedCache = $info['hasSharedCache']; 00052 } 00053 00057 function getMasterDB() { 00058 if ( !isset( $this->dbConn ) ) { 00059 $this->dbConn = DatabaseBase::factory( $this->dbType, 00060 array( 00061 'host' => $this->dbServer, 00062 'user' => $this->dbUser, 00063 'password' => $this->dbPassword, 00064 'dbname' => $this->dbName, 00065 'flags' => $this->dbFlags, 00066 'tablePrefix' => $this->tablePrefix, 00067 'foreign' => true, 00068 ) 00069 ); 00070 } 00071 return $this->dbConn; 00072 } 00073 00077 function getSlaveDB() { 00078 return $this->getMasterDB(); 00079 } 00080 00084 function hasSharedCache() { 00085 return $this->hasSharedCache; 00086 } 00087 00094 function getSharedCacheKey( /*...*/ ) { 00095 if ( $this->hasSharedCache() ) { 00096 $args = func_get_args(); 00097 array_unshift( $args, $this->dbName, $this->tablePrefix ); 00098 return call_user_func_array( 'wfForeignMemcKey', $args ); 00099 } else { 00100 return false; 00101 } 00102 } 00103 00104 protected function assertWritableRepo() { 00105 throw new MWException( get_class( $this ) . ': write operations are not supported.' ); 00106 } 00107 }