Add requirement for title and pattern fields

Currently users can save filters without title or pattern. This
shouldn't be allowed since it leads to lack of clarity. The check is
only performed server-side, since when implementing Ace editor we won't
be able to (easily) add a pure HTML requirement for the pattern field.

Bug: T173947
Change-Id: I1a0418b87cdb1ff423238fcdf1c743930500e605
This commit is contained in:
Daimona Eaytoy 2018-03-09 13:20:33 +01:00
parent 6a518a7d6b
commit e53811ecb3
3 changed files with 29 additions and 1 deletions

View file

@ -164,6 +164,7 @@
"abusefilter-edit-id": "Filter ID:",
"abusefilter-edit-switch-editor": "Switch editor",
"abusefilter-edit-description": "Description:\n:''(publicly viewable)''",
"abusefilter-edit-field-description": "description",
"abusefilter-edit-group": "Filter group:",
"abusefilter-edit-flags": "Flags:",
"abusefilter-edit-enabled": "Enable this filter",
@ -171,6 +172,7 @@
"abusefilter-edit-hidden": "Hide details of this filter from public view",
"abusefilter-edit-global": "Global filter",
"abusefilter-edit-rules": "Conditions:",
"abusefilter-edit-field-conditions": "conditions",
"abusefilter-edit-notes": "Notes:",
"abusefilter-edit-lastmod": "Filter last modified:",
"abusefilter-edit-lastmod-text": "$1 by $2",
@ -205,6 +207,7 @@
"abusefilter-edit-done-subtitle": "Filter edited",
"abusefilter-edit-done": "[[Special:AbuseFilter/history/$1/diff/prev/$2|Your changes]] to [[Special:AbuseFilter/$1|filter $3]] have been saved.",
"abusefilter-edit-badsyntax": "There is a syntax error in the filter you specified.\nThe output from the parser was: <pre>$1</pre>",
"abusefilter-edit-missingfields": "The following fields are required and must be filled: $1",
"abusefilter-edit-restricted": "You cannot edit this filter, because it contains one or more restricted actions.\nPlease ask a user with permission to add restricted actions to make the change for you.",
"abusefilter-edit-viewhistory": "View this filter's history",
"abusefilter-edit-history": "History:",

View file

@ -196,6 +196,7 @@
"abusefilter-edit-id": "Field label for filter identifier.\n{{Identical|Filter ID}}",
"abusefilter-edit-switch-editor": "Button to switch between classic editor and Ace editor",
"abusefilter-edit-description": "Field label for publicly viewable abuse filter description.",
"abusefilter-edit-field-description": "Name of the filter public description, to be used in error message.",
"abusefilter-edit-group": "\"Filter group\" a filter is in. Filters can be grouped, and only one group is run per action. The default group, \"default\", will be used in 99% of cases.",
"abusefilter-edit-flags": "Field label for abuse filter flags (checkboxes for \"hidden\", \"enabled\" and \"deleted\").\n{{Identical|Flag}}",
"abusefilter-edit-enabled": "Checkbox label for a filter flag.",
@ -203,6 +204,7 @@
"abusefilter-edit-hidden": "Checkbox label for a filter flag.",
"abusefilter-edit-global": "Checkbox label for a filter flag.",
"abusefilter-edit-rules": "Field label for filter rules.\n{{Identical|Condition}}",
"abusefilter-edit-field-conditions": "Description for filter rules, to be used in error message.\n{{Identical|Condition}}",
"abusefilter-edit-notes": "Field label for filter notes.\n{{Identical|Note}}",
"abusefilter-edit-lastmod": "Field label for filter's last modified timestamp.",
"abusefilter-edit-lastmod-text": "This message is used on [[Special:AbuseFilter]] to indicate the last modified date, time and user for existing rules.\n\nParameters:\n* $1 - a time and date (duplicated in $3 and $4)\n* $2 - a link to a user page with a user name as link text, followed by a series of related links\n* $3 - (Optional) the date\n* $4 - (Optional) the time\n* $5 - (Optional) the username, for GENDER support",
@ -237,6 +239,7 @@
"abusefilter-edit-done-subtitle": "Page subtitle when as filter was edited and saved.",
"abusefilter-edit-done": "Text displayed to a user after editing a filter. Parameters:\n* $1 - a filter ID\n* $2 - the ID of the change itself\n* $3 - localized filter ID",
"abusefilter-edit-badsyntax": "Message to warn a user that a filter could not be edited for a given reason. Parameters:\n* $1 is a parser error text.",
"abusefilter-edit-missingfields": "Message to warn a user that a filter could not be edited for a given reason. Parameters:\n* $1 is a list of missing fields.",
"abusefilter-edit-restricted": "Message to warn a user that a filter could not be edited for a given reason.",
"abusefilter-edit-viewhistory": "Link description for link that leads to a revision overview for a filter.",
"abusefilter-edit-history": "Field label for {{msg-mw|abusefilter-edit-viewhistory}}.\n{{Identical|History}}",

View file

@ -104,6 +104,28 @@ class AbuseFilterViewEdit extends AbuseFilterView {
);
return;
}
// 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;
}
$dbw = wfGetDB( DB_MASTER );
@ -491,7 +513,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
$readOnlyAttrib
);
// Build checkboxen
// Build checkboxes
$checkboxes = [ 'hidden', 'enabled', 'deleted' ];
$flags = '';