r17051 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17050‎ | r17051 | r17052 >
Date:07:19, 16 October 2006
Author:yurik
Status:old
Tags:
Comment:
* API: logevents query module (incomplete)
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllpages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (added) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -47,13 +47,13 @@
4848
4949 private $mQueryListModules = array (
5050 'allpages' => 'ApiQueryAllpages',
 51+ 'logevents' => 'ApiQueryLogEvents',
5152 'watchlist' => 'ApiQueryWatchlist'
5253 );
5354 // 'backlinks' => 'ApiQueryBacklinks',
5455 // 'categorymembers' => 'ApiQueryCategorymembers',
5556 // 'embeddedin' => 'ApiQueryEmbeddedin',
5657 // 'imagelinks' => 'ApiQueryImagelinks',
57 - // 'logevents' => 'ApiQueryLogevents',
5858 // 'recentchanges' => 'ApiQueryRecentchanges',
5959 // 'usercontribs' => 'ApiQueryUsercontribs',
6060 // 'users' => 'ApiQueryUsers',
Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -119,7 +119,7 @@
120120
121121 if (is_null($resultPageSet)) {
122122 ApiResult :: setIndexedTagName($data, 'p');
123 - $this->getResult()->addValue('query', 'allpages', $data);
 123+ $this->getResult()->addValue('query', $this->getModuleName(), $data);
124124 }
125125 }
126126
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -198,7 +198,7 @@
199199
200200 if (is_null($resultPageSet)) {
201201 ApiResult :: setIndexedTagName($data, 'item');
202 - $this->getResult()->addValue('query', 'watchlist', $data);
 202+ $this->getResult()->addValue('query', $this->getModuleName(), $data);
203203 }
204204 elseif ($allrev) {
205205 $resultPageSet->populateFromRevisionIDs($data);
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -0,0 +1,160 @@
 2+<?php
 3+
 4+
 5+/*
 6+ * Created on Oct 16, 2006
 7+ *
 8+ * API for MediaWiki 1.8+
 9+ *
 10+ * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
 11+ *
 12+ * This program is free software; you can redistribute it and/or modify
 13+ * it under the terms of the GNU General Public License as published by
 14+ * the Free Software Foundation; either version 2 of the License, or
 15+ * (at your option) any later version.
 16+ *
 17+ * This program is distributed in the hope that it will be useful,
 18+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 20+ * GNU General Public License for more details.
 21+ *
 22+ * You should have received a copy of the GNU General Public License along
 23+ * with this program; if not, write to the Free Software Foundation, Inc.,
 24+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 25+ * http://www.gnu.org/copyleft/gpl.html
 26+ */
 27+
 28+if (!defined('MEDIAWIKI')) {
 29+ // Eclipse helper - will be ignored in production
 30+ require_once ('ApiQueryBase.php');
 31+}
 32+
 33+class ApiQueryLogEvents extends ApiQueryBase {
 34+
 35+ public function __construct($query, $moduleName) {
 36+ parent :: __construct($query, $moduleName, 'le');
 37+ }
 38+
 39+ public function execute() {
 40+ $limit = $type = $from = $to = $dir = $user = $title = $namespace = null;
 41+ extract($this->extractRequestParams());
 42+
 43+ $db = $this->getDB();
 44+
 45+ extract($db->tableNames('logging', 'page', 'user'), EXTR_PREFIX_ALL, 'tbl');
 46+
 47+ $tables = "$tbl_logging LEFT OUTER JOIN $tbl_page ON log_namespace=page_namespace AND log_title=page_title " .
 48+ "INNER JOIN $tbl_user ON user_id=log_user";
 49+
 50+ $fields = array (
 51+ 'log_type',
 52+ 'log_action',
 53+ 'log_timestamp',
 54+ 'log_user',
 55+ 'user_name',
 56+ 'log_namespace',
 57+ 'log_title',
 58+ 'page_id',
 59+ 'log_comment',
 60+ 'log_params'
 61+ );
 62+
 63+ $where = array ();
 64+ if (!is_null($type))
 65+ $where['log_type'] = $type;
 66+
 67+ if (!is_null($user)) {
 68+ $userid = $db->selectField('user', 'user_id', array (
 69+ 'user_name' => $user
 70+ ));
 71+ if (!$userid)
 72+ $this->dieUsage("User name $user not found", 'param_user');
 73+ $where['log_user'] = $userid;
 74+ }
 75+
 76+ if (!is_null($title)) {
 77+ $titleObj = Title :: newFromText($title);
 78+ if (is_null($titleObj))
 79+ $this->dieUsage("Bad title value '$title'", 'param_title');
 80+ $where['log_namespace'] = $titleObj->getNamespace();
 81+ $where['log_title'] = $titleObj->getDBkey();
 82+ }
 83+
 84+ // $where[] = "log_timestamp $direction '$safetime'";
 85+
 86+ $options = array (
 87+ 'LIMIT' => $limit +1
 88+ );
 89+
 90+ $this->profileDBIn();
 91+ $res = $db->select($tables, $fields, $where, __METHOD__, $options);
 92+ $this->profileDBOut();
 93+
 94+ $data = array ();
 95+ $count = 0;
 96+ while ($row = $db->fetchObject($res)) {
 97+ if (++ $count > $limit) {
 98+ // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 99+ $this->setContinueEnumParameter('from', ApiQueryBase :: keyToTitle($row->page_title));
 100+ break;
 101+ }
 102+
 103+ $vals = array (
 104+ 'type' => $row->log_type,
 105+ 'action' => $row->log_action,
 106+ 'timestamp' => $row->log_timestamp,
 107+ 'comment' => $row->log_comment,
 108+ 'params' => $row->log_params,
 109+ 'pageid' => intval($row->page_id)
 110+ );
 111+
 112+ $title = Title :: makeTitle($row->log_namespace, $row->log_title);
 113+ $vals['ns'] = $title->getNamespace();
 114+ $vals['title'] = $title->getPrefixedText();
 115+
 116+ if (!$row->log_user)
 117+ $vals['anon'] = '';
 118+ $vals['user'] = $row->user_name;
 119+
 120+ $data[] = $vals;
 121+ }
 122+ $db->freeResult($res);
 123+
 124+ ApiResult :: setIndexedTagName($data, 'item');
 125+ $this->getResult()->addValue('query', $this->getModuleName(), $data);
 126+ }
 127+
 128+ protected function getAllowedParams() {
 129+
 130+ return array (
 131+ 'limit' => array (
 132+ ApiBase :: PARAM_DFLT => 10,
 133+ ApiBase :: PARAM_TYPE => 'limit',
 134+ ApiBase :: PARAM_MIN => 1,
 135+ ApiBase :: PARAM_MAX1 => 500,
 136+ ApiBase :: PARAM_MAX2 => 5000
 137+ )
 138+ );
 139+ }
 140+
 141+ protected function getParamDescription() {
 142+ return array (
 143+ 'limit' => 'How many total items to return.'
 144+ );
 145+ }
 146+
 147+ protected function getDescription() {
 148+ return 'Get events from logs.';
 149+ }
 150+
 151+ protected function getExamples() {
 152+ return array (
 153+ 'api.php?action=query&list=logevents'
 154+ );
 155+ }
 156+
 157+ public function getVersion() {
 158+ return __CLASS__ . ': $Id:$';
 159+ }
 160+}
 161+?>
\ No newline at end of file
Property changes on: trunk/phase3/includes/api/ApiQueryLogEvents.php
___________________________________________________________________
Added: svn:eol-style
1162 + native
Added: svn:keywords
2163 + Id
Index: trunk/phase3/includes/AutoLoader.php
@@ -254,6 +254,7 @@
255255 'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php',
256256 'ApiQueryBase' => 'includes/api/ApiQueryBase.php',
257257 'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php',
 258+ 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
258259 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php',
259260 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php',
260261 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php',