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 = $prop = $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 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']));
56 $this->addFields(array (
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');
75 if (isset ($prop['flags'])) {
76 $this->addFields('rc_minor');
77 $this->addFields('rc_bot');
78 $this->addFields('rc_new');
82 $this->addOption('LIMIT', $limit +
1);
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
);
95 $vals = $this->addRowInfo('rc', $row);
99 $db->freeResult($res);
101 $result = $this->getResult();
102 $result->setIndexedTagName($data, 'rc');
103 $result->addValue('query', $this->getModuleName(), $data);
106 protected function getAllowedParams() {
107 $namespaces = $this->getQuery()->getValidNamespaces();
110 ApiBase
:: PARAM_DFLT
=> 'older',
111 ApiBase
:: PARAM_TYPE
=> array (
117 ApiBase
:: PARAM_TYPE
=> 'timestamp'
120 ApiBase
:: PARAM_TYPE
=> 'timestamp'
122 'namespace' => array (
123 ApiBase
:: PARAM_DFLT
=> 0,
124 ApiBase
:: PARAM_TYPE
=> $namespaces
127 ApiBase
:: PARAM_ISMULTI
=> true,
128 ApiBase
:: PARAM_TYPE
=> array (
135 ApiBase
:: PARAM_ISMULTI
=> true,
136 ApiBase
:: PARAM_TYPE
=> 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
153 protected function getParamDescription() {
155 'start' => 'The timestamp to start enumerating from.',
156 'end' => 'The timestamp to end enumerating.',
157 'limit' => 'How many total pages to return.'
161 protected function getDescription() {
162 return 'Enumerate recent changes';
165 protected function getExamples() {
167 'api.php?action=query&list=recentchanges',
171 public function getVersion() {
172 return __CLASS__
. ': $Id$';