r48975 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48974‎ | r48975 | r48976 >
Date:23:40, 28 March 2009
Author:mrzman
Status:ok
Tags:
Comment:
(bug 18063) Add API module for abuse log (list=abuselog)
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.php (modified) (history)
  • /trunk/extensions/AbuseFilter/ApiQueryAbuseLog.php (added) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.php
@@ -53,6 +53,9 @@
5454 $wgSpecialPageGroups['AbuseLog'] = 'changes';
5555 $wgSpecialPageGroups['AbuseFilter'] = 'wiki';
5656
 57+$wgAutoloadClasses['ApiQueryAbuseLog'] = "$dir/ApiQueryAbuseLog.php";
 58+$wgAPIListModules['abuselog'] = 'ApiQueryAbuseLog';
 59+
5760 $wgHooks['EditFilterMerged'][] = 'AbuseFilterHooks::onEditFilterMerged';
5861 $wgHooks['GetAutoPromoteGroups'][] = 'AbuseFilterHooks::onGetAutoPromoteGroups';
5962 $wgHooks['AbortMove'][] = 'AbuseFilterHooks::onAbortMove';
Index: trunk/extensions/AbuseFilter/ApiQueryAbuseLog.php
@@ -0,0 +1,202 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Mar 28, 2009
 6+ *
 7+ * AbuseFilter extension
 8+ *
 9+ * Copyright (C) 2008 Alex Z. mrzmanwiki AT gmail DOT com
 10+ * Based mostly on code by Bryan Tong Minh and Roan Kattouw
 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+/**
 29+ * Query module to list abuse log entries.
 30+ *
 31+ * @ingroup API
 32+ * @ingroup Extensions
 33+ */
 34+class ApiQueryAbuseLog extends ApiQueryBase {
 35+
 36+ public function __construct($query, $moduleName) {
 37+ parent :: __construct($query, $moduleName, 'afl');
 38+ }
 39+
 40+ public function execute() {
 41+ global $wgUser;
 42+ if(!$wgUser->isAllowed('abusefilter-log'))
 43+ $this->dieUsage('You don\'t have permission to view the abuse log', 'permissiondenied');
 44+
 45+ $params = $this->extractRequestParams();
 46+
 47+ $prop = array_flip($params['prop']);
 48+ $fld_ids = isset($prop['ids']);
 49+ $fld_filter = isset($prop['filter']);
 50+ $fld_user = isset($prop['user']);
 51+ $fld_title = isset($prop['title']);
 52+ $fld_action = isset($prop['action']);
 53+ $fld_details = isset($prop['details']);
 54+ if($fld_details && !$wgUser->isAllowed('abusefilter-log-detail'))
 55+ $this->dieUsage('You don\'t have permission to view detailed abuse log entries', 'permissiondenied');
 56+ $fld_result = isset($prop['result']);
 57+ $fld_timestamp = isset($prop['timestamp']);
 58+
 59+ $result = $this->getResult();
 60+ $data = array();
 61+
 62+ $this->addTables('abuse_filter_log');
 63+ if($fld_filter) {
 64+ $this->addTables('abuse_filter');
 65+ $this->addFields('af_public_comments');
 66+ $this->addJoinConds(array('abuse_filter' =>
 67+ array('JOIN', 'afl_filter=af_id'))
 68+ );
 69+ }
 70+ $this->addFieldsIf(array('afl_id', 'afl_filter'), $fld_ids);
 71+ $this->addFieldsIf('afl_user_text', $fld_user);
 72+ $this->addFieldsIf(array('afl_namespace', 'afl_title'), $fld_title);
 73+ $this->addFieldsIf('afl_action', $fld_action);
 74+ $this->addFieldsIf('afl_var_dump', $fld_details);
 75+ $this->addFieldsIf('afl_actions', $fld_result);
 76+ $this->addFields('afl_timestamp');
 77+
 78+ $this->addOption('LIMIT', $params['limit'] + 1);
 79+
 80+ $this->addWhereRange('afl_timestamp', $params['dir'], $params['start'], $params['end']);
 81+
 82+ $this->addWhereIf( array('afl_user_text' => $params['user']), isset($params['user']));
 83+
 84+ $title = $params['title'];
 85+ if (!is_null($title)) {
 86+ $titleObj = Title :: newFromText($title);
 87+ if (is_null($titleObj))
 88+ $this->dieUsage("Bad title value '$title'", 'param_title');
 89+ $this->addWhereFld('afl_namespace', $titleObj->getNamespace());
 90+ $this->addWhereFld('afl_title', $titleObj->getDBkey());
 91+ }
 92+ $res = $this->select(__METHOD__);
 93+
 94+ $count = 0;
 95+ while($row = $res->fetchObject())
 96+ {
 97+ if(++$count > $params['limit'])
 98+ {
 99+ // We've had enough
 100+ $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->afl_timestamp));
 101+ break;
 102+ }
 103+ $entry = array();
 104+ if($fld_ids) {
 105+ $entry['id'] = $row->afl_id;
 106+ $entry['filter_id'] = $row->afl_filter;
 107+ }
 108+ if($fld_filter)
 109+ $entry['filter'] = $row->af_public_comments;
 110+ if($fld_user)
 111+ $entry['user'] = $row->afl_user_text;
 112+ if($fld_title) {
 113+ $title = Title::makeTitle($row->afl_namespace, $row->afl_title);
 114+ ApiQueryBase::addTitleInfo($entry, $title);
 115+ }
 116+ if($fld_action)
 117+ $entry['action'] = $row->afl_action;
 118+ if($fld_result)
 119+ $entry['result'] = $row->afl_actions;
 120+ if($fld_timestamp)
 121+ $entry['timestamp'] = wfTimestamp(TS_ISO_8601, $row->afl_timestamp);
 122+ if($fld_details) {
 123+ $vars = AbuseFilter::loadVarDump($row->afl_var_dump);
 124+ if ($vars instanceof AbuseFilterVariableHolder) {
 125+ $entry['details'] = $vars->exportAllVars();
 126+ } else {
 127+ $entry['details'] = array_change_key_case($vars, CASE_LOWER);
 128+ }
 129+ }
 130+ if ($entry)
 131+ $data[] = $entry;
 132+ }
 133+ $result->setIndexedTagName($data, 'item');
 134+ $result->addValue('query', $this->getModuleName(), $data);
 135+ }
 136+
 137+ public function getAllowedParams() {
 138+ return array (
 139+ 'start' => array(
 140+ ApiBase :: PARAM_TYPE => 'timestamp'
 141+ ),
 142+ 'end' => array(
 143+ ApiBase :: PARAM_TYPE => 'timestamp',
 144+ ),
 145+ 'dir' => array(
 146+ ApiBase :: PARAM_TYPE => array(
 147+ 'newer',
 148+ 'older'
 149+ ),
 150+ ApiBase :: PARAM_DFLT => 'older'
 151+ ),
 152+ 'user' => null,
 153+ 'title' => null,
 154+ 'limit' => array(
 155+ ApiBase :: PARAM_DFLT => 10,
 156+ ApiBase :: PARAM_TYPE => 'limit',
 157+ ApiBase :: PARAM_MIN => 1,
 158+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 159+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 160+ ),
 161+ 'prop' => array(
 162+ ApiBase :: PARAM_DFLT => 'ids|user|title|action|result|timestamp',
 163+ ApiBase :: PARAM_TYPE => array(
 164+ 'ids',
 165+ 'filter',
 166+ 'user',
 167+ 'title',
 168+ 'action',
 169+ 'details',
 170+ 'result',
 171+ 'timestamp',
 172+ ),
 173+ ApiBase :: PARAM_ISMULTI => true
 174+ )
 175+ );
 176+ }
 177+
 178+ public function getParamDescription() {
 179+ return array (
 180+ 'start' => 'The timestamp to start enumerating from',
 181+ 'end' => 'The timestamp to stop enumerating at',
 182+ 'dir' => 'The direction in which to enumerate',
 183+ 'title' => 'Filter entries to those occurring on a given page.',
 184+ 'user' => 'Filter entries to those done by a given user or IP address.',
 185+ 'limit' => 'The maximum amount of entries to list',
 186+ 'prop' => 'Which properties to get',
 187+ );
 188+ }
 189+
 190+ public function getDescription() {
 191+ return 'Show events that were caught by one of the abuse filters.';
 192+ }
 193+
 194+ protected function getExamples() {
 195+ return array('api.php?action=query&list=abuselog',
 196+ 'api.php?action=query&list=abuselog&afltitle=API'
 197+ );
 198+ }
 199+
 200+ public function getVersion() {
 201+ return __CLASS__ . ': $Id$';
 202+ }
 203+}
Property changes on: trunk/extensions/AbuseFilter/ApiQueryAbuseLog.php
___________________________________________________________________
Name: svn:eol-style
1204 + native
Name: svn:keywords
2205 + Id

Follow-up revisions

RevisionCommit summaryAuthorDate
r48980(bug 18063) Add API module to list filter information.mrzman04:23, 29 March 2009

Status & tagging log