7da11b02d8df6802270de622d9feb518af63b1cf
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 $tables = "$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";
64 $where['log_type'] = $type;
66 if (!is_null($user)) {
67 $userid = $db->selectField('user', 'user_id', array (
71 $this->dieUsage("User name $user not found", 'param_user');
72 $where['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 $where['log_namespace'] = $titleObj->getNamespace();
80 $where['log_title'] = $titleObj->getDBkey();
83 $dirNewer = ($dir === 'newer');
84 $before = ($dirNewer ?
'<=' : '>=');
85 $after = ($dirNewer ?
'>=' : '<=');
88 $where[] = 'log_timestamp' . $after . $db->addQuotes($start);
90 $where[] = 'log_timestamp' . $before . $db->addQuotes($end);
94 'ORDER BY' => 'log_timestamp' . ($dirNewer ?
'' : ' DESC'
98 $res = $db->select($tables, $fields, $where, __METHOD__
, $options);
99 $this->profileDBOut();
103 while ($row = $db->fetchObject($res)) {
104 if (++
$count > $limit) {
105 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
106 $this->setContinueEnumParameter('start', ApiQueryBase
:: keyToTitle($row->log_timestamp
));
111 'action' => "$row->log_type/$row->log_action",
112 'timestamp' => $row->log_timestamp
,
113 'comment' => $row->log_comment
,
114 'pageid' => intval($row->page_id
117 $title = Title
:: makeTitle($row->log_namespace
, $row->log_title
);
118 $vals['ns'] = $title->getNamespace();
119 $vals['title'] = $title->getPrefixedText();
121 if ($row->log_params
!== '') {
122 $params = explode("\n", $row->log_params
);
123 if ($row->log_type
== 'move' && isset ($params[0])) {
124 $destTitle = Title
:: newFromText($params[0]);
126 $vals['tons'] = $destTitle->getNamespace();
127 $vals['totitle'] = $destTitle->getPrefixedText();
132 if(!empty($params)) {
133 ApiResult
:: setIndexedTagName($params, 'param');
134 $vals = array_merge($vals, $params);
140 $vals['user'] = $row->user_name
;
144 $db->freeResult($res);
146 ApiResult
:: setIndexedTagName($data, 'item');
147 $this->getResult()->addValue('query', $this->getModuleName(), $data);
150 protected function getAllowedParams() {
153 ApiBase
:: PARAM_DFLT
=> 10,
154 ApiBase
:: PARAM_TYPE
=> 'limit',
155 ApiBase
:: PARAM_MIN
=> 1,
156 ApiBase
:: PARAM_MAX1
=> ApiBase
:: LIMIT_BIG1
,
157 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
160 ApiBase
:: PARAM_ISMULTI
=> true,
161 ApiBase
:: PARAM_TYPE
=> array (
175 ApiBase
:: PARAM_TYPE
=> 'timestamp'
178 ApiBase
:: PARAM_TYPE
=> 'timestamp'
181 ApiBase
:: PARAM_DFLT
=> 'older',
182 ApiBase
:: PARAM_TYPE
=> array (
192 protected function getParamDescription() {
204 protected function getDescription() {
205 return 'Get events from logs.';
208 protected function getExamples() {
210 'api.php?action=query&list=logevents'
214 public function getVersion() {
215 return __CLASS__
. ': $Id$';