5 * Created on Sep 25, 2006
7 * API for MediaWiki 1.8+
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ('ApiQueryBase.php');
32 class ApiQueryWatchlist
extends ApiQueryGeneratorBase
{
34 public function __construct($query, $moduleName) {
35 parent
:: __construct($query, $moduleName, 'wl');
38 public function execute() {
42 public function executeGenerator($resultPageSet) {
43 $this->run($resultPageSet);
46 private function run($resultPageSet = null) {
49 if (!$wgUser->isLoggedIn())
50 $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
52 $allrev = $start = $end = $namespace = $dir = $limit = $prop = null;
53 extract($this->extractRequestParams());
55 $patrol = $timestamp = $user = $comment = false;
56 if (!is_null($prop)) {
57 if (!is_null($resultPageSet))
58 $this->dieUsage('prop parameter may not be used in a generator', 'params');
60 $user = (false !== array_search('user', $prop));
61 $comment = (false !== array_search('comment', $prop));
62 $timestamp = (false !== array_search('timestamp', $prop)); // TODO: $timestamp not currently being used.
63 $patrol = (false !== array_search('patrol', $prop));
66 global $wgUseRCPatrol, $wgUser;
67 if (!$wgUseRCPatrol ||
!$wgUser->isAllowed('patrol'))
68 $this->dieUsage('patrol property is not available', 'patrol');
72 if (is_null($resultPageSet)) {
73 $this->addFields(array (
83 $this->addFieldsIf('rc_user', $user);
84 $this->addFieldsIf('rc_user_text', $user);
85 $this->addFieldsIf('rc_comment', $comment);
86 $this->addFieldsIf('rc_patrolled', $patrol);
89 $this->addFields(array (
96 $this->addFields(array (
104 $this->addTables(array (
110 $userId = $wgUser->getID();
111 $this->addWhere(array (
112 'wl_namespace = rc_namespace',
113 'wl_title = rc_title',
114 'rc_cur_id = page_id',
117 $this->addWhereRange('rc_timestamp', $dir, $start, $end);
118 $this->addWhereFld('wl_namespace', $namespace);
119 $this->addWhereIf('rc_this_oldid=page_latest', !$allrev);
120 $this->addWhereIf("rc_timestamp > ''", !isset ($start) && !isset ($end));
122 $this->addOption('LIMIT', $limit +
1);
126 $res = $this->select(__METHOD__
);
128 $db = $this->getDB();
129 while ($row = $db->fetchObject($res)) {
130 if (++
$count > $limit) {
131 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
132 $this->setContinueEnumParameter('start', $row->rc_timestamp
);
136 if (is_null($resultPageSet)) {
137 $vals = $this->addRowInfo('rc', $row);
141 $title = Title
:: makeTitle($row->rc_namespace
, $row->rc_title
);
142 // skip any pages that user has no rights to read
143 if ($title->userCanRead()) {
145 $data[] = intval($row->rc_this_oldid
);
147 $data[] = intval($row->rc_cur_id
);
153 $db->freeResult($res);
155 if (is_null($resultPageSet)) {
156 $this->getResult()->setIndexedTagName($data, 'item');
157 $this->getResult()->addValue('query', $this->getModuleName(), $data);
160 $resultPageSet->populateFromRevisionIDs($data);
162 $resultPageSet->populateFromPageIDs($data);
166 protected function getAllowedParams() {
170 ApiBase
:: PARAM_TYPE
=> 'timestamp'
173 ApiBase
:: PARAM_TYPE
=> 'timestamp'
175 'namespace' => array (
176 ApiBase
:: PARAM_ISMULTI
=> true,
177 ApiBase
:: PARAM_TYPE
=> 'namespace'
180 ApiBase
:: PARAM_DFLT
=> 'older',
181 ApiBase
:: PARAM_TYPE
=> array (
187 ApiBase
:: PARAM_DFLT
=> 10,
188 ApiBase
:: PARAM_TYPE
=> 'limit',
189 ApiBase
:: PARAM_MIN
=> 1,
190 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
191 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
194 APIBase
:: PARAM_ISMULTI
=> true,
195 APIBase
:: PARAM_TYPE
=> array (
205 protected function getParamDescription() {
207 'allrev' => 'Include multiple revisions of the same page within given timeframe.',
208 'start' => 'The timestamp to start enumerating from.',
209 'end' => 'The timestamp to end enumerating.',
210 'namespace' => 'Filter changes to only the given namespace(s).',
211 'dir' => 'In which direction to enumerate pages.',
212 'limit' => 'How many total pages to return per request.',
213 'prop' => 'Which additional items to get (non-generator mode only).'
217 protected function getDescription() {
221 protected function getExamples() {
223 'api.php?action=query&list=watchlist',
224 'api.php?action=query&list=watchlist&wlallrev',
225 'api.php?action=query&generator=watchlist&prop=info',
226 'api.php?action=query&generator=watchlist&gwlallrev&prop=revisions&rvprop=timestamp|user'
230 public function getVersion() {
231 return __CLASS__
. ': $Id$';