API * Added rudimentary RC list
[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 = $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 $this->addWhereIf('rc_minor = 0', isset ($hide['minor']));
49 $this->addWhereIf('rc_bot = 0', isset ($hide['bots']));
50 $this->addWhereIf('rc_user != 0', isset ($hide['anons']));
51 $this->addWhereIf('rc_user = 0', isset ($hide['liu']));
52 }
53
54 $this->addFields(array (
55 'rc_timestamp',
56 'rc_user',
57 'rc_user_text',
58 'rc_namespace',
59 'rc_title',
60 'rc_comment',
61 'rc_minor',
62 'rc_bot',
63 'rc_new',
64 'rc_cur_id',
65 'rc_this_oldid',
66 'rc_last_oldid',
67 'rc_type',
68 'rc_moved_to_ns',
69 'rc_moved_to_title'
70 ));
71
72 $this->addOption('LIMIT', $limit +1);
73
74 $data = array ();
75 $count = 0;
76 $db = $this->getDB();
77 $res = $this->select(__METHOD__);
78 while ($row = $db->fetchObject($res)) {
79 if (++ $count > $limit) {
80 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
81 $this->setContinueEnumParameter('start', $row->rc_timestamp);
82 break;
83 }
84
85 $title = Title :: makeTitle($row->rc_namespace, $row->rc_title);
86 // skip any pages that user has no rights to read
87 if ($title->userCanRead()) {
88
89 $id = intval($row->rc_cur_id);
90 $data[] = array (
91 'id' => $id,
92 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText(),
93 'timestamp' => $row->rc_timestamp,
94 'user' => $row->rc_user_text,
95 'comment' => $row->rc_comment,
96 'this_oldid' => $row->rc_this_oldid,
97 'last_oldid' => $row->rc_last_oldid,
98 'type' => $row->rc_type,
99 'moved_to_ns' => $row->rc_moved_to_ns,
100 'moved_to_title' => $row->rc_moved_to_title);
101
102 if (!$row->rc_user)
103 $vals['anon'] = '';
104 if ($row->rc_new)
105 $vals['new'] = '';
106 if ($row->rc_bot)
107 $vals['bot'] = '';
108 if ($row->rc_minor)
109 $vals['minor'] = '';
110 }
111 }
112 $db->freeResult($res);
113
114 $result = $this->getResult();
115 $result->setIndexedTagName($data, 'rc');
116 $result->addValue('query', $this->getModuleName(), $data);
117 }
118
119 protected function getAllowedParams() {
120 $namespaces = $this->getQuery()->getValidNamespaces();
121 return array (
122 'dir' => array (
123 ApiBase :: PARAM_DFLT => 'older',
124 ApiBase :: PARAM_TYPE => array (
125 'newer',
126 'older'
127 )
128 ),
129 'start' => array (
130 ApiBase :: PARAM_TYPE => 'timestamp'
131 ),
132 'end' => array (
133 ApiBase :: PARAM_TYPE => 'timestamp'
134 ),
135 'namespace' => array (
136 ApiBase :: PARAM_DFLT => 0,
137 ApiBase :: PARAM_TYPE => $namespaces
138 ),
139 'hide' => array (
140 ApiBase :: PARAM_ISMULTI => true,
141 ApiBase :: PARAM_TYPE => array (
142 'minor',
143 'bots',
144 'anons',
145 'liu'
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 'limit' => 'How many total pages to return.'
163 );
164 }
165
166 protected function getDescription() {
167 return 'Enumerate recent changes';
168 }
169
170 protected function getExamples() {
171 return array (
172 'api.php?action=query&list=recentchanges',
173 );
174 }
175
176 public function getVersion() {
177 return __CLASS__ . ': $Id$';
178 }
179 }
180 ?>