Merge "tests related to API block action and its gettoken"
[lhc/web/wiklou.git] / includes / filerepo / ForeignDBViaLBRepo.php
1 <?php
2 /**
3 * A foreign repository with a MediaWiki database accessible via the configured LBFactory
4 *
5 * @file
6 * @ingroup FileRepo
7 */
8
9 /**
10 * A foreign repository with a MediaWiki database accessible via the configured LBFactory
11 *
12 * @ingroup FileRepo
13 */
14 class ForeignDBViaLBRepo extends LocalRepo {
15 var $wiki, $dbName, $tablePrefix;
16 var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
17 var $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
18
19 function __construct( $info ) {
20 parent::__construct( $info );
21 $this->wiki = $info['wiki'];
22 list( $this->dbName, $this->tablePrefix ) = wfSplitWikiID( $this->wiki );
23 $this->hasSharedCache = $info['hasSharedCache'];
24 }
25
26 function getMasterDB() {
27 return wfGetDB( DB_MASTER, array(), $this->wiki );
28 }
29
30 function getSlaveDB() {
31 return wfGetDB( DB_SLAVE, array(), $this->wiki );
32 }
33
34 function hasSharedCache() {
35 return $this->hasSharedCache;
36 }
37
38 /**
39 * Get a key on the primary cache for this repository.
40 * Returns false if the repository's cache is not accessible at this site.
41 * The parameters are the parts of the key, as for wfMemcKey().
42 * @return bool|string
43 */
44 function getSharedCacheKey( /*...*/ ) {
45 if ( $this->hasSharedCache() ) {
46 $args = func_get_args();
47 array_unshift( $args, $this->wiki );
48 return implode( ':', $args );
49 } else {
50 return false;
51 }
52 }
53
54 protected function assertWritableRepo() {
55 throw new MWException( get_class( $this ) . ': write operations are not supported.' );
56 }
57 }