* Use a proper factory for newFromRow
[lhc/web/wiklou.git] / includes / filerepo / ForeignDBRepo.php
1 <?php
2
3 /**
4 * A foreign repository with an accessible MediaWiki database
5 * @ingroup FileRepo
6 */
7 class ForeignDBRepo extends LocalRepo {
8 # Settings
9 var $dbType, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags,
10 $tablePrefix, $hasSharedCache;
11
12 # Other stuff
13 var $dbConn;
14 var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
15 var $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
16
17 function newFileFromRow( $row ) {
18 if ( isset( $row->img_name ) )
19 return ForeignDBFile::newFromRow( $row, $this );
20 return parent::newFileFromRow( $row );
21 }
22
23 function __construct( $info ) {
24 parent::__construct( $info );
25 $this->dbType = $info['dbType'];
26 $this->dbServer = $info['dbServer'];
27 $this->dbUser = $info['dbUser'];
28 $this->dbPassword = $info['dbPassword'];
29 $this->dbName = $info['dbName'];
30 $this->dbFlags = $info['dbFlags'];
31 $this->tablePrefix = $info['tablePrefix'];
32 $this->hasSharedCache = $info['hasSharedCache'];
33 }
34
35 function getMasterDB() {
36 if ( !isset( $this->dbConn ) ) {
37 $class = 'Database' . ucfirst( $this->dbType );
38 $this->dbConn = new $class( $this->dbServer, $this->dbUser,
39 $this->dbPassword, $this->dbName, false, $this->dbFlags,
40 $this->tablePrefix );
41 }
42 return $this->dbConn;
43 }
44
45 function getSlaveDB() {
46 return $this->getMasterDB();
47 }
48
49 function hasSharedCache() {
50 return $this->hasSharedCache;
51 }
52
53 function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
54 throw new MWException( get_class($this) . ': write operations are not supported' );
55 }
56 function publish( $srcPath, $dstRel, $archiveRel, $flags = 0 ) {
57 throw new MWException( get_class($this) . ': write operations are not supported' );
58 }
59 function deleteBatch( $fileMap ) {
60 throw new MWException( get_class($this) . ': write operations are not supported' );
61 }
62 }