MediaWiki  REL1_24
ForeignDBRepo.php
Go to the documentation of this file.
00001 <?php
00029 class ForeignDBRepo extends LocalRepo {
00031     protected $dbType;
00032 
00034     protected $dbServer;
00035 
00037     protected $dbUser;
00038 
00040     protected $dbPassword;
00041 
00043     protected $dbName;
00044 
00046     protected $dbFlags;
00047 
00049     protected $tablePrefix;
00050 
00052     protected $hasSharedCache;
00053 
00054     # Other stuff
00055     protected $dbConn;
00056     protected $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
00057     protected $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
00058 
00062     function __construct( $info ) {
00063         parent::__construct( $info );
00064         $this->dbType = $info['dbType'];
00065         $this->dbServer = $info['dbServer'];
00066         $this->dbUser = $info['dbUser'];
00067         $this->dbPassword = $info['dbPassword'];
00068         $this->dbName = $info['dbName'];
00069         $this->dbFlags = $info['dbFlags'];
00070         $this->tablePrefix = $info['tablePrefix'];
00071         $this->hasSharedCache = $info['hasSharedCache'];
00072     }
00073 
00077     function getMasterDB() {
00078         if ( !isset( $this->dbConn ) ) {
00079             $this->dbConn = DatabaseBase::factory( $this->dbType,
00080                 array(
00081                     'host' => $this->dbServer,
00082                     'user' => $this->dbUser,
00083                     'password' => $this->dbPassword,
00084                     'dbname' => $this->dbName,
00085                     'flags' => $this->dbFlags,
00086                     'tablePrefix' => $this->tablePrefix,
00087                     'foreign' => true,
00088                 )
00089             );
00090         }
00091 
00092         return $this->dbConn;
00093     }
00094 
00098     function getSlaveDB() {
00099         return $this->getMasterDB();
00100     }
00101 
00105     function hasSharedCache() {
00106         return $this->hasSharedCache;
00107     }
00108 
00115     function getSharedCacheKey( /*...*/ ) {
00116         if ( $this->hasSharedCache() ) {
00117             $args = func_get_args();
00118             array_unshift( $args, $this->dbName, $this->tablePrefix );
00119 
00120             return call_user_func_array( 'wfForeignMemcKey', $args );
00121         } else {
00122             return false;
00123         }
00124     }
00125 
00126     protected function assertWritableRepo() {
00127         throw new MWException( get_class( $this ) . ': write operations are not supported.' );
00128     }
00129 
00136     function getInfo() {
00137         return FileRepo::getInfo();
00138     }
00139 }