Merge "jquery.textSelection.test: Fix regression in Opera"
[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 /**
40 * @param $info array|null
41 */
42 function __construct( $info ) {
43 parent::__construct( $info );
44 $this->dbType = $info['dbType'];
45 $this->dbServer = $info['dbServer'];
46 $this->dbUser = $info['dbUser'];
47 $this->dbPassword = $info['dbPassword'];
48 $this->dbName = $info['dbName'];
49 $this->dbFlags = $info['dbFlags'];
50 $this->tablePrefix = $info['tablePrefix'];
51 $this->hasSharedCache = $info['hasSharedCache'];
52 }
53
54 /**
55 * @return DatabaseBase
56 */
57 function getMasterDB() {
58 if ( !isset( $this->dbConn ) ) {
59 $this->dbConn = DatabaseBase::factory( $this->dbType,
60 array(
61 'host' => $this->dbServer,
62 'user' => $this->dbUser,
63 'password' => $this->dbPassword,
64 'dbname' => $this->dbName,
65 'flags' => $this->dbFlags,
66 'tablePrefix' => $this->tablePrefix
67 )
68 );
69 }
70 return $this->dbConn;
71 }
72
73 /**
74 * @return DatabaseBase
75 */
76 function getSlaveDB() {
77 return $this->getMasterDB();
78 }
79
80 /**
81 * @return bool
82 */
83 function hasSharedCache() {
84 return $this->hasSharedCache;
85 }
86
87 /**
88 * Get a key on the primary cache for this repository.
89 * Returns false if the repository's cache is not accessible at this site.
90 * The parameters are the parts of the key, as for wfMemcKey().
91 * @return bool|mixed
92 */
93 function getSharedCacheKey( /*...*/ ) {
94 if ( $this->hasSharedCache() ) {
95 $args = func_get_args();
96 array_unshift( $args, $this->dbName, $this->tablePrefix );
97 return call_user_func_array( 'wfForeignMemcKey', $args );
98 } else {
99 return false;
100 }
101 }
102
103 protected function assertWritableRepo() {
104 throw new MWException( get_class( $this ) . ': write operations are not supported.' );
105 }
106 }