[MediaWiki-commits] [Gerrit] Story 1604: Remember mobile thanks - change (mediawiki...Thanks)

2014-01-17 Thread jenkins-bot (Code Review)
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', 

[MediaWiki-commits] [Gerrit] Story 1604: Remember mobile thanks - change (mediawiki...Thanks)

2014-01-15 Thread Kaldari (Code Review)
Kaldari has uploaded a new change for review.

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


Change subject: Story 1604: Remember mobile thanks
..

Story 1604: Remember mobile thanks

After someone thanks a user, have it remember the revision in a
cookie. If the user has already been thanked, make the button
greyed out and display the text Thanked instead of Thank.

Bug: 59828
Change-Id: Ifab78fe62910c9c3f2a927a6a4bbe28fb953b160
---
M Thanks.php
M modules/ext.thanks.mobilediff.js
2 files changed, 61 insertions(+), 19 deletions(-)


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

diff --git a/Thanks.php b/Thanks.php
index 4d703e9..9bc81b6 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -87,6 +87,7 @@
'mediawiki.api',
'user.tokens',
'jquery.ui.dialog',
+   'jquery.cookie',
),
'localBasePath' = $dir . '/modules',
'remoteExtPath' = 'Thanks/modules',
@@ -94,6 +95,7 @@
 $wgResourceModules['ext.thanks.mobilediff'] = array(
'dependencies' = array(
'mobile.mobilediff.scripts',
+   'jquery.cookie',
),
'scripts' = array(
'ext.thanks.mobilediff.js',
diff --git a/modules/ext.thanks.mobilediff.js b/modules/ext.thanks.mobilediff.js
index f8add6a..b0142c9 100644
--- a/modules/ext.thanks.mobilediff.js
+++ b/modules/ext.thanks.mobilediff.js
@@ -3,17 +3,48 @@
popup = M.require( 'toast' ),
schema = M.require( 'loggingSchemas/MobileWebClickTracking' );
 
-   function thankUser( name, revision, gender ) {
+   // Keep track of which revisions the user has already thanked for
+   var thanked = {
+   maxHistory: 100,
+   load: function() {
+   var cookie = $.cookie( 'thanks-thanked' );
+   if ( cookie === null ) {
+   return [];
+   }
+   return unescape( cookie ).split( ',' );
+   },
+   push: function( rev ) {
+   var saved = this.load();
+   saved.push( rev );
+   // Prevent cookie from growing forever
+   if ( saved.length  this.maxHistory ) {
+   saved = saved.slice( saved.length - 
this.maxHistory );
+   }
+   $.cookie( 'thanks-thanked', escape( saved.join( ',' ) ) 
);
+   },
+   contains: function( rev ) {
+   if ( $.inArray( rev.toString(), this.load() ) !== -1 ) {
+   return true;
+   } else {
+   return false;
+   }
+   }
+   };
+
+   function thankUser( name, rev, gender ) {
var d = $.Deferred();
api.getToken( 'edit' ).done( function( token ) {
api.get( {
'action' : 'thank',
-   'rev' : revision,
+   'rev' : rev,
'source' : 'mobilediff',
'token' : token
} )
.done( function() {
+   // Show pop-up notification that sending thanks 
was successful
popup.show( mw.msg( 'thanks-thanked-notice', 
name, gender ) );
+   // Remember that user has been thanked for this 
edit
+   thanked.push( rev );
d.resolve();
} )
.fail( function( errorCode ) {
@@ -41,25 +72,34 @@
 * @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 );
-