jenkins-bot has submitted this change and it was merged. Change subject: Story 1604: Remember mobile thanks ......................................................................
Story 1604: Remember mobile thanks If the user has already been thanked, make the button greyed out and display the text "Thanked" instead of "Thank". Dependency: Ife9f456a7a9cf74b1b54fdc6128feb230fd6f671 Bug: 59828 Change-Id: Ifab78fe62910c9c3f2a927a6a4bbe28fb953b160 --- M Thanks.hooks.php M modules/ext.thanks.mobilediff.js 2 files changed, 33 insertions(+), 18 deletions(-) Approvals: Jdlrobson: Looks good to me, approved jenkins-bot: Verified diff --git a/Thanks.hooks.php b/Thanks.hooks.php index a65d30c..059f4f0 100644 --- a/Thanks.hooks.php +++ b/Thanks.hooks.php @@ -194,9 +194,10 @@ * 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 @@ && $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; } diff --git a/modules/ext.thanks.mobilediff.js b/modules/ext.thanks.mobilediff.js index f8add6a..b87041b 100644 --- a/modules/ext.thanks.mobilediff.js +++ b/modules/ext.thanks.mobilediff.js @@ -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; } } -- To view, visit https://gerrit.wikimedia.org/r/107633 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ifab78fe62910c9c3f2a927a6a4bbe28fb953b160 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Thanks Gerrit-Branch: master Gerrit-Owner: Kaldari <rkald...@wikimedia.org> Gerrit-Reviewer: JGonera <jgon...@wikimedia.org> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Kaldari <rkald...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits