mediawiki-extensions-Thanks/ApiThank.php
wctaiwan 98726b568b Add "Thanks" for comments on Flow boards
bug: 61930
Change-Id: Id37a14e3c75c63419fc34e0b7c2e21f74b3fa875
Co-authored-by: Bencmq <bencmqwiki@gmail.com>
2014-03-14 11:03:11 +00:00

57 lines
1.5 KiB
PHP

<?php
/**
* Base API module for Thanks
*
* @ingroup API
* @ingroup Extensions
*/
abstract class ApiThank extends ApiBase {
protected function dieIfEchoNotInstalled() {
if ( !class_exists( 'EchoNotifier' ) ) {
$this->dieUsage( 'Echo is not installed on this wiki', 'echonotinstalled' );
}
}
protected function dieOnBadUser( User $user ) {
if ( $user->isAnon() ) {
$this->dieUsage( 'Anonymous users cannot send thanks', 'notloggedin' );
} elseif ( $user->pingLimiter( 'thanks-notification' ) ) {
$this->dieUsageMsg( array( 'actionthrottledtext' ) );
} elseif ( $user->isBlocked() ) {
$this->dieUsageMsg( array( 'blockedtext' ) );
}
}
protected function dieOnBadRecipient( User $user, User $recipient ) {
global $wgThanksSendToBots;
if ( $user->getId() === $recipient->getId() ) {
$this->dieUsage( 'You cannot thank yourself', 'invalidrecipient' );
} elseif ( !$wgThanksSendToBots && in_array( 'bot', $recipient->getGroups() ) ) {
$this->dieUsage( 'Bots cannot be thanked', 'invalidrecipient' );
}
}
protected function logThanks( User $user, User $recipient ) {
$logEntry = new ManualLogEntry( 'thanks', 'thank' );
$logEntry->setPerformer( $user );
$target = $recipient->getUserPage();
$logEntry->setTarget( $target );
$logId = $logEntry->insert();
$logEntry->publish( $logId, 'udp' );
}
public function needsToken() {
return true;
}
// Writes to the Echo database and sometimes log tables.
public function isWriteMode() {
return true;
}
public function getTokenSalt() {
return '';
}
}