From: Yuri Astrakhan Date: Tue, 15 May 2007 02:16:48 +0000 (+0000) Subject: * API: fixed watchlist db selection ('watchlist' db group) X-Git-Tag: 1.31.0-rc.0~52912 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=adf1fb1b31818f24a28c9ff7bde584e8763f39e2;p=lhc%2Fweb%2Fwiklou.git * API: fixed watchlist db selection ('watchlist' db group) --- diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 04dee33000..7a7c9385a3 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -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; } diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 89b2b6d71b..de1e6ed87b 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -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(); } /** diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 99e7151efc..1b7b72da67 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -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');