3 * A foreign repository with an accessible MediaWiki database.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * A foreign repository with an accessible MediaWiki database
29 class ForeignDBRepo
extends LocalRepo
{
40 protected $dbPassword;
49 protected $tablePrefix;
52 protected $hasSharedCache;
56 protected $fileFactory = [ 'ForeignDBFile', 'newFromTitle' ];
57 protected $fileFromRowFactory = [ 'ForeignDBFile', 'newFromRow' ];
60 * @param array|null $info
62 function __construct( $info ) {
63 parent
::__construct( $info );
64 $this->dbType
= $info['dbType'];
65 $this->dbServer
= $info['dbServer'];
66 $this->dbUser
= $info['dbUser'];
67 $this->dbPassword
= $info['dbPassword'];
68 $this->dbName
= $info['dbName'];
69 $this->dbFlags
= $info['dbFlags'];
70 $this->tablePrefix
= $info['tablePrefix'];
71 $this->hasSharedCache
= $info['hasSharedCache'];
77 function getMasterDB() {
78 if ( !isset( $this->dbConn
) ) {
79 $func = $this->getDBFactory();
80 $this->dbConn
= $func( DB_MASTER
);
89 function getSlaveDB() {
90 return $this->getMasterDB();
96 protected function getDBFactory() {
97 $type = $this->dbType
;
99 'host' => $this->dbServer
,
100 'user' => $this->dbUser
,
101 'password' => $this->dbPassword
,
102 'dbname' => $this->dbName
,
103 'flags' => $this->dbFlags
,
104 'tablePrefix' => $this->tablePrefix
,
108 return function ( $index ) use ( $type, $params ) {
109 return DatabaseBase
::factory( $type, $params );
116 function hasSharedCache() {
117 return $this->hasSharedCache
;
121 * Get a key on the primary cache for this repository.
122 * Returns false if the repository's cache is not accessible at this site.
123 * The parameters are the parts of the key, as for wfMemcKey().
126 function getSharedCacheKey( /*...*/ ) {
127 if ( $this->hasSharedCache() ) {
128 $args = func_get_args();
129 array_unshift( $args, $this->dbName
, $this->tablePrefix
);
131 return call_user_func_array( 'wfForeignMemcKey', $args );
137 protected function assertWritableRepo() {
138 throw new MWException( get_class( $this ) . ': write operations are not supported.' );
142 * Return information about the repository.
148 return FileRepo
::getInfo();