2009-01-23 19:23:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewEdit extends AbuseFilterView {
|
2012-09-02 11:07:02 +00:00
|
|
|
/**
|
2013-10-15 13:22:05 +00:00
|
|
|
* @param SpecialAbuseFilter $page
|
2012-09-02 11:07:02 +00:00
|
|
|
* @param array $params
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function __construct( $page, $params ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
parent::__construct( $page, $params );
|
|
|
|
$this->mFilter = $page->mFilter;
|
|
|
|
$this->mHistoryID = $page->mHistoryID;
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:00:14 +00:00
|
|
|
/**
|
|
|
|
* Check whether a filter is allowed to use a tag
|
|
|
|
*
|
|
|
|
* @param string $tag Tag name
|
|
|
|
* @return Status
|
|
|
|
*/
|
|
|
|
protected function isAllowedTag( $tag ) {
|
2017-10-31 13:36:57 +00:00
|
|
|
$tagNameStatus = ChangeTags::isTagNameValid( $tag );
|
2015-03-17 13:00:14 +00:00
|
|
|
|
|
|
|
if ( !$tagNameStatus->isGood() ) {
|
|
|
|
return $tagNameStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
$finalStatus = Status::newGood();
|
|
|
|
|
|
|
|
$canAddStatus =
|
|
|
|
ChangeTags::canAddTagsAccompanyingChange(
|
|
|
|
[ $tag ]
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $canAddStatus->isGood() ) {
|
|
|
|
return $finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
$alreadyDefinedTags = [];
|
|
|
|
AbuseFilterHooks::onListDefinedTags( $alreadyDefinedTags );
|
|
|
|
|
|
|
|
if ( in_array( $tag, $alreadyDefinedTags, true ) ) {
|
|
|
|
return $finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
$canCreateTagStatus = ChangeTags::canCreateTag( $tag );
|
|
|
|
if ( $canCreateTagStatus->isGood() ) {
|
|
|
|
return $finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
$finalStatus->fatal( 'abusefilter-edit-bad-tags' );
|
|
|
|
return $finalStatus;
|
|
|
|
}
|
|
|
|
|
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();
|
2018-03-10 21:47:33 +00:00
|
|
|
$config = $this->getConfig();
|
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
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$filter = $this->mFilter;
|
|
|
|
$history_id = $this->mHistoryID;
|
2016-12-02 18:05:36 +00:00
|
|
|
if ( $this->mHistoryID ) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-12-02 18:05:36 +00:00
|
|
|
$row = $dbr->selectRow(
|
|
|
|
'abuse_filter_history',
|
|
|
|
'afh_id',
|
|
|
|
[
|
|
|
|
'afh_filter' => $filter,
|
|
|
|
],
|
|
|
|
__METHOD__,
|
|
|
|
[ 'ORDER BY' => 'afh_timestamp DESC' ]
|
|
|
|
);
|
|
|
|
// change $history_id to null if it's current version id
|
|
|
|
if ( $row->afh_id === $this->mHistoryID ) {
|
|
|
|
$history_id = null;
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-06-06 05:18:31 +00:00
|
|
|
// Add default warning messages
|
|
|
|
$this->exposeWarningMessages();
|
|
|
|
|
2017-04-07 19:23:11 +00:00
|
|
|
if ( $filter == 'new' && !$this->canEdit() ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed' );
|
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 );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2017-04-07 19:23:11 +00:00
|
|
|
if ( $tokenMatches && $this->canEdit() ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Check syntax
|
2011-11-16 05:34:24 +00:00
|
|
|
$syntaxerr = AbuseFilter::checkSyntax( $request->getVal( 'wpFilterRules' ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $syntaxerr !== true ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML(
|
2009-02-07 09:34:11 +00:00
|
|
|
$this->buildFilterEditor(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-edit-badsyntax',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ $syntaxerr[0] ]
|
2012-09-02 11:07:02 +00:00
|
|
|
)->parseAsBlock(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$filter, $history_id
|
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-27 19:51:38 +00:00
|
|
|
return;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2018-03-09 12:20:33 +00:00
|
|
|
// Check for missing required fields (title and pattern)
|
|
|
|
$missing = [];
|
|
|
|
if ( !$request->getVal( 'wpFilterRules' ) ||
|
|
|
|
trim( $request->getVal( 'wpFilterRules' ) ) === '' ) {
|
|
|
|
$missing[] = $this->msg( 'abusefilter-edit-field-conditions' )->escaped();
|
|
|
|
}
|
|
|
|
if ( !$request->getVal( 'wpFilterDescription' ) ) {
|
|
|
|
$missing[] = $this->msg( 'abusefilter-edit-field-description' )->escaped();
|
|
|
|
}
|
|
|
|
if ( count( $missing ) !== 0 ) {
|
|
|
|
$missing = $this->getLanguage()->commaList( $missing );
|
|
|
|
$out->addHTML(
|
|
|
|
$this->buildFilterEditor(
|
|
|
|
$this->msg(
|
|
|
|
'abusefilter-edit-missingfields',
|
|
|
|
$missing
|
|
|
|
)->parseAsBlock(),
|
|
|
|
$filter, $history_id
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2018-05-02 16:59:55 +00:00
|
|
|
// Don't allow setting as deleted an active filter
|
|
|
|
if ( $request->getBool( 'wpFilterEnabled' ) == true &&
|
|
|
|
$request->getBool( 'wpFilterDeleted' ) == true ) {
|
|
|
|
$out->addHTML(
|
|
|
|
$this->buildFilterEditor(
|
|
|
|
$this->msg(
|
|
|
|
'abusefilter-edit-deleting-enabled'
|
|
|
|
)->parseAsBlock(),
|
|
|
|
$filter, $history_id
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $newRow, $actions ) = $this->loadRequest( $filter );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$differences = AbuseFilter::compareVersions(
|
2017-06-15 14:23:16 +00:00
|
|
|
[ $newRow, $actions ],
|
|
|
|
[ $newRow->mOriginalRow, $newRow->mOriginalActions ]
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-01-26 22:31:02 +00:00
|
|
|
|
2012-09-12 15:31:24 +00:00
|
|
|
// Don't allow adding a new global rule, or updating a
|
|
|
|
// rule that is currently global, without permissions.
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( !$this->canEditFilter( $newRow ) || !$this->canEditFilter( $newRow->mOriginalRow ) ) {
|
2012-09-12 15:31:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed-global' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-26 21:57:20 +00:00
|
|
|
// Don't allow custom messages on global rules
|
2015-09-28 18:03:35 +00:00
|
|
|
if ( $newRow->af_global == 1 &&
|
|
|
|
$request->getVal( 'wpFilterWarnMessage' ) !== 'abusefilter-warning'
|
|
|
|
) {
|
2013-06-26 21:57:20 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed-global-custom-msg' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-08 01:02:11 +00:00
|
|
|
$origActions = $newRow->mOriginalActions;
|
2016-08-10 17:05:27 +00:00
|
|
|
$wasGlobal = (bool)$newRow->mOriginalRow->af_global;
|
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
unset( $newRow->mOriginalRow );
|
|
|
|
unset( $newRow->mOriginalActions );
|
2009-01-26 22:30:42 +00:00
|
|
|
|
2009-01-27 19:51:38 +00:00
|
|
|
// Check for non-changes
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !count( $differences ) ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->redirect( $this->getTitle()->getLocalURL() );
|
2009-01-26 22:30:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-27 19:51:38 +00:00
|
|
|
// Check for restricted actions
|
2016-06-03 18:01:56 +00:00
|
|
|
if ( count( array_intersect_key(
|
2018-03-10 21:47:33 +00:00
|
|
|
array_filter( $config->get( 'AbuseFilterRestrictions' ) ),
|
2017-07-08 18:49:13 +00:00
|
|
|
array_merge(
|
|
|
|
array_filter( $actions ),
|
|
|
|
array_filter( $origActions )
|
|
|
|
)
|
2012-02-08 01:02:11 +00:00
|
|
|
) )
|
|
|
|
&& !$user->isAllowed( 'abusefilter-modify-restricted' )
|
|
|
|
) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->buildFilterEditor(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-restricted' )->parseAsBlock(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mFilter,
|
|
|
|
$history_id
|
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-27 19:51:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-07-17 15:37:03 +00:00
|
|
|
// If we've activated the 'tag' option, check the arguments for validity.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !empty( $actions['tag'] ) ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions['tag']['parameters'] as $tag ) {
|
2015-03-17 13:00:14 +00:00
|
|
|
$status = $this->isAllowedTag( $tag );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2015-03-17 13:00:14 +00:00
|
|
|
if ( !$status->isGood() ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML(
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->buildFilterEditor(
|
2015-03-17 13:00:14 +00:00
|
|
|
$status->getMessage()->parseAsBlock(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mFilter,
|
|
|
|
$history_id
|
|
|
|
)
|
|
|
|
);
|
2009-07-17 15:37:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-27 19:51:38 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
// Convert from object to array
|
|
|
|
$newRow = get_object_vars( $newRow );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Set last modifier.
|
|
|
|
$newRow['af_timestamp'] = $dbw->timestamp( wfTimestampNow() );
|
2011-11-16 05:34:24 +00:00
|
|
|
$newRow['af_user'] = $user->getId();
|
|
|
|
$newRow['af_user_text'] = $user->getName();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2015-10-08 05:54:58 +00:00
|
|
|
$dbw->startAtomic( __METHOD__ );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Insert MAIN row.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $filter == 'new' ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$new_id = $dbw->nextSequenceValue( 'abuse_filter_af_id_seq' );
|
|
|
|
$is_new = true;
|
|
|
|
} else {
|
|
|
|
$new_id = $this->mFilter;
|
|
|
|
$is_new = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset throttled marker, if we're re-enabling it.
|
|
|
|
$newRow['af_throttled'] = $newRow['af_throttled'] && !$newRow['af_enabled'];
|
2018-04-04 21:14:25 +00:00
|
|
|
// ID.
|
|
|
|
$newRow['af_id'] = $new_id;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2014-05-27 13:29:27 +00:00
|
|
|
// T67807
|
|
|
|
// integer 1's & 0's might be better understood than booleans
|
2017-07-08 18:49:13 +00:00
|
|
|
$newRow['af_enabled'] = (int)$newRow['af_enabled'];
|
|
|
|
$newRow['af_hidden'] = (int)$newRow['af_hidden'];
|
|
|
|
$newRow['af_throttled'] = (int)$newRow['af_throttled'];
|
|
|
|
$newRow['af_deleted'] = (int)$newRow['af_deleted'];
|
|
|
|
$newRow['af_global'] = (int)$newRow['af_global'];
|
2014-05-27 13:29:27 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$dbw->replace( 'abuse_filter', [ 'af_id' ], $newRow, __METHOD__ );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $is_new ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$new_id = $dbw->insertId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
2017-06-15 14:23:16 +00:00
|
|
|
$actionsRows = [];
|
2018-03-10 21:47:33 +00:00
|
|
|
foreach ( array_filter( $config->get( 'AbuseFilterActions' ) ) as $action => $_ ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Check if it's set
|
2010-02-13 14:10:36 +00:00
|
|
|
$enabled = isset( $actions[$action] ) && (bool)$actions[$action];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $enabled ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$parameters = $actions[$action]['parameters'];
|
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$thisRow = [
|
2009-10-07 13:57:06 +00:00
|
|
|
'afa_filter' => $new_id,
|
|
|
|
'afa_consequence' => $action,
|
|
|
|
'afa_parameters' => implode( "\n", $parameters )
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-01-23 19:23:19 +00:00
|
|
|
$actionsRows[] = $thisRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a history row
|
2017-06-15 14:23:16 +00:00
|
|
|
$afh_row = [];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( AbuseFilter::$history_mappings as $af_col => $afh_col ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$afh_row[$afh_col] = $newRow[$af_col];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions
|
2017-06-15 14:23:16 +00:00
|
|
|
$displayActions = [];
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $actions as $action ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$displayActions[$action['action']] = $action['parameters'];
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$afh_row['afh_actions'] = serialize( $displayActions );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-26 22:31:02 +00:00
|
|
|
$afh_row['afh_changed_fields'] = implode( ',', $differences );
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Flags
|
2017-06-15 14:23:16 +00:00
|
|
|
$flags = [];
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $newRow['af_hidden'] ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags[] = 'hidden';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $newRow['af_enabled'] ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags[] = 'enabled';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $newRow['af_deleted'] ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$flags[] = 'deleted';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $newRow['af_global'] ) {
|
2009-03-30 06:12:12 +00:00
|
|
|
$flags[] = 'global';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
$afh_row['afh_flags'] = implode( ',', $flags );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$afh_row['afh_filter'] = $new_id;
|
2010-10-29 21:55:29 +00:00
|
|
|
$afh_row['afh_id'] = $dbw->nextSequenceValue( 'abuse_filter_af_id_seq' );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Do the update
|
|
|
|
$dbw->insert( 'abuse_filter_history', $afh_row, __METHOD__ );
|
2009-03-11 07:12:42 +00:00
|
|
|
$history_id = $dbw->insertId();
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $filter != 'new' ) {
|
|
|
|
$dbw->delete(
|
|
|
|
'abuse_filter_action',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'afa_filter' => $filter ],
|
2010-08-19 21:12:09 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
$dbw->insert( 'abuse_filter_action', $actionsRows, __METHOD__ );
|
|
|
|
|
2015-10-08 05:54:58 +00:00
|
|
|
$dbw->endAtomic( __METHOD__ );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-08-10 17:05:27 +00:00
|
|
|
// Invalidate cache if this was a global rule
|
|
|
|
if ( $wasGlobal || $newRow['af_global'] ) {
|
2012-08-03 21:55:35 +00:00
|
|
|
$group = 'default';
|
|
|
|
if ( isset( $newRow['af_group'] ) && $newRow['af_group'] != '' ) {
|
|
|
|
$group = $newRow['af_group'];
|
|
|
|
}
|
|
|
|
|
2015-05-13 05:46:33 +00:00
|
|
|
$globalRulesKey = AbuseFilter::getGlobalRulesKey( $group );
|
|
|
|
ObjectCache::getMainWANInstance()->touchCheckKey( $globalRulesKey );
|
2012-08-03 21:55:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 07:12:42 +00:00
|
|
|
// Logging
|
2017-10-16 11:19:30 +00:00
|
|
|
$subtype = $filter === 'new' ? 'create' : 'modify';
|
|
|
|
$logEntry = new ManualLogEntry( 'abusefilter', $subtype );
|
2016-06-04 13:33:32 +00:00
|
|
|
$logEntry->setPerformer( $user );
|
|
|
|
$logEntry->setTarget( $this->getTitle( $new_id ) );
|
|
|
|
$logEntry->setParameters( [
|
|
|
|
'historyId' => $history_id,
|
|
|
|
'newId' => $new_id
|
|
|
|
] );
|
|
|
|
$logid = $logEntry->insert();
|
|
|
|
$logEntry->publish( $logid );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2015-04-29 22:42:14 +00:00
|
|
|
// Purge the tag list cache so the fetchAllTags hook applies tag changes
|
2009-01-30 23:24:29 +00:00
|
|
|
if ( isset( $actions['tag'] ) ) {
|
2015-03-17 13:00:14 +00:00
|
|
|
AbuseFilterHooks::purgeTagCache();
|
2009-01-30 23:24:29 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-04-08 13:51:54 +00:00
|
|
|
AbuseFilter::resetFilterProfile( $new_id );
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->redirect(
|
2013-10-06 02:30:37 +00:00
|
|
|
$this->getTitle()->getLocalURL(
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2013-10-06 02:30:37 +00:00
|
|
|
'result' => 'success',
|
|
|
|
'changedfilter' => $new_id,
|
|
|
|
'changeid' => $history_id,
|
2017-06-15 14:23:16 +00:00
|
|
|
]
|
2013-10-06 02:30:37 +00:00
|
|
|
)
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
} else {
|
2017-04-07 19:23:11 +00:00
|
|
|
if ( $tokenMatches ) {
|
|
|
|
// lost rights meanwhile
|
|
|
|
$out->addWikiMsg( 'abusefilter-edit-notallowed' );
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $history_id ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg(
|
2016-12-02 18:05:36 +00:00
|
|
|
'abusefilter-edit-oldwarning', $history_id, $filter );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-12-02 18:05:36 +00:00
|
|
|
$out->addHTML( $this->buildFilterEditor( null, $filter, $history_id ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $history_id ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg(
|
2016-12-02 18:05:36 +00:00
|
|
|
'abusefilter-edit-oldwarning', $history_id, $filter );
|
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 full form for edit filters.
|
|
|
|
* Loads data either from the database or from the HTTP request.
|
|
|
|
* The request takes precedence over the database
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param string $error An error message to show above the filter box.
|
|
|
|
* @param int $filter The filter ID
|
2018-05-25 23:31:49 +00:00
|
|
|
* @param int|null $history_id The history ID of the filter, if applicable. Otherwise null
|
2015-09-28 18:03:35 +00:00
|
|
|
* @return bool|string False if there is a failure building the editor,
|
|
|
|
* otherwise the HTML text for the editor.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function buildFilterEditor( $error, $filter, $history_id = null ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $filter === null ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the edit form
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2011-11-22 16:08:18 +00:00
|
|
|
$lang = $this->getLanguage();
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load from request OR database.
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $row, $actions ) = $this->loadRequest( $filter, $history_id );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( !$row ) {
|
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
|
|
|
|
] );
|
2012-09-02 11:07:02 +00:00
|
|
|
return false;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 10:18:25 +00:00
|
|
|
$out->addSubtitle( $this->msg(
|
2012-06-09 15:10:36 +00:00
|
|
|
$filter === 'new' ? 'abusefilter-edit-subtitle-new' : 'abusefilter-edit-subtitle',
|
2012-10-26 07:40:14 +00:00
|
|
|
$this->getLanguage()->formatNum( $filter ), $history_id
|
2017-02-05 21:56:39 +00:00
|
|
|
)->parse() );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Hide hidden filters.
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( ( ( isset( $row->af_hidden ) && $row->af_hidden ) ||
|
2009-08-07 16:13:06 +00:00
|
|
|
AbuseFilter::filterHidden( $filter ) )
|
|
|
|
&& !$this->canViewPrivate() ) {
|
2018-05-01 12:13:57 +00:00
|
|
|
return $this->msg( 'abusefilter-edit-denied' )->escaped();
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $error ) {
|
2018-04-29 17:52:45 +00:00
|
|
|
$output .= Html::errorBox( $error );
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-01 04:34:21 +00:00
|
|
|
// Read-only attribute
|
2017-06-15 14:23:16 +00:00
|
|
|
$readOnlyAttrib = [];
|
2018-04-04 21:14:25 +00:00
|
|
|
// For checkboxes
|
|
|
|
$cbReadOnlyAttrib = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2017-03-07 15:40:20 +00:00
|
|
|
$styleAttrib = [ 'style' => 'width:95%' ];
|
|
|
|
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( !$this->canEditFilter( $row ) ) {
|
2009-04-01 04:34:21 +00:00
|
|
|
$readOnlyAttrib['readonly'] = 'readonly';
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib['disabled'] = 'disabled';
|
2009-04-01 04:34:21 +00:00
|
|
|
}
|
2009-01-23 19:23:19 +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'] =
|
2015-09-28 18:03:35 +00:00
|
|
|
$this->mFilter == 'new' ?
|
2018-05-01 12:13:57 +00:00
|
|
|
$this->msg( 'abusefilter-edit-new' )->escaped() :
|
2015-09-28 18:03:35 +00:00
|
|
|
$lang->formatNum( $filter );
|
2009-10-07 13:57:06 +00:00
|
|
|
$fields['abusefilter-edit-description'] =
|
|
|
|
Xml::input(
|
|
|
|
'wpFilterDescription',
|
|
|
|
45,
|
2018-05-31 18:53:03 +00:00
|
|
|
$row->af_public_comments ?? '',
|
2017-03-07 15:40:20 +00:00
|
|
|
array_merge( $readOnlyAttrib, $styleAttrib )
|
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 ) {
|
2012-05-06 06:44:45 +00:00
|
|
|
$groupSelector = new XmlSelect(
|
|
|
|
'wpFilterGroup',
|
2012-06-06 05:18:31 +00:00
|
|
|
'mw-abusefilter-edit-group-input',
|
2012-05-06 06:44:45 +00:00
|
|
|
'default'
|
|
|
|
);
|
|
|
|
|
2012-09-27 10:10:10 +00:00
|
|
|
if ( isset( $row->af_group ) && $row->af_group ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
$groupSelector->setDefault( $row->af_group );
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 21:47:33 +00:00
|
|
|
foreach ( $validGroups as $group ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
$groupSelector->addOption( AbuseFilter::nameGroup( $group ), $group );
|
2012-05-06 06:44:45 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 13:09:03 +00:00
|
|
|
if ( !empty( $readOnlyAttrib ) ) {
|
|
|
|
$groupSelector->setAttribute( 'disabled', 'disabled' );
|
|
|
|
}
|
|
|
|
|
2012-05-06 06:44:45 +00:00
|
|
|
$fields['abusefilter-edit-group'] = $groupSelector->getHTML();
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
// Hit count display
|
2016-11-14 14:04:31 +00:00
|
|
|
if ( !empty( $row->af_hit_count ) && $user->isAllowed( 'abusefilter-log-detail' ) ) {
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $filter !== 'new' ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
// Statistics
|
2016-04-13 18:06:24 +00:00
|
|
|
$stash = ObjectCache::getMainStashInstance();
|
2017-01-01 20:11:27 +00:00
|
|
|
$matches_count = (int)$stash->get( AbuseFilter::filterMatchesKey( $filter ) );
|
|
|
|
$total = (int)$stash->get( AbuseFilter::filterUsedKey( $row->af_group ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $total > 0 ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
$matches_percent = sprintf( '%.2f', 100 * $matches_count / $total );
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $this->getConfig()->get( 'AbuseFilterProfile' ) ) {
|
2016-04-08 16:22:39 +00:00
|
|
|
list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter );
|
|
|
|
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status-profile' )
|
|
|
|
->numParams( $total, $matches_count, $matches_percent, $timeProfile, $condProfile )
|
|
|
|
->escaped();
|
|
|
|
} else {
|
|
|
|
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' )
|
|
|
|
->numParams( $total, $matches_count, $matches_percent )
|
2017-02-05 21:56:39 +00:00
|
|
|
->parse();
|
2016-04-08 16:22:39 +00:00
|
|
|
}
|
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,
|
|
|
|
'wpFilterRules',
|
2018-04-08 15:57:23 +00:00
|
|
|
true
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
|
|
|
$fields['abusefilter-edit-notes'] = Xml::textarea(
|
|
|
|
'wpFilterNotes',
|
|
|
|
( isset( $row->af_comments ) ? $row->af_comments . "\n" : "\n" ),
|
2014-01-10 14:39:12 +00:00
|
|
|
40, 15,
|
2012-09-02 11:07:02 +00:00
|
|
|
$readOnlyAttrib
|
|
|
|
);
|
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 );
|
|
|
|
$throttledActions = array_intersect_key(
|
|
|
|
array_flip( $filterActions ),
|
2018-03-10 21:47:33 +00:00
|
|
|
array_filter( $this->getConfig()->get( 'AbuseFilterRestrictions' ) )
|
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 ) {
|
|
|
|
return $this->msg( 'abusefilter-action-' . $filterAction )->text();
|
|
|
|
},
|
|
|
|
array_keys( $throttledActions )
|
|
|
|
);
|
|
|
|
|
|
|
|
$flags .= $out->parse(
|
2018-02-21 14:20:15 +00:00
|
|
|
Html::warningBox(
|
|
|
|
$this->msg( 'abusefilter-edit-throttled-warning' )
|
|
|
|
->plaintextParams( $lang->commaList( $throttledActions ) )
|
2018-03-02 19:22:18 +00:00
|
|
|
->escaped()
|
2018-02-21 14:20:15 +00:00
|
|
|
)
|
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-05-05 12:35:01 +00:00
|
|
|
$localReadOnlyAttrib = [];
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2012-09-12 15:31:24 +00:00
|
|
|
if ( $checkboxId == 'global' && !$this->canEditGlobal() ) {
|
2018-05-05 12:35:01 +00:00
|
|
|
$localReadOnlyAttrib['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
|
|
|
|
if ( $checkboxId == 'deleted' && $row->af_enabled == 1 ) {
|
2018-05-05 12:35:01 +00:00
|
|
|
$localReadOnlyAttrib['disabled'] = 'disabled';
|
2018-05-02 16:59:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 12:35:01 +00:00
|
|
|
$readOnly = array_merge( $cbReadOnlyAttrib, $localReadOnlyAttrib );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( $message )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$postVar,
|
|
|
|
$postVar,
|
2018-05-31 18:53:03 +00:00
|
|
|
$row->$dbField ?? false,
|
2018-05-05 12:35:01 +00:00
|
|
|
$readOnly
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
$checkbox = Xml::tags( 'p', null, $checkbox );
|
|
|
|
$flags .= $checkbox;
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$fields['abusefilter-edit-flags'] = $flags;
|
2009-01-30 19:30:51 +00:00
|
|
|
$tools = '';
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $filter != 'new' ) {
|
2016-12-16 20:08:52 +00:00
|
|
|
if ( $user->isAllowed( 'abusefilter-revert' ) ) {
|
|
|
|
$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
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-07 19:23:11 +00:00
|
|
|
if ( $this->canEdit() ) {
|
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 );
|
|
|
|
$userName = $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' )
|
|
|
|
->rawParams(
|
|
|
|
$lang->timeanddate( $row->af_timestamp, true ),
|
|
|
|
$userLink,
|
|
|
|
$lang->date( $row->af_timestamp, true ),
|
|
|
|
$lang->time( $row->af_timestamp, true ),
|
|
|
|
$userName
|
|
|
|
)->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-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
// Add export
|
2017-06-15 14:23:16 +00:00
|
|
|
$exportText = FormatJson::encode( [ 'row' => $row, 'actions' => $actions ] );
|
|
|
|
$tools .= Xml::tags( 'a', [ 'href' => '#', 'id' => 'mw-abusefilter-export-link' ],
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-export' )->parse() );
|
2009-04-23 04:23:56 +00:00
|
|
|
$tools .= Xml::element( 'textarea',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'readonly' => 'readonly', 'id' => 'mw-abusefilter-export' ],
|
2009-10-07 13:57:06 +00:00
|
|
|
$exportText
|
|
|
|
);
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-04-23 04:23:56 +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
|
|
|
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( $this->canEditFilter( $row ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$form .= Xml::submitButton(
|
|
|
|
$this->msg( 'abusefilter-edit-save' )->text(),
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'accesskey' => 's' ]
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$form = Xml::tags( 'form',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'action' => $this->getTitle( $filter )->getFullURL(),
|
|
|
|
'method' => 'post'
|
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
|
|
|
|
|
|
|
$output .= $form;
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* @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
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function buildConsequenceEditor( $row, $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 => $_ ) {
|
2018-04-18 14:29:13 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2015-09-28 18:03:35 +00:00
|
|
|
$params = $actions[$action]['parameters'];
|
2018-04-18 14:29:13 +00:00
|
|
|
Wikimedia\restoreWarnings();
|
2010-02-13 14:10:36 +00:00
|
|
|
$output .= $this->buildConsequenceSelector(
|
2015-09-28 18:03:35 +00:00
|
|
|
$action, $setActions[$action], $params, $row );
|
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 array $parameters Action parameters
|
|
|
|
* @param stdClass $row abuse_filter row object
|
2012-06-06 05:18:31 +00:00
|
|
|
* @return string
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function buildConsequenceSelector( $action, $set, $parameters, $row ) {
|
2018-03-10 21:47:33 +00:00
|
|
|
$config = $this->getConfig();
|
|
|
|
$actions = $config->get( 'AbuseFilterActions' );
|
|
|
|
if ( empty( $actions[$action] ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
return '';
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$readOnlyAttrib = [];
|
2018-04-04 21:14:25 +00:00
|
|
|
// For checkboxes
|
|
|
|
$cbReadOnlyAttrib = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-07-09 13:35:06 +00:00
|
|
|
if ( !$this->canEditFilter( $row ) ) {
|
2009-04-01 04:34:21 +00:00
|
|
|
$readOnlyAttrib['readonly'] = 'readonly';
|
2009-07-03 13:54:08 +00:00
|
|
|
$cbReadOnlyAttrib['disabled'] = 'disabled';
|
2009-04-01 04:34:21 +00:00
|
|
|
}
|
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 '';
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleSettings = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-throttle' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpFilterActionThrottle',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'class' => 'mw-abusefilter-action-checkbox' ] + $cbReadOnlyAttrib );
|
|
|
|
$throttleFields = [];
|
2009-01-23 19:23:44 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $set ) {
|
2009-01-23 19:23:44 +00:00
|
|
|
array_shift( $parameters );
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleRate = explode( ',', $parameters[0] );
|
2009-01-23 19:23:44 +00:00
|
|
|
$throttleCount = $throttleRate[0];
|
|
|
|
$throttlePeriod = $throttleRate[1];
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleGroups = implode( "\n", array_slice( $parameters, 1 ) );
|
2009-01-23 19:23:44 +00:00
|
|
|
} else {
|
|
|
|
$throttleCount = 3;
|
|
|
|
$throttlePeriod = 60;
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-01-23 19:23:44 +00:00
|
|
|
$throttleGroups = "user\n";
|
|
|
|
}
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-count'] =
|
2009-04-01 04:34:21 +00:00
|
|
|
Xml::input( 'wpFilterThrottleCount', 20, $throttleCount, $readOnlyAttrib );
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-period'] =
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-throttle-seconds' )
|
|
|
|
->rawParams( Xml::input( 'wpFilterThrottlePeriod', 20, $throttlePeriod,
|
|
|
|
$readOnlyAttrib )
|
|
|
|
)->parse();
|
2009-10-07 13:57:06 +00:00
|
|
|
$throttleFields['abusefilter-edit-throttle-groups'] =
|
|
|
|
Xml::textarea( 'wpFilterThrottleGroups', $throttleGroups . "\n",
|
2009-04-01 04:34:21 +00:00
|
|
|
40, 5, $readOnlyAttrib );
|
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' ],
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::buildForm( $throttleFields )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:40:15 +00:00
|
|
|
return $throttleSettings;
|
2009-01-23 19:23:44 +00:00
|
|
|
case 'warn':
|
|
|
|
$output = '';
|
2010-02-13 14:10:36 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-warn' )->text(),
|
2010-02-13 14:10:36 +00:00
|
|
|
'wpFilterActionWarn',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'class' => 'mw-abusefilter-action-checkbox' ] + $cbReadOnlyAttrib );
|
2009-01-23 19:23:44 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
2012-06-06 05:18:31 +00:00
|
|
|
if ( $set ) {
|
|
|
|
$warnMsg = $parameters[0];
|
|
|
|
} elseif (
|
|
|
|
$row &&
|
2012-09-27 10:10:10 +00:00
|
|
|
isset( $row->af_group ) && $row->af_group &&
|
2018-03-10 21:47:33 +00:00
|
|
|
isset( $config->get( 'AbuseFilterDefaultWarningMessage' )[$row->af_group] )
|
2012-06-06 05:18:31 +00:00
|
|
|
) {
|
2018-03-10 21:47:33 +00:00
|
|
|
$warnMsg = $config->get( 'AbuseFilterDefaultWarningMessage' )[$row->af_group];
|
2012-06-06 05:18:31 +00:00
|
|
|
} else {
|
|
|
|
$warnMsg = 'abusefilter-warning';
|
|
|
|
}
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-message'] =
|
2016-12-15 13:09:03 +00:00
|
|
|
$this->getExistingSelector( $warnMsg, !empty( $readOnlyAttrib ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-other-label'] =
|
2010-02-13 14:10:36 +00:00
|
|
|
Xml::input(
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpFilterWarnMessageOther',
|
|
|
|
45,
|
2014-10-04 14:53:20 +00:00
|
|
|
$warnMsg,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'id' => 'mw-abusefilter-warn-message-other' ] + $cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$previewButton = Xml::element(
|
|
|
|
'input',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'mw-abusefilter-warn-preview-button',
|
2012-09-02 11:07:02 +00:00
|
|
|
'value' => $this->msg( 'abusefilter-edit-warn-preview' )->text()
|
2017-06-15 14:23:16 +00:00
|
|
|
]
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2016-12-15 13:09:03 +00:00
|
|
|
$editButton = '';
|
|
|
|
if ( $this->getUser()->isAllowed( 'editinterface' ) ) {
|
|
|
|
$editButton .= ' ' . Xml::element(
|
|
|
|
'input',
|
|
|
|
[
|
|
|
|
'type' => 'button',
|
|
|
|
'id' => 'mw-abusefilter-warn-edit-button',
|
|
|
|
'value' => $this->msg( 'abusefilter-edit-warn-edit' )->text()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
$previewHolder = Xml::element(
|
|
|
|
'div',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'id' => 'mw-abusefilter-warn-preview' ], ''
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$warnFields['abusefilter-edit-warn-actions'] =
|
2016-12-15 13:09:03 +00:00
|
|
|
Xml::tags( 'p', null, $previewButton . $editButton ) . "\n$previewHolder";
|
2009-10-07 13:57:06 +00:00
|
|
|
$output .=
|
|
|
|
Xml::tags(
|
|
|
|
'div',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'id' => 'mw-abusefilter-warn-parameters' ],
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::buildForm( $warnFields )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:44 +00:00
|
|
|
return $output;
|
2009-01-28 19:08:18 +00:00
|
|
|
case 'tag':
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $set ) {
|
2009-01-28 19:08:18 +00:00
|
|
|
$tags = $parameters;
|
|
|
|
} else {
|
2017-06-15 14:23:16 +00:00
|
|
|
$tags = [];
|
2009-01-28 19:08:18 +00:00
|
|
|
}
|
|
|
|
$output = '';
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$checkbox = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-edit-action-tag' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpFilterActionTag',
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$set,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'class' => 'mw-abusefilter-action-checkbox' ] + $cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$tagFields['abusefilter-edit-tag-tag'] =
|
2009-04-01 04:34:21 +00:00
|
|
|
Xml::textarea( 'wpFilterTags', implode( "\n", $tags ), 40, 5, $readOnlyAttrib );
|
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' ],
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::buildForm( $tagFields )
|
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
|
|
|
|
$blockTalk = $parameters[0];
|
|
|
|
$defaultAnonDuration = $parameters[1];
|
|
|
|
$defaultUserDuration = $parameters[2];
|
|
|
|
} else {
|
|
|
|
if ( $set && count( $parameters ) === 1 ) {
|
|
|
|
// Only blocktalk available
|
|
|
|
$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
|
|
|
}
|
|
|
|
$suggestedBlocks = SpecialBlock::getSuggestedDurations();
|
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 = '';
|
|
|
|
$checkbox = Xml::checkLabel(
|
|
|
|
$this->msg( 'abusefilter-edit-action-block' )->text(),
|
|
|
|
'wpFilterActionBlock',
|
|
|
|
"mw-abusefilter-action-checkbox-block",
|
|
|
|
$set,
|
|
|
|
[ 'class' => 'mw-abusefilter-action-checkbox' ] + $cbReadOnlyAttrib );
|
|
|
|
$output .= Xml::tags( 'p', null, $checkbox );
|
2018-03-10 21:47:33 +00:00
|
|
|
if ( $config->get( 'BlockAllowsUTEdit' ) === true ) {
|
2018-02-20 12:36:32 +00:00
|
|
|
$talkCheckbox =
|
2017-08-22 18:23:01 +00:00
|
|
|
Xml::checkLabel(
|
|
|
|
$this->msg( 'abusefilter-edit-action-blocktalk' )->text(),
|
|
|
|
'wpFilterBlockTalk',
|
|
|
|
'mw-abusefilter-action-checkbox-blocktalk',
|
2018-02-20 12:36:32 +00:00
|
|
|
isset( $blockTalk ) && $blockTalk == 'blocktalk',
|
2017-08-22 18:23:01 +00:00
|
|
|
[ 'class' => 'mw-abusefilter-action-checkbox' ] + $cbReadOnlyAttrib
|
|
|
|
);
|
|
|
|
}
|
2018-02-20 12:36:32 +00:00
|
|
|
|
|
|
|
$anonDuration = new XmlSelect(
|
|
|
|
'wpBlockAnonDuration',
|
|
|
|
false,
|
|
|
|
'default'
|
|
|
|
);
|
|
|
|
$anonDuration->addOptions( $suggestedBlocks );
|
|
|
|
|
|
|
|
$userDuration = new XmlSelect(
|
|
|
|
'wpBlockUserDuration',
|
|
|
|
false,
|
|
|
|
'default'
|
|
|
|
);
|
|
|
|
$userDuration->addOptions( $suggestedBlocks );
|
|
|
|
|
|
|
|
// Set defaults
|
|
|
|
$anonDuration->setDefault( $defaultAnonDuration );
|
|
|
|
$userDuration->setDefault( $defaultUserDuration );
|
|
|
|
|
|
|
|
if ( !$this->canEditFilter( $row ) ) {
|
|
|
|
$anonDuration->setAttribute( 'disabled', 'disabled' );
|
|
|
|
$userDuration->setAttribute( 'disabled', 'disabled' );
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:21:18 +00:00
|
|
|
if ( $config->get( 'BlockAllowsUTEdit' ) === true ) {
|
|
|
|
$durations['abusefilter-edit-block-options'] = $talkCheckbox;
|
|
|
|
}
|
2018-02-20 12:36:32 +00:00
|
|
|
$durations['abusefilter-edit-block-anon-durations'] = $anonDuration->getHTML();
|
|
|
|
$durations['abusefilter-edit-block-user-durations'] = $userDuration->getHTML();
|
|
|
|
|
|
|
|
$rawOutput = Xml::buildForm( $durations );
|
|
|
|
|
|
|
|
$output .= Xml::tags(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'mw-abusefilter-block-parameters' ],
|
|
|
|
$rawOutput
|
|
|
|
);
|
|
|
|
|
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:
|
|
|
|
// abusefilter-edit-action-warn, abusefilter-edit-action-disallow
|
2017-02-13 17:36:36 +00:00
|
|
|
// abusefilter-edit-action-blockautopromote
|
2018-02-20 12:36:32 +00:00
|
|
|
// abusefilter-edit-action-degroup, abusefilter-edit-action-throttle
|
|
|
|
// abusefilter-edit-action-rangeblock, abusefilter-edit-action-tag
|
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;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$thisAction = Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( $message )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$form_field,
|
|
|
|
"mw-abusefilter-action-checkbox-$action",
|
|
|
|
$status,
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'class' => 'mw-abusefilter-action-checkbox' ] + $cbReadOnlyAttrib
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-23 19:23:44 +00:00
|
|
|
$thisAction = Xml::tags( 'p', null, $thisAction );
|
|
|
|
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
|
2012-03-11 20:51:54 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function getExistingSelector( $warnMsg, $readOnly = false ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$existingSelector = new XmlSelect(
|
|
|
|
'wpFilterWarnMessage',
|
|
|
|
'mw-abusefilter-warn-message-existing',
|
|
|
|
$warnMsg == 'abusefilter-warning' ? 'abusefilter-warning' : 'other'
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
$existingSelector->addOption( 'abusefilter-warning' );
|
|
|
|
|
2016-12-15 13:09:03 +00:00
|
|
|
if ( $readOnly ) {
|
|
|
|
$existingSelector->setAttribute( 'disabled', 'disabled' );
|
|
|
|
} else {
|
|
|
|
// Find other messages.
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-12-15 13:09:03 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'page',
|
|
|
|
[ 'page_title' ],
|
|
|
|
[
|
|
|
|
'page_namespace' => 8,
|
|
|
|
'page_title LIKE ' . $dbr->addQuotes( 'Abusefilter-warning%' )
|
|
|
|
],
|
|
|
|
__METHOD__
|
|
|
|
);
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2016-12-15 13:09:03 +00:00
|
|
|
$lang = $this->getLanguage();
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
if ( $lang->lcfirst( $row->page_title ) == $lang->lcfirst( $warnMsg ) ) {
|
|
|
|
$existingSelector->setDefault( $lang->lcfirst( $warnMsg ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $row->page_title != 'Abusefilter-warning' ) {
|
|
|
|
$existingSelector->addOption( $lang->lcfirst( $row->page_title ) );
|
|
|
|
}
|
2009-02-03 22:45:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$existingSelector->addOption( $this->msg( 'abusefilter-edit-warn-other' )->text(), 'other' );
|
2009-02-03 22:45:42 +00:00
|
|
|
|
|
|
|
return $existingSelector->getHTML();
|
|
|
|
}
|
|
|
|
|
2018-03-24 09:45:54 +00:00
|
|
|
/**
|
|
|
|
* @ToDo: Maybe we should also check if global values belong to $durations
|
|
|
|
* and determine the right point to add them if missing.
|
|
|
|
*
|
|
|
|
* @param array $durations
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected static function normalizeBlocks( $durations ) {
|
|
|
|
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.
|
|
|
|
foreach ( $durations as &$duration ) {
|
|
|
|
$currentDuration = SpecialBlock::parseExpiryInput( $duration );
|
|
|
|
$anonDuration = SpecialBlock::parseExpiryInput( $wgAbuseFilterAnonBlockDuration );
|
|
|
|
$userDuration = SpecialBlock::parseExpiryInput( $wgAbuseFilterBlockDuration );
|
|
|
|
|
|
|
|
if ( $duration !== $wgAbuseFilterBlockDuration &&
|
|
|
|
$currentDuration === $userDuration ) {
|
|
|
|
$duration = $wgAbuseFilterBlockDuration;
|
|
|
|
|
|
|
|
} elseif ( $duration !== $wgAbuseFilterAnonBlockDuration &&
|
|
|
|
$currentDuration === $anonDuration ) {
|
|
|
|
$duration = $wgAbuseFilterAnonBlockDuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $durations;
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:51:54 +00:00
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Loads filter data from the database by ID.
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param int $id The filter's ID number
|
2012-05-06 05:59:35 +00:00
|
|
|
* @return array|null Either an associative array representing the filter,
|
|
|
|
* or NULL if the filter does not exist.
|
2012-03-11 20:51:54 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function loadFilterData( $id ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $id == 'new' ) {
|
2009-01-25 04:55:02 +00:00
|
|
|
$obj = new stdClass;
|
|
|
|
$obj->af_pattern = '';
|
|
|
|
$obj->af_enabled = 1;
|
|
|
|
$obj->af_hidden = 0;
|
2009-03-30 06:12:12 +00:00
|
|
|
$obj->af_global = 0;
|
2014-05-27 13:01:34 +00:00
|
|
|
$obj->af_throttled = 0;
|
2017-06-15 14:23:16 +00:00
|
|
|
return [ $obj, [] ];
|
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
|
2017-06-15 14:23:16 +00:00
|
|
|
$actions = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
$res = $dbr->select( 'abuse_filter_action',
|
|
|
|
'*',
|
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
|
|
|
|
|
|
|
foreach ( $res as $actionRow ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
$thisAction = [];
|
2009-01-23 19:23:19 +00:00
|
|
|
$thisAction['action'] = $actionRow->afa_consequence;
|
2018-04-04 11:46:58 +00:00
|
|
|
$thisAction['parameters'] = array_filter( explode( "\n", $actionRow->afa_parameters ) );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
$actions[$actionRow->afa_consequence] = $thisAction;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
2012-05-06 05:59:35 +00:00
|
|
|
* Load filter data to show in the edit view.
|
|
|
|
* Either from the HTTP request or from the filter/history_id given.
|
|
|
|
* The HTTP request always takes precedence.
|
|
|
|
* Includes caching.
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param int $filter The filter ID being requested.
|
2018-05-25 23:31:49 +00:00
|
|
|
* @param int|null $history_id If any, the history ID being requested.
|
2012-05-06 05:59:35 +00:00
|
|
|
* @return Array with filter data if available, otherwise null.
|
|
|
|
* 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
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function loadRequest( $filter, $history_id = null ) {
|
2009-01-23 19:23:19 +00:00
|
|
|
static $row = null;
|
|
|
|
static $actions = null;
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
2009-01-23 19:23:19 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !is_null( $actions ) && !is_null( $row ) ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
return [ $row, $actions ];
|
2011-11-16 05:34:24 +00:00
|
|
|
} elseif ( $request->wasPosted() ) {
|
2018-04-04 21:14:25 +00:00
|
|
|
// Nothing, we do it all later
|
2009-01-23 19:23:19 +00:00
|
|
|
} elseif ( $history_id ) {
|
|
|
|
return $this->loadHistoryItem( $history_id );
|
|
|
|
} else {
|
|
|
|
return $this->loadFilterData( $filter );
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need some details like last editor
|
2009-10-07 13:57:06 +00:00
|
|
|
list( $row, $origActions ) = $this->loadFilterData( $filter );
|
2009-01-26 22:30:42 +00:00
|
|
|
|
|
|
|
$row->mOriginalRow = clone $row;
|
|
|
|
$row->mOriginalActions = $origActions;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
// Check for importing
|
2011-11-16 05:34:24 +00:00
|
|
|
$import = $request->getVal( 'wpImportText' );
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $import ) {
|
2014-02-27 16:38:07 +00:00
|
|
|
$data = FormatJson::decode( $import );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-06-02 12:59:05 +00:00
|
|
|
$importRow = $data->row;
|
|
|
|
$actions = wfObjectToArray( $data->actions );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$copy = [
|
2009-10-07 13:57:06 +00:00
|
|
|
'af_public_comments',
|
|
|
|
'af_pattern',
|
|
|
|
'af_comments',
|
|
|
|
'af_deleted',
|
|
|
|
'af_enabled',
|
|
|
|
'af_hidden',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $copy as $name ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
$row->$name = $importRow->$name;
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-15 14:23:16 +00:00
|
|
|
$textLoads = [
|
2009-10-07 13:57:06 +00:00
|
|
|
'af_public_comments' => 'wpFilterDescription',
|
|
|
|
'af_pattern' => 'wpFilterRules',
|
2012-05-06 06:44:45 +00:00
|
|
|
'af_comments' => 'wpFilterNotes',
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $textLoads as $col => $field ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$row->$col = trim( $request->getVal( $field ) );
|
2009-04-23 04:23:56 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-05-06 06:44:45 +00:00
|
|
|
$row->af_group = $request->getVal( 'wpFilterGroup', 'default' );
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$row->af_deleted = $request->getBool( 'wpFilterDeleted' );
|
|
|
|
$row->af_enabled = $request->getBool( 'wpFilterEnabled' ) && !$row->af_deleted;
|
|
|
|
$row->af_hidden = $request->getBool( 'wpFilterHidden' );
|
2018-03-10 21:47:33 +00:00
|
|
|
$row->af_global = $request->getBool( 'wpFilterGlobal' )
|
|
|
|
&& $this->getConfig()->get( 'AbuseFilterIsCentral' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
// Actions
|
2017-06-15 14:23:16 +00:00
|
|
|
$actions = [];
|
2018-03-10 21:47:33 +00:00
|
|
|
foreach ( array_filter( $this->getConfig()->get( 'AbuseFilterActions' ) ) as $action => $_ ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
// Check if it's set
|
2011-11-16 05:34:24 +00:00
|
|
|
$enabled = $request->getBool( 'wpFilterAction' . ucfirst( $action ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $enabled ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
$parameters = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $action == 'throttle' ) {
|
2009-04-23 04:23:56 +00:00
|
|
|
// We need to load the parameters
|
2011-11-16 05:34:24 +00:00
|
|
|
$throttleCount = $request->getIntOrNull( 'wpFilterThrottleCount' );
|
|
|
|
$throttlePeriod = $request->getIntOrNull( 'wpFilterThrottlePeriod' );
|
2010-02-13 14:10:36 +00:00
|
|
|
$throttleGroups = explode( "\n",
|
2011-11-16 05:34:24 +00:00
|
|
|
trim( $request->getText( 'wpFilterThrottleGroups' ) ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
// For now, anyway
|
|
|
|
$parameters[0] = $this->mFilter;
|
2009-04-23 04:23:56 +00:00
|
|
|
$parameters[1] = "$throttleCount,$throttlePeriod";
|
|
|
|
$parameters = array_merge( $parameters, $throttleGroups );
|
2009-10-07 13:57:06 +00:00
|
|
|
} elseif ( $action == 'warn' ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessage' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2016-01-06 20:17:41 +00:00
|
|
|
if ( $specMsg == 'other' ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$specMsg = $request->getVal( 'wpFilterWarnMessageOther' );
|
2016-01-06 20:17:41 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-23 04:23:56 +00:00
|
|
|
$parameters[0] = $specMsg;
|
2017-08-22 18:23:01 +00:00
|
|
|
} elseif ( $action == 'block' ) {
|
2018-02-20 12:36:32 +00:00
|
|
|
$parameters[0] = $request->getCheck( 'wpFilterBlockTalk' ) ?
|
2018-04-24 09:54:39 +00:00
|
|
|
'blocktalk' : 'noTalkBlockSet';
|
2018-02-20 12:36:32 +00:00
|
|
|
$parameters[1] = $request->getVal( 'wpBlockAnonDuration' );
|
|
|
|
$parameters[2] = $request->getVal( 'wpBlockUserDuration' );
|
2009-10-07 13:57:06 +00:00
|
|
|
} elseif ( $action == 'tag' ) {
|
2018-04-04 11:46:58 +00:00
|
|
|
$parameters = explode( "\n", trim( $request->getText( 'wpFilterTags' ) ) );
|
2009-04-23 04:23:56 +00:00
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$thisAction = [ 'action' => $action, 'parameters' => $parameters ];
|
2009-04-23 04:23:56 +00:00
|
|
|
$actions[$action] = $thisAction;
|
2009-01-23 19:23:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-27 18:32:17 +00:00
|
|
|
$row->af_actions = implode( ',', array_keys( array_filter( $actions ) ) );
|
|
|
|
|
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
|
|
|
/**
|
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
|
2016-04-02 22:11:29 +00:00
|
|
|
* @return array|bool False 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
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function loadHistoryItem( $id ) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-01-23 19:23:19 +00:00
|
|
|
|
|
|
|
// Load the row.
|
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 ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @return null
|
|
|
|
*/
|
2012-06-06 05:18:31 +00:00
|
|
|
protected function exposeWarningMessages() {
|
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
|
|
|
);
|
2012-06-06 05:18:31 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|