The war on redundant ampersand usage!
[lhc/web/wiklou.git] / includes / api / ApiQueryLogEvents.php
1 <?php
2
3
4 /*
5 * Created on Oct 16, 2006
6 *
7 * API for MediaWiki 1.8+
8 *
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
10 *
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.
15 *
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.
20 *
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
25 */
26
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ('ApiQueryBase.php');
30 }
31
32 class ApiQueryLogEvents extends ApiQueryBase {
33
34 public function __construct($query, $moduleName) {
35 parent :: __construct($query, $moduleName, 'le');
36 }
37
38 public function execute() {
39 $limit = $type = $start = $end = $dir = $user = $title = null;
40 extract($this->extractRequestParams());
41
42 $db = $this->getDB();
43
44 list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
45
46 $this->addOption('STRAIGHT_JOIN');
47 $this->addTables("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
48 "log_namespace=page_namespace AND log_title=page_title " .
49 "INNER JOIN $tbl_user ON user_id=log_user");
50
51 $this->addFields(array (
52 'log_type',
53 'log_action',
54 'log_timestamp',
55 'log_user',
56 'user_name',
57 'log_namespace',
58 'log_title',
59 'page_id',
60 'log_comment',
61 'log_params'
62 ));
63
64 $this->addWhereFld('log_type', $type);
65 $this->addWhereRange('log_timestamp', $dir, $start, $end);
66 $this->addOption('LIMIT', $limit +1);
67
68 if (!is_null($user)) {
69 $userid = $db->selectField('user', 'user_id', array (
70 'user_name' => $user
71 ));
72 if (!$userid)
73 $this->dieUsage("User name $user not found", 'param_user');
74 $this->addWhereFld('log_user', $userid);
75 }
76
77 if (!is_null($title)) {
78 $titleObj = Title :: newFromText($title);
79 if (is_null($titleObj))
80 $this->dieUsage("Bad title value '$title'", 'param_title');
81 $this->addWhereFld('log_namespace', $titleObj->getNamespace());
82 $this->addWhereFld('log_title', $titleObj->getDBkey());
83 }
84
85 $data = array ();
86 $count = 0;
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->log_timestamp);
92 break;
93 }
94
95 $vals = $this->addRowInfo('log', $row);
96 if($vals)
97 $data[] = $vals;
98 }
99 $db->freeResult($res);
100
101 $this->getResult()->setIndexedTagName($data, 'item');
102 $this->getResult()->addValue('query', $this->getModuleName(), $data);
103 }
104
105 protected function getAllowedParams() {
106 return array (
107 'type' => array (
108 ApiBase :: PARAM_ISMULTI => true,
109 ApiBase :: PARAM_TYPE => array (
110 'block',
111 'protect',
112 'rights',
113 'delete',
114 'upload',
115 'move',
116 'import',
117 'renameuser',
118 'newusers',
119 'makebot'
120 )
121 ),
122 'start' => array (
123 ApiBase :: PARAM_TYPE => 'timestamp'
124 ),
125 'end' => array (
126 ApiBase :: PARAM_TYPE => 'timestamp'
127 ),
128 'dir' => array (
129 ApiBase :: PARAM_DFLT => 'older',
130 ApiBase :: PARAM_TYPE => array (
131 'newer',
132 'older'
133 )
134 ),
135 'user' => null,
136 'title' => null,
137 'limit' => array (
138 ApiBase :: PARAM_DFLT => 10,
139 ApiBase :: PARAM_TYPE => 'limit',
140 ApiBase :: PARAM_MIN => 1,
141 ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
142 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
143 )
144 );
145 }
146
147 protected function getParamDescription() {
148 return array (
149 'type' => 'Filter log entries to only this type(s)',
150 'start' => 'The timestamp to start enumerating from.',
151 'end' => 'The timestamp to end enumerating.',
152 'dir' => 'In which direction to enumerate.',
153 'user' => 'Filter entries to those made by the given user.',
154 'title' => 'Filter entries to those related to a page.',
155 'limit' => 'How many total event entries to return.'
156 );
157 }
158
159 protected function getDescription() {
160 return 'Get events from logs.';
161 }
162
163 protected function getExamples() {
164 return array (
165 'api.php?action=query&list=logevents'
166 );
167 }
168
169 public function getVersion() {
170 return __CLASS__ . ': $Id$';
171 }
172 }
173 ?>