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