r48980 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48979‎ | r48980 | r48981 >
Date:04:23, 29 March 2009
Author:mrzman
Status:ok
Tags:
Comment:
(bug 18063) Add API module to list filter information.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.php (modified) (history)
  • /trunk/extensions/AbuseFilter/ApiQueryAbuseFilters.php (added) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.php
@@ -55,6 +55,8 @@
5656
5757 $wgAutoloadClasses['ApiQueryAbuseLog'] = "$dir/ApiQueryAbuseLog.php";
5858 $wgAPIListModules['abuselog'] = 'ApiQueryAbuseLog';
 59+$wgAutoloadClasses['ApiQueryAbuseFilters'] = "$dir/ApiQueryAbuseFilters.php";
 60+$wgAPIListModules['abusefilters'] = 'ApiQueryAbuseFilters';
5961
6062 $wgHooks['EditFilterMerged'][] = 'AbuseFilterHooks::onEditFilterMerged';
6163 $wgHooks['GetAutoPromoteGroups'][] = 'AbuseFilterHooks::onGetAutoPromoteGroups';
Index: trunk/extensions/AbuseFilter/ApiQueryAbuseFilters.php
@@ -0,0 +1,218 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Mar 29, 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 filter details.
 30+ *
 31+ * @ingroup API
 32+ * @ingroup Extensions
 33+ */
 34+class ApiQueryAbuseFilters extends ApiQueryBase {
 35+
 36+ public function __construct($query, $moduleName) {
 37+ parent :: __construct($query, $moduleName, 'abf');
 38+ }
 39+
 40+ public function execute() {
 41+ global $wgUser;
 42+ if(!$wgUser->isAllowed('abusefilter-view'))
 43+ $this->dieUsage('You don\'t have permission to view abuse filters', 'permissiondenied');
 44+
 45+ $params = $this->extractRequestParams();
 46+
 47+ $prop = array_flip($params['prop']);
 48+ $fld_id = isset($prop['id']);
 49+ $fld_desc = isset($prop['description']);
 50+ $fld_pattern = isset($prop['pattern']);
 51+ $fld_actions = isset($prop['actions']);
 52+ $fld_hits = isset($prop['hits']);
 53+ $fld_comments = isset($prop['comments']);
 54+ $fld_user = isset($prop['lasteditor']);
 55+ $fld_time = isset($prop['lastedittime']);
 56+ $fld_status = isset($prop['status']);
 57+ $fld_private = isset($prop['private']);
 58+
 59+ $result = $this->getResult();
 60+ $data = array();
 61+
 62+ $this->addTables('abuse_filter');
 63+
 64+ $this->addFields('af_id');
 65+ $this->addFields('af_hidden');
 66+ $this->addFieldsIf('af_hit_count', $fld_hits);
 67+ $this->addFieldsIf('af_enabled', $fld_status);
 68+ $this->addFieldsIf('af_deleted', $fld_status);
 69+ $this->addFieldsIf('af_public_comments', $fld_desc);
 70+ $this->addFieldsIf('af_pattern', $fld_pattern);
 71+ $this->addFieldsIf('af_actions', $fld_actions);
 72+ $this->addFieldsIf('af_comments', $fld_comments);
 73+ $this->addFieldsIf('af_user_text', $fld_user);
 74+ $this->addFieldsIf('af_timestamp', $fld_time);
 75+
 76+ $this->addOption('LIMIT', $params['limit'] + 1);
 77+
 78+ $this->addWhereRange('af_id', $params['dir'], $params['startid'], $params['endid']);
 79+
 80+ if (!is_null($params['show'])) {
 81+ $show = array_flip($params['show']);
 82+
 83+ /* Check for conflicting parameters. */
 84+ if ((isset ($show['enabled']) && isset ($show['!enabled']))
 85+ || (isset ($show['deleted']) && isset ($show['!deleted']))
 86+ || (isset ($show['private']) && isset ($show['!private']))) {
 87+ $this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
 88+ }
 89+
 90+ $this->addWhereIf('af_enabled = 0', isset ($show['!enabled']));
 91+ $this->addWhereIf('af_enabled != 0', isset ($show['enabled']));
 92+ $this->addWhereIf('af_deleted = 0', isset ($show['!deleted']));
 93+ $this->addWhereIf('af_deleted != 0', isset ($show['deleted']));
 94+ $this->addWhereIf('af_hidden = 0', isset ($show['!private']));
 95+ $this->addWhereIf('af_hidden != 0', isset ($show['private']));
 96+ }
 97+
 98+ $res = $this->select(__METHOD__);
 99+
 100+ $showhidden = $wgUser->isAllowed('abusefilter-modify');
 101+
 102+ $count = 0;
 103+ while($row = $res->fetchObject())
 104+ {
 105+ if(++$count > $params['limit'])
 106+ {
 107+ // We've had enough
 108+ $this->setContinueEnumParameter('startid', $row->af_id);
 109+ break;
 110+ }
 111+ $entry = array();
 112+ if($fld_id)
 113+ $entry['id'] = $row->af_id;
 114+ if($fld_desc)
 115+ $entry['description'] = $row->af_public_comments;
 116+ if($fld_pattern && (!$row->af_hidden || $showhidden))
 117+ $entry['pattern'] = $row->af_pattern;
 118+ if($fld_actions)
 119+ $entry['actions'] = $row->af_actions;
 120+ if($fld_hits)
 121+ $entry['hits'] = $row->af_hit_count;
 122+ if($fld_comments && (!$row->af_hidden || $showhidden))
 123+ $entry['comments'] = $row->af_comments;
 124+ if($fld_user)
 125+ $entry['lasteditor'] = $row->af_user_text;
 126+ if($fld_time)
 127+ $entry['lastedittime'] = wfTimestamp(TS_ISO_8601, $row->af_timestamp);
 128+ if($fld_private && $row->af_hidden)
 129+ $entry['private'] = '';
 130+ if($fld_status) {
 131+ if($row->af_enabled)
 132+ $entry['enabled'] = '';
 133+ if($row->af_deleted)
 134+ $entry['deleted'] = '';
 135+ }
 136+ if ($entry)
 137+ $data[] = $entry;
 138+ }
 139+ $result->setIndexedTagName($data, 'filter');
 140+ $result->addValue('query', $this->getModuleName(), $data);
 141+ }
 142+
 143+ public function getAllowedParams() {
 144+ return array (
 145+ 'startid' => array(
 146+ ApiBase :: PARAM_TYPE => 'integer'
 147+ ),
 148+ 'endid' => array(
 149+ ApiBase :: PARAM_TYPE => 'integer',
 150+ ),
 151+ 'dir' => array(
 152+ ApiBase :: PARAM_TYPE => array(
 153+ 'older',
 154+ 'newer'
 155+ ),
 156+ ApiBase :: PARAM_DFLT => 'newer'
 157+ ),
 158+ 'show' => array(
 159+ ApiBase :: PARAM_ISMULTI => true,
 160+ ApiBase :: PARAM_TYPE => array (
 161+ 'enabled',
 162+ '!enabled',
 163+ 'deleted',
 164+ '!deleted',
 165+ 'private',
 166+ '!private',
 167+ ),
 168+ ),
 169+ 'limit' => array(
 170+ ApiBase :: PARAM_DFLT => 10,
 171+ ApiBase :: PARAM_TYPE => 'limit',
 172+ ApiBase :: PARAM_MIN => 1,
 173+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 174+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 175+ ),
 176+ 'prop' => array(
 177+ ApiBase :: PARAM_DFLT => 'id|description|actions|status',
 178+ ApiBase :: PARAM_TYPE => array(
 179+ 'id',
 180+ 'description',
 181+ 'pattern',
 182+ 'actions',
 183+ 'hits',
 184+ 'comments',
 185+ 'lasteditor',
 186+ 'lastedittime',
 187+ 'status',
 188+ 'private',
 189+ ),
 190+ ApiBase :: PARAM_ISMULTI => true
 191+ )
 192+ );
 193+ }
 194+
 195+ public function getParamDescription() {
 196+ return array (
 197+ 'startid' => 'The filter id to start enumerating from',
 198+ 'endid' => 'The filter if to stop enumerating at',
 199+ 'dir' => 'The direction in which to enumerate',
 200+ 'show' => 'Shoe only filters which meet this criteria',
 201+ 'limit' => 'The maximum number of filters to list',
 202+ 'prop' => 'Which properties to get',
 203+ );
 204+ }
 205+
 206+ public function getDescription() {
 207+ return 'Show details of the abuse filters.';
 208+ }
 209+
 210+ protected function getExamples() {
 211+ return array('api.php?action=query&list=abusefilters&abfshow=enabled|!private',
 212+ 'api.php?action=query&list=abusefilters&abfprop=id|description|pattern'
 213+ );
 214+ }
 215+
 216+ public function getVersion() {
 217+ return __CLASS__ . ': $Id$';
 218+ }
 219+}
Property changes on: trunk/extensions/AbuseFilter/ApiQueryAbuseFilters.php
___________________________________________________________________
Added: svn:eol-style
1220 + native
Added: svn:keywords
2221 + Id

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r48975(bug 18063) Add API module for abuse log (list=abuselog)mrzman23:40, 28 March 2009

Status & tagging log