API: disabled login module until it is more secure. added performance comment in...
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
1 <?php
2
3 /*
4 * Created on Oct 19, 2006
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
9 *
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.
14 *
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.
19 *
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
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * @addtogroup API
33 */
34 class ApiQueryRecentChanges extends ApiQueryBase {
35
36 public function __construct($query, $moduleName) {
37 parent :: __construct($query, $moduleName, 'rc');
38 }
39
40 public function execute() {
41 $limit = $prop = $namespace = $show = $dir = $start = $end = null;
42 extract($this->extractRequestParams());
43
44 $this->addTables('recentchanges');
45 $this->addWhereRange('rc_timestamp', $dir, $start, $end);
46 $this->addWhereFld('rc_namespace', $namespace);
47
48 if (!is_null($show)) {
49 $show = array_flip($show);
50 if ((isset ($show['minor']) && isset ($show['!minor'])) || (isset ($show['bot']) && isset ($show['!bot'])) || (isset ($show['anon']) && isset ($show['!anon'])))
51 $this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
52
53 $this->addWhereIf('rc_minor = 0', isset ($show['!minor']));
54 $this->addWhereIf('rc_minor != 0', isset ($show['minor']));
55 $this->addWhereIf('rc_bot = 0', isset ($show['!bot']));
56 $this->addWhereIf('rc_bot != 0', isset ($show['bot']));
57 $this->addWhereIf('rc_user = 0', isset ($show['anon']));
58 $this->addWhereIf('rc_user != 0', isset ($show['!anon']));
59 }
60
61 $this->addFields(array (
62 'rc_timestamp',
63 'rc_namespace',
64 'rc_title',
65 'rc_cur_id',
66 'rc_this_oldid',
67 'rc_last_oldid',
68 'rc_type',
69 'rc_moved_to_ns',
70 'rc_moved_to_title'
71 ));
72
73 if (!is_null($prop)) {
74 $prop = array_flip($prop);
75 $this->addFieldsIf('rc_comment', isset ($prop['comment']));
76 if (isset ($prop['user'])) {
77 $this->addFields('rc_user');
78 $this->addFields('rc_user_text');
79 }
80 if (isset ($prop['flags'])) {
81 $this->addFields('rc_minor');
82 $this->addFields('rc_bot');
83 $this->addFields('rc_new');
84 }
85 }
86
87 $this->addOption('LIMIT', $limit +1);
88 $this->addOption('USE INDEX', 'rc_timestamp');
89
90 $data = array ();
91 $count = 0;
92 $db = $this->getDB();
93 $res = $this->select(__METHOD__);
94 while ($row = $db->fetchObject($res)) {
95 if (++ $count > $limit) {
96 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
97 $this->setContinueEnumParameter('start', $row->rc_timestamp);
98 break;
99 }
100
101 $vals = $this->addRowInfo('rc', $row);
102 if ($vals)
103 $data[] = $vals;
104 }
105 $db->freeResult($res);
106
107 $result = $this->getResult();
108 $result->setIndexedTagName($data, 'rc');
109 $result->addValue('query', $this->getModuleName(), $data);
110 }
111
112 protected function getAllowedParams() {
113 return array (
114 'start' => array (
115 ApiBase :: PARAM_TYPE => 'timestamp'
116 ),
117 'end' => array (
118 ApiBase :: PARAM_TYPE => 'timestamp'
119 ),
120 'dir' => array (
121 ApiBase :: PARAM_DFLT => 'older',
122 ApiBase :: PARAM_TYPE => array (
123 'newer',
124 'older'
125 )
126 ),
127 'namespace' => array (
128 ApiBase :: PARAM_ISMULTI => true,
129 ApiBase :: PARAM_TYPE => 'namespace'
130 ),
131 'prop' => array (
132 ApiBase :: PARAM_ISMULTI => true,
133 ApiBase :: PARAM_TYPE => array (
134 'user',
135 'comment',
136 'flags'
137 )
138 ),
139 'show' => array (
140 ApiBase :: PARAM_ISMULTI => true,
141 ApiBase :: PARAM_TYPE => array (
142 'minor',
143 '!minor',
144 'bot',
145 '!bot',
146 'anon',
147 '!anon'
148 )
149 ),
150 'limit' => array (
151 ApiBase :: PARAM_DFLT => 10,
152 ApiBase :: PARAM_TYPE => 'limit',
153 ApiBase :: PARAM_MIN => 1,
154 ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
155 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
156 )
157 );
158 }
159
160 protected function getParamDescription() {
161 return array (
162 'start' => 'The timestamp to start enumerating from.',
163 'end' => 'The timestamp to end enumerating.',
164 'dir' => 'In which direction to enumerate.',
165 'namespace' => 'Filter log entries to only this namespace(s)',
166 'prop' => 'Include additional pieces of information',
167 'show' => array (
168 'Show only items that meet this criteria.',
169 'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
170 ),
171 'limit' => 'How many total pages to return.'
172 );
173 }
174
175 protected function getDescription() {
176 return 'Enumerate recent changes';
177 }
178
179 protected function getExamples() {
180 return array (
181 'api.php?action=query&list=recentchanges'
182 );
183 }
184
185 public function getVersion() {
186 return __CLASS__ . ': $Id$';
187 }
188 }
189 ?>