Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/295596

Change subject: Allow setting a custom message for filters that disallow actions
......................................................................

Allow setting a custom message for filters that disallow actions

We already have the code to produce the right response if a custom
message is set, but the user interface did not allow setting it.

Bug: T138435
Change-Id: Ib47810f78dcf1c8b01fd5e7dff9c5821e2447bbe
---
M Views/AbuseFilterViewEdit.php
1 file changed, 42 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter 
refs/changes/96/295596/1

diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php
index 7cee9c7..4f2dbcf 100644
--- a/Views/AbuseFilterViewEdit.php
+++ b/Views/AbuseFilterViewEdit.php
@@ -655,11 +655,17 @@
                                        array( 'disabled' => '1', 'class' => 
'mw-abusefilter-action-checkbox' ) );
                                return Xml::tags( 'p', null, $checkbox );
                        case 'warn':
+                       case 'disallow':
                                global $wgAbuseFilterDefaultWarningMessage;
                                $output = '';
+                               // abusefilter-edit-action-warn, 
abusefilter-edit-action-disallow
+                               $message = 'abusefilter-edit-action-' . $action;
+                               // wpFilterActionWarn, wpFilterActionDisallow
+                               $form_field = 'wpFilterAction' . ucfirst( 
$action );
+                               $status = $set;
                                $checkbox = Xml::checkLabel(
-                                       $this->msg( 
'abusefilter-edit-action-warn' )->text(),
-                                       'wpFilterActionWarn',
+                                       $this->msg( $message )->text(),
+                                       $form_field,
                                        
"mw-abusefilter-action-checkbox-$action",
                                        $set,
                                        array( 'class' => 
'mw-abusefilter-action-checkbox' ) + $cbReadOnlyAttrib );
@@ -667,51 +673,54 @@
                                if ( $set ) {
                                        $warnMsg = $parameters[0];
                                } elseif (
-                                       $row &&
+                                       $action === 'warn' && $row &&
                                        isset( $row->af_group ) && 
$row->af_group &&
                                        isset( 
$wgAbuseFilterDefaultWarningMessage[$row->af_group] )
                                ) {
                                        $warnMsg = 
$wgAbuseFilterDefaultWarningMessage[$row->af_group];
-                               } else {
+                               } elseif ( $action === 'warn' ) {
                                        $warnMsg = 'abusefilter-warning';
+                               } else {
+                                       $warnMsg = 'abusefilter-disallow';
                                }
 
-                               $warnFields['abusefilter-edit-warn-message'] =
-                                       $this->getExistingSelector( $warnMsg );
-                               
$warnFields['abusefilter-edit-warn-other-label'] =
+                               $warnFields["abusefilter-edit-warn-message"] =
+                                       $this->getExistingSelector( $action, 
$warnMsg );
+                               
$warnFields["abusefilter-edit-warn-other-label"] =
                                        Xml::input(
-                                               'wpFilterWarnMessageOther',
+                                               // wpFilterWarnMessageOther, 
wpFilterDisallowMessageOther
+                                               'wpFilter' . ucfirst( $action ) 
. 'MessageOther',
                                                45,
                                                $warnMsg,
-                                               array( 'id' => 
'mw-abusefilter-warn-message-other' ) + $cbReadOnlyAttrib
+                                               array( 'id' => 
"mw-abusefilter-warn-message-other" ) + $cbReadOnlyAttrib
                                        );
 
                                $previewButton = Xml::element(
                                        'input',
                                        array(
                                                'type' => 'button',
-                                               'id' => 
'mw-abusefilter-warn-preview-button',
-                                               'value' => $this->msg( 
'abusefilter-edit-warn-preview' )->text()
+                                               'id' => 
"mw-abusefilter-$action-preview-button",
+                                               'value' => $this->msg( 
"abusefilter-edit-warn-preview" )->text()
                                        )
                                );
                                $editButton = Xml::element(
                                        'input',
                                        array(
                                                'type' => 'button',
-                                               'id' => 
'mw-abusefilter-warn-edit-button',
-                                               'value' => $this->msg( 
'abusefilter-edit-warn-edit' )->text()
+                                               'id' => 
"mw-abusefilter-$action-edit-button",
+                                               'value' => $this->msg( 
"abusefilter-edit-warn-edit" )->text()
                                        )
                                );
                                $previewHolder = Xml::element(
                                        'div',
-                                       array( 'id' => 
'mw-abusefilter-warn-preview' ), ''
+                                       array( 'id' => 
"mw-abusefilter-$action-preview" ), ''
                                );
