3 * A foreign repository with a MediaWiki database accessible via the configured LBFactory.
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 Wikimedia\Rdbms\IDatabase
;
26 use Wikimedia\Rdbms\ILoadBalancer
;
29 * A foreign repository with a MediaWiki database accessible via the configured LBFactory
33 class ForeignDBViaLBRepo
extends LocalRepo
{
38 protected $fileFactory = [ ForeignDBFile
::class, 'newFromTitle' ];
41 protected $fileFromRowFactory = [ ForeignDBFile
::class, 'newFromRow' ];
44 protected $hasSharedCache;
47 * @param array|null $info
49 function __construct( $info ) {
50 parent
::__construct( $info );
51 $this->wiki
= $info['wiki'];
52 $this->hasSharedCache
= $info['hasSharedCache'];
58 function getMasterDB() {
59 return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER
, [], $this->wiki
);
65 function getReplicaDB() {
66 return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA
, [], $this->wiki
);
72 protected function getDBFactory() {
73 return function ( $index ) {
74 return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->wiki
);
79 * @return ILoadBalancer
81 protected function getDBLoadBalancer() {
82 $lbFactory = MediaWikiServices
::getInstance()->getDBLoadBalancerFactory();
84 return $lbFactory->getMainLB( $this->wiki
);
87 function hasSharedCache() {
88 return $this->hasSharedCache
;
92 * Get a key on the primary cache for this repository.
93 * Returns false if the repository's cache is not accessible at this site.
94 * The parameters are the parts of the key, as for wfMemcKey().
97 function getSharedCacheKey( /*...*/ ) {
98 if ( $this->hasSharedCache() ) {
99 $args = func_get_args();
100 array_unshift( $args, $this->wiki
);
102 return implode( ':', $args );
108 protected function assertWritableRepo() {
109 throw new MWException( static::class . ': write operations are not supported.' );
112 public function getInfo() {
113 return FileRepo
::getInfo();