2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
2012-05-07 07:11:33 +00:00
|
|
|
* A foreign repository with an accessible MediaWiki database.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-09-04 18:13:18 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup FileRepo
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-05-20 18:49:11 +00:00
|
|
|
* A foreign repository with an accessible MediaWiki database
|
2010-09-04 18:13:18 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup FileRepo
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
class ForeignDBRepo extends LocalRepo {
|
2013-12-04 16:18:05 +00:00
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbType;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbServer;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbUser;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbPassword;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbName;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbFlags;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $tablePrefix;
|
2013-12-04 16:18:05 +00:00
|
|
|
|
|
|
|
|
/** @var bool */
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $hasSharedCache;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
# Other stuff
|
2013-11-24 09:44:10 +00:00
|
|
|
protected $dbConn;
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $fileFactory = [ 'ForeignDBFile', 'newFromTitle' ];
|
|
|
|
|
protected $fileFromRowFactory = [ 'ForeignDBFile', 'newFromRow' ];
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param array|null $info
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function __construct( $info ) {
|
|
|
|
|
parent::__construct( $info );
|
|
|
|
|
$this->dbType = $info['dbType'];
|
|
|
|
|
$this->dbServer = $info['dbServer'];
|
|
|
|
|
$this->dbUser = $info['dbUser'];
|
|
|
|
|
$this->dbPassword = $info['dbPassword'];
|
|
|
|
|
$this->dbName = $info['dbName'];
|
|
|
|
|
$this->dbFlags = $info['dbFlags'];
|
|
|
|
|
$this->tablePrefix = $info['tablePrefix'];
|
|
|
|
|
$this->hasSharedCache = $info['hasSharedCache'];
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2015-10-06 05:39:37 +00:00
|
|
|
* @return IDatabase
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getMasterDB() {
|
|
|
|
|
if ( !isset( $this->dbConn ) ) {
|
2015-03-10 13:26:14 +00:00
|
|
|
$func = $this->getDBFactory();
|
|
|
|
|
$this->dbConn = $func( DB_MASTER );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->dbConn;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
2015-10-06 05:39:37 +00:00
|
|
|
* @return IDatabase
|
2012-05-18 02:58:15 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getSlaveDB() {
|
|
|
|
|
return $this->getMasterDB();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 13:26:14 +00:00
|
|
|
/**
|
|
|
|
|
* @return Closure
|
|
|
|
|
*/
|
|
|
|
|
protected function getDBFactory() {
|
2015-10-08 05:36:49 +00:00
|
|
|
$type = $this->dbType;
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [
|
2015-10-08 05:36:49 +00:00
|
|
|
'host' => $this->dbServer,
|
|
|
|
|
'user' => $this->dbUser,
|
|
|
|
|
'password' => $this->dbPassword,
|
|
|
|
|
'dbname' => $this->dbName,
|
|
|
|
|
'flags' => $this->dbFlags,
|
|
|
|
|
'tablePrefix' => $this->tablePrefix,
|
|
|
|
|
'foreign' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-10-08 05:36:49 +00:00
|
|
|
|
|
|
|
|
return function ( $index ) use ( $type, $params ) {
|
|
|
|
|
return DatabaseBase::factory( $type, $params );
|
2015-03-10 13:26:14 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function hasSharedCache() {
|
|
|
|
|
return $this->hasSharedCache;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
/**
|
|
|
|
|
* Get a key on the primary cache for this repository.
|
2012-10-19 20:03:05 +00:00
|
|
|
* Returns false if the repository's cache is not accessible at this site.
|
2009-06-17 07:31:00 +00:00
|
|
|
* The parameters are the parts of the key, as for wfMemcKey().
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool|mixed
|
2009-06-17 07:31:00 +00:00
|
|
|
*/
|
|
|
|
|
function getSharedCacheKey( /*...*/ ) {
|
|
|
|
|
if ( $this->hasSharedCache() ) {
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
array_unshift( $args, $this->dbName, $this->tablePrefix );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-06-17 07:31:00 +00:00
|
|
|
return call_user_func_array( 'wfForeignMemcKey', $args );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-05 04:10:50 +00:00
|
|
|
protected function assertWritableRepo() {
|
|
|
|
|
throw new MWException( get_class( $this ) . ': write operations are not supported.' );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
2014-01-15 20:38:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return information about the repository.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
function getInfo() {
|
|
|
|
|
return FileRepo::getInfo();
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|