summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/AbuseFilter/includes/api
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/AbuseFilter/includes/api')
-rw-r--r--www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckMatch.php94
-rw-r--r--www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckSyntax.php49
-rw-r--r--www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterEvalExpression.php30
-rw-r--r--www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterUnblockAutopromote.php62
-rw-r--r--www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseFilters.php218
-rw-r--r--www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseLog.php313
6 files changed, 766 insertions, 0 deletions
diff --git a/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckMatch.php b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckMatch.php
new file mode 100644
index 00000000..252c153d
--- /dev/null
+++ b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckMatch.php
@@ -0,0 +1,94 @@
+<?php
+
+class ApiAbuseFilterCheckMatch extends ApiBase {
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $this->requireOnlyOneParameter( $params, 'vars', 'rcid', 'logid' );
+
+ // "Anti-DoS"
+ if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
+ $this->dieWithError( 'apierror-abusefilter-canttest', 'permissiondenied' );
+ }
+
+ $vars = null;
+ if ( $params['vars'] ) {
+ $vars = new AbuseFilterVariableHolder;
+ $pairs = FormatJson::decode( $params['vars'], true );
+ foreach ( $pairs as $name => $value ) {
+ $vars->setVar( $name, $value );
+ }
+ } elseif ( $params['rcid'] ) {
+ $dbr = wfGetDB( DB_REPLICA );
+ $rcQuery = RecentChange::getQueryInfo();
+ $row = $dbr->selectRow(
+ $rcQuery['tables'],
+ $rcQuery['fields'],
+ [ 'rc_id' => $params['rcid'] ],
+ __METHOD__,
+ [],
+ $rcQuery['joins']
+ );
+
+ if ( !$row ) {
+ $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
+ }
+
+ $vars = AbuseFilter::getVarsFromRCRow( $row );
+ } elseif ( $params['logid'] ) {
+ $dbr = wfGetDB( DB_REPLICA );
+ $row = $dbr->selectRow(
+ 'abuse_filter_log',
+ 'afl_var_dump',
+ [ 'afl_id' => $params['logid'] ],
+ __METHOD__
+ );
+
+ if ( !$row ) {
+ $this->dieWithError( [ 'apierror-abusefilter-nosuchlogid', $params['logid'] ], 'nosuchlogid' );
+ }
+
+ $vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
+ }
+
+ if ( AbuseFilter::checkSyntax( $params[ 'filter' ] ) !== true ) {
+ $this->dieWithError( 'apierror-abusefilter-badsyntax', 'badsyntax' );
+ }
+
+ $result = [
+ ApiResult::META_BC_BOOLS => [ 'result' ],
+ 'result' => AbuseFilter::checkConditions( $params['filter'], $vars ),
+ ];
+
+ $this->getResult()->addValue(
+ null,
+ $this->getModuleName(),
+ $result
+ );
+ }
+
+ public function getAllowedParams() {
+ return [
+ 'filter' => [
+ ApiBase::PARAM_REQUIRED => true,
+ ],
+ 'vars' => null,
+ 'rcid' => [
+ ApiBase::PARAM_TYPE => 'integer'
+ ],
+ 'logid' => [
+ ApiBase::PARAM_TYPE => 'integer'
+ ],
+ ];
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ * @return array
+ */
+ protected function getExamplesMessages() {
+ return [
+ 'action=abusefiltercheckmatch&filter=!("autoconfirmed"%20in%20user_groups)&rcid=15'
+ => 'apihelp-abusefiltercheckmatch-example-1',
+ ];
+ }
+}
diff --git a/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckSyntax.php b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckSyntax.php
new file mode 100644
index 00000000..4854024d
--- /dev/null
+++ b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterCheckSyntax.php
@@ -0,0 +1,49 @@
+<?php
+
+class ApiAbuseFilterCheckSyntax extends ApiBase {
+
+ public function execute() {
+ // "Anti-DoS"
+ if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
+ $this->dieWithError( 'apierror-abusefilter-cantcheck', 'permissiondenied' );
+ }
+
+ $params = $this->extractRequestParams();
+ $result = AbuseFilter::checkSyntax( $params[ 'filter' ] );
+
+ $r = [];
+ if ( $result === true ) {
+ // Everything went better than expected :)
+ $r['status'] = 'ok';
+ } else {
+ $r = [
+ 'status' => 'error',
+ 'message' => $result[0],
+ 'character' => $result[1],
+ ];
+ }
+
+ $this->getResult()->addValue( null, $this->getModuleName(), $r );
+ }
+
+ public function getAllowedParams() {
+ return [
+ 'filter' => [
+ ApiBase::PARAM_REQUIRED => true,
+ ],
+ ];
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ * @return array
+ */
+ protected function getExamplesMessages() {
+ return [
+ 'action=abusefilterchecksyntax&filter="foo"'
+ => 'apihelp-abusefilterchecksyntax-example-1',
+ 'action=abusefilterchecksyntax&filter="bar"%20bad_variable'
+ => 'apihelp-abusefilterchecksyntax-example-2',
+ ];
+ }
+}
diff --git a/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterEvalExpression.php b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterEvalExpression.php
new file mode 100644
index 00000000..edf4b688
--- /dev/null
+++ b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterEvalExpression.php
@@ -0,0 +1,30 @@
+<?php
+
+class ApiAbuseFilterEvalExpression extends ApiBase {
+ public function execute() {
+ $params = $this->extractRequestParams();
+
+ $result = AbuseFilter::evaluateExpression( $params['expression'] );
+
+ $this->getResult()->addValue( null, $this->getModuleName(), [ 'result' => $result ] );
+ }
+
+ public function getAllowedParams() {
+ return [
+ 'expression' => [
+ ApiBase::PARAM_REQUIRED => true,
+ ],
+ ];
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ * @return array
+ */
+ protected function getExamplesMessages() {
+ return [
+ 'action=abusefilterevalexpression&expression=lcase("FOO")'
+ => 'apihelp-abusefilterevalexpression-example-1',
+ ];
+ }
+}
diff --git a/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterUnblockAutopromote.php b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterUnblockAutopromote.php
new file mode 100644
index 00000000..07f134ec
--- /dev/null
+++ b/www/wiki/extensions/AbuseFilter/includes/api/ApiAbuseFilterUnblockAutopromote.php
@@ -0,0 +1,62 @@
+<?php
+
+class ApiAbuseFilterUnblockAutopromote extends ApiBase {
+ public function execute() {
+ $this->checkUserRightsAny( 'abusefilter-modify' );
+
+ $params = $this->extractRequestParams();
+ $user = User::newFromName( $params['user'] );
+
+ if ( $user === false ) {
+ $encParamName = $this->encodeParamName( 'user' );
+ $this->dieWithError(
+ [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $param['user'] ) ],
+ "baduser_{$encParamName}"
+ );
+ }
+
+ $key = AbuseFilter::autoPromoteBlockKey( $user );
+ $stash = ObjectCache::getMainStashInstance();
+ if ( !$stash->get( $key ) ) {
+ $this->dieWithError( [ 'abusefilter-reautoconfirm-none', $user->getName() ], 'notsuspended' );
+ }
+
+ $stash->delete( $key );
+
+ $res = [ 'user' => $params['user'] ];
+ $this->getResult()->addValue( null, $this->getModuleName(), $res );
+ }
+
+ public function mustBePosted() {
+ return true;
+ }
+
+ public function isWriteMode() {
+ return true;
+ }
+
+ public function getAllowedParams() {
+ return [
+ 'user' => [
+ ApiBase::PARAM_TYPE => 'user',
+ ApiBase::PARAM_REQUIRED => true
+ ],
+ 'token' => null,
+ ];
+ }
+
+ public function needsToken() {
+ return 'csrf';
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ * @return array
+ */
+ protected function getExamplesMessages() {
+ return [
+ 'action=abusefilterunblockautopromote&user=Example&token=123ABC'
+ => 'apihelp-abusefilterunblockautopromote-example-1',
+ ];
+ }
+}
diff --git a/www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseFilters.php b/www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseFilters.php
new file mode 100644
index 00000000..d730483d
--- /dev/null
+++ b/www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseFilters.php
@@ -0,0 +1,218 @@
+<?php
+/**
+ * Created on Mar 29, 2009
+ *
+ * AbuseFilter extension
+ *
+ * Copyright © 2008 Alex Z. mrzmanwiki AT gmail DOT com
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Query module to list abuse filter details.
+ *
+ * @ingroup API
+ * @ingroup Extensions
+ */
+class ApiQueryAbuseFilters extends ApiQueryBase {
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'abf' );
+ }
+
+ public function execute() {
+ $user = $this->getUser();
+ $this->checkUserRightsAny( 'abusefilter-view' );
+
+ $params = $this->extractRequestParams();
+
+ $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'] );
+
+ $result = $this->getResult();
+
+ $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 );
+ $this->addFieldsIf( 'af_user_text', $fld_user );
+ $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'] );
+
+ /* Check for conflicting parameters. */
+ if ( ( isset( $show['enabled'] ) && isset( $show['!enabled'] ) )
+ || ( isset( $show['deleted'] ) && isset( $show['!deleted'] ) )
+ || ( isset( $show['private'] ) && isset( $show['!private'] ) )
+ ) {
+ $this->dieWithError( 'apierror-show' );
+ }
+
+ $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'] ) );
+ }
+
+ $res = $this->select( __METHOD__ );
+
+ $showhidden = $user->isAllowedAny( 'abusefilter-modify', 'abusefilter-view-private' );
+
+ $count = 0;
+ foreach ( $res as $row ) {
+ if ( ++$count > $params['limit'] ) {
+ // We've had enough
+ $this->setContinueEnumParameter( 'startid', $row->af_id );
+ break;
+ }
+ $entry = [];
+ if ( $fld_id ) {
+ $entry['id'] = intval( $row->af_id );
+ }
+ if ( $fld_desc ) {
+ $entry['description'] = $row->af_public_comments;
+ }
+ if ( $fld_pattern && ( !$row->af_hidden || $showhidden ) ) {
+ $entry['pattern'] = $row->af_pattern;
+ }
+ if ( $fld_actions ) {
+ $entry['actions'] = $row->af_actions;
+ }
+ if ( $fld_hits ) {
+ $entry['hits'] = intval( $row->af_hit_count );
+ }
+ if ( $fld_comments && ( !$row->af_hidden || $showhidden ) ) {
+ $entry['comments'] = $row->af_comments;
+ }
+ if ( $fld_user ) {
+ $entry['lasteditor'] = $row->af_user_text;
+ }
+ if ( $fld_time ) {
+ $ts = new MWTimestamp( $row->af_timestamp );
+ $entry['lastedittime'] = $ts->getTimestamp( TS_ISO_8601 );
+ }
+ if ( $fld_private && $row->af_hidden ) {
+ $entry['private'] = '';
+ }
+ if ( $fld_status ) {
+ if ( $row->af_enabled ) {
+ $entry['enabled'] = '';
+ }
+ if ( $row->af_deleted ) {
+ $entry['deleted'] = '';
+ }
+ }
+ if ( $entry ) {
+ $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $entry );
+ if ( !$fit ) {
+ $this->setContinueEnumParameter( 'startid', $row->af_id );
+ break;
+ }
+ }
+ }
+ $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'filter' );
+ }
+
+ public function getAllowedParams() {
+ return [
+ 'startid' => [
+ ApiBase::PARAM_TYPE => 'integer'
+ ],
+ 'endid' => [
+ ApiBase::PARAM_TYPE => 'integer',
+ ],
+ 'dir' => [
+ ApiBase::PARAM_TYPE => [
+ 'older',
+ 'newer'
+ ],
+ ApiBase::PARAM_DFLT => 'newer',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+ ],
+ 'show' => [
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => [
+ 'enabled',
+ '!enabled',
+ 'deleted',
+ '!deleted',
+ 'private',
+ '!private',
+ ],
+ ],
+ 'limit' => [
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+ ],
+ 'prop' => [
+ ApiBase::PARAM_DFLT => 'id|description|actions|status',
+ ApiBase::PARAM_TYPE => [
+ 'id',
+ 'description',
+ 'pattern',
+ 'actions',
+ 'hits',
+ 'comments',
+ 'lasteditor',
+ 'lastedittime',
+ 'status',
+ 'private',
+ ],
+ ApiBase::PARAM_ISMULTI => true
+ ]
+ ];
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ * @return array
+ */
+ protected function getExamplesMessages() {
+ return [
+ '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',
+ ];
+ }
+}
diff --git a/www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseLog.php b/www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseLog.php
new file mode 100644
index 00000000..6cd4f17c
--- /dev/null
+++ b/www/wiki/extensions/AbuseFilter/includes/api/ApiQueryAbuseLog.php
@@ -0,0 +1,313 @@
+<?php
+/**
+ * Created on Mar 28, 2009
+ *
+ * AbuseFilter extension
+ *
+ * Copyright © 2008 Alex Z. mrzmanwiki AT gmail DOT com
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Query module to list abuse log entries.
+ *
+ * @ingroup API
+ * @ingroup Extensions
+ */
+class ApiQueryAbuseLog extends ApiQueryBase {
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'afl' );
+ }
+
+ public function execute() {
+ global $wgAbuseFilterIsCentral;
+
+ $user = $this->getUser();
+ $errors = $this->getTitle()->getUserPermissionsErrors(
+ 'abusefilter-log', $user, true, [ 'ns-specialprotected' ] );
+ if ( count( $errors ) ) {
+ $this->dieStatus( $this->errorArrayToStatus( $errors ) );
+ return;
+ }
+
+ $params = $this->extractRequestParams();
+
+ $prop = array_flip( $params['prop'] );
+ $fld_ids = isset( $prop['ids'] );
+ $fld_filter = isset( $prop['filter'] );
+ $fld_user = isset( $prop['user'] );
+ $fld_title = isset( $prop['title'] );
+ $fld_action = isset( $prop['action'] );
+ $fld_details = isset( $prop['details'] );
+ $fld_result = isset( $prop['result'] );
+ $fld_timestamp = isset( $prop['timestamp'] );
+ $fld_hidden = isset( $prop['hidden'] );
+ $fld_revid = isset( $prop['revid'] );
+ $fld_wiki = $wgAbuseFilterIsCentral && isset( $prop['wiki'] );
+
+ if ( $fld_details ) {
+ $this->checkUserRightsAny( 'abusefilter-log-detail' );
+ }
+ // Match permissions for viewing events on private filters to SpecialAbuseLog (bug 42814)
+ if ( $params['filter'] &&
+ !( AbuseFilterView::canViewPrivate() || $user->isAllowed( 'abusefilter-log-private' ) )
+ ) {
+ // A specific filter parameter is set but the user isn't allowed to view all filters
+ if ( !is_array( $params['filter'] ) ) {
+ $params['filter'] = [ $params['filter'] ];
+ }
+ foreach ( $params['filter'] as $filter ) {
+ if ( AbuseFilter::filterHidden( $filter ) ) {
+ $this->dieWithError(
+ [ 'apierror-permissiondenied', $this->msg( 'action-abusefilter-log-private' ) ]
+ );
+ }
+ }
+ }
+
+ $result = $this->getResult();
+
+ $this->addTables( 'abuse_filter_log' );
+ $this->addFields( 'afl_timestamp' );
+ $this->addFields( 'afl_rev_id' );
+ $this->addFields( 'afl_deleted' );
+ $this->addFields( 'afl_filter' );
+ $this->addFieldsIf( 'afl_id', $fld_ids );
+ $this->addFieldsIf( 'afl_user_text', $fld_user );
+ $this->addFieldsIf( [ 'afl_namespace', 'afl_title' ], $fld_title );
+ $this->addFieldsIf( 'afl_action', $fld_action );
+ $this->addFieldsIf( 'afl_var_dump', $fld_details );
+ $this->addFieldsIf( 'afl_actions', $fld_result );
+ $this->addFieldsIf( 'afl_wiki', $fld_wiki );
+
+ if ( $fld_filter ) {
+ $this->addTables( 'abuse_filter' );
+ $this->addFields( 'af_public_comments' );
+ $this->addJoinConds( [ 'abuse_filter' => [ 'LEFT JOIN',
+ 'af_id=afl_filter' ] ] );
+ }
+
+ $this->addOption( 'LIMIT', $params['limit'] + 1 );
+
+ $this->addWhereRange( 'afl_timestamp', $params['dir'], $params['start'], $params['end'] );
+
+ $db = $this->getDB();
+ $notDeletedCond = SpecialAbuseLog::getNotDeletedCond( $db );
+
+ if ( isset( $params['user'] ) ) {
+ $u = User::newFromName( $params['user'] );
+ if ( $u ) {
+ // Username normalisation
+ $params['user'] = $u->getName();
+ $userId = $u->getId();
+ } elseif ( IP::isIPAddress( $params['user'] ) ) {
+ // It's an IP, sanitize it
+ $params['user'] = IP::sanitizeIP( $params['user'] );
+ $userId = 0;
+ }
+
+ if ( isset( $userId ) ) {
+ // Only add the WHERE for user in case it's either a valid user
+ // (but not necessary an existing one) or an IP.
+ $this->addWhere(
+ [
+ 'afl_user' => $userId,
+ 'afl_user_text' => $params['user']
+ ]
+ );
+ }
+ }
+
+ $this->addWhereIf( [ 'afl_filter' => $params['filter'] ], isset( $params['filter'] ) );
+ $this->addWhereIf( $notDeletedCond, !SpecialAbuseLog::canSeeHidden( $user ) );
+ if ( isset( $params['wiki'] ) ) {
+ // 'wiki' won't be set if $wgAbuseFilterIsCentral = false
+ $this->addWhereIf( [ 'afl_wiki' => $params['wiki'] ], $wgAbuseFilterIsCentral );
+ }
+
+ $title = $params['title'];
+ if ( !is_null( $title ) ) {
+ $titleObj = Title::newFromText( $title );
+ if ( is_null( $titleObj ) ) {
+ $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
+ }
+ $this->addWhereFld( 'afl_namespace', $titleObj->getNamespace() );
+ $this->addWhereFld( 'afl_title', $titleObj->getDBkey() );
+ }
+ $res = $this->select( __METHOD__ );
+
+ $count = 0;
+ foreach ( $res as $row ) {
+ if ( ++$count > $params['limit'] ) {
+ // We've had enough
+ $ts = new MWTimestamp( $row->afl_timestamp );
+ $this->setContinueEnumParameter( 'start', $ts->getTimestamp( TS_ISO_8601 ) );
+ break;
+ }
+ $hidden = SpecialAbuseLog::isHidden( $row );
+ if ( $hidden === true && !SpecialAbuseLog::canSeeHidden() ) {
+ continue;
+ } elseif ( $hidden === 'implicit' ) {
+ $rev = Revision::newFromId( $row->afl_rev_id );
+ if ( !$rev->userCan( Revision::SUPPRESSED_ALL, $user ) ) {
+ continue;
+ }
+ }
+ $canSeeDetails = SpecialAbuseLog::canSeeDetails( $row->afl_filter );
+
+ $entry = [];
+ if ( $fld_ids ) {
+ $entry['id'] = intval( $row->afl_id );
+ $entry['filter_id'] = '';
+ if ( $canSeeDetails ) {
+ $entry['filter_id'] = $row->afl_filter;
+ }
+ }
+ if ( $fld_filter ) {
+ $globalIndex = AbuseFilter::decodeGlobalName( $row->afl_filter );
+ if ( $globalIndex ) {
+ $entry['filter'] = AbuseFilter::getGlobalFilterDescription( $globalIndex );
+ } else {
+ $entry['filter'] = $row->af_public_comments;
+ }
+ }
+ if ( $fld_user ) {
+ $entry['user'] = $row->afl_user_text;
+ }
+ if ( $fld_wiki ) {
+ $entry['wiki'] = $row->afl_wiki;
+ }
+ if ( $fld_title ) {
+ $title = Title::makeTitle( $row->afl_namespace, $row->afl_title );
+ ApiQueryBase::addTitleInfo( $entry, $title );
+ }
+ if ( $fld_action ) {
+ $entry['action'] = $row->afl_action;
+ }
+ if ( $fld_result ) {
+ $entry['result'] = $row->afl_actions;
+ }
+ if ( $fld_revid && !is_null( $row->afl_rev_id ) ) {
+ $entry['revid'] = '';
+ if ( $canSeeDetails ) {
+ $entry['revid'] = $row->afl_rev_id;
+ }
+ }
+ if ( $fld_timestamp ) {
+ $ts = new MWTimestamp( $row->afl_timestamp );
+ $entry['timestamp'] = $ts->getTimestamp( TS_ISO_8601 );
+ }
+ if ( $fld_details ) {
+ $entry['details'] = [];
+ if ( $canSeeDetails ) {
+ $vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
+ if ( $vars instanceof AbuseFilterVariableHolder ) {
+ $entry['details'] = $vars->exportAllVars();
+ } else {
+ $entry['details'] = array_change_key_case( $vars, CASE_LOWER );
+ }
+ }
+ }
+
+ if ( $fld_hidden && $hidden ) {
+ $entry['hidden'] = $hidden;
+ }
+
+ if ( $entry ) {
+ $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $entry );
+ if ( !$fit ) {
+ $ts = new MWTimestamp( $row->afl_timestamp );
+ $this->setContinueEnumParameter( 'start', $ts->getTimestamp( TS_ISO_8601 ) );
+ break;
+ }
+ }
+ }
+ $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'item' );
+ }
+
+ public function getAllowedParams() {
+ global $wgAbuseFilterIsCentral;
+
+ $params = [
+ 'start' => [
+ ApiBase::PARAM_TYPE => 'timestamp'
+ ],
+ 'end' => [
+ ApiBase::PARAM_TYPE => 'timestamp'
+ ],
+ 'dir' => [
+ ApiBase::PARAM_TYPE => [
+ 'newer',
+ 'older'
+ ],
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+ ],
+ 'user' => null,
+ 'title' => null,
+ 'filter' => [
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_ISMULTI => true
+ ],
+ 'limit' => [
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+ ],
+ 'prop' => [
+ ApiBase::PARAM_DFLT => 'ids|user|title|action|result|timestamp|hidden|revid',
+ ApiBase::PARAM_TYPE => [
+ 'ids',
+ 'filter',
+ 'user',
+ 'title',
+ 'action',
+ 'details',
+ 'result',
+ 'timestamp',
+ 'hidden',
+ 'revid',
+ ],
+ ApiBase::PARAM_ISMULTI => true
+ ]
+ ];
+ if ( $wgAbuseFilterIsCentral ) {
+ $params['wiki'] = [
+ ApiBase::PARAM_TYPE => 'string',
+ ];
+ $params['prop'][ApiBase::PARAM_DFLT] .= '|wiki';
+ $params['prop'][ApiBase::PARAM_TYPE][] = 'wiki';
+ }
+ return $params;
+ }
+
+ /**
+ * @see ApiBase::getExamplesMessages()
+ * @return array
+ */
+ protected function getExamplesMessages() {
+ return [
+ 'action=query&list=abuselog'
+ => 'apihelp-query+abuselog-example-1',
+ 'action=query&list=abuselog&afltitle=API'
+ => 'apihelp-query+abuselog-example-2',
+ ];
+ }
+}