mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-15 19:09:52 +00:00
Support updated flow frontend
* Flow no-longer allows arbitrary html insertion, so remove * Update ext.thanks.flowthank.js to work with thank links generated directly by flow. Change-Id: I8ae14352f1b177446f3696ffadd6921a5125238e
This commit is contained in:
parent
8f95163ea2
commit
ccdca0d0d7
|
@ -272,86 +272,18 @@ class ThanksHooks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Handler for FlowAddModules
|
||||
* Handler for FlowAddModules. Inserts javascript to enhance thank
|
||||
* links from static urls to in-page dialogs along with reloading
|
||||
* the previously thanked state.
|
||||
*
|
||||
* @param OutputPage $out OutputPage object
|
||||
* @param mixed $skin
|
||||
* @return bool
|
||||
*/
|
||||
public static function onFlowAddModules( OutputPage $out ) {
|
||||
$out->addModules( 'ext.thanks.flowthank' );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for FlowAddInteractionLinks
|
||||
* Appends a 'thank' button or a 'thanked' label to interaction links for Flow comments
|
||||
* @param Flow\Model\PostRevision $post Flow PostRevision object for the comment
|
||||
* @param User $user User viewing the page
|
||||
* @param array $links Array of interaction links to be displayed
|
||||
* @return bool
|
||||
*/
|
||||
public static function onFlowAddPostInteractionLinks( $post, $user, &$links ) {
|
||||
global $wgThanksSendToBots;
|
||||
// Make sure Echo is turned on.
|
||||
// Exclude anonymous users.
|
||||
// Don't let users thank themselves.
|
||||
// Exclude users who are blocked.
|
||||
if ( class_exists( 'EchoNotifier' )
|
||||
&& !$user->isAnon()
|
||||
&& $post->getCreatorId() != $user->getId()
|
||||
&& !$user->isBlocked()
|
||||
) {
|
||||
$recipient = User::newFromId( $post->getCreatorId() );
|
||||
$recipientAllowed = true;
|
||||
// If bots are not allowed, exclude them as recipients
|
||||
if ( !$wgThanksSendToBots ) {
|
||||
$recipientAllowed = !in_array( 'bot', $recipient->getGroups() );
|
||||
}
|
||||
if ( $recipientAllowed && !$recipient->isAnon() ) {
|
||||
$links[] = self::generateFlowThankElement( $post, $user, $recipient );
|
||||
}
|
||||
public static function onBeforePageDisplay( OutputPage $out, $skin ) {
|
||||
if ( $out->getTitle()->getContentModel() === 'flow-board' ) {
|
||||
$out->addModules( 'ext.thanks.flowthank' );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates either a 'thank' button or a 'thanked' label based on session data
|
||||
* @param Flow\Model\PostRevision $post Flow PostRevision object for the comment
|
||||
* @param User $user User viewing the page
|
||||
* @param User $recipient User who receives thanks notification
|
||||
* @return string HTML segment for the links
|
||||
*/
|
||||
protected static function generateFlowThankElement( $post, $user, $recipient ) {
|
||||
$cssActiveClass = 'mw-thanks-flow-thank-link mw-ui-button mw-ui-quiet mw-ui-constructive';
|
||||
$cssInactiveClass = 'mw-thanks-flow-thanked mw-ui-button mw-ui-quiet mw-ui-disabled';
|
||||
|
||||
$uuid = $post->getPostId()->getAlphadecimal();
|
||||
|
||||
// User has already thanked for revision
|
||||
if ( $user->getRequest()->getSessionData( "flow-thanked-{$uuid}" ) ) {
|
||||
return Html::rawElement(
|
||||
'span',
|
||||
array( 'class' => $cssInactiveClass ),
|
||||
wfMessage( 'thanks-button-thanked', $user )->escaped()
|
||||
);
|
||||
}
|
||||
|
||||
// Add 'thank' link
|
||||
$tooltip = wfMessage( 'thanks-thank-tooltip' )
|
||||
->params( $user->getName(), $recipient->getName() )
|
||||
->text();
|
||||
|
||||
return Html::rawElement(
|
||||
'a',
|
||||
array(
|
||||
'class' => $cssActiveClass,
|
||||
'href' => SpecialPage::getTitleFor(
|
||||
'Thanks',
|
||||
'Flow/' . $uuid
|
||||
)->getFullURL(),
|
||||
'title' => $tooltip,
|
||||
'data-post-id' => $uuid
|
||||
),
|
||||
wfMessage( 'thanks-button-thank', $user )->escaped()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,9 +73,7 @@ $wgHooks['AddNewAccount'][] = 'ThanksHooks::onAccountCreated';
|
|||
$wgHooks['BeforeSpecialMobileDiffDisplay'][] = 'ThanksHooks::onBeforeSpecialMobileDiffDisplay';
|
||||
$wgHooks['UnitTestsList'][] = 'ThanksHooks::registerUnitTests';
|
||||
$wgHooks['GetLogTypesOnUser'][] = 'ThanksHooks::onGetLogTypesOnUser';
|
||||
|
||||
$wgHooks['FlowAddPostInteractionLinks'][] = 'ThanksHooks::onFlowAddPostInteractionLinks';
|
||||
$wgHooks['FlowAddModules'][] = 'ThanksHooks::onFlowAddModules';
|
||||
$wgHooks['BeforePageDisplay'][] = 'ThanksHooks::onBeforePageDisplay';
|
||||
|
||||
// Register modules
|
||||
$wgResourceModules['ext.thanks'] = array(
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
'use strict';
|
||||
|
||||
mw.thanks.thanked.cookieName = 'flow-thanked';
|
||||
mw.thanks.thanked.attrName = 'data-post-id';
|
||||
mw.thanks.thanked.attrName = 'data-flow-id';
|
||||
|
||||
var $thankedLabel = $( '<span></span>' )
|
||||
.append( mw.msg( 'thanks-button-thanked', mw.user ) )
|
||||
.addClass( 'mw-thanks-flow-thanked mw-ui-button mw-ui-quiet mw-ui-disabled' );
|
||||
.addClass( 'mw-thanks-flow-thanked mw-ui-quiet' );
|
||||
|
||||
var reloadThankedState = function() {
|
||||
$( 'a.mw-thanks-flow-thank-link' ).each( function( idx, el ) {
|
||||
var $thankLink = $( el );
|
||||
if ( mw.thanks.thanked.contains( $thankLink ) ) {
|
||||
if ( mw.thanks.thanked.contains( $thankLink.closest( '.flow-post' ) ) ) {
|
||||
$thankLink.before( $thankedLabel.clone() );
|
||||
$thankLink.remove();
|
||||
}
|
||||
|
@ -21,13 +21,13 @@
|
|||
var sendFlowThanks = function( $thankLink ) {
|
||||
( new mw.Api ).get( {
|
||||
'action' : 'flowthank',
|
||||
'postid' : $thankLink.attr( 'data-post-id' ),
|
||||
'postid' : $thankLink.closest( '.flow-post' ).attr( mw.thanks.thanked.attrName ),
|
||||
'token' : mw.user.tokens.get( 'editToken' )
|
||||
} )
|
||||
.done( function( data ) {
|
||||
mw.thanks.thanked.push( $thankLink.closest( '.flow-post' ) );
|
||||
$thankLink.before( $thankedLabel.clone() );
|
||||
$thankLink.remove();
|
||||
mw.thanks.thanked.push( $thankLink );
|
||||
} )
|
||||
.fail( function( errorCode, details ) {
|
||||
// TODO: use something besides alert for the error messages
|
||||
|
@ -50,7 +50,7 @@
|
|||
}
|
||||
|
||||
// .on() is needed to make the button work for dynamically loaded posts
|
||||
$( '.flow-container' ).on( 'click', 'a.mw-thanks-flow-thank-link', function( e ) {
|
||||
$( '.flow-board' ).on( 'click', 'a.mw-thanks-flow-thank-link', function( e ) {
|
||||
var $thankLink = $( this );
|
||||
e.preventDefault();
|
||||
sendFlowThanks( $thankLink );
|
||||
|
|
Loading…
Reference in a new issue