diff --git a/AbuseFilter.php b/AbuseFilter.php index 51e780b72..67b7416cf 100644 --- a/AbuseFilter.php +++ b/AbuseFilter.php @@ -173,3 +173,8 @@ $wgAbuseFilterCustomActionsHandlers = array(); // Valid "filter groups" – used for applying edit filters to certain types of actions $wgAbuseFilterValidGroups = array('default'); + +// Default warning messages, per filter group +$wgAbuseFilterDefaultWarningMessage = array( + 'default' => 'abusefilter-warning', +); diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php index 1c75ac254..a0e04bf91 100644 --- a/Views/AbuseFilterViewEdit.php +++ b/Views/AbuseFilterViewEdit.php @@ -18,6 +18,9 @@ class AbuseFilterViewEdit extends AbuseFilterView { $filter = $this->mFilter; $history_id = $this->mHistoryID; + // Add default warning messages + $this->exposeWarningMessages(); + if ( $filter == 'new' && !$user->isAllowed( 'abusefilter-modify' ) ) { $out->addWikiMsg( 'abusefilter-edit-notallowed' ); return; @@ -307,7 +310,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { if ( count($wgAbuseFilterValidGroups) > 1 ) { $groupSelector = new XmlSelect( 'wpFilterGroup', - 'mw-abusefilter-edit-group', + 'mw-abusefilter-edit-group-input', 'default' ); @@ -509,21 +512,20 @@ class AbuseFilterViewEdit extends AbuseFilterView { foreach ( $wgAbuseFilterAvailableActions as $action ) { $output .= $this->buildConsequenceSelector( - $action, $setActions[$action], @$actions[$action]['parameters'] ); + $action, $setActions[$action], @$actions[$action]['parameters'], $row ); } return $output; } /** - * Builds a selector for a single AbuseFilter action. - * @param $action String identifier for the action. - * Should be in $wgAbuseFilterAvailableActions - * @param $set Whether or not the action is set. - * @param $parameters If the action is set up, the parameters for it. - * @return string HTML text for the action editor, or NULL if the $action is invalid. + * @param $action The action to build an editor for + * @param $set Whether or not the action is activated + * @param $parameters Action parameters + * @param $row abuse_filter row object + * @return string */ - function buildConsequenceSelector( $action, $set, $parameters ) { + function buildConsequenceSelector( $action, $set, $parameters, $row ) { global $wgAbuseFilterAvailableActions; if ( !in_array( $action, $wgAbuseFilterAvailableActions ) ) { @@ -592,6 +594,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { array( 'disabled' => '1', 'class' => 'mw-abusefilter-action-checkbox' ) ); return Xml::tags( 'p', null, $checkbox ); case 'warn': + global $wgAbuseFilterDefaultWarningMessage; $output = ''; $checkbox = Xml::checkLabel( wfMsg( 'abusefilter-edit-action-warn' ), @@ -600,7 +603,17 @@ class AbuseFilterViewEdit extends AbuseFilterView { $set, array( 'class' => 'mw-abusefilter-action-checkbox' ) + $cbReadOnlyAttrib ); $output .= Xml::tags( 'p', null, $checkbox ); - $warnMsg = empty( $set ) ? 'abusefilter-warning' : $parameters[0]; + if ( $set ) { + $warnMsg = $parameters[0]; + } elseif ( + $row && + $row->af_group && + isset($wgAbuseFilterDefaultWarningMessage[$row->af_group] ) + ) { + $warnMsg = $wgAbuseFilterDefaultWarningMessage[$row->af_group]; + } else { + $warnMsg = 'abusefilter-warning'; + } $warnFields['abusefilter-edit-warn-message'] = $this->getExistingSelector( $warnMsg ); @@ -922,4 +935,9 @@ class AbuseFilterViewEdit extends AbuseFilterView { return AbuseFilter::translateFromHistory( $row ); } + + protected function exposeWarningMessages() { + global $wgOut, $wgAbuseFilterDefaultWarningMessage; + $wgOut->addJsConfigVars( 'wgAbuseFilterDefaultWarningMessage', $wgAbuseFilterDefaultWarningMessage ); + } } diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js index b392ab37a..9a60c7c6a 100644 --- a/modules/ext.abuseFilter.edit.js +++ b/modules/ext.abuseFilter.edit.js @@ -1,7 +1,7 @@ /** * AbuseFilter editing stuff */ -new ( function( $, mw ) { +( function( $, mw ) { /** * Filter textarea * @@ -160,9 +160,11 @@ new ( function( $, mw ) { $.get( mw.config.get('wgScript'), { title: 'MediaWiki:' + message, action: 'render' - }, function( data ) { - $( '#mw-abusefilter-warn-preview' ).html( data ) - } ); + }, + function( data ) { + $( '#mw-abusefilter-warn-preview' ).html( data ); + } + ); }; /** @@ -198,9 +200,22 @@ new ( function( $, mw ) { var $exportBox = $( '#mw-abusefilter-export' ); $( '#mw-abusefilter-export-link' ).toggle( function() { - $exportBox.show() + $exportBox.show(); }, function() { $exportBox.hide(); } ); + + $('#mw-abusefilter-edit-group-input').change( function() { + var newVal = mw.config.get('wgAbuseFilterDefaultWarningMessage')[$(this).val()]; + if ( !$('#mw-abusefilter-action-warn-checkbox').is(':checked') ) { + if ($('#mw-abusefilter-warn-message-existing').find("option[value='"+newVal+"']").length ) { + $('#mw-abusefilter-warn-message-existing').val(newVal); + $('#mw-abusefilter-warn-message-other').val(''); + } else { + $('#mw-abusefilter-warn-message-existing').val('other'); + $('#mw-abusefilter-warn-message-other').val(newVal); + } + } + }); } ); })( jQuery, mediaWiki );