7c3e6862dbc2bb2a359d2e1a707b5931087bbd5d
4 * Created on Oct 16, 2006
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@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');
32 * Query action to List the log events, with optional filtering by various parameters.
36 class ApiQueryLogEvents
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'le');
42 public function execute() {
43 $limit = $type = $start = $end = $dir = $user = $title = null;
44 extract($this->extractRequestParams());
48 list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
50 $this->addOption('STRAIGHT_JOIN');
51 $this->addTables("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
52 "log_namespace=page_namespace AND log_title=page_title " .
53 "INNER JOIN $tbl_user ON user_id=log_user");
55 $this->addFields(array (
68 $this->addWhereFld('log_deleted', 0);
69 $this->addWhereFld('log_type', $type);
70 $this->addWhereRange('log_timestamp', $dir, $start, $end);
71 $this->addOption('LIMIT', $limit +
1);
73 if (!is_null($user)) {
74 $userid = $db->selectField('user', 'user_id', array (
78 $this->dieUsage("User name $user not found", 'param_user');
79 $this->addWhereFld('log_user', $userid);
82 if (!is_null($title)) {
83 $titleObj = Title
:: newFromText($title);
84 if (is_null($titleObj))
85 $this->dieUsage("Bad title value '$title'", 'param_title');
86 $this->addWhereFld('log_namespace', $titleObj->getNamespace());
87 $this->addWhereFld('log_title', $titleObj->getDBkey());
92 $res = $this->select(__METHOD__
);
93 while ($row = $db->fetchObject($res)) {
94 if (++
$count > $limit) {
95 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
96 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601
, $row->log_timestamp
));
100 $vals = $this->extractRowInfo($row);
104 $db->freeResult($res);
106 $this->getResult()->setIndexedTagName($data, 'item');
107 $this->getResult()->addValue('query', $this->getModuleName(), $data);
110 private function extractRowInfo($row) {
111 $title = Title
:: makeTitle($row->log_namespace
, $row->log_title
);
112 if (!$title->userCanRead())
117 $vals['pageid'] = intval($row->page_id
);
118 ApiQueryBase
:: addTitleInfo($vals, $title);
119 $vals['type'] = $row->log_type
;
120 $vals['action'] = $row->log_action
;
122 if ($row->log_params
!== '') {
123 $params = explode("\n", $row->log_params
);
124 switch ($row->log_type
) {
126 if (isset ($params[0])) {
127 $title = Title
:: newFromText($params[0]);
129 ApiQueryBase
:: addTitleInfo($vals, $title, false, "new_");
135 list( $cur, $prev, $auto ) = $params;
136 $vals['patrol_prev'] = $prev;
137 $vals['patrol_cur'] = $cur;
138 $vals['patrol_auto'] = $auto;
143 if (!empty ($params)) {
144 $this->getResult()->setIndexedTagName($params, 'param');
145 $vals = array_merge($vals, $params);
149 $vals['user'] = $row->user_name
;
152 $vals['timestamp'] = wfTimestamp(TS_ISO_8601
, $row->log_timestamp
);
154 if (!empty ($row->log_comment
))
155 $vals['comment'] = $row->log_comment
;
161 protected function getAllowedParams() {
165 ApiBase
:: PARAM_ISMULTI
=> true,
166 ApiBase
:: PARAM_TYPE
=> $wgLogTypes
169 ApiBase
:: PARAM_TYPE
=> 'timestamp'
172 ApiBase
:: PARAM_TYPE
=> 'timestamp'
175 ApiBase
:: PARAM_DFLT
=> 'older',
176 ApiBase
:: PARAM_TYPE
=> array (
184 ApiBase
:: PARAM_DFLT
=> 10,
185 ApiBase
:: PARAM_TYPE
=> 'limit',
186 ApiBase
:: PARAM_MIN
=> 1,
187 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
188 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
193 protected function getParamDescription() {
195 'type' => 'Filter log entries to only this type(s)',
196 'start' => 'The timestamp to start enumerating from.',
197 'end' => 'The timestamp to end enumerating.',
198 'dir' => 'In which direction to enumerate.',
199 'user' => 'Filter entries to those made by the given user.',
200 'title' => 'Filter entries to those related to a page.',
201 'limit' => 'How many total event entries to return.'
205 protected function getDescription() {
206 return 'Get events from logs.';
209 protected function getExamples() {
211 'api.php?action=query&list=logevents'
215 public function getVersion() {
216 return __CLASS__
. ': $Id$';