2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
2020-09-20 22:31:41 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
|
2020-10-03 17:13:32 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2019-09-18 21:48:40 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
class AbuseFilterViewEdit extends AbuseFilterView {
|
2020-10-03 13:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int|null The history ID of the current filter
|
|
|
|
*/
|
|
|
|
private $historyID;
|
2020-10-03 17:13:32 +00:00
|
|
|
/** @var int|string */
|
|
|
|
private $filter;
|
2020-10-03 13:05:20 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
/**
|
2020-10-03 17:13:32 +00:00
|
|
|
* @param IContextSource $context
|
|
|
|
* @param LinkRenderer $linkRenderer
|
2020-10-16 22:36:15 +00:00
|
|
|
* @param string $basePageName
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param array $params
|
|
|
|
*/
|
2020-10-16 22:36:15 +00:00
|
|
|
public function __construct(
|
|
|
|
IContextSource $context,
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
string $basePageName,
|
|
|
|
array $params
|
|
|
|
) {
|
|
|
|
parent::__construct( $context, $linkRenderer, $basePageName, $params );
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->filter = $this->mParams['filter'];
|
2020-10-03 13:05:20 +00:00
|
|
|
$this->historyID = $this->mParams['history'] ?? null;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the page
|
|
|
|
*/
|
|
|
|
public function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
$out = $this->getOutput();
|
|
|
|
$request = $this->getRequest();
|
2020-09-18 14:49:13 +00:00
|
|
|
$afPermManager = AbuseFilterServices::getPermissionManager();
|
2012-12-15 10:18:25 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-edit' ) );
|
2015-03-29 12:38:53 +00:00
|
|
|
$out->addHelpLink( 'Extension:AbuseFilter/Rules format' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-03 17:13:32 +00:00
|
|
|
$filter = $this->filter;
|
2020-09-20 10:18:46 +00:00
|
|
|
if ( !is_numeric( $filter ) && $filter !== null ) {
|
2019-08-28 14:06:33 +00:00
|
|
|
$out->addHTML(
|
|
|
|
Xml::tags(
|
|
|
|
'p',
|
|
|
|
null,
|
|
|
|
Html::errorBox( $this->msg( 'abusefilter-edit-badfilter' )->parse() )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-03 13:05:20 +00:00
|
|
|
$history_id = $this->historyID;
|
|
|
|
if ( $this->historyID ) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2020-02-08 13:55:12 +00:00
|
|
|
$lastID = (int)$dbr->selectField(
|
2016-12-02 18:05:36 +00:00
|
|
|
'abuse_filter_history',
|
|
|
|
'afh_id',
|
|
|
|
[
|
|
|
|
'afh_filter' => $filter,
|
|
|
|
],
|
|
|
|
__METHOD__,
|
2019-03-01 14:24:30 +00:00
|
|
|
[ 'ORDER BY' => 'afh_id DESC' ]
|
2016-12-02 18:05:36 +00:00
|
|
|
);
|
|
|
|
// change $history_id to null if it's current version id
|
2020-10-03 13:05:20 +00:00
|
|
|
if ( $lastID === $this->historyID ) {
|
2016-12-02 18:05:36 +00:00
|
|
|
$history_id = null;
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2014-10-04 14:42:46 +00:00
|
|
|
// Add the default warning and disallow messages in a JS variable
|
|
|
|
$this->exposeMessages();
|
2012-06-06 05:18:31 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
$canEdit = $afPermManager->canEdit( $user );
|
2020-02-08 13:55:12 +00:00
|
|
|
|
2020-09-20 10:18:46 +00:00
|
|
|
if ( $filter === null && !$canEdit ) {
|
2018-07-08 22:23:38 +00:00
|
|
|
$out->addHTML(
|
|
|
|
Xml::tags(
|
|
|
|
'p',
|
|
|
|
null,
|
|
|
|
Html::errorBox( $this->msg( 'abusefilter-edit-notallowed' )->parse() )
|
|
|
|
)
|
|
|
|
);
|
2009-09-18 10:05:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$editToken = $request->getVal( 'wpEditToken' );
|
2017-04-07 19:23:11 +00:00
|
|
|
$tokenMatches = $user->matchEditToken(
|
2017-06-15 14:23:16 +00:00
|
|
|
$editToken, [ 'abusefilter', $filter ], $request );
|
2020-09-22 22:19:50 +00:00
|
|
|
$isImport = $request->wasPosted() && $request->getRawVal( 'wpImportText' ) !== null;
|
2019-03-01 14:24:30 +00:00
|
|
|
|
2020-02-08 13:55:12 +00:00
|
|
|
if ( $request->wasPosted() && $canEdit && $tokenMatches ) {
|
|
|
|
$this->saveCurrentFilter( $filter, $history_id );
|
2019-03-01 14:24:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
if ( $isImport ) {
|
|
|
|
$data = $this->loadImportRequest();
|
|
|
|
if ( $data === null ) {
|
|
|
|
$out->addHTML( Html::errorBox( $this->msg( 'abusefilter-import-invalid-data' )->parseAsBlock() ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} elseif ( $request->wasPosted() && !$tokenMatches ) {
|
|
|
|
// Token invalid or expired while the page was open, warn to retry
|
2020-02-08 13:55:12 +00:00
|
|
|
$out->addHTML(
|
|
|
|
Html::warningBox( $this->msg( 'abusefilter-edit-token-not-match' )->escaped() )
|
|
|
|
);
|
|
|
|
// Make sure to load from HTTP if the token doesn't match!
|
2020-09-22 22:19:50 +00:00
|
|
|
$data = $this->loadRequest( $filter );
|
2020-02-08 13:55:12 +00:00
|
|
|
} else {
|
2020-09-22 22:19:50 +00:00
|
|
|
$data = $this->loadFromDatabase( $filter, $history_id ) ?? [ null, [] ];
|
2020-02-08 13:55:12 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
list( $row, $actions ) = $data;
|
2020-02-08 13:55:12 +00:00
|
|
|
|
|
|
|
// Either the user is just viewing the filter, they cannot edit it, they lost the
|
|
|
|
// abusefilter-modify right with the page open, the token is invalid, or they're viewing
|
|
|
|
// the result of importing a filter
|
|
|
|
$this->buildFilterEditor( null, $row, $actions, $filter, $history_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-20 10:18:46 +00:00
|
|
|
* @param int|null $filter The filter ID or null for a new filter
|
2020-02-08 13:55:12 +00:00
|
|
|
* @param int|null $history_id The history ID of the filter, if applicable. Otherwise null
|
|
|
|
*/
|
2020-09-20 10:18:46 +00:00
|
|
|
private function saveCurrentFilter( ?int $filter, $history_id ) : void {
|
2020-02-08 13:55:12 +00:00
|
|
|
$out = $this->getOutput();
|
2020-09-22 22:19:50 +00:00
|
|
|
[ $newRow, $actions, $origRow, $origActions ] = $this->loadRequest( $filter );
|
2019-03-01 14:24:30 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2020-09-19 15:14:31 +00:00
|
|
|
$status = AbuseFilter::saveFilter(
|
|
|
|
$this->getUser(), $filter, $newRow, $actions,
|
|
|
|
$origRow, $origActions, $dbw, $this->getConfig()
|
|
|
|
);
|
2019-03-01 14:24:30 +00:00
|
|
|
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
$err = $status->getErrors();
|
|
|
|
$msg = $err[0]['message'];
|
|
|
|
$params = $err[0]['params'];
|
|
|
|
if ( $status->isOK() ) {
|
|
|
|
// Fixable error, show the editing interface
|
|
|
|
$this->buildFilterEditor(
|
|
|
|
$this->msg( $msg, $params )->parseAsBlock(),
|
|
|
|
$newRow,
|
2020-02-08 13:55:12 +00:00
|
|
|
$actions,
|
|
|
|
$filter,
|
|
|
|
$history_id
|
2019-03-01 14:24:30 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Permission-related error
|
|
|
|
$out->addWikiMsg( $msg );
|
|
|
|
}
|
|
|
|
} elseif ( $status->getValue() === false ) {
|
|
|
|
// No change
|
|
|
|
$out->redirect( $this->getTitle()->getLocalURL() );
|
|
|
|
} else {
|
|
|
|
// Everything went fine!
|
|
|
|
list( $new_id, $history_id ) = $status->getValue();
|
|
|
|
$out->redirect(
|
|
|
|
$this->getTitle()->getLocalURL(
|
|
|
|
[
|
|
|
|
'result' => 'success',
|
|
|
|
'changedfilter' => $new_id,
|
|
|
|
'changeid' => $history_id,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2019-03-01 14:24:30 +00:00
|
|
|
* Builds the full form for edit filters, adding it to the OutputPage. $row and $actions can be
|
|
|
|
* passed in (for instance if there was a failure during save) to avoid searching the DB.
|
|
|
|
*
|
2018-10-03 12:02:00 +00:00
|
|
|
* @param string|null $error An error message to show above the filter box.
|
2020-02-08 13:55:12 +00:00
|
|
|
* @param stdClass|null $row abuse_filter row representing this filter, null if it doesn't exist
|
|
|
|
* @param array $actions Actions enabled and their parameters
|
2020-09-20 10:18:46 +00:00
|
|
|
* @param int|null $filter The filter ID, or null for a new filter
|
2018-05-25 23:31:49 +00:00
|
|
|
* @param int|null $history_id The history ID of the filter, if applicable. Otherwise null
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2019-03-01 14:24:30 +00:00
|
|
|
protected function buildFilterEditor(
|
|
|
|
$error,
|
2020-02-08 13:55:12 +00:00
|
|
|
?stdClass $row,
|
|
|
|
array $actions,
|
2020-09-20 10:18:46 +00:00
|
|
|
?int $filter,
|
2020-02-08 13:55:12 +00:00
|
|
|
$history_id
|
2019-03-01 14:24:30 +00:00
|
|
|
) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2018-05-03 07:45:18 +00:00
|
|
|
$out->enableOOUI();
|
2018-03-23 09:13:41 +00:00
|
|
|
$out->addJsConfigVars( 'isFilterEditor', true );
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
2020-09-18 14:49:13 +00:00
|
|
|
$afPermManager = AbuseFilterServices::getPermissionManager();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2019-11-10 22:11:34 +00:00
|
|
|
if (
|
2020-02-08 13:55:12 +00:00
|
|
|
$row === null ||
|
2019-11-10 22:11:34 +00:00
|
|
|
// @fixme Temporary stopgap for T237887
|
2020-09-20 10:18:46 +00:00
|
|
|
( $history_id && (int)$row->af_id !== $filter )
|
2019-11-10 22:11:34 +00:00
|
|
|
) {
|
2018-05-01 12:55:35 +00:00
|
|
|
$out->addHTML(
|
|
|
|
Xml::tags(
|
|
|
|
'p',
|
|
|
|
null,
|
|
|
|
Html::errorBox( $this->msg( 'abusefilter-edit-badfilter' )->parse() )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$href = $this->getTitle()->getFullURL();
|
|
|
|
$btn = new OOUI\ButtonWidget( [
|
|
|
|
'label' => $this->msg( 'abusefilter-return' )->text(),
|
|
|
|
'href' => $href
|
|
|
|
] );
|
2018-05-03 07:45:18 +00:00
|
|
|
$out->addHTML( $btn );
|
2019-01-18 11:01:32 +00:00
|
|
|
return;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 10:18:25 +00:00
|
|
|
$out->addSubtitle( $this->msg(
|
2020-09-20 10:18:46 +00:00
|
|
|
$filter === null ? 'abusefilter-edit-subtitle-new' : 'abusefilter-edit-subtitle',
|
|
|
|
$filter === null ? $filter : $this->getLanguage()->formatNum( $filter ),
|
2020-09-09 05:38:20 +00:00
|
|
|
$history_id
|
2017-02-05 21:56:39 +00:00
|
|
|
)->parse() );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Hide hidden filters.
|
2019-01-18 11:01:32 +00:00
|
|
|
if (
|
2020-09-20 10:18:46 +00:00
|
|
|
( $row->af_hidden || ( $filter !== null && AbuseFilter::filterHidden( $filter ) ) ) &&
|
2020-09-18 14:49:13 +00:00
|
|
|
!$afPermManager->canViewPrivateFilters( $user )
|
2019-03-28 19:59:53 +00:00
|
|
|
) {
|
2019-01-18 11:01:32 +00:00
|
|
|
$out->addHTML( $this->msg( 'abusefilter-edit-denied' )->escaped() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
$readOnly = !$afPermManager->canEditFilter( $user, $row );
|
|
|
|
|
2019-01-18 11:01:32 +00:00
|
|
|
if ( $history_id ) {
|
2020-09-18 14:49:13 +00:00
|
|
|
$oldWarningMessage = $readOnly
|
|
|
|
? 'abusefilter-edit-oldwarning-view'
|
|
|
|
: 'abusefilter-edit-oldwarning';
|
2019-01-18 11:01:32 +00:00
|
|
|
$out->addWikiMsg(
|
2019-11-04 18:26:53 +00:00
|
|
|
$oldWarningMessage,
|
|
|
|
$history_id,
|
|
|
|
$filter
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $error ) {
|
2019-01-18 11:01:32 +00:00
|
|
|
$out->addHTML( Html::errorBox( $error ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$fields = [];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
$fields['abusefilter-edit-id'] =
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->filter === null ?
|
2018-05-01 12:13:57 +00:00
|
|
|
$this->msg( 'abusefilter-edit-new' )->escaped() :
|
2020-09-20 10:18:46 +00:00
|
|
|
$lang->formatNum( (string)$filter );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-description'] =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\TextInputWidget( [
|
|
|
|
'name' => 'wpFilterDescription',
|
2019-02-27 10:52:59 +00:00
|
|
|
'value' => $row->af_public_comments ?? '',
|
|
|
|
'readOnly' => $readOnly
|
|
|
|
]
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2018-03-10 21:47:33 +00:00
|
|
|
$validGroups = $this->getConfig()->get( 'AbuseFilterValidGroups' );
|
|
|
|
if ( count( $validGroups ) > 1 ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$groupSelector =
|
|
|
|
new OOUI\DropdownInputWidget( [
|
|
|
|
'name' => 'wpFilterGroup',
|
|
|
|
'id' => 'mw-abusefilter-edit-group-input',
|
|
|
|
'value' => 'default',
|
2019-02-27 10:52:59 +00:00
|
|
|
'disabled' => $readOnly
|
2018-03-23 09:13:41 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
$options = [];
|
2012-09-27 10:10:10 +00:00
|
|
|
if ( isset( $row->af_group ) && $row->af_group ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$groupSelector->setValue( $row->af_group );
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 21:47:33 +00:00
|
|
|
foreach ( $validGroups as $group ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$options += [ AbuseFilter::nameGroup( $group ) => $group ];
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$options = Xml::listDropDownOptionsOoui( $options );
|
|
|
|
$groupSelector->setOptions( $options );
|
2016-12-15 13:09:03 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$fields['abusefilter-edit-group'] = $groupSelector;
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Hit count display
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( !empty( $row->af_hit_count ) && $afPermManager->canSeeLogDetails( $user ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$count_display = $this->msg( 'abusefilter-hitcount' )
|
2017-07-08 18:49:13 +00:00
|
|
|
->numParams( (int)$row->af_hit_count )->text();
|
2016-12-04 15:13:16 +00:00
|
|
|
$hitCount = $this->linkRenderer->makeKnownLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
$count_display,
|
2017-06-15 14:23:16 +00:00
|
|
|
[],
|
|
|
|
[ 'wpSearchFilter' => $row->af_id ]
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$fields['abusefilter-edit-hitcount'] = $hitCount;
|
|
|
|
}
|
|
|
|
|
2020-09-20 10:18:46 +00:00
|
|
|
if ( $filter !== null && $row->af_enabled ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Statistics
|
2019-02-10 10:57:37 +00:00
|
|
|
list( $totalCount, $matchesCount, $avgTime, $avgCond ) =
|
2020-09-20 22:31:41 +00:00
|
|
|
AbuseFilterServices::getFilterProfiler()->getFilterProfile( $filter );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2019-02-10 10:57:37 +00:00
|
|
|
if ( $totalCount > 0 ) {
|
|
|
|
$matchesPercent = round( 100 * $matchesCount / $totalCount, 2 );
|
2019-01-24 12:33:31 +00:00
|
|
|
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' )
|
2019-02-10 10:57:37 +00:00
|
|
|
->numParams( $totalCount, $matchesCount, $matchesPercent, $avgTime, $avgCond )
|
2019-03-29 08:54:30 +00:00
|
|
|
->parse();
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-08 15:57:23 +00:00
|
|
|
$fields['abusefilter-edit-rules'] = $this->buildEditBox(
|
2012-09-02 11:07:02 +00:00
|
|
|
$row->af_pattern,
|
2018-04-08 15:57:23 +00:00
|
|
|
true
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
2018-03-23 09:13:41 +00:00
|
|
|
$fields['abusefilter-edit-notes'] =
|
|
|
|
new OOUI\MultilineTextInputWidget( [
|
|
|
|
'name' => 'wpFilterNotes',
|
|
|
|
'value' => isset( $row->af_comments ) ? $row->af_comments . "\n" : "\n",
|
2019-02-27 10:52:59 +00:00
|
|
|
'rows' => 15,
|
2019-08-17 16:53:13 +00:00
|
|
|
'readOnly' => $readOnly,
|
|
|
|
'id' => 'mw-abusefilter-notes-editor'
|
|
|
|
] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-09 12:20:33 +00:00
|
|
|
// Build checkboxes
|
2017-06-15 14:23:16 +00:00
|
|
|
$checkboxes = [ 'hidden', 'enabled', 'deleted' ];
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags = '';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $this->getConfig()->get( 'AbuseFilterIsCentral' ) ) {
|
2009-03-30 06:12:12 +00:00
|
|
|
$checkboxes[] = 'global';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( isset( $row->af_throttled ) && $row->af_throttled ) {
|
2017-09-05 20:11:18 +00:00
|
|
|
$filterActions = explode( ',', $row->af_actions );
|
2018-09-22 10:18:50 +00:00
|
|
|
$throttledActions = array_intersect(
|
|
|
|
$filterActions,
|
|
|
|
AbuseFilter::getDangerousActions()
|
2015-09-28 18:03:35 +00:00
|
|
|
);
|
2012-10-23 13:14:34 +00:00
|
|
|
|
2017-09-05 20:11:18 +00:00
|
|
|
if ( $throttledActions ) {
|
|
|
|
$throttledActions = array_map(
|
|
|
|
function ( $filterAction ) {
|
2018-09-22 10:18:50 +00:00
|
|
|
// TODO: This is AbuseFilter::getActionDisplay, but not escaped
|
2017-09-05 20:11:18 +00:00
|
|
|
return $this->msg( 'abusefilter-action-' . $filterAction )->text();
|
|
|
|
},
|
2018-09-22 10:18:50 +00:00
|
|
|
$throttledActions
|
2017-09-05 20:11:18 +00:00
|
|
|
);
|
|
|
|
|
2018-10-26 17:32:17 +00:00
|
|
|
$flags .= Html::warningBox(
|
|
|
|
$this->msg( 'abusefilter-edit-throttled-warning' )
|
|
|
|
->plaintextParams( $lang->commaList( $throttledActions ) )
|
|
|
|
->parseAsBlock()
|
2017-09-05 20:11:18 +00:00
|
|
|
);
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $checkboxes as $checkboxId ) {
|
2012-09-04 08:37:12 +00:00
|
|
|
// Messages that can be used here:
|
|
|
|
// * abusefilter-edit-enabled
|
|
|
|
// * abusefilter-edit-deleted
|
|
|
|
// * abusefilter-edit-hidden
|
|
|
|
// * abusefilter-edit-global
|
2009-01-23 19:23:19 +00:00
|
|
|
$message = "abusefilter-edit-$checkboxId";
|
|
|
|
$dbField = "af_$checkboxId";
|
2009-10-07 13:57:06 +00:00
|
|
|
$postVar = 'wpFilter' . ucfirst( $checkboxId );
|
2018-03-23 09:13:41 +00:00
|
|
|
|
|
|
|
$checkboxAttribs = [
|
|
|
|
'name' => $postVar,
|
|
|
|
'id' => $postVar,
|
|
|
|
'selected' => $row->$dbField ?? false,
|
2019-02-27 10:52:59 +00:00
|
|
|
'disabled' => $readOnly
|
|
|
|
];
|
2018-03-23 09:13:41 +00:00
|
|
|
$labelAttribs = [
|
|
|
|
'label' => $this->msg( $message )->text(),
|
|
|
|
'align' => 'inline',
|
|
|
|
];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $checkboxId === 'global' && !$afPermManager->canEditGlobal( $user ) ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkboxAttribs['disabled'] = 'disabled';
|
2012-09-12 15:31:24 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 16:59:55 +00:00
|
|
|
// Set readonly on deleted if the filter isn't disabled
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $checkboxId === 'deleted' && $row->af_enabled == 1 ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkboxAttribs['disabled'] = 'disabled';
|
2018-05-02 16:59:55 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
// Add infusable where needed
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $checkboxId === 'deleted' || $checkboxId === 'enabled' ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkboxAttribs['infusable'] = true;
|
2018-08-26 08:34:42 +00:00
|
|
|
if ( $checkboxId === 'deleted' ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$labelAttribs['id'] = $postVar . 'Label';
|
|
|
|
$labelAttribs['infusable'] = true;
|
|
|
|
}
|
|
|
|
}
|
2018-05-05 12:35:01 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkbox =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( $checkboxAttribs ),
|
|
|
|
$labelAttribs
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags .= $checkbox;
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$fields['abusefilter-edit-flags'] = $flags;
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2020-09-20 10:18:46 +00:00
|
|
|
if ( $filter !== null ) {
|
2019-08-21 15:32:43 +00:00
|
|
|
$tools = '';
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $afPermManager->canRevertFilterActions( $user ) ) {
|
2016-12-16 20:08:52 +00:00
|
|
|
$tools .= Xml::tags(
|
|
|
|
'p', null,
|
|
|
|
$this->linkRenderer->makeLink(
|
|
|
|
$this->getTitle( "revert/$filter" ),
|
2017-02-05 21:56:39 +00:00
|
|
|
new HtmlArmor( $this->msg( 'abusefilter-edit-revert' )->parse() )
|
2016-12-16 20:08:52 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( $afPermManager->canViewPrivateFilters( $user ) ) {
|
2016-12-16 20:08:52 +00:00
|
|
|
// Test link
|
|
|
|
$tools .= Xml::tags(
|
|
|
|
'p', null,
|
|
|
|
$this->linkRenderer->makeLink(
|
|
|
|
$this->getTitle( "test/$filter" ),
|
|
|
|
new HtmlArmor( $this->msg( 'abusefilter-edit-test-link' )->parse() )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
// Last modification details
|
2009-10-07 13:57:06 +00:00
|
|
|
$userLink =
|
2013-06-26 22:58:36 +00:00
|
|
|
Linker::userLink( $row->af_user, $row->af_user_text ) .
|
|
|
|
Linker::userToolLinks( $row->af_user, $row->af_user_text );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-lastmod'] =
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-lastmod-text' )
|
2016-01-21 09:57:56 +00:00
|
|
|
->rawParams(
|
|
|
|
$this->getLinkToLatestDiff(
|
|
|
|
$filter,
|
|
|
|
$lang->timeanddate( $row->af_timestamp, true )
|
|
|
|
),
|
|
|
|
$userLink,
|
|
|
|
$this->getLinkToLatestDiff(
|
|
|
|
$filter,
|
|
|
|
$lang->date( $row->af_timestamp, true )
|
|
|
|
),
|
|
|
|
$this->getLinkToLatestDiff(
|
|
|
|
$filter,
|
|
|
|
$lang->time( $row->af_timestamp, true )
|
|
|
|
)
|
2018-07-04 15:04:05 +00:00
|
|
|
)->params(
|
2016-01-21 09:57:56 +00:00
|
|
|
wfEscapeWikiText( $row->af_user_text )
|
2012-09-02 11:07:02 +00:00
|
|
|
)->parse();
|
2016-12-04 15:13:16 +00:00
|
|
|
$history_display = new HtmlArmor( $this->msg( 'abusefilter-edit-viewhistory' )->parse() );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-history'] =
|
2016-12-04 15:13:16 +00:00
|
|
|
$this->linkRenderer->makeKnownLink( $this->getTitle( 'history/' . $filter ), $history_display );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2019-08-11 10:21:36 +00:00
|
|
|
// Add export
|
|
|
|
$exportText = FormatJson::encode( [ 'row' => $row, 'actions' => $actions ] );
|
|
|
|
$tools .= Xml::tags( 'a', [ 'href' => '#', 'id' => 'mw-abusefilter-export-link' ],
|
|
|
|
$this->msg( 'abusefilter-edit-export' )->parse() );
|
|
|
|
$tools .=
|
|
|
|
new OOUI\MultilineTextInputWidget( [
|
|
|
|
'id' => 'mw-abusefilter-export',
|
|
|
|
'readOnly' => true,
|
|
|
|
'value' => $exportText,
|
|
|
|
'rows' => 10
|
|
|
|
] );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2019-08-21 15:32:43 +00:00
|
|
|
$fields['abusefilter-edit-tools'] = $tools;
|
|
|
|
}
|
2009-01-30 19:30:51 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$form = Xml::buildForm( $fields );
|
2012-09-02 11:07:02 +00:00
|
|
|
$form = Xml::fieldset( $this->msg( 'abusefilter-edit-main' )->text(), $form );
|
2009-10-07 13:57:06 +00:00
|
|
|
$form .= Xml::fieldset(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-consequences' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->buildConsequenceEditor( $row, $actions )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
if ( !$readOnly ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$form .=
|
|
|
|
new OOUI\ButtonInputWidget( [
|
|
|
|
'type' => 'submit',
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-save' )->text(),
|
|
|
|
'useInputTag' => true,
|
|
|
|
'accesskey' => 's',
|
|
|
|
'flags' => [ 'progressive', 'primary' ]
|
|
|
|
] );
|
2010-10-29 15:32:44 +00:00
|
|
|
$form .= Html::hidden(
|
2010-02-13 14:10:36 +00:00
|
|
|
'wpEditToken',
|
2017-06-15 14:23:16 +00:00
|
|
|
$user->getEditToken( [ 'abusefilter', $filter ] )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 10:18:46 +00:00
|
|
|
$urlFilter = $filter === null ? 'new' : (string)$filter;
|
2009-10-07 13:57:06 +00:00
|
|
|
$form = Xml::tags( 'form',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2020-09-20 10:18:46 +00:00
|
|
|
'action' => $this->getTitle( $urlFilter )->getFullURL(),
|
2018-12-04 12:06:46 +00:00
|
|
|
'method' => 'post',
|
|
|
|
'id' => 'mw-abusefilter-editing-form'
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2009-10-07 13:57:06 +00:00
|
|
|
$form
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2019-01-18 11:01:32 +00:00
|
|
|
$out->addHTML( $form );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2019-01-18 11:01:32 +00:00
|
|
|
if ( $history_id ) {
|
2020-01-28 17:43:26 +00:00
|
|
|
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable
|
2019-11-04 18:26:53 +00:00
|
|
|
$out->addWikiMsg( $oldWarningMessage, $history_id, $filter );
|
2019-01-18 11:01:32 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Builds the "actions" editor for a given filter.
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param stdClass $row A row from the abuse_filter table.
|
2019-08-17 15:51:44 +00:00
|
|
|
* @param array[] $actions Array of rows from the abuse_filter_action table
|
2012-05-06 05:59:35 +00:00
|
|
|
* corresponding to the abuse filter held in $row.
|
2018-04-29 17:52:45 +00:00
|
|
|
* @return string HTML text for an action editor.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2019-08-17 15:51:44 +00:00
|
|
|
private function buildConsequenceEditor( $row, array $actions ) {
|
2018-03-10 21:47:33 +00:00
|
|
|
$enabledActions = array_filter(
|
|
|
|
$this->getConfig()->get( 'AbuseFilterActions' )
|
|
|
|
);
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$setActions = [];
|
2016-06-03 18:01:56 +00:00
|
|
|
foreach ( $enabledActions as $action => $_ ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$setActions[$action] = array_key_exists( $action, $actions );
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
2016-06-03 18:01:56 +00:00
|
|
|
foreach ( $enabledActions as $action => $_ ) {
|
2019-10-23 16:44:06 +00:00
|
|
|
$params = $actions[$action] ?? null;
|
|
|
|
$output .= $this->buildConsequenceSelector(
|
|
|
|
$action, $setActions[$action], $row, $params );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
return $output;
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param string $action The action to build an editor for
|
|
|
|
* @param bool $set Whether or not the action is activated
|
|
|
|
* @param stdClass $row abuse_filter row object
|
2019-12-07 17:20:10 +00:00
|
|
|
* @param string[]|null $parameters Action parameters. Null iff $set is false.
|
2018-10-03 12:02:00 +00:00
|
|
|
* @return string|\OOUI\FieldLayout
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2019-10-23 16:44:06 +00:00
|
|
|
private function buildConsequenceSelector( $action, $set, $row, ?array $parameters ) {
|
2018-03-10 21:47:33 +00:00
|
|
|
$config = $this->getConfig();
|
2019-08-27 09:40:01 +00:00
|
|
|
$user = $this->getUser();
|
2020-09-18 14:49:13 +00:00
|
|
|
$afPermManager = AbuseFilterServices::getPermissionManager();
|
2019-10-23 16:44:06 +00:00
|
|
|
$actions = $config->get( 'AbuseFilterActions' );
|
|
|
|
if ( empty( $actions[$action] ) ) {
|
|
|
|
return '';
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-18 14:49:13 +00:00
|
|
|
$readOnly = !$afPermManager->canEditFilter( $user, $row );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
switch ( $action ) {
|
2009-01-23 19:23:44 +00:00
|
|
|
case 'throttle':
|
2013-10-28 05:47:14 +00:00
|
|
|
// Throttling is only available via object caching
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $config->get( 'MainCacheType' ) === CACHE_NONE ) {
|
2013-10-28 05:47:14 +00:00
|
|
|
return '';
|
|
|
|
}
|
2018-03-23 09:13:41 +00:00
|
|
|
$throttleSettings =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
'name' => 'wpFilterActionThrottle',
|
|
|
|
'id' => 'mw-abusefilter-action-checkbox-throttle',
|
|
|
|
'selected' => $set,
|
2019-02-27 10:52:59 +00:00
|
|
|
'classes' => [ 'mw-abusefilter-action-checkbox' ],
|
|
|
|
'disabled' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-action-throttle' )->text(),
|
|
|
|
'align' => 'inline'
|
|
|
|
]
|
|
|
|
);
|
2017-06-15 14:23:16 +00:00
|
|
|
$throttleFields = [];
|
2009-01-23 19:23:44 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $set ) {
|
2019-10-23 16:44:06 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable $parameters is array here
|
2019-05-15 14:14:12 +00:00
|
|
|
list( $throttleCount, $throttlePeriod ) = explode( ',', $parameters[1], 2 );
|
2009-01-23 19:23:44 +00:00
|
|
|
|
2019-05-15 14:14:12 +00:00
|
|
|
$throttleGroups = array_slice( $parameters, 2 );
|
2009-01-23 19:23:44 +00:00
|
|
|
} else {
|
|
|
|
$throttleCount = 3;
|
|
|
|
$throttlePeriod = 60;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$throttleGroups = [ 'user' ];
|
2009-01-23 19:23:44 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-count'] =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\TextInputWidget( [
|
|
|
|
'type' => 'number',
|
|
|
|
'name' => 'wpFilterThrottleCount',
|
2019-02-27 10:52:59 +00:00
|
|
|
'value' => $throttleCount,
|
|
|
|
'readOnly' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-throttle-count' )->text()
|
|
|
|
]
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-period'] =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\TextInputWidget( [
|
|
|
|
'type' => 'number',
|
|
|
|
'name' => 'wpFilterThrottlePeriod',
|
2019-02-27 10:52:59 +00:00
|
|
|
'value' => $throttlePeriod,
|
|
|
|
'readOnly' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-throttle-period' )->text()
|
|
|
|
]
|
|
|
|
);
|
2018-09-09 10:14:31 +00:00
|
|
|
|
2019-03-18 09:51:53 +00:00
|
|
|
$groupsHelpLink = Html::element(
|
|
|
|
'a',
|
|
|
|
[
|
|
|
|
'href' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/' .
|
|
|
|
'Extension:AbuseFilter/Actions#Throttling',
|
|
|
|
'target' => '_blank'
|
|
|
|
],
|
|
|
|
$this->msg( 'abusefilter-edit-throttle-groups-help-text' )->text()
|
|
|
|
);
|
|
|
|
$groupsHelp = $this->msg( 'abusefilter-edit-throttle-groups-help' )
|
|
|
|
->rawParams( $groupsHelpLink )->escaped();
|
2018-09-09 10:14:31 +00:00
|
|
|
$hiddenGroups =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldLayout(
|
2018-09-09 10:14:31 +00:00
|
|
|
new OOUI\MultilineTextInputWidget( [
|
|
|
|
'name' => 'wpFilterThrottleGroups',
|
|
|
|
'value' => implode( "\n", $throttleGroups ),
|
|
|
|
'rows' => 5,
|
|
|
|
'placeholder' => $this->msg( 'abusefilter-edit-throttle-hidden-placeholder' )->text(),
|
|
|
|
'infusable' => true,
|
2019-02-27 10:52:59 +00:00
|
|
|
'id' => 'mw-abusefilter-hidden-throttle-field',
|
|
|
|
'readOnly' => $readOnly
|
|
|
|
]
|
2018-09-09 10:14:31 +00:00
|
|
|
),
|
2018-03-23 09:13:41 +00:00
|
|
|
[
|
2018-09-09 10:14:31 +00:00
|
|
|
'label' => new OOUI\HtmlSnippet(
|
|
|
|
$this->msg( 'abusefilter-edit-throttle-groups' )->parse()
|
|
|
|
),
|
|
|
|
'align' => 'top',
|
2019-01-24 11:58:41 +00:00
|
|
|
'id' => 'mw-abusefilter-hidden-throttle',
|
2019-03-18 09:51:53 +00:00
|
|
|
'help' => new OOUI\HtmlSnippet( $groupsHelp ),
|
2019-01-24 11:58:41 +00:00
|
|
|
'helpInline' => true
|
2018-03-23 09:13:41 +00:00
|
|
|
]
|
|
|
|
);
|
2018-09-09 10:14:31 +00:00
|
|
|
|
|
|
|
$throttleFields['abusefilter-edit-throttle-groups'] = $hiddenGroups;
|
|
|
|
|
2019-03-18 09:51:53 +00:00
|
|
|
$throttleConfig = [
|
|
|
|
'values' => $throttleGroups,
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-throttle-groups' )->parse(),
|
|
|
|
'disabled' => $readOnly,
|
|
|
|
'help' => $groupsHelp
|
|
|
|
];
|
|
|
|
$this->getOutput()->addJsConfigVars( 'throttleConfig', $throttleConfig );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleSettings .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'id' => 'mw-abusefilter-throttle-parameters' ],
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldsetLayout( [ 'items' => $throttleFields ] )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:40:15 +00:00
|
|
|
return $throttleSettings;
|
2014-10-04 14:42:46 +00:00
|
|
|
case 'disallow':
|
2009-01-23 19:23:44 +00:00
|
|
|
case 'warn':
|
|
|
|
$output = '';
|
2014-10-04 14:42:46 +00:00
|
|
|
$formName = $action === 'warn' ? 'wpFilterActionWarn' : 'wpFilterActionDisallow';
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkbox =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
2014-10-04 14:42:46 +00:00
|
|
|
'name' => $formName,
|
|
|
|
// mw-abusefilter-action-checkbox-warn, mw-abusefilter-action-checkbox-disallow
|
|
|
|
'id' => "mw-abusefilter-action-checkbox-$action",
|
2018-03-23 09:13:41 +00:00
|
|
|
'selected' => $set,
|
2019-02-27 10:52:59 +00:00
|
|
|
'classes' => [ 'mw-abusefilter-action-checkbox' ],
|
|
|
|
'disabled' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-edit-action-warn, abusefilter-edit-action-disallow
|
|
|
|
'label' => $this->msg( "abusefilter-edit-action-$action" )->text(),
|
2018-03-23 09:13:41 +00:00
|
|
|
'align' => 'inline'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$output .= $checkbox;
|
2014-10-04 14:42:46 +00:00
|
|
|
$defaultWarnMsg = $config->get( 'AbuseFilterDefaultWarningMessage' );
|
|
|
|
$defaultDisallowMsg = $config->get( 'AbuseFilterDefaultDisallowMessage' );
|
|
|
|
|
|
|
|
if ( $set && isset( $parameters[0] ) ) {
|
|
|
|
$msg = $parameters[0];
|
2012-06-06 05:18:31 +00:00
|
|
|
} elseif (
|
|
|
|
$row &&
|
2014-10-04 14:42:46 +00:00
|
|
|
isset( $row->af_group ) && $row->af_group && (
|
|
|
|
( $action === 'warn' && isset( $defaultWarnMsg[$row->af_group] ) ) ||
|
|
|
|
( $action === 'disallow' && isset( $defaultDisallowMsg[$row->af_group] ) )
|
|
|
|
)
|
2012-06-06 05:18:31 +00:00
|
|
|
) {
|
2014-10-04 14:42:46 +00:00
|
|
|
$msg = $action === 'warn' ? $defaultWarnMsg[$row->af_group] :
|
|
|
|
$defaultDisallowMsg[$row->af_group];
|
2012-06-06 05:18:31 +00:00
|
|
|
} else {
|
2014-10-04 14:42:46 +00:00
|
|
|
$msg = $action === 'warn' ? 'abusefilter-warning' : 'abusefilter-disallowed';
|
2012-06-06 05:18:31 +00:00
|
|
|
}
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2018-10-03 15:55:06 +00:00
|
|
|
$fields = [];
|
2014-10-04 14:42:46 +00:00
|
|
|
$fields["abusefilter-edit-$action-message"] =
|
2019-02-27 10:52:59 +00:00
|
|
|
$this->getExistingSelector( $msg, $readOnly, $action );
|
2014-10-04 14:42:46 +00:00
|
|
|
$otherFieldName = $action === 'warn' ? 'wpFilterWarnMessageOther'
|
|
|
|
: 'wpFilterDisallowMessageOther';
|
|
|
|
|
|
|
|
$fields["abusefilter-edit-$action-other-label"] =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\TextInputWidget( [
|
2014-10-04 14:42:46 +00:00
|
|
|
'name' => $otherFieldName,
|
|
|
|
'value' => $msg,
|
|
|
|
// mw-abusefilter-warn-message-other, mw-abusefilter-disallow-message-other
|
|
|
|
'id' => "mw-abusefilter-$action-message-other",
|
2019-02-27 10:52:59 +00:00
|
|
|
'infusable' => true,
|
|
|
|
'readOnly' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => new OOUI\HtmlSnippet(
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-edit-warn-other-label, abusefilter-edit-disallow-other-label
|
|
|
|
$this->msg( "abusefilter-edit-$action-other-label" )->parse()
|
2018-03-23 09:13:41 +00:00
|
|
|
)
|
|
|
|
]
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$previewButton =
|
|
|
|
new OOUI\ButtonInputWidget( [
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-edit-warn-preview, abusefilter-edit-disallow-preview
|
|
|
|
'label' => $this->msg( "abusefilter-edit-$action-preview" )->text(),
|
|
|
|
// mw-abusefilter-warn-preview-button, mw-abusefilter-disallow-preview-button
|
|
|
|
'id' => "mw-abusefilter-$action-preview-button",
|
2018-03-23 09:13:41 +00:00
|
|
|
'infusable' => true,
|
|
|
|
'flags' => 'progressive'
|
2016-12-15 13:09:03 +00:00
|
|
|
]
|
|
|
|
);
|
2018-03-23 09:13:41 +00:00
|
|
|
|
|
|
|
$buttonGroup = $previewButton;
|
2019-09-18 21:48:40 +00:00
|
|
|
if ( MediaWikiServices::getInstance()->getPermissionManager()
|
|
|
|
->userHasRight( $user, 'editinterface' )
|
|
|
|
) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$editButton =
|
|
|
|
new OOUI\ButtonInputWidget( [
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-edit-warn-edit, abusefilter-edit-disallow-edit
|
|
|
|
'label' => $this->msg( "abusefilter-edit-$action-edit" )->text(),
|
|
|
|
// mw-abusefilter-warn-edit-button, mw-abusefilter-disallow-edit-button
|
|
|
|
'id' => "mw-abusefilter-$action-edit-button"
|
2018-03-23 09:13:41 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$buttonGroup =
|
|
|
|
new OOUI\Widget( [
|
|
|
|
'content' =>
|
|
|
|
new OOUI\HorizontalLayout( [
|
|
|
|
'items' => [ $previewButton, $editButton ],
|
|
|
|
'classes' => [
|
2014-10-04 14:42:46 +00:00
|
|
|
'mw-abusefilter-preview-buttons',
|
2018-03-23 09:13:41 +00:00
|
|
|
'mw-abusefilter-javascript-tools'
|
|
|
|
]
|
|
|
|
] )
|
|
|
|
] );
|
2016-12-15 13:09:03 +00:00
|
|
|
}
|
2018-03-23 09:13:41 +00:00
|
|
|
$previewHolder = Xml::tags(
|
2009-10-07 13:57:06 +00:00
|
|
|
'div',
|
2014-10-04 14:42:46 +00:00
|
|
|
[
|
|
|
|
// mw-abusefilter-warn-preview, mw-abusefilter-disallow-preview
|
|
|
|
'id' => "mw-abusefilter-$action-preview",
|
|
|
|
'style' => 'display:none'
|
|
|
|
],
|
2018-03-23 09:13:41 +00:00
|
|
|
''
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2014-10-04 14:42:46 +00:00
|
|
|
$fields["abusefilter-edit-$action-actions"] = $buttonGroup;
|
2009-10-07 13:57:06 +00:00
|
|
|
$output .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
2014-10-04 14:42:46 +00:00
|
|
|
// mw-abusefilter-warn-parameters, mw-abusefilter-disallow-parameters
|
|
|
|
[ 'id' => "mw-abusefilter-$action-parameters" ],
|
|
|
|
new OOUI\FieldsetLayout( [ 'items' => $fields ] )
|
2018-03-23 09:13:41 +00:00
|
|
|
) . $previewHolder;
|
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
return $output;
|
2009-01-28 19:08:18 +00:00
|
|
|
case 'tag':
|
2019-12-07 17:20:10 +00:00
|
|
|
$tags = $set ? $parameters : [];
|
|
|
|
'@phan-var string[] $parameters';
|
2009-01-28 19:08:18 +00:00
|
|
|
$output = '';
|
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkbox =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
'name' => 'wpFilterActionTag',
|
|
|
|
'id' => 'mw-abusefilter-action-checkbox-tag',
|
|
|
|
'selected' => $set,
|
2019-02-27 10:52:59 +00:00
|
|
|
'classes' => [ 'mw-abusefilter-action-checkbox' ],
|
|
|
|
'disabled' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-action-tag' )->text(),
|
|
|
|
'align' => 'inline'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$output .= $checkbox;
|
|
|
|
|
|
|
|
$tagConfig = [
|
2018-09-09 10:14:31 +00:00
|
|
|
'values' => $tags,
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-tag-tag' )->parse(),
|
2019-02-27 10:52:59 +00:00
|
|
|
'disabled' => $readOnly
|
2018-03-23 09:13:41 +00:00
|
|
|
];
|
|
|
|
$this->getOutput()->addJsConfigVars( 'tagConfig', $tagConfig );
|
|
|
|
|
|
|
|
$hiddenTags =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\MultilineTextInputWidget( [
|
|
|
|
'name' => 'wpFilterTags',
|
|
|
|
'value' => implode( ',', $tags ),
|
2018-08-22 09:02:51 +00:00
|
|
|
'rows' => 5,
|
2018-08-19 16:59:26 +00:00
|
|
|
'placeholder' => $this->msg( 'abusefilter-edit-tag-hidden-placeholder' )->text(),
|
|
|
|
'infusable' => true,
|
2019-02-27 10:52:59 +00:00
|
|
|
'id' => 'mw-abusefilter-hidden-tag-field',
|
|
|
|
'readOnly' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => new OOUI\HtmlSnippet(
|
|
|
|
$this->msg( 'abusefilter-edit-tag-tag' )->parse()
|
|
|
|
),
|
|
|
|
'align' => 'top',
|
2018-09-09 10:14:31 +00:00
|
|
|
'id' => 'mw-abusefilter-hidden-tag'
|
2018-03-23 09:13:41 +00:00
|
|
|
]
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$output .=
|
|
|
|
Xml::tags( 'div',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'id' => 'mw-abusefilter-tag-parameters' ],
|
2018-03-23 09:13:41 +00:00
|
|
|
$hiddenTags
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
return $output;
|
2017-08-22 18:23:01 +00:00
|
|
|
case 'block':
|
2018-02-20 12:36:32 +00:00
|
|
|
if ( $set && count( $parameters ) === 3 ) {
|
|
|
|
// Both blocktalk and custom block durations available
|
2019-05-15 14:12:51 +00:00
|
|
|
list( $blockTalk, $defaultAnonDuration, $defaultUserDuration ) = $parameters;
|
2018-02-20 12:36:32 +00:00
|
|
|
} else {
|
|
|
|
if ( $set && count( $parameters ) === 1 ) {
|
|
|
|
// Only blocktalk available
|
2019-10-23 16:44:06 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable $parameters is array here
|
2018-02-20 12:36:32 +00:00
|
|
|
$blockTalk = $parameters[0];
|
|
|
|
}
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $config->get( 'AbuseFilterAnonBlockDuration' ) ) {
|
|
|
|
$defaultAnonDuration = $config->get( 'AbuseFilterAnonBlockDuration' );
|
2018-02-20 12:36:32 +00:00
|
|
|
} else {
|
2018-03-10 21:47:33 +00:00
|
|
|
$defaultAnonDuration = $config->get( 'AbuseFilterBlockDuration' );
|
2018-02-20 12:36:32 +00:00
|
|
|
}
|
2018-03-10 21:47:33 +00:00
|
|
|
$defaultUserDuration = $config->get( 'AbuseFilterBlockDuration' );
|
2018-02-20 12:36:32 +00:00
|
|
|
}
|
2018-05-03 16:34:18 +00:00
|
|
|
$suggestedBlocks = SpecialBlock::getSuggestedDurations( null, false );
|
2018-03-24 09:45:54 +00:00
|
|
|
$suggestedBlocks = self::normalizeBlocks( $suggestedBlocks );
|
2018-02-20 12:36:32 +00:00
|
|
|
|
2017-08-22 18:23:01 +00:00
|
|
|
$output = '';
|
2018-03-23 09:13:41 +00:00
|
|
|
$checkbox =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
'name' => 'wpFilterActionBlock',
|
|
|
|
'id' => 'mw-abusefilter-action-checkbox-block',
|
|
|
|
'selected' => $set,
|
2019-02-27 10:52:59 +00:00
|
|
|
'classes' => [ 'mw-abusefilter-action-checkbox' ],
|
|
|
|
'disabled' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-action-block' )->text(),
|
|
|
|
'align' => 'inline'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$output .= $checkbox;
|
2018-02-20 12:36:32 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$suggestedBlocks = Xml::listDropDownOptionsOoui( $suggestedBlocks );
|
2018-02-20 12:36:32 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$anonDuration =
|
|
|
|
new OOUI\DropdownInputWidget( [
|
|
|
|
'name' => 'wpBlockAnonDuration',
|
|
|
|
'options' => $suggestedBlocks,
|
|
|
|
'value' => $defaultAnonDuration,
|
2020-09-18 14:49:13 +00:00
|
|
|
'disabled' => $readOnly
|
2018-03-23 09:13:41 +00:00
|
|
|
] );
|
2018-02-20 12:36:32 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$userDuration =
|
|
|
|
new OOUI\DropdownInputWidget( [
|
|
|
|
'name' => 'wpBlockUserDuration',
|
|
|
|
'options' => $suggestedBlocks,
|
|
|
|
'value' => $defaultUserDuration,
|
2020-09-18 14:49:13 +00:00
|
|
|
'disabled' => $readOnly
|
2018-03-23 09:13:41 +00:00
|
|
|
] );
|
2018-02-20 12:36:32 +00:00
|
|
|
|
2018-08-25 16:56:44 +00:00
|
|
|
$blockOptions = [];
|
2018-04-28 15:21:18 +00:00
|
|
|
if ( $config->get( 'BlockAllowsUTEdit' ) === true ) {
|
2018-08-25 16:56:44 +00:00
|
|
|
$talkCheckbox =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
'name' => 'wpFilterBlockTalk',
|
|
|
|
'id' => 'mw-abusefilter-action-checkbox-blocktalk',
|
2018-08-26 08:34:42 +00:00
|
|
|
'selected' => isset( $blockTalk ) && $blockTalk === 'blocktalk',
|
2019-02-27 10:52:59 +00:00
|
|
|
'classes' => [ 'mw-abusefilter-action-checkbox' ],
|
|
|
|
'disabled' => $readOnly
|
|
|
|
]
|
2018-08-25 16:56:44 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-action-blocktalk' )->text(),
|
|
|
|
'align' => 'left'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$blockOptions['abusefilter-edit-block-options'] = $talkCheckbox;
|
2018-04-28 15:21:18 +00:00
|
|
|
}
|
2018-08-25 16:56:44 +00:00
|
|
|
$blockOptions['abusefilter-edit-block-anon-durations'] =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldLayout(
|
|
|
|
$anonDuration,
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-block-anon-durations' )->text()
|
|
|
|
]
|
|
|
|
);
|
2018-08-25 16:56:44 +00:00
|
|
|
$blockOptions['abusefilter-edit-block-user-durations'] =
|
2018-03-23 09:13:41 +00:00
|
|
|
new OOUI\FieldLayout(
|
|
|
|
$userDuration,
|
|
|
|
[
|
|
|
|
'label' => $this->msg( 'abusefilter-edit-block-user-durations' )->text()
|
|
|
|
]
|
|
|
|
);
|
2018-02-20 12:36:32 +00:00
|
|
|
|
|
|
|
$output .= Xml::tags(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'mw-abusefilter-block-parameters' ],
|
2018-08-25 16:56:44 +00:00
|
|
|
new OOUI\FieldsetLayout( [ 'items' => $blockOptions ] )
|
2018-02-20 12:36:32 +00:00
|
|
|
);
|
|
|
|
|
2017-08-22 18:23:01 +00:00
|
|
|
return $output;
|
2018-02-20 12:36:32 +00:00
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
default:
|
2013-03-07 00:04:39 +00:00
|
|
|
// Give grep a chance to find the usages:
|
2018-03-23 09:13:41 +00:00
|
|
|
// abusefilter-edit-action-disallow,
|
|
|
|
// abusefilter-edit-action-blockautopromote,
|
|
|
|
// abusefilter-edit-action-degroup,
|
|
|
|
// abusefilter-edit-action-rangeblock,
|
2009-10-07 13:57:06 +00:00
|
|
|
$message = 'abusefilter-edit-action-' . $action;
|
|
|
|
$form_field = 'wpFilterAction' . ucfirst( $action );
|
2009-01-23 19:23:44 +00:00
|
|
|
$status = $set;
|
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$thisAction =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
'name' => $form_field,
|
|
|
|
'id' => "mw-abusefilter-action-checkbox-$action",
|
|
|
|
'selected' => $status,
|
2019-02-27 10:52:59 +00:00
|
|
|
'classes' => [ 'mw-abusefilter-action-checkbox' ],
|
|
|
|
'disabled' => $readOnly
|
|
|
|
]
|
2018-03-23 09:13:41 +00:00
|
|
|
),
|
|
|
|
[
|
|
|
|
'label' => $this->msg( $message )->text(),
|
|
|
|
'align' => 'inline'
|
|
|
|
]
|
|
|
|
);
|
2009-01-23 19:23:44 +00:00
|
|
|
return $thisAction;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param string $warnMsg
|
|
|
|
* @param bool $readOnly
|
2014-10-04 14:42:46 +00:00
|
|
|
* @param string $action
|
2018-10-03 12:02:00 +00:00
|
|
|
* @return \OOUI\FieldLayout
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2014-10-04 14:42:46 +00:00
|
|
|
public function getExistingSelector( $warnMsg, $readOnly = false, $action = 'warn' ) {
|
|
|
|
if ( $action === 'warn' ) {
|
|
|
|
$action = 'warning';
|
|
|
|
$formId = 'warn';
|
|
|
|
$inputName = 'wpFilterWarnMessage';
|
|
|
|
} elseif ( $action === 'disallow' ) {
|
|
|
|
$action = 'disallowed';
|
|
|
|
$formId = 'disallow';
|
|
|
|
$inputName = 'wpFilterDisallowMessage';
|
|
|
|
} else {
|
|
|
|
throw new MWException( "Unexpected action value $action" );
|
|
|
|
}
|
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
$existingSelector =
|
|
|
|
new OOUI\DropdownInputWidget( [
|
2014-10-04 14:42:46 +00:00
|
|
|
'name' => $inputName,
|
|
|
|
// mw-abusefilter-warn-message-existing, mw-abusefilter-disallow-message-existing
|
|
|
|
'id' => "mw-abusefilter-$formId-message-existing",
|
|
|
|
// abusefilter-warning, abusefilter-disallowed
|
2018-08-26 08:34:42 +00:00
|
|
|
'value' => $warnMsg === "abusefilter-$action" ? "abusefilter-$action" : 'other',
|
2018-03-23 09:13:41 +00:00
|
|
|
'infusable' => true
|
|
|
|
] );
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-warning, abusefilter-disallowed
|
|
|
|
$options = [ "abusefilter-$action" => "abusefilter-$action" ];
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2016-12-15 13:09:03 +00:00
|
|
|
if ( $readOnly ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$existingSelector->setDisabled( true );
|
2016-12-15 13:09:03 +00:00
|
|
|
} else {
|
|
|
|
// Find other messages.
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2014-10-04 14:42:46 +00:00
|
|
|
$pageTitlePrefix = "Abusefilter-$action";
|
2019-12-07 17:20:10 +00:00
|
|
|
$titles = $dbr->selectFieldValues(
|
2016-12-15 13:09:03 +00:00
|
|
|
'page',
|
2019-12-07 17:20:10 +00:00
|
|
|
'page_title',
|
2016-12-15 13:09:03 +00:00
|
|
|
[
|
|
|
|
'page_namespace' => 8,
|
2014-10-04 14:42:46 +00:00
|
|
|
'page_title LIKE ' . $dbr->addQuotes( $pageTitlePrefix . '%' )
|
2016-12-15 13:09:03 +00:00
|
|
|
],
|
|
|
|
__METHOD__
|
|
|
|
);
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2016-12-15 13:09:03 +00:00
|
|
|
$lang = $this->getLanguage();
|
2019-12-07 17:20:10 +00:00
|
|
|
foreach ( $titles as $title ) {
|
|
|
|
if ( $lang->lcfirst( $title ) === $lang->lcfirst( $warnMsg ) ) {
|
2018-03-23 09:13:41 +00:00
|
|
|
$existingSelector->setValue( $lang->lcfirst( $warnMsg ) );
|
2016-12-15 13:09:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 17:20:10 +00:00
|
|
|
if ( $title !== "Abusefilter-$action" ) {
|
|
|
|
$options[ $lang->lcfirst( $title ) ] = $lang->lcfirst( $title );
|
2016-12-15 13:09:03 +00:00
|
|
|
}
|
2009-02-03 22:45:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-edit-warn-other, abusefilter-edit-disallow-other
|
2019-12-07 17:20:10 +00:00
|
|
|
$options[ $this->msg( "abusefilter-edit-$formId-other" )->text() ] = 'other';
|
2018-03-23 09:13:41 +00:00
|
|
|
|
|
|
|
$options = Xml::listDropDownOptionsOoui( $options );
|
|
|
|
$existingSelector->setOptions( $options );
|
|
|
|
|
|
|
|
$existingSelector =
|
|
|
|
new OOUI\FieldLayout(
|
|
|
|
$existingSelector,
|
|
|
|
[
|
2014-10-04 14:42:46 +00:00
|
|
|
// abusefilter-edit-warn-message, abusefilter-edit-disallow-message
|
|
|
|
'label' => $this->msg( "abusefilter-edit-$formId-message" )->text()
|
2018-03-23 09:13:41 +00:00
|
|
|
]
|
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2018-03-23 09:13:41 +00:00
|
|
|
return $existingSelector;
|
2009-02-03 22:45:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 09:45:54 +00:00
|
|
|
/**
|
2018-07-27 00:27:11 +00:00
|
|
|
* @todo Maybe we should also check if global values belong to $durations
|
2018-03-24 09:45:54 +00:00
|
|
|
* and determine the right point to add them if missing.
|
|
|
|
*
|
|
|
|
* @param array $durations
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-08-17 15:51:44 +00:00
|
|
|
protected static function normalizeBlocks( array $durations ) {
|
2018-03-24 09:45:54 +00:00
|
|
|
global $wgAbuseFilterBlockDuration, $wgAbuseFilterAnonBlockDuration;
|
|
|
|
// We need to have same values since it may happen that ipblocklist
|
|
|
|
// and one (or both) of the global variables use different wording
|
|
|
|
// for the same duration. In such case, when setting the default of
|
|
|
|
// the dropdowns it would fail.
|
2018-05-02 12:13:00 +00:00
|
|
|
$anonDuration = self::getAbsoluteBlockDuration( $wgAbuseFilterAnonBlockDuration );
|
|
|
|
$userDuration = self::getAbsoluteBlockDuration( $wgAbuseFilterBlockDuration );
|
2018-03-24 09:45:54 +00:00
|
|
|
foreach ( $durations as &$duration ) {
|
2018-05-02 12:13:00 +00:00
|
|
|
$currentDuration = self::getAbsoluteBlockDuration( $duration );
|
2018-03-24 09:45:54 +00:00
|
|
|
|
|
|
|
if ( $duration !== $wgAbuseFilterBlockDuration &&
|
|
|
|
$currentDuration === $userDuration ) {
|
|
|
|
$duration = $wgAbuseFilterBlockDuration;
|
|
|
|
|
|
|
|
} elseif ( $duration !== $wgAbuseFilterAnonBlockDuration &&
|
|
|
|
$currentDuration === $anonDuration ) {
|
|
|
|
$duration = $wgAbuseFilterAnonBlockDuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $durations;
|
|
|
|
}
|
|
|
|
|
2018-05-02 12:13:00 +00:00
|
|
|
/**
|
|
|
|
* Converts a string duration to an absolute timestamp, i.e. unrelated to the current
|
|
|
|
* time, taking into account infinity durations as well. The second parameter of
|
|
|
|
* strtotime is set to 0 in order to convert the duration in seconds (instead of
|
|
|
|
* a timestamp), thus making it unaffected by the execution time of the code.
|
|
|
|
*
|
|
|
|
* @param string $duration
|
|
|
|
* @return string|int
|
|
|
|
*/
|
|
|
|
protected static function getAbsoluteBlockDuration( $duration ) {
|
|
|
|
if ( wfIsInfinity( $duration ) ) {
|
|
|
|
return 'infinity';
|
|
|
|
}
|
|
|
|
return strtotime( $duration, 0 );
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Loads filter data from the database by ID.
|
2020-09-20 10:18:46 +00:00
|
|
|
* @param int|null $id The filter's ID number, or null for a new filter
|
2019-03-01 15:05:26 +00:00
|
|
|
* @return array|null Either a [ DB row, actions ] array representing the filter,
|
2012-05-06 05:59:35 +00:00
|
|
|
* or NULL if the filter does not exist.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2020-09-20 10:18:46 +00:00
|
|
|
public function loadFilterData( ?int $id ) {
|
|
|
|
if ( $id === null ) {
|
2019-03-01 15:05:26 +00:00
|
|
|
return [
|
|
|
|
(object)[
|
|
|
|
'af_pattern' => '',
|
|
|
|
'af_enabled' => 1,
|
|
|
|
'af_hidden' => 0,
|
|
|
|
'af_global' => 0,
|
|
|
|
'af_throttled' => 0,
|
|
|
|
'af_hit_count' => 0
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
];
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2009-06-17 11:50:26 +00:00
|
|
|
// Load from master to avoid unintended reversions where there's replication lag.
|
2016-04-28 20:50:08 +00:00
|
|
|
$dbr = $this->getRequest()->wasPosted()
|
|
|
|
? wfGetDB( DB_MASTER )
|
2017-08-30 02:51:39 +00:00
|
|
|
: wfGetDB( DB_REPLICA );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-06-17 11:50:26 +00:00
|
|
|
// Load certain fields only. This prevents a condition seen on Wikimedia where
|
2009-10-07 13:57:06 +00:00
|
|
|
// a schema change adding a new field caused that extra field to be selected.
|
|
|
|
// Since the selected row may be inserted back into the database, this will cause
|
|
|
|
// an SQL error if, say, one server has the updated schema but another does not.
|
2017-06-15 14:23:16 +00:00
|
|
|
$loadFields = [
|
2009-06-17 11:50:26 +00:00
|
|
|
'af_id',
|
|
|
|
'af_pattern',
|
|
|
|
'af_user',
|
|
|
|
'af_user_text',
|
|
|
|
'af_timestamp',
|
|
|
|
'af_enabled',
|
|
|
|
'af_comments',
|
|
|
|
'af_public_comments',
|
|
|
|
'af_hidden',
|
|
|
|
'af_hit_count',
|
|
|
|
'af_throttled',
|
|
|
|
'af_deleted',
|
|
|
|
'af_actions',
|
|
|
|
'af_global',
|
2012-05-06 06:44:45 +00:00
|
|
|
'af_group',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load the main row
|
2017-06-15 14:23:16 +00:00
|
|
|
$row = $dbr->selectRow( 'abuse_filter', $loadFields, [ 'af_id' => $id ], __METHOD__ );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !isset( $row ) || !isset( $row->af_id ) || !$row->af_id ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return null;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load the actions
|
2018-08-31 14:19:44 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'abuse_filter_action',
|
|
|
|
[ 'afa_consequence', 'afa_parameters' ],
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'afa_filter' => $id ],
|
2009-10-07 13:57:06 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
2015-09-28 18:03:35 +00:00
|
|
|
|
2018-09-27 13:58:55 +00:00
|
|
|
$actions = [];
|
2015-09-28 18:03:35 +00:00
|
|
|
foreach ( $res as $actionRow ) {
|
2018-09-27 13:58:55 +00:00
|
|
|
$actions[$actionRow->afa_consequence] =
|
|
|
|
array_filter( explode( "\n", $actionRow->afa_parameters ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
return [ $row, $actions ];
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2019-03-01 14:24:30 +00:00
|
|
|
* Load filter data to show in the edit view from the DB.
|
2020-09-20 10:18:46 +00:00
|
|
|
* @param int|null $filter The filter ID being requested or null for a new filter
|
2018-05-25 23:31:49 +00:00
|
|
|
* @param int|null $history_id If any, the history ID being requested.
|
2018-06-08 06:11:09 +00:00
|
|
|
* @return array|null Array with filter data if available, otherwise null.
|
2012-05-06 05:59:35 +00:00
|
|
|
* The first element contains the abuse_filter database row,
|
|
|
|
* the second element is an array of related abuse_filter_action rows.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2020-09-20 10:18:46 +00:00
|
|
|
private function loadFromDatabase( ?int $filter, $history_id = null ) {
|
2019-03-01 14:24:30 +00:00
|
|
|
if ( $history_id ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return $this->loadHistoryItem( $history_id );
|
|
|
|
} else {
|
|
|
|
return $this->loadFilterData( $filter );
|
|
|
|
}
|
2019-03-01 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-22 22:19:50 +00:00
|
|
|
* Load data from the HTTP request. Used for saving the filter, and when the token doesn't match
|
|
|
|
* @param int|null $filter
|
|
|
|
* @return array
|
2019-03-01 14:24:30 +00:00
|
|
|
*/
|
2020-09-22 22:19:50 +00:00
|
|
|
private function loadRequest( ?int $filter ) : array {
|
2019-03-01 14:24:30 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ( !$request->wasPosted() ) {
|
|
|
|
// Sanity
|
|
|
|
throw new BadMethodCallException( __METHOD__ . ' called without the request being POSTed.' );
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2019-03-01 15:05:26 +00:00
|
|
|
list( $origRow, $origActions ) = $this->loadFilterData( $filter );
|
2009-01-26 22:30:42 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
// Unchangeable values
|
2019-03-01 15:05:26 +00:00
|
|
|
$row = (object)[
|
2020-09-22 22:19:50 +00:00
|
|
|
'af_throttled' => $filter === null ? 0 : $origRow->af_throttled,
|
|
|
|
'af_hit_count' => $filter === null ? 0 : $origRow->af_hit_count,
|
2019-03-01 15:05:26 +00:00
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
if ( $filter !== null ) {
|
|
|
|
// Needed if the save fails
|
|
|
|
$row->af_id = $origRow->af_id;
|
|
|
|
$row->af_user = $origRow->af_user;
|
|
|
|
$row->af_user_text = $origRow->af_user_text;
|
|
|
|
$row->af_timestamp = $origRow->af_timestamp;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$row->af_public_comments = trim( $request->getVal( 'wpFilterDescription' ) );
|
|
|
|
$row->af_pattern = trim( $request->getVal( 'wpFilterRules' ) );
|
|
|
|
$row->af_comments = trim( $request->getVal( 'wpFilterNotes' ) );
|
2019-08-11 12:29:37 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$row->af_group = $request->getVal( 'wpFilterGroup', 'default' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$row->af_deleted = $request->getCheck( 'wpFilterDeleted' );
|
|
|
|
$row->af_enabled = $request->getCheck( 'wpFilterEnabled' );
|
|
|
|
$row->af_hidden = $request->getCheck( 'wpFilterHidden' );
|
|
|
|
$row->af_global = $request->getCheck( 'wpFilterGlobal' )
|
|
|
|
&& $this->getConfig()->get( 'AbuseFilterIsCentral' );
|
2019-03-01 15:05:26 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$actions = $this->loadActions();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$row->af_actions = implode( ',', array_keys( $actions ) );
|
2020-02-08 20:07:44 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
return [ $row, $actions, $origRow, $origActions ];
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
/**
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
private function loadImportRequest() : ?array {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ( !$request->wasPosted() ) {
|
|
|
|
// Sanity
|
|
|
|
throw new BadMethodCallException( __METHOD__ . ' called without the request being POSTed.' );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$importData = FormatJson::decode( $request->getVal( 'wpImportText' ) );
|
|
|
|
if ( !$this->isValidImportData( $importData ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
// Default values
|
|
|
|
$row = (object)[
|
|
|
|
'af_throttled' => 0,
|
|
|
|
'af_hit_count' => 0,
|
|
|
|
'af_group' => 'default',
|
|
|
|
'af_global' => 0
|
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$importRow = $importData->row;
|
|
|
|
$actions = wfObjectToArray( $importData->actions );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$row->af_public_comments = $importRow->af_public_comments;
|
|
|
|
$row->af_pattern = $importRow->af_pattern;
|
|
|
|
$row->af_comments = $importRow->af_comments;
|
|
|
|
$row->af_deleted = $importRow->af_deleted;
|
|
|
|
$row->af_enabled = $importRow->af_enabled;
|
|
|
|
$row->af_hidden = $importRow->af_hidden;
|
|
|
|
$row->af_actions = implode( ',', array_keys( $actions ) );
|
|
|
|
|
|
|
|
return [ $row, $actions ];
|
|
|
|
}
|
2014-10-04 14:42:46 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
private function loadActions() : array {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$actions = [];
|
|
|
|
foreach ( array_filter( $this->getConfig()->get( 'AbuseFilterActions' ) ) as $action => $_ ) {
|
|
|
|
// Check if it's set
|
|
|
|
$enabled = $request->getCheck( 'wpFilterAction' . ucfirst( $action ) );
|
|
|
|
|
|
|
|
if ( $enabled ) {
|
|
|
|
$parameters = [];
|
|
|
|
|
|
|
|
if ( $action === 'throttle' ) {
|
|
|
|
// We need to load the parameters
|
|
|
|
$throttleCount = $request->getIntOrNull( 'wpFilterThrottleCount' );
|
|
|
|
$throttlePeriod = $request->getIntOrNull( 'wpFilterThrottlePeriod' );
|
|
|
|
// First explode with \n, which is the delimiter used in the textarea
|
|
|
|
$rawGroups = explode( "\n", $request->getText( 'wpFilterThrottleGroups' ) );
|
|
|
|
// Trim any space, both as an actual group and inside subgroups
|
|
|
|
$throttleGroups = [];
|
|
|
|
foreach ( $rawGroups as $group ) {
|
|
|
|
if ( strpos( $group, ',' ) !== false ) {
|
|
|
|
$subGroups = explode( ',', $group );
|
|
|
|
$throttleGroups[] = implode( ',', array_map( 'trim', $subGroups ) );
|
|
|
|
} elseif ( trim( $group ) !== '' ) {
|
|
|
|
$throttleGroups[] = trim( $group );
|
2018-09-03 12:03:33 +00:00
|
|
|
}
|
2009-04-23 04:23:56 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2020-09-22 22:19:50 +00:00
|
|
|
$parameters[0] = $this->filter;
|
|
|
|
$parameters[1] = "$throttleCount,$throttlePeriod";
|
|
|
|
$parameters = array_merge( $parameters, $throttleGroups );
|
|
|
|
} elseif ( $action === 'warn' ) {
|
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessage' );
|
|
|
|
|
|
|
|
if ( $specMsg === 'other' ) {
|
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessageOther' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$parameters[0] = $specMsg;
|
|
|
|
} elseif ( $action === 'block' ) {
|
|
|
|
$parameters[0] = $request->getCheck( 'wpFilterBlockTalk' ) ?
|
|
|
|
'blocktalk' : 'noTalkBlockSet';
|
|
|
|
$parameters[1] = $request->getVal( 'wpBlockAnonDuration' );
|
|
|
|
$parameters[2] = $request->getVal( 'wpBlockUserDuration' );
|
|
|
|
} elseif ( $action === 'disallow' ) {
|
|
|
|
$specMsg = $request->getVal( 'wpFilterDisallowMessage' );
|
|
|
|
|
|
|
|
if ( $specMsg === 'other' ) {
|
|
|
|
$specMsg = $request->getVal( 'wpFilterDisallowMessageOther' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$parameters[0] = $specMsg;
|
|
|
|
} elseif ( $action === 'tag' ) {
|
|
|
|
$parameters = explode( ',', trim( $request->getText( 'wpFilterTags' ) ) );
|
|
|
|
if ( $parameters === [ '' ] ) {
|
|
|
|
// Since it's not possible to manually add an empty tag, this only happens
|
|
|
|
// if the form is submitted without touching the tag input field.
|
|
|
|
// We pass an empty array so that the widget won't show an empty tag in the topbar
|
|
|
|
$parameters = [];
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2020-09-22 22:19:50 +00:00
|
|
|
|
|
|
|
$actions[$action] = $parameters;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-22 22:19:50 +00:00
|
|
|
return $actions;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Loads historical data in a form that the editor can understand.
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param int $id History ID
|
2020-02-08 13:55:12 +00:00
|
|
|
* @return array|null Null if the history ID is not valid, otherwise array in the usual format:
|
2012-05-06 05:59:35 +00:00
|
|
|
* First element contains the abuse_filter row (as it was).
|
|
|
|
* Second element contains an array of abuse_filter_action rows.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2020-02-08 13:55:12 +00:00
|
|
|
private function loadHistoryItem( $id ) : ?array {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$row = $dbr->selectRow( 'abuse_filter_history',
|
|
|
|
'*',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'afh_id' => $id ],
|
2009-10-07 13:57:06 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2016-04-02 22:11:29 +00:00
|
|
|
if ( !$row ) {
|
2020-02-08 13:55:12 +00:00
|
|
|
return null;
|
2016-04-02 22:11:29 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
return AbuseFilter::translateFromHistory( $row );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2012-06-06 05:18:31 +00:00
|
|
|
|
2017-10-20 17:46:31 +00:00
|
|
|
/**
|
2014-10-04 14:42:46 +00:00
|
|
|
* Exports the default warning and disallow messages to a JS variable
|
2017-10-20 17:46:31 +00:00
|
|
|
*/
|
2014-10-04 14:42:46 +00:00
|
|
|
protected function exposeMessages() {
|
2018-03-10 21:47:33 +00:00
|
|
|
$this->getOutput()->addJsConfigVars(
|
2015-09-28 18:03:35 +00:00
|
|
|
'wgAbuseFilterDefaultWarningMessage',
|
2018-03-10 21:47:33 +00:00
|
|
|
$this->getConfig()->get( 'AbuseFilterDefaultWarningMessage' )
|
2015-09-28 18:03:35 +00:00
|
|
|
);
|
2014-10-04 14:42:46 +00:00
|
|
|
$this->getOutput()->addJsConfigVars(
|
|
|
|
'wgAbuseFilterDefaultDisallowMessage',
|
|
|
|
$this->getConfig()->get( 'AbuseFilterDefaultDisallowMessage' )
|
|
|
|
);
|
2012-06-06 05:18:31 +00:00
|
|
|
}
|
2019-08-11 12:29:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform basic validation on the JSON-decoded import data. This doesn't check if parameters
|
|
|
|
* are valid etc., but only if the shape of the object is right.
|
2020-09-22 22:19:50 +00:00
|
|
|
* @todo This should live in ViewImport, but that's nontrivial due to form action
|
2019-08-11 12:29:37 +00:00
|
|
|
*
|
|
|
|
* @param mixed $data Already JSON-decoded
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isValidImportData( $data ) {
|
|
|
|
global $wgAbuseFilterActions;
|
|
|
|
|
|
|
|
if ( !is_object( $data ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr = get_object_vars( $data );
|
|
|
|
|
|
|
|
$expectedKeys = [ 'row' => true, 'actions' => true ];
|
|
|
|
if ( count( $arr ) !== count( $expectedKeys ) || array_diff_key( $arr, $expectedKeys ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 12:26:12 +00:00
|
|
|
if ( !is_object( $arr['row'] ) || !( is_object( $arr['actions'] ) || $arr['actions'] === [] ) ) {
|
2019-08-11 12:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $arr['actions'] as $action => $params ) {
|
|
|
|
if ( !array_key_exists( $action, $wgAbuseFilterActions ) || !is_array( $params ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !AbuseFilter::isFullAbuseFilterRow( $arr['row'] ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|