MediaWiki  REL1_20
ForeignDBRepo.php
Go to the documentation of this file.
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                                 )
00068                         );
00069                 }
00070                 return $this->dbConn;
00071         }
00072 
00076         function getSlaveDB() {
00077                 return $this->getMasterDB();
00078         }
00079 
00083         function hasSharedCache() {
00084                 return $this->hasSharedCache;
00085         }
00086 
00093         function getSharedCacheKey( /*...*/ ) {
00094                 if ( $this->hasSharedCache() ) {
00095                         $args = func_get_args();
00096                         array_unshift( $args, $this->dbName, $this->tablePrefix );
00097                         return call_user_func_array( 'wfForeignMemcKey', $args );
00098                 } else {
00099                         return false;
00100                 }
00101         }
00102 
00103         protected function assertWritableRepo() {
00104                 throw new MWException( get_class( $this ) . ': write operations are not supported.' );
00105         }
00106 }