2009-03-29 04:23:20 +00:00
|
|
|
<?php
|
2009-10-07 13:57:06 +00:00
|
|
|
/**
|
2009-03-29 04:23:20 +00:00
|
|
|
* Created on Mar 29, 2009
|
|
|
|
*
|
|
|
|
* AbuseFilter extension
|
|
|
|
*
|
2010-08-19 21:12:09 +00:00
|
|
|
* Copyright © 2008 Alex Z. mrzmanwiki AT gmail DOT com
|
2009-03-29 04:23:20 +00:00
|
|
|
* Based mostly on code by Bryan Tong Minh and Roan Kattouw
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:45:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-03-29 04:23:20 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query module to list abuse filter details.
|
|
|
|
*
|
|
|
|
* @ingroup API
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
class ApiQueryAbuseFilters extends ApiQueryBase {
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @param ApiQuery $query
|
|
|
|
* @param string $moduleName
|
|
|
|
*/
|
2018-10-17 01:22:23 +00:00
|
|
|
public function __construct( $query, $moduleName ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'abf' );
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiQueryBase::execute()
|
|
|
|
*/
|
2009-03-29 04:23:20 +00:00
|
|
|
public function execute() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->checkUserRightsAny( 'abusefilter-view' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-29 04:23:20 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$prop = array_flip( $params['prop'] );
|
|
|
|
$fld_id = isset( $prop['id'] );
|
|
|
|
$fld_desc = isset( $prop['description'] );
|
|
|
|
$fld_pattern = isset( $prop['pattern'] );
|
|
|
|
$fld_actions = isset( $prop['actions'] );
|
|
|
|
$fld_hits = isset( $prop['hits'] );
|
|
|
|
$fld_comments = isset( $prop['comments'] );
|
|
|
|
$fld_user = isset( $prop['lasteditor'] );
|
|
|
|
$fld_time = isset( $prop['lastedittime'] );
|
|
|
|
$fld_status = isset( $prop['status'] );
|
|
|
|
$fld_private = isset( $prop['private'] );
|
|
|
|
|
2009-03-29 04:23:20 +00:00
|
|
|
$result = $this->getResult();
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->addTables( 'abuse_filter' );
|
|
|
|
|
|
|
|
$this->addFields( 'af_id' );
|
|
|
|
$this->addFields( 'af_hidden' );
|
|
|
|
$this->addFieldsIf( 'af_hit_count', $fld_hits );
|
|
|
|
$this->addFieldsIf( 'af_enabled', $fld_status );
|
|
|
|
$this->addFieldsIf( 'af_deleted', $fld_status );
|
|
|
|
$this->addFieldsIf( 'af_public_comments', $fld_desc );
|
|
|
|
$this->addFieldsIf( 'af_pattern', $fld_pattern );
|
|
|
|
$this->addFieldsIf( 'af_actions', $fld_actions );
|
|
|
|
$this->addFieldsIf( 'af_comments', $fld_comments );
|
2013-06-26 22:58:36 +00:00
|
|
|
$this->addFieldsIf( 'af_user_text', $fld_user );
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->addFieldsIf( 'af_timestamp', $fld_time );
|
|
|
|
|
|
|
|
$this->addOption( 'LIMIT', $params['limit'] + 1 );
|
|
|
|
|
|
|
|
$this->addWhereRange( 'af_id', $params['dir'], $params['startid'], $params['endid'] );
|
|
|
|
|
|
|
|
if ( !is_null( $params['show'] ) ) {
|
|
|
|
$show = array_flip( $params['show'] );
|
|
|
|
|
2009-03-29 04:23:20 +00:00
|
|
|
/* Check for conflicting parameters. */
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( ( isset( $show['enabled'] ) && isset( $show['!enabled'] ) )
|
2016-11-03 19:16:55 +00:00
|
|
|
|| ( isset( $show['deleted'] ) && isset( $show['!deleted'] ) )
|
|
|
|
|| ( isset( $show['private'] ) && isset( $show['!private'] ) )
|
|
|
|
) {
|
2017-08-07 23:35:21 +00:00
|
|
|
$this->dieWithError( 'apierror-show' );
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$this->addWhereIf( 'af_enabled = 0', isset( $show['!enabled'] ) );
|
|
|
|
$this->addWhereIf( 'af_enabled != 0', isset( $show['enabled'] ) );
|
|
|
|
$this->addWhereIf( 'af_deleted = 0', isset( $show['!deleted'] ) );
|
|
|
|
$this->addWhereIf( 'af_deleted != 0', isset( $show['deleted'] ) );
|
|
|
|
$this->addWhereIf( 'af_hidden = 0', isset( $show['!private'] ) );
|
|
|
|
$this->addWhereIf( 'af_hidden != 0', isset( $show['private'] ) );
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$res = $this->select( __METHOD__ );
|
|
|
|
|
2016-12-24 06:50:01 +00:00
|
|
|
$showhidden = $user->isAllowedAny( 'abusefilter-modify', 'abusefilter-view-private' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-29 04:23:20 +00:00
|
|
|
$count = 0;
|
2011-02-10 17:25:25 +00:00
|
|
|
foreach ( $res as $row ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( ++$count > $params['limit'] ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
// We've had enough
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->setContinueEnumParameter( 'startid', $row->af_id );
|
2009-03-29 04:23:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-15 14:23:16 +00:00
|
|
|
$entry = [];
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $fld_id ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
$entry['id'] = intval( $row->af_id );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_desc ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['description'] = $row->af_public_comments;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_pattern && ( !$row->af_hidden || $showhidden ) ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['pattern'] = $row->af_pattern;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_actions ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['actions'] = $row->af_actions;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_hits ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$entry['hits'] = intval( $row->af_hit_count );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_comments && ( !$row->af_hidden || $showhidden ) ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['comments'] = $row->af_comments;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_user ) {
|
2013-06-26 22:58:36 +00:00
|
|
|
$entry['lasteditor'] = $row->af_user_text;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_time ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$ts = new MWTimestamp( $row->af_timestamp );
|
|
|
|
$entry['lastedittime'] = $ts->getTimestamp( TS_ISO_8601 );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $fld_private && $row->af_hidden ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['private'] = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $fld_status ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $row->af_enabled ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['enabled'] = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $row->af_deleted ) {
|
2009-03-29 04:23:20 +00:00
|
|
|
$entry['deleted'] = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $entry ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
$fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $entry );
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !$fit ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->setContinueEnumParameter( 'startid', $row->af_id );
|
2009-03-30 12:19:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
2017-06-15 14:23:16 +00:00
|
|
|
$result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'filter' );
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see ApiQueryBase::getAllowedParams()
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-03-29 04:23:20 +00:00
|
|
|
public function getAllowedParams() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
|
|
|
'startid' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'endid' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'dir' => [
|
|
|
|
ApiBase::PARAM_TYPE => [
|
2009-03-29 04:23:20 +00:00
|
|
|
'older',
|
|
|
|
'newer'
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2014-10-28 16:25:22 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'newer',
|
2016-09-20 18:39:11 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'show' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2017-06-15 14:23:16 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
2009-03-29 04:23:20 +00:00
|
|
|
'enabled',
|
|
|
|
'!enabled',
|
|
|
|
'deleted',
|
|
|
|
'!deleted',
|
|
|
|
'private',
|
|
|
|
'!private',
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'limit' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
ApiBase::PARAM_DFLT => 10,
|
|
|
|
ApiBase::PARAM_TYPE => 'limit',
|
|
|
|
ApiBase::PARAM_MIN => 1,
|
|
|
|
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
|
|
|
|
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'prop' => [
|
2009-10-07 13:57:06 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'id|description|actions|status',
|
2017-06-15 14:23:16 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
2009-10-07 13:57:06 +00:00
|
|
|
'id',
|
|
|
|
'description',
|
|
|
|
'pattern',
|
|
|
|
'actions',
|
|
|
|
'hits',
|
|
|
|
'comments',
|
|
|
|
'lasteditor',
|
|
|
|
'lastedittime',
|
|
|
|
'status',
|
|
|
|
'private',
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2009-10-07 13:57:06 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2017-06-15 14:23:16 +00:00
|
|
|
]
|
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:25:22 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2017-10-06 18:52:31 +00:00
|
|
|
* @return array
|
2014-10-28 16:25:22 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [
|
2014-10-28 16:25:22 +00:00
|
|
|
'action=query&list=abusefilters&abfshow=enabled|!private'
|
|
|
|
=> 'apihelp-query+abusefilters-example-1',
|
|
|
|
'action=query&list=abusefilters&abfprop=id|description|pattern'
|
|
|
|
=> 'apihelp-query+abusefilters-example-2',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-03-29 04:23:20 +00:00
|
|
|
}
|
|
|
|
}
|