Kaldari has uploaded a new change for review.

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


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, 60 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks 
refs/changes/91/67591/1

diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index 6e752d0..2ea1164 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -79,11 +79,13 @@
         * @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 +99,13 @@
         * @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..1724db9 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 their 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..3a5ebe0 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -69,6 +69,9 @@
                'thanks-error-undefined',
                'thanks-error-invalidrevision',
                'thanks-error-ratelimited',
+               'thanks-confirmation',
+               'ok',
+               'cancel',
        ),
        'dependencies' => array(
                'mediawiki.jqueryMsg',
@@ -91,6 +94,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..357e177 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() {
@@ -37,18 +38,33 @@
                        }
                } );
        };
-
-       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 +94,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: newchange
Gerrit-Change-Id: I4663844a324a2797917b027ceb1c8c07b1e180d5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>

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

Reply via email to