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() {
45 // Before doing anything at all, let's check permissions
46 if(!$wgUser->isAllowed('deletedhistory'))
47 $this->dieUsage('You don\'t have permission to view deleted revision information', 'permissiondenied');
50 $params = $this->extractRequestParams(false);
51 $prop = array_flip($params['prop']);
52 $fld_revid = isset($prop['revid']);
53 $fld_user = isset($prop['user']);
54 $fld_comment = isset($prop['comment']);
55 $fld_minor = isset($prop['minor']);
56 $fld_len = isset($prop['len']);
57 $fld_content = isset($prop['content']);
58 $fld_token = isset($prop['token']);
60 $result = $this->getResult();
61 $pageSet = $this->getPageSet();
62 $titles = $pageSet->getTitles();
65 $this->addTables('archive');
66 $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));
68 $this->addFields('ar_rev_id');
70 $this->addFields('ar_user_text');
72 $this->addFields('ar_comment');
74 $this->addFields('ar_minor_edit');
76 $this->addFields('ar_len');
79 $this->addTables('text');
80 $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));
81 $this->addWhere('ar_text_id = old_id');
83 // This also means stricter restrictions
84 if(!$wgUser->isAllowed('undelete'))
85 $this->dieUsage('You don\'t have permission to view deleted revision content', 'permissiondenied');
88 $userMax = $fld_content ? ApiBase
:: LIMIT_SML1
: ApiBase
:: LIMIT_BIG1
;
89 $botMax = $fld_content ? ApiBase
:: LIMIT_SML2
: ApiBase
:: LIMIT_BIG2
;
90 if( $limit == 'max' ) {
91 $limit = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
92 $this->getResult()->addValue( 'limits', 'limit', $limit );
94 $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax);
96 // Undelete tokens are identical for all pages, so we cache one here
97 $token = $wgUser->editToken();
99 // We need a custom WHERE clause that matches all titles.
100 if(count($titles) > 0)
102 $lb = new LinkBatch($titles);
103 $where = $lb->constructSet('ar', $db);
104 $this->addWhere($where);
107 $this->addOption('LIMIT', $params['limit'] +
1);
108 $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);
109 if(isset($params['namespace']))
110 $this->addWhereFld('ar_namespace', $params['namespace']);
111 $res = $this->select(__METHOD__
);
114 // First populate the $pages array
115 while($row = $db->fetchObject($res))
117 if($count++
== $params['limit'])
120 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601
, $row->ar_timestamp
));
125 $rev['timestamp'] = wfTimestamp(TS_ISO_8601
, $row->ar_timestamp
);
127 $rev['revid'] = $row->ar_rev_id
;
129 $rev['user'] = $row->ar_user_text
;
131 $rev['comment'] = $row->ar_comment
;
133 if($row->ar_minor_edit
== 1)
136 $rev['len'] = $row->ar_len
;
138 ApiResult
::setContent($rev, Revision
::getRevisionText($row));
140 $t = Title
::makeTitle($row->ar_namespace
, $row->ar_title
);
141 if(!isset($pages[$t->getPrefixedText()]))
143 $pages[$t->getPrefixedText()] = array(
144 'title' => $t->getPrefixedText(),
145 'ns' => intval($row->ar_namespace
),
146 'revisions' => array($rev)
149 $pages[$t->getPrefixedText()]['token'] = $token;
152 $pages[$t->getPrefixedText()]['revisions'][] = $rev;
154 $db->freeResult($res);
156 // We don't want entire pagenames as keys, so let's make this array indexed
157 foreach($pages as $page)
159 $result->setIndexedTagName($page['revisions'], 'rev');
162 $result->setIndexedTagName($data, 'page');
163 $result->addValue('query', $this->getModuleName(), $data);
166 protected function getAllowedParams() {
169 ApiBase
:: PARAM_TYPE
=> 'timestamp'
172 ApiBase
:: PARAM_TYPE
=> 'timestamp',
175 ApiBase
:: PARAM_TYPE
=> array(
179 ApiBase
:: PARAM_DFLT
=> 'older'
181 'namespace' => array(
182 ApiBase
:: PARAM_ISMULTI
=> true,
183 ApiBase
:: PARAM_TYPE
=> 'namespace'
186 ApiBase
:: PARAM_DFLT
=> 10,
187 ApiBase
:: PARAM_TYPE
=> 'limit',
188 ApiBase
:: PARAM_MIN
=> 1,
189 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
190 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
193 ApiBase
:: PARAM_DFLT
=> 'user|comment',
194 ApiBase
:: PARAM_TYPE
=> array(
203 ApiBase
:: PARAM_ISMULTI
=> true
208 protected function getParamDescription() {
210 'start' => 'The timestamp to start enumerating from',
211 'end' => 'The timestamp to stop enumerating at',
212 'dir' => 'The direction in which to enumerate',
213 'namespace' => 'The namespaces to search in',
214 'limit' => 'The maximum amount of revisions to list',
215 'prop' => 'Which properties to get'
219 protected function getDescription() {
220 return 'List deleted revisions.';
223 protected function getExamples() {
225 'List the first 50 deleted revisions in the Category and Category talk namespaces',
226 ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',
227 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',
228 ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'
232 public function getVersion() {
233 return __CLASS__
. ': $Id$';