4 * Created on Sep 25, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
34 class ApiQueryWatchlist
extends ApiQueryGeneratorBase
{
36 public function __construct($query, $moduleName) {
37 parent
:: __construct($query, $moduleName, 'wl');
40 public function execute() {
44 public function executeGenerator($resultPageSet) {
45 $this->run($resultPageSet);
48 private function run($resultPageSet = null) {
51 if (!$wgUser->isLoggedIn())
52 $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
54 $allrev = $start = $end = $namespace = $dir = $limit = $prop = null;
55 extract($this->extractRequestParams());
57 $patrol = $timestamp = $user = $comment = false;
58 if (!is_null($prop)) {
59 if (!is_null($resultPageSet))
60 $this->dieUsage('prop parameter may not be used in a generator', 'params');
62 $user = (false !== array_search('user', $prop));
63 $comment = (false !== array_search('comment', $prop));
64 $timestamp = (false !== array_search('timestamp', $prop)); // TODO: $timestamp not currently being used.
65 $patrol = (false !== array_search('patrol', $prop));
68 global $wgUseRCPatrol, $wgUser;
69 if (!$wgUseRCPatrol ||
!$wgUser->isAllowed('patrol'))
70 $this->dieUsage('patrol property is not available', 'patrol');
74 if (is_null($resultPageSet)) {
75 $this->addFields(array (
85 $this->addFieldsIf('rc_user', $user);
86 $this->addFieldsIf('rc_user_text', $user);
87 $this->addFieldsIf('rc_comment', $comment);
88 $this->addFieldsIf('rc_patrolled', $patrol);
91 $this->addFields(array (
98 $this->addFields(array (
106 $this->addTables(array (
112 $userId = $wgUser->getID();
113 $this->addWhere(array (
114 'wl_namespace = rc_namespace',
115 'wl_title = rc_title',
116 'rc_cur_id = page_id',
119 $this->addWhereRange('rc_timestamp', $dir, $start, $end);
120 $this->addWhereFld('wl_namespace', $namespace);
121 $this->addWhereIf('rc_this_oldid=page_latest', !$allrev);
122 $this->addWhereIf("rc_timestamp > ''", !isset ($start) && !isset ($end));
124 $this->addOption('LIMIT', $limit +
1);
128 $res = $this->select(__METHOD__
);
130 $db = $this->getDB();
131 while ($row = $db->fetchObject($res)) {
132 if (++
$count > $limit) {
133 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
134 $this->setContinueEnumParameter('start', $row->rc_timestamp
);
138 if (is_null($resultPageSet)) {
139 $vals = $this->addRowInfo('rc', $row);
143 $title = Title
:: makeTitle($row->rc_namespace
, $row->rc_title
);
144 // skip any pages that user has no rights to read
145 if ($title->userCanRead()) {
147 $data[] = intval($row->rc_this_oldid
);
149 $data[] = intval($row->rc_cur_id
);
155 $db->freeResult($res);
157 if (is_null($resultPageSet)) {
158 $this->getResult()->setIndexedTagName($data, 'item');
159 $this->getResult()->addValue('query', $this->getModuleName(), $data);
162 $resultPageSet->populateFromRevisionIDs($data);
164 $resultPageSet->populateFromPageIDs($data);
168 protected function getAllowedParams() {
172 ApiBase
:: PARAM_TYPE
=> 'timestamp'
175 ApiBase
:: PARAM_TYPE
=> 'timestamp'
177 'namespace' => array (
178 ApiBase
:: PARAM_ISMULTI
=> true,
179 ApiBase
:: PARAM_TYPE
=> 'namespace'
182 ApiBase
:: PARAM_DFLT
=> 'older',
183 ApiBase
:: PARAM_TYPE
=> array (
189 ApiBase
:: PARAM_DFLT
=> 10,
190 ApiBase
:: PARAM_TYPE
=> 'limit',
191 ApiBase
:: PARAM_MIN
=> 1,
192 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
193 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
196 APIBase
:: PARAM_ISMULTI
=> true,
197 APIBase
:: PARAM_TYPE
=> array (
207 protected function getParamDescription() {
209 'allrev' => 'Include multiple revisions of the same page within given timeframe.',
210 'start' => 'The timestamp to start enumerating from.',
211 'end' => 'The timestamp to end enumerating.',
212 'namespace' => 'Filter changes to only the given namespace(s).',
213 'dir' => 'In which direction to enumerate pages.',
214 'limit' => 'How many total pages to return per request.',
215 'prop' => 'Which additional items to get (non-generator mode only).'
219 protected function getDescription() {
223 protected function getExamples() {
225 'api.php?action=query&list=watchlist',
226 'api.php?action=query&list=watchlist&wlallrev',
227 'api.php?action=query&generator=watchlist&prop=info',
228 'api.php?action=query&generator=watchlist&gwlallrev&prop=revisions&rvprop=timestamp|user'
232 public function getVersion() {
233 return __CLASS__
. ': $Id$';