4 * Created on Oct 19, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@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');
32 * A query action to enumerate the recent changes that were done to the wiki.
33 * Various filters are supported.
37 class ApiQueryRecentChanges
extends ApiQueryBase
{
39 public function __construct($query, $moduleName) {
40 parent
:: __construct($query, $moduleName, 'rc');
43 public function execute() {
44 $limit = $prop = $namespace = $show = $dir = $start = $end = null;
45 extract($this->extractRequestParams());
47 $this->addTables('recentchanges');
48 $this->addWhereRange('rc_timestamp', $dir, $start, $end);
49 $this->addWhereFld('rc_namespace', $namespace);
51 if (!is_null($show)) {
52 $show = array_flip($show);
53 if ((isset ($show['minor']) && isset ($show['!minor'])) ||
(isset ($show['bot']) && isset ($show['!bot'])) ||
(isset ($show['anon']) && isset ($show['!anon'])))
54 $this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
56 $this->addWhereIf('rc_minor = 0', isset ($show['!minor']));
57 $this->addWhereIf('rc_minor != 0', isset ($show['minor']));
58 $this->addWhereIf('rc_bot = 0', isset ($show['!bot']));
59 $this->addWhereIf('rc_bot != 0', isset ($show['bot']));
60 $this->addWhereIf('rc_user = 0', isset ($show['anon']));
61 $this->addWhereIf('rc_user != 0', isset ($show['!anon']));
64 $this->addFields(array (
76 if (!is_null($prop)) {
77 $prop = array_flip($prop);
78 $this->addFieldsIf('rc_comment', isset ($prop['comment']));
79 if (isset ($prop['user'])) {
80 $this->addFields('rc_user');
81 $this->addFields('rc_user_text');
83 if (isset ($prop['flags'])) {
84 $this->addFields('rc_minor');
85 $this->addFields('rc_bot');
86 $this->addFields('rc_new');
90 $this->addOption('LIMIT', $limit +
1);
91 $this->addOption('USE INDEX', 'rc_timestamp');
96 $res = $this->select(__METHOD__
);
97 while ($row = $db->fetchObject($res)) {
98 if (++
$count > $limit) {
99 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
100 $this->setContinueEnumParameter('start', $row->rc_timestamp
);
104 $vals = $this->addRowInfo('rc', $row);
108 $db->freeResult($res);
110 $result = $this->getResult();
111 $result->setIndexedTagName($data, 'rc');
112 $result->addValue('query', $this->getModuleName(), $data);
115 protected function getAllowedParams() {
118 ApiBase
:: PARAM_TYPE
=> 'timestamp'
121 ApiBase
:: PARAM_TYPE
=> 'timestamp'
124 ApiBase
:: PARAM_DFLT
=> 'older',
125 ApiBase
:: PARAM_TYPE
=> array (
130 'namespace' => array (
131 ApiBase
:: PARAM_ISMULTI
=> true,
132 ApiBase
:: PARAM_TYPE
=> 'namespace'
135 ApiBase
:: PARAM_ISMULTI
=> true,
136 ApiBase
:: PARAM_TYPE
=> array (
143 ApiBase
:: PARAM_ISMULTI
=> true,
144 ApiBase
:: PARAM_TYPE
=> array (
154 ApiBase
:: PARAM_DFLT
=> 10,
155 ApiBase
:: PARAM_TYPE
=> 'limit',
156 ApiBase
:: PARAM_MIN
=> 1,
157 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
158 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
163 protected function getParamDescription() {
165 'start' => 'The timestamp to start enumerating from.',
166 'end' => 'The timestamp to end enumerating.',
167 'dir' => 'In which direction to enumerate.',
168 'namespace' => 'Filter log entries to only this namespace(s)',
169 'prop' => 'Include additional pieces of information',
171 'Show only items that meet this criteria.',
172 'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
174 'limit' => 'How many total pages to return.'
178 protected function getDescription() {
179 return 'Enumerate recent changes';
182 protected function getExamples() {
184 'api.php?action=query&list=recentchanges'
188 public function getVersion() {
189 return __CLASS__
. ': $Id$';