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
24 use MediaWiki\MediaWikiServices
;
25 use MediaWiki\Storage\BlobStore
;
26 use Wikimedia\Rdbms\DatabaseDomain
;
27 use Wikimedia\Rdbms\IDatabase
;
30 * A foreign repository with an accessible MediaWiki database
34 class ForeignDBRepo
extends LocalRepo
implements IForeignRepoWithDB
{
45 protected $dbPassword;
54 protected $tablePrefix;
60 protected $fileFactory = [ ForeignDBFile
::class, 'newFromTitle' ];
62 protected $fileFromRowFactory = [ ForeignDBFile
::class, 'newFromRow' ];
65 * @param array|null $info
67 public function __construct( $info ) {
68 parent
::__construct( $info );
70 '@phan-var array $info';
71 $this->dbType
= $info['dbType'];
72 $this->dbServer
= $info['dbServer'];
73 $this->dbUser
= $info['dbUser'];
74 $this->dbPassword
= $info['dbPassword'];
75 $this->dbName
= $info['dbName'];
76 $this->dbFlags
= $info['dbFlags'];
77 $this->tablePrefix
= $info['tablePrefix'];
78 $this->hasAccessibleSharedCache
= $info['hasSharedCache'];
80 $dbDomain = new DatabaseDomain( $this->dbName
, null, $this->tablePrefix
);
81 $this->dbDomain
= $dbDomain->getId();
84 public function getPrimaryDB() {
85 if ( !$this->dbConn
) {
86 $func = $this->getDBFactory();
87 $this->dbConn
= $func( DB_PRIMARY
);
93 public function getReplicaDB() {
94 return $this->getPrimaryDB();
100 protected function getDBFactory() {
101 $type = $this->dbType
;
103 'host' => $this->dbServer
,
104 'user' => $this->dbUser
,
105 'password' => $this->dbPassword
,
106 'dbname' => $this->dbName
,
107 'flags' => $this->dbFlags
,
108 'tablePrefix' => $this->tablePrefix
111 return static function ( $index ) use ( $type, $params ) {
112 $factory = MediaWikiServices
::getInstance()->getDatabaseFactory();
113 return $factory->create( $type, $params );
120 protected function assertWritableRepo() {
121 throw new LogicException( static::class . ': write operations are not supported.' );
124 public function getBlobStore(): ?BlobStore
{