Flow/Thanks

Upcoming feature, under development by Facebook Open Academy students. Trello card

Issues

 * see also Things to work on below


 * Figure out if we can re-use Extension:Thanks
 * Thanks stores states in session and cookies for last 100 thanks made
 * Thanks link for edits appears on a history page, but according to trello, Flow has it besides the post itself.
 * Thanks depends on revId, Flow stores its own id.
 * No-Javascript


 * on local wikis changed: earlier posts return a string, newer return an integer. As a result code confused about which posts were written by someone else and are thankable.

Things spage noticed
I wound up with two  cookies, one for the path /wiki/index.php and one for /wXXXXpath  That might be a Thanks issue.

After I did a Flow thanks, I had a thanks-thanked cookie with no value.

In the Thanks.flow  hook,   isn't a Revision object, it's a FlowRevision.

Approaches

 * Make Thanks aware of Flow
 * Reimplement Flow in Thanks
 * Subclass Thanks in Flow
 * getWithRoot
 * [16:54:21] to get the page its on you need the related workflow object, you can get that through the root post loader with $rootLoader->storage->get( 'Workflow', $res['root']->getPostId ); i think

What Thanks does

 * Register a new type of notifications with Echo
 * Eventually calls ApiThank::sendThanks, which creates an Echo event
 * Handles Echo's hooks to format and display notifications

Other (deferred)

 * remembering Thanked state (Thanks does it in PHP session and cookie)
 * The API should check whether a post ID is valid (and if possible, whether it matches the supplied workflow ID, titles and recipient) and reject invalid or inconsistent requests

Information needed for Flow Thanks API

 * PostRevision ID (post-id)
 * User ID of the original author (recipient; $origUserId in PostRevision)
 * Workflow ID (workflow)
 * Title of the topic (topic-title)
 * Page title (title)
 * Edit token (token; mw.user.tokens.values.editToken)
 * User object for the user sending Thanks ApiBase (through ContextSource) gives this to us for free

Sample API request from Thanks: ( new mw.Api ).get( {	'action' : 'thank',	'rev' : $thankLink.attr( 'data-revision-id' ),	'source' : source,	'token' : mw.user.tokens.values.editToken } )

Normal page Thanks implementation
Thanks responds to HistoryRevisionTools and PageHistoryBeforeList hooks,
 * responds in  by adding HTML

no-JavaScript: link to https://www.mediawiki.org/wiki/Special:Thanks/677745

JS: jQuery dialog, upon confirm make API call https://www.mediawiki.org/w/api.php?action=thank&format=json&rev=677745&source=diff&token=1aabf45aa2917fd61527b2941ad19304%2B%5C, response is success: 1, recipient: "username"

Recipient sees
 * Thanker thanked you for your edit on Page

Thanker links to person, the text links to https://www.mediawiki.org/w/index.php?title=Page&oldid=prev&diff=677745

Normal Echo notification of a Flow post
A Flow mention generates:
 * User mentioned you in their post Text of post on "Talk:Main Page".


 * User links to person
 * Entire notification links to https://www.mediawiki.org/w/index.php?title=Talk:Flow&workflow=050f35daa31600e9aae290b11c2788d8#flow-post-050f575cfa098b080b88782bcb087047
 * post links to the same thing

Script (WIP)

 * TODO: record this in a screen capture

Flow is a big initiative to improve discussion and collaboration to MediaWiki. MediaWiki currently allows users to thank other users for their edits, and we have added a similar "Thank" capability to Flow.
 * 1) We added a "hook" to Flow so other extensions can add additional buttons for a Flow comment
 * 2) We respond to this by appending a "Thank" button to the end of every comment.
 * 3) JavaScript modifies the button to make an in-page call to an API
 * 4) On clicking it
 * 5) Thanks generates a notification is sent to the author of the comment
 * 6) upon success the button changes to a disabled "Thanked"

If you log in as the author, you can see that you have received a new notification. When you click the indicator, you see that someone else has thanked you for your comment. By clicking on the notifcation, you're taken to the comment in question.

Biggest challenge was ...
 * where to put the code between the Flow and Thanks extension.
 * existing code does much the same thing, but everything slightly different

Things to work on include

 * improving the API
 * making the feature more refined.
 * security:
 * sanitizing all inputs
 * prevent spoof messages
 * supporting users with JavaScript disabled
 * Testing! JavaScript qunit tests and browser tests
 * ensure the cookie and session functionality to remember Thanked state does the right thing
 * validate assumptions (thanking original poster vs. editor, etc.)