jenkins-bot has submitted this change and it was merged.

Change subject: Prevent custom warning messages for global rules
......................................................................


Prevent custom warning messages for global rules

This prevents an abuse filter admin from setting a custom warning
message (which are references to a non-translated, local wiki page),
for global filters (which can be on any wiki in any language).

bug: 45164
Change-Id: If61716053b75f45e4b70f78d3809ddd02ac6d83e
---
M AbuseFilter.i18n.php
M Views/AbuseFilterViewEdit.php
M modules/ext.abuseFilter.edit.js
3 files changed, 29 insertions(+), 0 deletions(-)

Approvals:
  Matmarex: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AbuseFilter.i18n.php b/AbuseFilter.i18n.php
index 0b3baa9..d620013 100644
--- a/AbuseFilter.i18n.php
+++ b/AbuseFilter.i18n.php
@@ -249,6 +249,7 @@
 Tags should be short, and they should not contain special characters.',
        'abusefilter-edit-notallowed' => 'You are not permitted to create or 
edit abuse filters',
        'abusefilter-edit-notallowed-global' => 'You are not permitted to 
create or edit global abuse filters',
+       'abusefilter-edit-notallowed-global-custom-msg' => 'Custom warning 
messages are not supported for global filters',
 
        // Filter editing helpers
        'abusefilter-edit-builder-select' => 'Select an option to add it at the 
cursor',
@@ -794,6 +795,7 @@
        'abusefilter-edit-bad-tags' => 'Status message for filter test.',
        'abusefilter-edit-notallowed' => 'Error message when trying to modify a 
filter while not allowed.',
        'abusefilter-edit-notallowed-global' => 'Error message when trying to 
modify a global filter while not allowed.',
+       'abusefilter-edit-notallowed-global-custom-msg' => 'Error message when 
trying to add a custom warning message to a global filter, which is not 
allowed.',
        'abusefilter-edit-builder-select' => 'Default value for dropdown menu 
that allows inserting abuse filter syntax in the filter definition field.',
        'abusefilter-edit-builder-group-op-arithmetic' => 'Group entry in 
dropdown menu.',
        'abusefilter-edit-builder-op-arithmetic-addition' => 'Abuse filter 
syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-op-arithmetic}}.',
diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php
index 8c094a4..7d83847 100644
--- a/Views/AbuseFilterViewEdit.php
+++ b/Views/AbuseFilterViewEdit.php
@@ -66,6 +66,12 @@
                                return;
                        }
 
+                       // Don't allow custom messages on global rules
+                       if ( $newRow->af_global == 1 && $request->getVal( 
'wpFilterWarnMessage' ) !== 'abusefilter-warning' ) {
+                               $out->addWikiMsg( 
'abusefilter-edit-notallowed-global-custom-msg' );
+                               return;
+                       }
+
                        $origActions = $newRow->mOriginalActions;
                        unset( $newRow->mOriginalRow );
                        unset( $newRow->mOriginalActions );
diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js
index 2629dc7..f55cfbd 100644
--- a/modules/ext.abuseFilter.edit.js
+++ b/modules/ext.abuseFilter.edit.js
@@ -238,6 +238,24 @@
                }
        }
 
+       /**
+        * Remove the options for warning messages if the filter is set to 
global
+        */
+       function toggleCustomMessages() {
+               // Use the table over here as hideDeselectedActions might alter 
the visibility of the div
+               var $warnOptions = $( '#mw-abusefilter-warn-parameters > table' 
);
+
+               if ( $( '#wpFilterGlobal' ).is( ':checked' ) ) {
+                       // It's a global filter, so use the default message and 
hide the option from the user
+                       $( '#mw-abusefilter-warn-message-existing 
option[value="abusefilter-warning"]' )
+                               .prop( 'selected', true );
+
+                       $warnOptions.hide();
+               } else {
+                       $warnOptions.show();
+               }
+       }
+
        // On ready initialization
        $( document ).ready( function() {
                $filterBox = $( '#' + mw.config.get( 'abuseFilterBoxName' ) );
@@ -256,6 +274,9 @@
                $( 'input.mw-abusefilter-action-checkbox' ).click( 
hideDeselectedActions );
                hideDeselectedActions();
 
+               $( '#wpFilterGlobal' ).change( toggleCustomMessages );
+               toggleCustomMessages();
+
                $( '#mw-abusefilter-syntaxcheck' ).click( doSyntaxCheck );
                $( '#wpFilterBuilder' ).change( addText );
                $( '#mw-abusefilter-edit-group-input' ).change( 
onFilterGroupChange );

-- 
To view, visit https://gerrit.wikimedia.org/r/70583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If61716053b75f45e4b70f78d3809ddd02ac6d83e
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Matmarex <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to