Merge "Title::moveToInternal doesn't return anything, but it does throw an exception"
[lhc/web/wiklou.git] / includes / filerepo / ForeignDBRepo.php
1 <?php
2 /**
3 * A foreign repository with an accessible MediaWiki database.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup FileRepo
22 */
23
24 /**
25 * A foreign repository with an accessible MediaWiki database
26 *
27 * @ingroup FileRepo
28 */
29 class ForeignDBRepo extends LocalRepo {
30 # Settings
31 var $dbType, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags,
32 $tablePrefix, $hasSharedCache;
33
34 # Other stuff
35 var $dbConn;
36 var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
37 var $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
38
39 function __construct( $info ) {
40 parent::__construct( $info );
41 $this->dbType = $info['dbType'];
42 $this->dbServer = $info['dbServer'];
43 $this->dbUser = $info['dbUser'];
44 $this->dbPassword = $info['dbPassword'];
45 $this->dbName = $info['dbName'];
46 $this->dbFlags = $info['dbFlags'];
47 $this->tablePrefix = $info['tablePrefix'];
48 $this->hasSharedCache = $info['hasSharedCache'];
49 }
50
51 function getMasterDB() {
52 if ( !isset( $this->dbConn ) ) {
53 $this->dbConn = DatabaseBase::factory( $this->dbType,
54 array(
55 'host' => $this->dbServer,
56 'user' => $this->dbUser,
57 'password' => $this->dbPassword,
58 'dbname' => $this->dbName,
59 'flags' => $this->dbFlags,
60 'tablePrefix' => $this->tablePrefix
61 )
62 );
63 }
64 return $this->dbConn;
65 }
66
67 function getSlaveDB() {
68 return $this->getMasterDB();
69 }
70
71 function hasSharedCache() {
72 return $this->hasSharedCache;
73 }
74
75 /**
76 * Get a key on the primary cache for this repository.
77 * Returns false if the repository's cache is not accessible at this site.
78 * The parameters are the parts of the key, as for wfMemcKey().
79 * @return bool|mixed
80 */
81 function getSharedCacheKey( /*...*/ ) {
82 if ( $this->hasSharedCache() ) {
83 $args = func_get_args();
84 array_unshift( $args, $this->dbName, $this->tablePrefix );
85 return call_user_func_array( 'wfForeignMemcKey', $args );
86 } else {
87 return false;
88 }
89 }
90
91 protected function assertWritableRepo() {
92 throw new MWException( get_class( $this ) . ': write operations are not supported.' );
93 }
94 }