5 * Created on Oct 19, 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 ApiQueryRecentChanges
extends ApiQueryBase
{
34 public function __construct($query, $moduleName) {
35 parent
:: __construct($query, $moduleName, 'rc');
38 public function execute() {
39 $limit = $prop = $namespace = $show = $dir = $start = $end = null;
40 extract($this->extractRequestParams());
42 $this->addTables('recentchanges');
43 $this->addWhereRange('rc_timestamp', $dir, $start, $end);
44 $this->addWhereFld('rc_namespace', $namespace);
46 if (!is_null($show)) {
47 $show = array_flip($show);
48 if ((isset ($show['minor']) && isset ($show['!minor'])) ||
(isset ($show['bot']) && isset ($show['!bot'])) ||
(isset ($show['anon']) && isset ($show['!anon'])))
49 $this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
51 $this->addWhereIf('rc_minor = 0', isset ($show['!minor']));
52 $this->addWhereIf('rc_minor != 0', isset ($show['minor']));
53 $this->addWhereIf('rc_bot = 0', isset ($show['!bot']));
54 $this->addWhereIf('rc_bot != 0', isset ($show['bot']));
55 $this->addWhereIf('rc_user = 0', isset ($show['anon']));
56 $this->addWhereIf('rc_user != 0', isset ($show['!anon']));
59 $this->addFields(array (
71 if (!is_null($prop)) {
72 $prop = array_flip($prop);
73 $this->addFieldsIf('rc_comment', isset ($prop['comment']));
74 if (isset ($prop['user'])) {
75 $this->addFields('rc_user');
76 $this->addFields('rc_user_text');
78 if (isset ($prop['flags'])) {
79 $this->addFields('rc_minor');
80 $this->addFields('rc_bot');
81 $this->addFields('rc_new');
85 $this->addOption('LIMIT', $limit +
1);
86 $this->addOption('USE INDEX', 'rc_timestamp');
90 $db = & $this->getDB();
91 $res = $this->select(__METHOD__
);
92 while ($row = $db->fetchObject($res)) {
93 if (++
$count > $limit) {
94 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
95 $this->setContinueEnumParameter('start', $row->rc_timestamp
);
99 $vals = $this->addRowInfo('rc', $row);
103 $db->freeResult($res);
105 $result = $this->getResult();
106 $result->setIndexedTagName($data, 'rc');
107 $result->addValue('query', $this->getModuleName(), $data);
110 protected function getAllowedParams() {
113 ApiBase
:: PARAM_TYPE
=> 'timestamp'
116 ApiBase
:: PARAM_TYPE
=> 'timestamp'
119 ApiBase
:: PARAM_DFLT
=> 'older',
120 ApiBase
:: PARAM_TYPE
=> array (
125 'namespace' => array (
126 ApiBase
:: PARAM_ISMULTI
=> true,
127 ApiBase
:: PARAM_TYPE
=> 'namespace'
130 ApiBase
:: PARAM_ISMULTI
=> true,
131 ApiBase
:: PARAM_TYPE
=> array (
138 ApiBase
:: PARAM_ISMULTI
=> true,
139 ApiBase
:: PARAM_TYPE
=> array (
149 ApiBase
:: PARAM_DFLT
=> 10,
150 ApiBase
:: PARAM_TYPE
=> 'limit',
151 ApiBase
:: PARAM_MIN
=> 1,
152 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
153 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
158 protected function getParamDescription() {
160 'start' => 'The timestamp to start enumerating from.',
161 'end' => 'The timestamp to end enumerating.',
162 'dir' => 'In which direction to enumerate.',
163 'namespace' => 'Filter log entries to only this namespace(s)',
164 'prop' => 'Include additional pieces of information',
166 'Show only items that meet this criteria.',
167 'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
169 'limit' => 'How many total pages to return.'
173 protected function getDescription() {
174 return 'Enumerate recent changes';
177 protected function getExamples() {
179 'api.php?action=query&list=recentchanges'
183 public function getVersion() {
184 return __CLASS__
. ': $Id$';