mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-09-24 10:48:17 +00:00
Avoid keeping superfluous row properties
Most of them are overwritten either in ViewEdit::loadRequest or AbuseFilter::saveFilter. af_hit_count and af_throttled are actually relevant for the old version, so list them explicitly. And also add default af_group and af_global, which are later read, for import action. Depends-On: Iabd0ae5b18571f8cad44ef2d86bcf2519e7f95ba Change-Id: Ie9aae938cca06e38a7a834a3f74f3e8735ab01ee
This commit is contained in:
parent
53b9f38888
commit
102789f62a
|
@ -1064,19 +1064,23 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
|
||||
/**
|
||||
* Loads filter data from the database by ID.
|
||||
* @param int $id The filter's ID number
|
||||
* @return array|null Either an associative array representing the filter,
|
||||
* @param int|string $id The filter's ID number, or 'new'
|
||||
* @return array|null Either a [ DB row, actions ] array representing the filter,
|
||||
* or NULL if the filter does not exist.
|
||||
*/
|
||||
public function loadFilterData( $id ) {
|
||||
if ( $id === 'new' ) {
|
||||
$obj = new stdClass;
|
||||
$obj->af_pattern = '';
|
||||
$obj->af_enabled = 1;
|
||||
$obj->af_hidden = 0;
|
||||
$obj->af_global = 0;
|
||||
$obj->af_throttled = 0;
|
||||
return [ $obj, [] ];
|
||||
return [
|
||||
(object)[
|
||||
'af_pattern' => '',
|
||||
'af_enabled' => 1,
|
||||
'af_hidden' => 0,
|
||||
'af_global' => 0,
|
||||
'af_throttled' => 0,
|
||||
'af_hit_count' => 0
|
||||
],
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
// Load from master to avoid unintended reversions where there's replication lag.
|
||||
|
@ -1149,7 +1153,8 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
/**
|
||||
* Load data from the already-POSTed HTTP request.
|
||||
*
|
||||
* @throws BadMethodCallException If called without the request being POSTed
|
||||
* @throws BadMethodCallException If called without the request being POSTed or when trying
|
||||
* to import a filter but $filter is not 'new'
|
||||
* @param int|string $filter The filter ID being requested.
|
||||
* @return array
|
||||
*/
|
||||
|
@ -1161,19 +1166,32 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
}
|
||||
|
||||
// We need some details like last editor
|
||||
list( $row, $origActions ) = $this->loadFilterData( $filter );
|
||||
list( $origRow, $origActions ) = $this->loadFilterData( $filter );
|
||||
|
||||
$row->mOriginalRow = clone $row;
|
||||
// Default values
|
||||
$row = (object)[
|
||||
'af_throttled' => $origRow->af_throttled,
|
||||
'af_hit_count' => $origRow->af_hit_count
|
||||
];
|
||||
$row->mOriginalRow = $origRow;
|
||||
$row->mOriginalActions = $origActions;
|
||||
|
||||
// Check for importing
|
||||
$import = $request->getVal( 'wpImportText' );
|
||||
if ( $import ) {
|
||||
if ( $filter !== 'new' ) {
|
||||
// Sanity
|
||||
throw new BadMethodCallException( __METHOD__ . ' called for importing on existing filter.' );
|
||||
}
|
||||
$data = FormatJson::decode( $import );
|
||||
|
||||
$importRow = $data->row;
|
||||
$actions = wfObjectToArray( $data->actions );
|
||||
|
||||
// Some more default values
|
||||
$row->af_group = 'default';
|
||||
$row->af_global = 0;
|
||||
|
||||
$copy = [
|
||||
'af_public_comments',
|
||||
'af_pattern',
|
||||
|
|
|
@ -112,7 +112,8 @@ class AbuseFilterSaveTest extends MediaWikiTestCase {
|
|||
'af_enabled' => 1,
|
||||
'af_hidden' => 0,
|
||||
'af_global' => 0,
|
||||
'af_throttled' => 0
|
||||
'af_throttled' => 0,
|
||||
'af_hit_count' => 0,
|
||||
],
|
||||
[]
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue