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

Change subject: Adding optional confirmation process to Thanks workflow
......................................................................


Adding optional confirmation process to Thanks workflow

If the new $wgThanksConfirmationRequired global variable is true,
require users to confirm that they want to send thanks.

Bug: 47658
Change-Id: I4663844a324a2797917b027ceb1c8c07b1e180d5
---
M Thanks.hooks.php
M Thanks.i18n.php
M Thanks.php
M modules/ext.thanks.thank.js
4 files changed, 65 insertions(+), 11 deletions(-)

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



diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index 6e752d0..d33221f 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -79,11 +79,14 @@
         * @return bool true in all cases
         */
        public static function onPageHistoryBeforeList( &$page, $context ) {
+               global $wgThanksConfirmationRequired;
                if ( class_exists( 'EchoNotifier' )
                        && $context->getUser()->isLoggedIn()
                ) {
                        // Load the module for the thank links
                        $context->getOutput()->addModules( array( 'ext.thanks' 
) );
+                       $context->getOutput()->addJsConfigVars( 
'thanks-confirmation-required',
+                               $wgThanksConfirmationRequired );
                }
                return true;
        }
@@ -97,11 +100,14 @@
         * @return bool true in all cases
         */
        public static function onDiffViewHeader( $diff, $oldRev, $newRev ) {
+               global $wgThanksConfirmationRequired;
                if ( class_exists( 'EchoNotifier' )
                        && $diff->getUser()->isLoggedIn()
                ) {
                        // Load the module for the thank link
                        $diff->getOutput()->addModules( array( 'ext.thanks' ) );
+                       $diff->getOutput()->addJsConfigVars( 
'thanks-confirmation-required',
+                               $wgThanksConfirmationRequired );
                }
                return true;
        }
diff --git a/Thanks.i18n.php b/Thanks.i18n.php
index c889b6f..83c99d4 100644
--- a/Thanks.i18n.php
+++ b/Thanks.i18n.php
@@ -18,6 +18,7 @@
        'thanks-error-invalidrevision' => 'Revision ID is not valid.',
        'thanks-error-ratelimited' => "You've exceeded your rate limit. Please 
wait some time and try again.",
        'thanks-thank-tooltip' => 'Send a thank you notification to this user',
+       'thanks-confirmation' => 'Are you sure you want to {{GENDER:$1|thank}} 
$2 for this edit?',
        'echo-pref-subscription-edit-thank' => 'Thanks me for my edit',
        'echo-pref-tooltip-edit-thank' => 'Notify me when someone thanks me for 
an edit I made.',
        'echo-category-title-edit-thank' => 'Thanks',
@@ -57,6 +58,9 @@
        'thanks-error-invalidrevision' => 'Error message that is displayed when 
the revision ID is not valid',
        'thanks-error-ratelimited' => 'Error message that is displayed when 
user exceeds rate limit',
        'thanks-thank-tooltip' => 'Tooltip that appears when a user hovers over 
the "thank" link',
+       'thanks-confirmation' => 'A confirmation message to make sure the user 
actually wants to send thanks to another user. Parameters:
+* $1 is the user sending the thanks. Can be used for GENDER.
+* $2 is the username of the recipient. Cannot be used for GENDER.',
        'echo-pref-subscription-edit-thank' => 'Option for getting 
notifications when someone thanks the user for their edit.
 
 This is the conclusion of the sentence begun by the header: 
{{msg-mw|Prefs-echosubscriptions}}.',
diff --git a/Thanks.php b/Thanks.php
index fab30d5..64d50b8 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -69,11 +69,15 @@
                'thanks-error-undefined',
                'thanks-error-invalidrevision',
                'thanks-error-ratelimited',
+               'thanks-confirmation',
+               'ok',
+               'cancel',
        ),
        'dependencies' => array(
                'mediawiki.jqueryMsg',
                'mediawiki.api',
                'user.tokens',
+               'jquery.ui.dialog',
        ),
        'localBasePath' => $dir . '/modules',
        'remoteExtPath' => 'Thanks/modules',
@@ -91,6 +95,9 @@
 // Whether or not thanks should be logged in Special:Log
 $wgThanksLogging = true;
 
+// Whether or not confirmation is required for sending thanks
+$wgThanksConfirmationRequired = true;
+
 // Set how many thanks can be sent per minute by a single user (default 10)
 $wgRateLimits += array(
        'thanks-notification' => array( 'user' => array( 10, 60 ) ),
diff --git a/modules/ext.thanks.thank.js b/modules/ext.thanks.thank.js
index 117ad7a..349dd56 100644
--- a/modules/ext.thanks.thank.js
+++ b/modules/ext.thanks.thank.js
@@ -1,6 +1,7 @@
 ( function ( $, mw ) {
        'use strict';
 
+       // Keep track of which revisions the user has already thanked for
        var thanked = {
                maxHistory: 100,
                load: function() {
@@ -38,17 +39,35 @@
                } );
        };
 
-       if ( $.isReady ) {
-               // This condition is required for soft-reloads
-               // to also trigger the reloadThankedState
-               reloadThankedState();
-       } else {
-               $( document ).ready( reloadThankedState );
-       }
-
-       $( 'a.mw-thanks-thank-link' ).click( function( e ) {
-               var source, $thankLink = $( this );
-               e.preventDefault();
+       var confirmThanks = function( $thankLink ) {
+               var recipient = $thankLink.parent().find( '.mw-userlink' 
).text();
+               var $dialog = $( '<div>' ).msg( 'thanks-confirmation', mw.user, 
recipient );
+               $dialog.dialog( {
+                       autoOpen: false,
+                       width: 400,
+                       modal: true,
+                       resizable: false,
+                       buttons: [
+                               {
+                                       text: mw.msg( 'ok' ),
+                                       class: 'ui-button-green',
+                                       click: function() {
+                                               $( this ).dialog( "close" );
+                                               sendThanks( $thankLink );
+                                       }
+                               },
+                               {
+                                       text: mw.msg( 'cancel' ),
+                                       class: 'ui-button-red',
+                                       click: function() { $( this ).dialog( 
"close" ); }
+                               }
+                       ]
+               } );
+               $dialog.dialog( 'open' );
+       };
+       
+       var sendThanks = function( $thankLink ) {
+               var source;
                if ( mw.config.get( 'wgAction' ) === 'history' ) {
                        source = 'history';
                } else {
@@ -78,6 +97,24 @@
                                        alert( mw.msg( 'thanks-error-undefined' 
) );
                        }
                } );
+       };
+
+       if ( $.isReady ) {
+               // This condition is required for soft-reloads
+               // to also trigger the reloadThankedState
+               reloadThankedState();
+       } else {
+               $( document ).ready( reloadThankedState );
+       }
+
+       $( 'a.mw-thanks-thank-link' ).click( function( e ) {
+               var $thankLink = $( this );
+               e.preventDefault();
+               if ( mw.config.get( 'thanks-confirmation-required' ) ) {
+                       confirmThanks( $thankLink );
+               } else {
+                       sendThanks( $thankLink );
+               }
        } );
 
 } )( jQuery, mediaWiki );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4663844a324a2797917b027ceb1c8c07b1e180d5
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson (WMF) <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to