Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / filerepo / ForeignDBRepo.php
blob15e8fbef6229272c5d96925aa03d445ff0e1fc8c
1 <?php
2 /**
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
20 * @file
21 * @ingroup FileRepo
24 use MediaWiki\MediaWikiServices;
25 use MediaWiki\Storage\BlobStore;
26 use Wikimedia\Rdbms\DatabaseDomain;
27 use Wikimedia\Rdbms\IDatabase;
29 /**
30 * A foreign repository with an accessible MediaWiki database
32 * @ingroup FileRepo
34 class ForeignDBRepo extends LocalRepo implements IForeignRepoWithDB {
35 /** @var string */
36 protected $dbType;
38 /** @var string */
39 protected $dbServer;
41 /** @var string */
42 protected $dbUser;
44 /** @var string */
45 protected $dbPassword;
47 /** @var string */
48 protected $dbName;
50 /** @var string */
51 protected $dbFlags;
53 /** @var string */
54 protected $tablePrefix;
56 /** @var IDatabase */
57 protected $dbConn;
59 /** @var callable */
60 protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
61 /** @var callable */
62 protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
64 /**
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 );
90 return $this->dbConn;
93 public function getReplicaDB() {
94 return $this->getPrimaryDB();
97 /**
98 * @return Closure
100 protected function getDBFactory() {
101 $type = $this->dbType;
102 $params = [
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 );
118 * @return never
120 protected function assertWritableRepo() {
121 throw new LogicException( static::class . ': write operations are not supported.' );
124 public function getBlobStore(): ?BlobStore {
125 return null;