If 'tables' is a string that starts with a space, treat it as user-enforced FROM...
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
1 <?php
2
3
4 /*
5 * Created on Oct 19, 2006
6 *
7 * API for MediaWiki 1.8+
8 *
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
10 *
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.
15 *
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.
20 *
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
25 */
26
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ('ApiQueryBase.php');
30 }
31
32 class ApiQueryRecentChanges extends ApiQueryBase {
33
34 public function __construct($query, $moduleName) {
35 parent :: __construct($query, $moduleName, 'rc');
36 }
37
38 public function execute() {
39 $limit = $prop = $namespace = $show = $dir = $start = $end = null;
40 extract($this->extractRequestParams());
41
42 $this->addTables('recentchanges');
43 $this->addWhereRange('rc_timestamp', $dir, $start, $end);
44 $this->addWhereFld('rc_namespace', $namespace);
45
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');
50
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']));
57 }
58
59 $this->addFields(array (
60 'rc_timestamp',
61 'rc_namespace',
62 'rc_title',
63 'rc_cur_id',
64 'rc_this_oldid',
65 'rc_last_oldid',
66 'rc_type',
67 'rc_moved_to_ns',
68 'rc_moved_to_title'
69 ));
70
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');
77 }
78 if (isset ($prop['flags'])) {
79 $this->addFields('rc_minor');
80 $this->addFields('rc_bot');
81 $this->addFields('rc_new');
82 }
83 }
84
85 $this->addOption('LIMIT', $limit +1);
86 $this->addOption('USE INDEX', 'rc_timestamp');
87
88 $data = array ();
89 $count = 0;
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);
96 break;
97 }
98
99 $vals = $this->addRowInfo('rc', $row);
100 if ($vals)
101 $data[] = $vals;
102 }
103 $db->freeResult($res);
104
105 $result = $this->getResult();
106 $result->setIndexedTagName($data, 'rc');
107 $result->addValue('query', $this->getModuleName(), $data);
108 }
109
110 protected function getAllowedParams() {
111 return array (
112 'start' => array (
113 ApiBase :: PARAM_TYPE => 'timestamp'
114 ),
115 'end' => array (
116 ApiBase :: PARAM_TYPE => 'timestamp'
117 ),
118 'dir' => array (
119 ApiBase :: PARAM_DFLT => 'older',
120 ApiBase :: PARAM_TYPE => array (
121 'newer',
122 'older'
123 )
124 ),
125 'namespace' => array (
126 ApiBase :: PARAM_ISMULTI => true,
127 ApiBase :: PARAM_TYPE => 'namespace'
128 ),
129 'prop' => array (
130 ApiBase :: PARAM_ISMULTI => true,
131 ApiBase :: PARAM_TYPE => array (
132 'user',
133 'comment',
134 'flags'
135 )
136 ),
137 'show' => array (
138 ApiBase :: PARAM_ISMULTI => true,
139 ApiBase :: PARAM_TYPE => array (
140 'minor',
141 '!minor',
142 'bot',
143 '!bot',
144 'anon',
145 '!anon'
146 )
147 ),
148 'limit' => 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
154 )
155 );
156 }
157
158 protected function getParamDescription() {
159 return array (
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',
165 'show' => array (
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'
168 ),
169 'limit' => 'How many total pages to return.'
170 );
171 }
172
173 protected function getDescription() {
174 return 'Enumerate recent changes';
175 }
176
177 protected function getExamples() {
178 return array (
179 'api.php?action=query&list=recentchanges'
180 );
181 }
182
183 public function getVersion() {
184 return __CLASS__ . ': $Id$';
185 }
186 }
187 ?>