Special:BlockList: Use mw-ui-progressive for search button
[mediawiki.git] / includes / filerepo / ForeignDBRepo.php
blob6e9e6add48b6e4493570c26fd3f8c768f5d57d27
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 /**
25 * A foreign repository with an accessible MediaWiki database
27 * @ingroup FileRepo
29 class ForeignDBRepo extends LocalRepo {
30 /** @var string */
31 protected $dbType;
33 /** @var string */
34 protected $dbServer;
36 /** @var string */
37 protected $dbUser;
39 /** @var string */
40 protected $dbPassword;
42 /** @var string */
43 protected $dbName;
45 /** @var string */
46 protected $dbFlags;
48 /** @var string */
49 protected $tablePrefix;
51 /** @var bool */
52 protected $hasSharedCache;
54 # Other stuff
55 protected $dbConn;
56 protected $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
57 protected $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
59 /**
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'];
74 /**
75 * @return DatabaseBase
77 function getMasterDB() {
78 if ( !isset( $this->dbConn ) ) {
79 $this->dbConn = DatabaseBase::factory( $this->dbType,
80 array(
81 'host' => $this->dbServer,
82 'user' => $this->dbUser,
83 'password' => $this->dbPassword,
84 'dbname' => $this->dbName,
85 'flags' => $this->dbFlags,
86 'tablePrefix' => $this->tablePrefix,
87 'foreign' => true,
92 return $this->dbConn;
95 /**
96 * @return DatabaseBase
98 function getSlaveDB() {
99 return $this->getMasterDB();
103 * @return bool
105 function hasSharedCache() {
106 return $this->hasSharedCache;
110 * Get a key on the primary cache for this repository.
111 * Returns false if the repository's cache is not accessible at this site.
112 * The parameters are the parts of the key, as for wfMemcKey().
113 * @return bool|mixed
115 function getSharedCacheKey( /*...*/ ) {
116 if ( $this->hasSharedCache() ) {
117 $args = func_get_args();
118 array_unshift( $args, $this->dbName, $this->tablePrefix );
120 return call_user_func_array( 'wfForeignMemcKey', $args );
121 } else {
122 return false;
126 protected function assertWritableRepo() {
127 throw new MWException( get_class( $this ) . ': write operations are not supported.' );
131 * Return information about the repository.
133 * @return array
134 * @since 1.22
136 function getInfo() {
137 return FileRepo::getInfo();