Trailing whitespace in messages is not supported
[lhc/web/wiklou.git] / includes / filerepo / ForeignDBRepo.php
1 <?php
2 /**
3 * A foreign repository with an accessible MediaWiki database
4 *
5 * @file
6 * @ingroup FileRepo
7 */
8
9 /**
10 * A foreign repository with an accessible MediaWiki database
11 *
12 * @ingroup FileRepo
13 */
14 class ForeignDBRepo extends LocalRepo {
15 # Settings
16 var $dbType, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags,
17 $tablePrefix, $hasSharedCache;
18
19 # Other stuff
20 var $dbConn;
21 var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
22 var $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
23
24 function __construct( $info ) {
25 parent::__construct( $info );
26 $this->dbType = $info['dbType'];
27 $this->dbServer = $info['dbServer'];
28 $this->dbUser = $info['dbUser'];
29 $this->dbPassword = $info['dbPassword'];
30 $this->dbName = $info['dbName'];
31 $this->dbFlags = $info['dbFlags'];
32 $this->tablePrefix = $info['tablePrefix'];
33 $this->hasSharedCache = $info['hasSharedCache'];
34 }
35
36 function getMasterDB() {
37 if ( !isset( $this->dbConn ) ) {
38 $class = 'Database' . ucfirst( $this->dbType );
39 $this->dbConn = new $class( $this->dbServer, $this->dbUser,
40 $this->dbPassword, $this->dbName, false, $this->dbFlags,
41 $this->tablePrefix );
42 }
43 return $this->dbConn;
44 }
45
46 function getSlaveDB() {
47 return $this->getMasterDB();
48 }
49
50 function hasSharedCache() {
51 return $this->hasSharedCache;
52 }
53
54 /**
55 * Get a key on the primary cache for this repository.
56 * Returns false if the repository's cache is not accessible at this site.
57 * The parameters are the parts of the key, as for wfMemcKey().
58 */
59 function getSharedCacheKey( /*...*/ ) {
60 if ( $this->hasSharedCache() ) {
61 $args = func_get_args();
62 array_unshift( $args, $this->dbName, $this->tablePrefix );
63 return call_user_func_array( 'wfForeignMemcKey', $args );
64 } else {
65 return false;
66 }
67 }
68
69 function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
70 throw new MWException( get_class($this) . ': write operations are not supported' );
71 }
72 function publish( $srcPath, $dstRel, $archiveRel, $flags = 0 ) {
73 throw new MWException( get_class($this) . ': write operations are not supported' );
74 }
75 function deleteBatch( $sourceDestPairs ) {
76 throw new MWException( get_class($this) . ': write operations are not supported' );
77 }
78 }