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');
55 $userid = $db->selectField('user', 'user_id', array (
59 $this->dieUsage("User name $user not found", 'param_user');
62 list ($tbl_page, $tbl_revision) = $db->tableNamesN('page', 'revision');
64 //We're after the revision table, and the corresponding page row for
65 //anything we retrieve.
66 $this->addTables("$tbl_revision LEFT OUTER JOIN $tbl_page ON " .
69 //We want to know the namespace, title, new-ness, and ID of a page,
70 // and the id, text-id, timestamp, minor-status, summary and page
72 $this->addFields(array('page_namespace', 'page_title', 'page_is_new',
73 'rev_id', 'rev_text_id', 'rev_timestamp', 'rev_minor_edit',
74 'rev_comment', 'rev_page'));
76 // We only want pages by the specified user.
77 $this->addWhereFld('rev_user_text', $user);
78 // ... and in the specified timeframe.
79 $this->addWhereRange('rev_timestamp', $dir, $start, $end );
81 $this->addOption('LIMIT', $limit +
1);
83 //Initialise some variables
87 //Do the actual query.
88 $res = $this->select( __METHOD__
);
91 while ( $row = $db->fetchObject( $res ) ) {
92 if (++
$count > $limit) {
93 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
94 $this->setContinueEnumParameter('start', $row->rev_timestamp
);
98 //There's a fancy function in ApiQueryBase that does
99 // most of the work for us. Use that for the page
101 $revvals = $this->addRowInfo('rev', $row);
102 $pagevals = $this->addRowInfo('page', $row);
104 //If we got data on the revision only, use only
106 if($revvals && !$pagevals) {
109 //If we got data on the page only, use only
111 else if($pagevals && !$revvals) {
114 //... and if we got data on both the revision and
115 // the page, merge the data and send it out.
116 else if($pagevals && $revvals) {
117 $data[] = array_merge($revvals, $pagevals);
121 //Free the database record so the connection can get on with other stuff
122 $db->freeResult($res);
124 //And send the whole shebang out as output.
125 $this->getResult()->setIndexedTagName($data, 'item');
126 $this->getResult()->addValue('query', $this->getModuleName(), $data);
129 protected function getAllowedParams() {
132 ApiBase
:: PARAM_DFLT
=> 10,
133 ApiBase
:: PARAM_TYPE
=> 'limit',
134 ApiBase
:: PARAM_MIN
=> 1,
135 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
136 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
139 ApiBase
:: PARAM_TYPE
=> 'timestamp'
142 ApiBase
:: PARAM_TYPE
=> 'timestamp'
146 ApiBase
:: PARAM_DFLT
=> 'older',
147 ApiBase
:: PARAM_TYPE
=> array (
155 protected function getParamDescription() {
157 'limit' => 'The maximum number of contributions to return.',
158 'start' => 'The start timestamp to return from.',
159 'end' => 'The end timestamp to return to.',
160 'user' => 'The user to retrieve contributions for.',
161 'dir' => 'The direction to search (older or newer).'
165 protected function getDescription() {
166 return 'Get edits by a user..';
169 protected function getExamples() {
171 'api.php?action=query&list=usercontribs&ucuser=YurikBot'
175 public function getVersion() {
176 return __CLASS__
. ': $Id$';