5 * Created on Oct 16, 2006
7 * API for MediaWiki 1.8+
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
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.
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.
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
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ('ApiQueryBase.php');
32 class ApiQueryLogEvents
extends ApiQueryBase
{
34 public function __construct($query, $moduleName) {
35 parent
:: __construct($query, $moduleName, 'le');
38 public function execute() {
39 $limit = $type = $start = $end = $dir = $user = $title = null;
40 extract($this->extractRequestParams());
42 $db = & $this->getDB();
44 extract($db->tableNames('logging', 'page', 'user'), EXTR_PREFIX_ALL
, 'tbl');
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");
51 $this->addFields(array (
64 $this->addWhereFld('log_type', $type);
65 $this->addWhereRange('log_timestamp', $dir, $start, $end);
66 $this->addOption('LIMIT', $limit +
1);
68 if (!is_null($user)) {
69 $userid = $db->selectField('user', 'user_id', array (
73 $this->dieUsage("User name $user not found", 'param_user');
74 $this->addWhereFld('log_user', $userid);
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());
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
);
95 $vals = $this->addRowInfo('log', $row);
99 $db->freeResult($res);
101 $this->getResult()->setIndexedTagName($data, 'item');
102 $this->getResult()->addValue('query', $this->getModuleName(), $data);
105 protected function getAllowedParams() {
108 ApiBase
:: PARAM_DFLT
=> 10,
109 ApiBase
:: PARAM_TYPE
=> 'limit',
110 ApiBase
:: PARAM_MIN
=> 1,
111 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
112 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
115 ApiBase
:: PARAM_ISMULTI
=> true,
116 ApiBase
:: PARAM_TYPE
=> array (
130 ApiBase
:: PARAM_TYPE
=> 'timestamp'
133 ApiBase
:: PARAM_TYPE
=> 'timestamp'
136 ApiBase
:: PARAM_DFLT
=> 'older',
137 ApiBase
:: PARAM_TYPE
=> array (
147 protected function getParamDescription() {
159 protected function getDescription() {
160 return 'Get events from logs.';
163 protected function getExamples() {
165 'api.php?action=query&list=logevents'
169 public function getVersion() {
170 return __CLASS__
. ': $Id$';