renaming ApiQueryRecentchanges.php to ApiQueryRecentChanges.php (step 2 of 2)
[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 = $from = $namespace = $hide = $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($hide)) {
47 $hide = array_flip($hide);
48 if(isset ($hide['anons']) && isset ($hide['liu']))
49 $this->dieUsage( "Both 'anons' and 'liu' cannot be set at the same time", 'hide' );
50 $this->addWhereIf('rc_minor = 0', isset ($hide['minor']));
51 $this->addWhereIf('rc_bot = 0', isset ($hide['bots']));
52 $this->addWhereIf('rc_user != 0', isset ($hide['anons']));
53 $this->addWhereIf('rc_user = 0', isset ($hide['liu']));
54 }
55
56 $this->addFields(array (
57 'rc_timestamp',
58 'rc_namespace',
59 'rc_title',
60 'rc_cur_id',
61 'rc_this_oldid',
62 'rc_last_oldid',
63 'rc_type',
64 'rc_moved_to_ns',
65 'rc_moved_to_title'
66 ));
67
68 if (!is_null($prop)) {
69 $prop = array_flip($prop);
70 $this->addFieldsIf('rc_comment', isset ($prop['comment']));
71 if (isset ($prop['user'])) {
72 $this->addFields('rc_user');
73 $this->addFields('rc_user_text');
74 }
75 if (isset ($prop['flags'])) {
76 $this->addFields('rc_minor');
77 $this->addFields('rc_bot');
78 $this->addFields('rc_new');
79 }
80 }
81
82 $this->addOption('LIMIT', $limit +1);
83
84 $data = array ();
85 $count = 0;
86 $db = $this->getDB();
87 $res = $this->select(__METHOD__);
88 while ($row = $db->fetchObject($res)) {
89 if (++ $count > $limit) {
90 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
91 $this->setContinueEnumParameter('start', $row->rc_timestamp);
92 break;
93 }
94
95 $vals = $this->addRowInfo('rc', $row);
96 if($vals)
97 $data[] = $vals;
98 }
99 $db->freeResult($res);
100
101 $result = $this->getResult();
102 $result->setIndexedTagName($data, 'rc');
103 $result->addValue('query', $this->getModuleName(), $data);
104 }
105
106 protected function getAllowedParams() {
107 $namespaces = $this->getQuery()->getValidNamespaces();
108 return array (
109 'dir' => array (
110 ApiBase :: PARAM_DFLT => 'older',
111 ApiBase :: PARAM_TYPE => array (
112 'newer',
113 'older'
114 )
115 ),
116 'start' => array (
117 ApiBase :: PARAM_TYPE => 'timestamp'
118 ),
119 'end' => array (
120 ApiBase :: PARAM_TYPE => 'timestamp'
121 ),
122 'namespace' => array (
123 ApiBase :: PARAM_DFLT => 0,
124 ApiBase :: PARAM_TYPE => $namespaces
125 ),
126 'prop' => array (
127 ApiBase :: PARAM_ISMULTI => true,
128 ApiBase :: PARAM_TYPE => array (
129 'user',
130 'comment',
131 'flags'
132 )
133 ),
134 'hide' => array (
135 ApiBase :: PARAM_ISMULTI => true,
136 ApiBase :: PARAM_TYPE => array (
137 'minor',
138 'bots',
139 'anons',
140 'liu'
141 )
142 ),
143 'limit' => array (
144 ApiBase :: PARAM_DFLT => 10,
145 ApiBase :: PARAM_TYPE => 'limit',
146 ApiBase :: PARAM_MIN => 1,
147 ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
148 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
149 )
150 );
151 }
152
153 protected function getParamDescription() {
154 return array (
155 'start' => 'The timestamp to start enumerating from.',
156 'end' => 'The timestamp to end enumerating.',
157 'limit' => 'How many total pages to return.'
158 );
159 }
160
161 protected function getDescription() {
162 return 'Enumerate recent changes';
163 }
164
165 protected function getExamples() {
166 return array (
167 'api.php?action=query&list=recentchanges',
168 );
169 }
170
171 public function getVersion() {
172 return __CLASS__ . ': $Id$';
173 }
174 }
175 ?>