4 * Created on Oct 16, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
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');
34 class ApiQueryContributions
extends ApiQueryBase
{
36 public function __construct($query, $moduleName) {
37 parent
:: __construct($query, $moduleName, 'uc');
40 public function execute() {
42 $this->selectNamedDB('contributions', DB_SLAVE
, 'contributions');
44 //Blank all our variables
45 $limit = $user = $start = $end = $dir = null;
47 //Get our parameters out
48 extract($this->extractRequestParams());
50 //Get a database instance
54 $this->dieUsage("User parameter may not be empty", 'param_user');
57 list ($tbl_page, $tbl_revision) = $db->tableNamesN('page', 'revision');
59 //We're after the revision table, and the corresponding page row for
60 //anything we retrieve.
61 $this->addTables("$tbl_revision LEFT OUTER JOIN $tbl_page ON " .
64 //We want to know the namespace, title, new-ness, and ID of a page,
65 // and the id, text-id, timestamp, minor-status, summary and page
67 $this->addFields(array('page_namespace', 'page_title', 'page_is_new',
68 'rev_id', 'rev_text_id', 'rev_timestamp', 'rev_minor_edit',
69 'rev_comment', 'rev_page'));
71 // We only want pages by the specified user.
72 $this->addWhereFld('rev_user_text', $user);
73 // ... and in the specified timeframe.
74 $this->addWhereRange('rev_timestamp', $dir, $start, $end );
76 $this->addOption('LIMIT', $limit +
1);
78 //Initialise some variables
82 //Do the actual query.
83 $res = $this->select( __METHOD__
);
86 while ( $row = $db->fetchObject( $res ) ) {
87 if (++
$count > $limit) {
88 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
89 $this->setContinueEnumParameter('start', $row->rev_timestamp
);
93 //There's a fancy function in ApiQueryBase that does
94 // most of the work for us. Use that for the page
96 $revvals = $this->addRowInfo('rev', $row);
97 $pagevals = $this->addRowInfo('page', $row);
99 //If we got data on the revision only, use only
101 if($revvals && !$pagevals) {
104 //If we got data on the page only, use only
106 else if($pagevals && !$revvals) {
109 //... and if we got data on both the revision and
110 // the page, merge the data and send it out.
111 else if($pagevals && $revvals) {
112 $data[] = array_merge($revvals, $pagevals);
116 //Free the database record so the connection can get on with other stuff
117 $db->freeResult($res);
119 //And send the whole shebang out as output.
120 $this->getResult()->setIndexedTagName($data, 'item');
121 $this->getResult()->addValue('query', $this->getModuleName(), $data);
124 protected function getAllowedParams() {
127 ApiBase
:: PARAM_DFLT
=> 10,
128 ApiBase
:: PARAM_TYPE
=> 'limit',
129 ApiBase
:: PARAM_MIN
=> 1,
130 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
131 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
134 ApiBase
:: PARAM_TYPE
=> 'timestamp'
137 ApiBase
:: PARAM_TYPE
=> 'timestamp'
140 ApiBase
:: PARAM_TYPE
=> 'user'
143 ApiBase
:: PARAM_DFLT
=> 'older',
144 ApiBase
:: PARAM_TYPE
=> array (
152 protected function getParamDescription() {
154 'limit' => 'The maximum number of contributions to return.',
155 'start' => 'The start timestamp to return from.',
156 'end' => 'The end timestamp to return to.',
157 'user' => 'The user to retrieve contributions for.',
158 'dir' => 'The direction to search (older or newer).'
162 protected function getDescription() {
163 return 'Get edits by a user..';
166 protected function getExamples() {
168 'api.php?action=query&list=usercontribs&ucuser=YurikBot'
172 public function getVersion() {
173 return __CLASS__
. ': $Id$';