Merge "Adding optional confirmation process to Thanks workflow"

This commit is contained in:
jenkins-bot 2013-06-11 17:51:31 +00:00 committed by Gerrit Code Review
commit 81364e9f56
4 changed files with 65 additions and 11 deletions

View file

@ -79,11 +79,14 @@ class ThanksHooks {
* @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 @@ class ThanksHooks {
* @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;
}

View file

@ -18,6 +18,7 @@ $messages['en'] = array(
'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 @@ Parameters:
'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}}.',

View file

@ -69,11 +69,15 @@ $wgResourceModules['ext.thanks'] = array(
'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 @@ $wgThanksSendToBots = false;
// 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 ) ),

View file

@ -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 );