Merge "Story 1604: Remember mobile thanks"

This commit is contained in:
jenkins-bot 2014-01-18 00:40:30 +00:00 committed by Gerrit Code Review
commit f635813b98
2 changed files with 33 additions and 18 deletions

View file

@ -194,9 +194,10 @@ class ThanksHooks {
* Add thanks button to SpecialMobileDiff page
* @param &$output OutputPage object
* @param $ctx MobileContext object
* @param $revisions Array of the two revisions that are being compared in the diff
* @return bool true in all cases
*/
public static function onBeforeSpecialMobileDiffDisplay( &$output, $ctx ) {
public static function onBeforeSpecialMobileDiffDisplay( &$output, $ctx, $revisions ) {
// If the Echo and MobileFrontend extensions are installed and the user is
// logged in, show a 'Thank' link.
if ( class_exists( 'EchoNotifier' )
@ -204,6 +205,13 @@ class ThanksHooks {
&& $output->getUser()->isLoggedIn()
) {
$output->addModules( array( 'ext.thanks.mobilediff' ) );
$rev = $revisions[1];
if ( $rev ) {
if ( $output->getRequest()->getSessionData( 'thanks-thanked-' . $rev->getId() ) ) {
// User already sent thanks for this revision
$output->addJsConfigVars( 'wgThanksAlreadySent', true );
}
}
}
return true;
}

View file

@ -41,25 +41,32 @@
* @param gender String The gender of the user who made the edit
*/
function createThankLink( name, rev, gender ) {
var thankImg = mw.config.get( 'wgExtensionAssetsPath' ) + '/Thanks/WhiteSmiley.png';
var thankImg = mw.config.get( 'wgExtensionAssetsPath' ) + '/Thanks/WhiteSmiley.png',
thankImgTag = '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>',
$thankBtn;
// Don't make thank button for self
if ( name !== mw.config.get( 'wgUserName' ) ) {
return $( '<button class="mw-mf-action-button">' )
.html( '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>' +
mw.message( 'thanks-button-thank', mw.user ).escaped()
)
.on( 'click', function() {
var $thankLink = $( this );
schema.log( 'diff-thank', name );
if ( !$thankLink.hasClass( 'thanked' ) ) {
thankUser( name, rev, gender ).done( function() {
$thankLink.addClass( 'thanked' ).attr( 'disabled', true );
$thankLink.html( '<img width="25" height="20" src="' + thankImg + '" class="mw-mf-action-button-icon"/>' +
mw.message( 'thanks-button-thanked', mw.user ).escaped()
);
} );
}
} );
// See if user has already been thanked for this edit
if ( mw.config.get( 'wgThanksAlreadySent' ) ) {
$thankBtn = $( '<button class="mw-mf-action-button thanked">' )
.attr( 'disabled', true )
.html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() );
} else {
$thankBtn = $( '<button class="mw-mf-action-button">' )
.html( thankImgTag + mw.message( 'thanks-button-thank', mw.user ).escaped()
)
.on( 'click', function() {
var $this = $( this );
schema.log( 'diff-thank', name );
if ( !$this.hasClass( 'thanked' ) ) {
thankUser( name, rev, gender ).done( function() {
$this.addClass( 'thanked' ).attr( 'disabled', true )
.html( thankImgTag + mw.message( 'thanks-button-thanked', mw.user ).escaped() );
} );
}
} );
}
return $thankBtn;
}
}