* API: fixed watchlist db selection ('watchlist' db group)

This commit is contained in:
Yuri Astrakhan 2007-05-15 02:16:48 +00:00
parent 7d6df9e31b
commit adf1fb1b31
3 changed files with 34 additions and 3 deletions

View file

@ -71,6 +71,7 @@ class ApiQuery extends ApiBase {
// 'userinfo' => 'ApiQueryUserinfo',
private $mSlaveDB = null;
private $mNamedDB = array();
public function __construct($main, $action) {
parent :: __construct($main, $action);
@ -92,6 +93,21 @@ class ApiQuery extends ApiBase {
return $this->mSlaveDB;
}
/**
* Get the query database connection with the given name.
* If no such connection has been requested before, it will be created.
* Subsequent calls with the same $name will return the same connection
* as the first, regardless of $db or $groups new values.
*/
public function getNamedDB($name, $db, $groups) {
if (!array_key_exists($name, $this->mNamedDB)) {
$this->profileDBIn();
$this->mNamedDB[$name] = wfGetDB($db, $groups);
$this->profileDBOut();
}
return $this->mNamedDB[$name];
}
public function getPageSet() {
return $this->mPageSet;
}

View file

@ -33,11 +33,12 @@ if (!defined('MEDIAWIKI')) {
*/
abstract class ApiQueryBase extends ApiBase {
private $mQueryModule, $tables, $where, $fields, $options;
private $mQueryModule, $mDb, $tables, $where, $fields, $options;
public function __construct($query, $moduleName, $paramPrefix = '') {
parent :: __construct($query->getMain(), $moduleName, $paramPrefix);
$this->mQueryModule = $query;
$this->mDb = null;
$this->resetQueryParams();
}
@ -315,7 +316,19 @@ abstract class ApiQueryBase extends ApiBase {
* Get the Query database connection (readonly)
*/
protected function getDB() {
return $this->getQuery()->getDB();
if (is_null($this->mDb))
$this->mDb = $this->getQuery()->getDB();
return $this->mDb;
}
/**
* Selects the query database connection with the given name.
* If no such connection has been requested before, it will be created.
* Subsequent calls with the same $name will return the same connection
* as the first, regardless of $db or $groups new values.
*/
public function selectNamedDB($name, $db, $groups) {
$this->mDb = $this->getQuery()->getNamedDB($name, $db, $groups);
}
/**
@ -323,7 +336,7 @@ abstract class ApiQueryBase extends ApiBase {
* @return ApiPageSet data
*/
protected function getPageSet() {
return $this->mQueryModule->getPageSet();
return $this->getQuery()->getPageSet();
}
/**

View file

@ -48,6 +48,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
private function run($resultPageSet = null) {
global $wgUser;
$this->selectNamedDB('watchlist', DB_SLAVE, 'watchlist');
if (!$wgUser->isLoggedIn())
$this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');