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 = $from = $namespace = $hide = $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($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']));
54 $this->addFields(array (
72 $this->addOption('LIMIT', $limit +
1);
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
);
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()) {
89 $id = intval($row->rc_cur_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
);
112 $db->freeResult($res);
114 $result = $this->getResult();
115 $result->setIndexedTagName($data, 'rc');
116 $result->addValue('query', $this->getModuleName(), $data);
119 protected function getAllowedParams() {
120 $namespaces = $this->getQuery()->getValidNamespaces();
123 ApiBase
:: PARAM_DFLT
=> 'older',
124 ApiBase
:: PARAM_TYPE
=> array (
130 ApiBase
:: PARAM_TYPE
=> 'timestamp'
133 ApiBase
:: PARAM_TYPE
=> 'timestamp'
135 'namespace' => array (
136 ApiBase
:: PARAM_DFLT
=> 0,
137 ApiBase
:: PARAM_TYPE
=> $namespaces
140 ApiBase
:: PARAM_ISMULTI
=> true,
141 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 'limit' => 'How many total pages to return.'
166 protected function getDescription() {
167 return 'Enumerate recent changes';
170 protected function getExamples() {
172 'api.php?action=query&list=recentchanges',
176 public function getVersion() {
177 return __CLASS__
. ': $Id$';