MediaWiki REL1_33
ForeignDBRepo.php
Go to the documentation of this file.
1<?php
26
32class ForeignDBRepo extends LocalRepo {
34 protected $dbType;
35
37 protected $dbServer;
38
40 protected $dbUser;
41
43 protected $dbPassword;
44
46 protected $dbName;
47
49 protected $dbFlags;
50
52 protected $tablePrefix;
53
55 protected $hasSharedCache;
56
58 protected $dbConn;
59
61 protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
63 protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
64
68 function __construct( $info ) {
69 parent::__construct( $info );
70 $this->dbType = $info['dbType'];
71 $this->dbServer = $info['dbServer'];
72 $this->dbUser = $info['dbUser'];
73 $this->dbPassword = $info['dbPassword'];
74 $this->dbName = $info['dbName'];
75 $this->dbFlags = $info['dbFlags'];
76 $this->tablePrefix = $info['tablePrefix'];
77 $this->hasSharedCache = $info['hasSharedCache'];
78 }
79
83 function getMasterDB() {
84 if ( !isset( $this->dbConn ) ) {
85 $func = $this->getDBFactory();
86 $this->dbConn = $func( DB_MASTER );
87 }
88
89 return $this->dbConn;
90 }
91
95 function getReplicaDB() {
96 return $this->getMasterDB();
97 }
98
102 protected function getDBFactory() {
104 $params = [
105 'host' => $this->dbServer,
106 'user' => $this->dbUser,
107 'password' => $this->dbPassword,
108 'dbname' => $this->dbName,
109 'flags' => $this->dbFlags,
110 'tablePrefix' => $this->tablePrefix,
111 'foreign' => true,
112 ];
113
114 return function ( $index ) use ( $type, $params ) {
115 return Database::factory( $type, $params );
116 };
117 }
118
122 function hasSharedCache() {
124 }
125
132 function getSharedCacheKey( /*...*/ ) {
133 if ( $this->hasSharedCache() ) {
135
136 return wfForeignMemcKey( $this->dbName, $this->tablePrefix, ...$args );
137 } else {
138 return false;
139 }
140 }
141
142 protected function assertWritableRepo() {
143 throw new MWException( static::class . ': write operations are not supported.' );
144 }
145
152 function getInfo() {
153 return FileRepo::getInfo();
154 }
155}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfForeignMemcKey( $db, $prefix,... $args)
Make a cache key for a foreign DB.
if( $line===false) $args
Definition cdb.php:64
getInfo()
Return information about the repository.
A foreign repository with an accessible MediaWiki database.
getSharedCacheKey()
Get a key on the primary cache for this repository.
getInfo()
Return information about the repository.
callable $fileFactory
IDatabase $dbConn
assertWritableRepo()
Throw an exception if this repo is read-only by design.
callable $fileFromRowFactory
__construct( $info)
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition LocalRepo.php:36
MediaWiki exception.
Relational database abstraction object.
Definition Database.php:49
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
const DB_MASTER
Definition defines.php:26
$params