4 * Created on Jul 2, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
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.
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.
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
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * Query module to enumerate all available pages.
36 class ApiQueryDeletedrevs
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'dr');
42 public function execute() {
46 private function run() {
49 // Before doing anything at all, let's check permissions
50 if(!$wgUser->isAllowed('deletedhistory'))
51 $this->dieUsage('You don\'t have permission to view deleted revisions', 'permissiondenied');
54 $params = $this->extractRequestParams();
55 $prop = array_flip($params['prop']);
56 $fld_revid = isset($prop['revid']);
57 $fld_user = isset($prop['user']);
58 $fld_comment = isset($prop['comment']);
59 $fld_minor = isset($prop['minor']);
60 $fld_len = isset($prop['len']);
61 $fld_content = isset($prop['content']);
62 $fld_token = isset($prop['token']);
64 $result = $this->getResult();
65 $pageSet = $this->getPageSet();
66 $titles = $pageSet->getTitles();
69 $this->addTables('archive');
70 $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));
72 $this->addFields('ar_rev_id');
74 $this->addFields('ar_user_text');
76 $this->addFields('ar_comment');
78 $this->addFields('ar_minor_edit');
80 $this->addFields('ar_len');
83 $this->addTables('text');
84 $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));
85 $this->addWhere('ar_text_id = old_id');
87 // This also means stricter limits
90 $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax);
93 // Undelete tokens are identical for all pages, so we cache one here
94 $token = $wgUser->editToken();
96 // We need a custom WHERE clause that matches all titles.
97 if(count($titles) > 0)
99 $lb = new LinkBatch($titles);
100 $where = $lb->constructSet('ar', $db);
101 $this->addWhere($where);
104 $this->addOption('LIMIT', $params['limit'] +
1);
105 $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
106 if(isset($params['namespace']))
107 $this->addWhereFld('ar_namespace', $params['namespace']);
108 $res = $this->select(__METHOD__
);
111 // First populate the $pages array
112 while($row = $db->fetchObject($res))
114 if($count++
== $params['limit'])
117 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601
, $row->ar_timestamp
));
122 $rev['timestamp'] = wfTimestamp(TS_ISO_8601
, $row->ar_timestamp
);
124 $rev['revid'] = $row->ar_rev_id
;
126 $rev['user'] = $row->ar_user_text
;
128 $rev['comment'] = $row->ar_comment
;
130 if($row->ar_minor_edit
== 1)
133 $rev['len'] = $row->ar_len
;
135 ApiResult
::setContent($rev, Revision
::getRevisionText($row));
137 $t = Title
::makeTitle($row->ar_namespace
, $row->ar_title
);
138 if(!isset($pages[$t->getPrefixedText()]))
140 $pages[$t->getPrefixedText()] = array(
141 'title' => $t->getPrefixedText(),
142 'ns' => intval($row->ar_namespace
),
143 'revisions' => array($rev)
146 $pages[$t->getPrefixedText()]['token'] = $token;
149 $pages[$t->getPrefixedText()]['revisions'][] = $rev;
151 $db->freeResult($res);
153 // We don't want entire pagenames as keys, so let's make this array indexed
154 foreach($pages as $page)
156 $result->setIndexedTagName($page['revisions'], 'rev');
159 $result->setIndexedTagName($data, 'page');
160 $result->addValue('query', $this->getModuleName(), $data);
163 protected function getAllowedParams() {
166 ApiBase
:: PARAM_TYPE
=> 'timestamp'
169 ApiBase
:: PARAM_TYPE
=> 'timestamp',
172 ApiBase
:: PARAM_TYPE
=> array(
176 ApiBase
:: PARAM_DFLT
=> 'older'
178 'namespace' => array(
179 ApiBase
:: PARAM_ISMULTI
=> true,
180 ApiBase
:: PARAM_TYPE
=> 'namespace'
183 ApiBase
:: PARAM_DFLT
=> 10,
184 ApiBase
:: PARAM_TYPE
=> 'limit',
185 ApiBase
:: PARAM_MIN
=> 1,
186 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
187 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
190 ApiBase
:: PARAM_DFLT
=> 'user|comment',
191 ApiBase
:: PARAM_TYPE
=> array(
200 ApiBase
:: PARAM_ISMULTI
=> true
205 protected function getParamDescription() {
207 'start' => 'The timestamp to start enumerating from',
208 'end' => 'The timestamp to stop enumerating at',
209 'dir' => 'The direction in which to enumerate',
210 'namespace' => 'The namespaces to search in',
211 'limit' => 'The maximum amount of revisions to list',
212 'prop' => 'Which properties to get'
216 protected function getDescription() {
217 return 'List deleted revisions.';
220 protected function getExamples() {
222 'List the first 50 deleted revisions in the Category and Category talk namespaces',
223 ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
224 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
225 ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
229 public function getVersion() {
230 return __CLASS__
. ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $';