decde3e9699ef3abe8373f48a7d4ee261852244c
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());
44 extract($db->tableNames('logging', 'page', 'user'), EXTR_PREFIX_ALL
, 'tbl');
45 $this->setTablesAsExpression("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
46 "log_namespace=page_namespace AND log_title=page_title " .
47 "INNER JOIN $tbl_user ON user_id=log_user");
49 $this->addFields(array (
62 $this->addWhereFld('log_type', $type);
63 $this->addWhereRange('log_timestamp', $dir, $start, $end);
64 $this->addOption('LIMIT', $limit +
1);
66 if (!is_null($user)) {
67 $userid = $db->selectField('user', 'user_id', array (
71 $this->dieUsage("User name $user not found", 'param_user');
72 $this->addWhereFld('log_user', $userid);
75 if (!is_null($title)) {
76 $titleObj = Title
:: newFromText($title);
77 if (is_null($titleObj))
78 $this->dieUsage("Bad title value '$title'", 'param_title');
79 $this->addWhereFld('log_namespace', $titleObj->getNamespace());
80 $this->addWhereFld('log_title', $titleObj->getDBkey());
85 $res = $this->select(__METHOD__
);
86 while ($row = $db->fetchObject($res)) {
87 if (++
$count > $limit) {
88 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
89 $this->setContinueEnumParameter('start', ApiQueryBase
:: keyToTitle($row->log_timestamp
));
94 'action' => "$row->log_type/$row->log_action",
95 'timestamp' => $row->log_timestamp
,
96 'comment' => $row->log_comment
,
97 'pageid' => intval($row->page_id
100 $title = Title
:: makeTitle($row->log_namespace
, $row->log_title
);
101 $vals['ns'] = $title->getNamespace();
102 $vals['title'] = $title->getPrefixedText();
104 if ($row->log_params
!== '') {
105 $params = explode("\n", $row->log_params
);
106 if ($row->log_type
== 'move' && isset ($params[0])) {
107 $destTitle = Title
:: newFromText($params[0]);
109 $vals['tons'] = $destTitle->getNamespace();
110 $vals['totitle'] = $destTitle->getPrefixedText();
115 if (!empty ($params)) {
116 $this->getResult()->setIndexedTagName($params, 'param');
117 $vals = array_merge($vals, $params);
123 $vals['user'] = $row->user_name
;
127 $db->freeResult($res);
129 $this->getResult()->setIndexedTagName($data, 'item');
130 $this->getResult()->addValue('query', $this->getModuleName(), $data);
133 protected function getAllowedParams() {
136 ApiBase
:: PARAM_DFLT
=> 10,
137 ApiBase
:: PARAM_TYPE
=> 'limit',
138 ApiBase
:: PARAM_MIN
=> 1,
139 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
140 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
143 ApiBase
:: PARAM_ISMULTI
=> true,
144 ApiBase
:: PARAM_TYPE
=> array (
158 ApiBase
:: PARAM_TYPE
=> 'timestamp'
161 ApiBase
:: PARAM_TYPE
=> 'timestamp'
164 ApiBase
:: PARAM_DFLT
=> 'older',
165 ApiBase
:: PARAM_TYPE
=> array (
175 protected function getParamDescription() {
187 protected function getDescription() {
188 return 'Get events from logs.';
191 protected function getExamples() {
193 'api.php?action=query&list=logevents'
197 public function getVersion() {
198 return __CLASS__
. ': $Id$';