-                               $warnFields['abusefilter-edit-warn-actions'] =
+                               $warnFields["abusefilter-edit-warn-actions"] =
                                        Xml::tags( 'p', null, "$previewButton 
$editButton" ) . "\n$previewHolder";
                                $output .=
                                        Xml::tags(
                                                'div',
-                                               array( 'id' => 
'mw-abusefilter-warn-parameters' ),
+                                               array( 'id' => 
"mw-abusefilter-$action-parameters" ),
                                                Xml::buildForm( $warnFields )
                                        );
                                return $output;
@@ -742,7 +751,6 @@
                                return $output;
                        default:
                                // Give grep a chance to find the usages:
-                               // abusefilter-edit-action-warn, 
abusefilter-edit-action-disallow
                                // abusefilter-edit-action-flag, 
abusefilter-edit-action-blockautopromote
                                // abusefilter-edit-action-degroup, 
abusefilter-edit-action-block
                                // abusefilter-edit-action-throttle, 
abusefilter-edit-action-rangeblock
@@ -764,14 +772,17 @@
        }
 
        /**
-        * @param $warnMsg
+        * @param string $action
+        * @param string $warnMsg
         * @return string
         */
-       function getExistingSelector( $warnMsg ) {
+       function getExistingSelector( $action, $warnMsg ) {
+               $msg = $action === 'warn' ? 'warning' : $action;
                $existingSelector = new XmlSelect(
-                       'wpFilterWarnMessage',
+                       // wpFilterWarnMessage, wpFilterDisallowMessage
+                       'wpFilter' . ucfirst( $action ) . 'Message',
                        'mw-abusefilter-warn-message-existing',
-                       $warnMsg == 'abusefilter-warning' ? 
'abusefilter-warning' : 'other'
+                       $warnMsg == "abusefilter-$msg" ? "abusefilter-$msg" : 
'other'
                );
 
                // Find other messages.
@@ -781,12 +792,12 @@
                        array( 'page_title' ),
                        array(
                                'page_namespace' => 8,
-                               'page_title LIKE ' . $dbr->addQuotes( 
'Abusefilter-warning%' )
+                               'page_title LIKE ' . $dbr->addQuotes( 
"Abusefilter-$msg%" )
                        ),
                        __METHOD__
                );
 
-               $existingSelector->addOption( 'abusefilter-warning' );
+               $existingSelector->addOption( "abusefilter-$msg" );
 
                $lang = $this->getLanguage();
                foreach ( $res as $row ) {
@@ -794,7 +805,7 @@
                                $existingSelector->setDefault( $lang->lcfirst( 
$warnMsg ) );
                        }
 
-                       if ( $row->page_title != 'Abusefilter-warning' ) {
+                       if ( $row->page_title != "Abusefilter-$msg" ) {
                                $existingSelector->addOption( $lang->lcfirst( 
$row->page_title ) );
                        }
                }
@@ -972,6 +983,13 @@
                                                        $specMsg = 
$request->getVal( 'wpFilterWarnMessageOther' );
 
                                                $parameters[0] = $specMsg;
+                                       } elseif ( $action == 'disallow' ) {
+                                               $specMsg = $request->getVal( 
'wpFilterDisallowMessage' );
+
+                                               if ( $specMsg == 'other' )
+                                                       $specMsg = 
$request->getVal( 'wpFilterDisallowMessageOther' );
+
+                                               $parameters[0] = $specMsg;
                                        } elseif ( $action == 'tag' ) {
                                                $parameters = explode( "\n", 
$request->getText( 'wpFilterTags' ) );
                                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib47810f78dcf1c8b01fd5e7dff9c5821e2447bbe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to