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 ApiQueryLogEvents
extends ApiQueryBase
{
36 public function __construct($query, $moduleName) {
37 parent
:: __construct($query, $moduleName, 'le');
40 public function execute() {
41 $limit = $type = $start = $end = $dir = $user = $title = null;
42 extract($this->extractRequestParams());
46 list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
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");
53 $this->addFields(array (
66 $this->addWhereFld('log_type', $type);
67 $this->addWhereRange('log_timestamp', $dir, $start, $end);
68 $this->addOption('LIMIT', $limit +
1);
70 if (!is_null($user)) {
71 $userid = $db->selectField('user', 'user_id', array (
75 $this->dieUsage("User name $user not found", 'param_user');
76 $this->addWhereFld('log_user', $userid);
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());
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
);
97 $vals = $this->extractRowInfo($row);
101 $db->freeResult($res);
103 $this->getResult()->setIndexedTagName($data, 'item');
104 $this->getResult()->addValue('query', $this->getModuleName(), $data);
107 private function extractRowInfo($row) {
108 $title = Title
:: makeTitle($row->log_namespace
, $row->log_title
);
109 if (!$title->userCanRead())
114 $vals['pageid'] = intval($row->page_id
);
115 ApiQueryBase
:: addTitleInfo($vals, $title);
116 $vals['type'] = $row->log_type
;
117 $vals['action'] = $row->log_action
;
119 if ($row->log_params
!== '') {
120 $params = explode("\n", $row->log_params
);
121 switch ($row->log_type
) {
123 if (isset ($params[0])) {
124 $title = Title
:: newFromText($params[0]);
126 ApiQueryBase
:: addTitleInfo($vals, $title, "new_");
132 list( $cur, $prev, $auto ) = $params;
133 $vals['patrol_prev'] = $prev;
134 $vals['patrol_cur'] = $cur;
135 $vals['patrol_auto'] = $auto;
140 if (!empty ($params)) {
141 $this->getResult()->setIndexedTagName($params, 'param');
142 $vals = array_merge($vals, $params);
146 $vals['user'] = $row->user_name
;
149 $vals['timestamp'] = wfTimestamp(TS_ISO_8601
, $row->log_timestamp
);
151 if (!empty ($row->log_comment
))
152 $vals['comment'] = $row->log_comment
;
158 protected function getAllowedParams() {
162 ApiBase
:: PARAM_ISMULTI
=> true,
163 ApiBase
:: PARAM_TYPE
=> $wgLogTypes
166 ApiBase
:: PARAM_TYPE
=> 'timestamp'
169 ApiBase
:: PARAM_TYPE
=> 'timestamp'
172 ApiBase
:: PARAM_DFLT
=> 'older',
173 ApiBase
:: PARAM_TYPE
=> array (
181 ApiBase
:: PARAM_DFLT
=> 10,
182 ApiBase
:: PARAM_TYPE
=> 'limit',
183 ApiBase
:: PARAM_MIN
=> 1,
184 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
185 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
190 protected function getParamDescription() {
192 'type' => 'Filter log entries to only this type(s)',
193 'start' => 'The timestamp to start enumerating from.',
194 'end' => 'The timestamp to end enumerating.',
195 'dir' => 'In which direction to enumerate.',
196 'user' => 'Filter entries to those made by the given user.',
197 'title' => 'Filter entries to those related to a page.',
198 'limit' => 'How many total event entries to return.'
202 protected function getDescription() {
203 return 'Get events from logs.';
206 protected function getExamples() {
208 'api.php?action=query&list=logevents'
212 public function getVersion() {
213 return __CLASS__
. ': $Id$';