Bsitu has uploaded a new change for review. https://gerrit.wikimedia.org/r/73732
Change subject: (bug 51303) Do not send duplicate thanks notification ...................................................................... (bug 51303) Do not send duplicate thanks notification Change-Id: Ie3c31e4ce155541a6aa9b6feae433742be2967e8 --- M ApiThank.php 1 file changed, 42 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks refs/changes/32/73732/1 diff --git a/ApiThank.php b/ApiThank.php index 23f72b7..1576f10 100644 --- a/ApiThank.php +++ b/ApiThank.php @@ -29,46 +29,51 @@ if ( !$rev ) { $this->dieUsage( 'Revision ID is not valid', 'invalidrevision' ); } else { - $title = Title::newFromID( $rev->getPage() ); - if ( !$title ) { - $this->dieUsage( 'Page title could not be retrieved', 'notitle' ); - } - - // Get the user ID of the user who performed the edit - $recipient = $rev->getUser(); - - if ( !$recipient ) { - $this->dieUsage( 'No valid recipient found', 'invalidrecipient' ); - } else { - // Set the source of the thanks, e.g. 'diff' or 'history' - if ( $params['source'] ) { - $source = trim( $params['source'] ); + // Do not send notification if session data says "it has already been sent" + if ( !$agent->getRequest()->getSessionData( "thanks-thanked-{$rev->getId()}" ) ) { + $title = Title::newFromID( $rev->getPage() ); + if ( !$title ) { + $this->dieUsage( 'Page title could not be retrieved', 'notitle' ); + } + + // Get the user ID of the user who performed the edit + $recipient = $rev->getUser(); + + if ( !$recipient ) { + $this->dieUsage( 'No valid recipient found', 'invalidrecipient' ); } else { - $source = 'undefined'; + // Set the source of the thanks, e.g. 'diff' or 'history' + if ( $params['source'] ) { + $source = trim( $params['source'] ); + } else { + $source = 'undefined'; + } + // Create the notification via Echo extension + EchoEvent::create( array( + 'type' => 'edit-thank', + 'title' => $title, + 'extra' => array( + 'revid' => $rev->getId(), + 'thanked-user-id' => $recipient, + 'source' => $source, + ), + 'agent' => $agent, + ) ); + // Mark the thank in session to prevent duplicates (Bug 46690) + $agent->getRequest()->setSessionData( "thanks-thanked-{$rev->getId()}", true ); + // Set success message + $result['success'] = '1'; + // Log it if we're supposed to log it + if ( $wgThanksLogging ) { + $logEntry = new ManualLogEntry( 'thanks', 'thank' ); + $logEntry->setPerformer( $agent ); + $target = User::newFromId( $recipient )->getUserPage(); + $logEntry->setTarget( $target ); + $logid = $logEntry->insert(); + } } - // Create the notification via Echo extension - EchoEvent::create( array( - 'type' => 'edit-thank', - 'title' => $title, - 'extra' => array( - 'revid' => $rev->getId(), - 'thanked-user-id' => $recipient, - 'source' => $source, - ), - 'agent' => $agent, - ) ); - // Mark the thank in session to prevent duplicates (Bug 46690) - $agent->getRequest()->setSessionData( "thanks-thanked-{$rev->getId()}", true ); - // Set success message + } else { $result['success'] = '1'; - // Log it if we're supposed to log it - if ( $wgThanksLogging ) { - $logEntry = new ManualLogEntry( 'thanks', 'thank' ); - $logEntry->setPerformer( $agent ); - $target = User::newFromId( $recipient )->getUserPage(); - $logEntry->setTarget( $target ); - $logid = $logEntry->insert(); - } } } $this->getResult()->addValue( null, 'result', $result ); -- To view, visit https://gerrit.wikimedia.org/r/73732 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie3c31e4ce155541a6aa9b6feae433742be2967e8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Thanks Gerrit-Branch: master Gerrit-Owner: Bsitu <bs...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits