2013-03-18 19:56:12 +00:00
|
|
|
<?php
|
2013-04-05 23:47:49 +00:00
|
|
|
/**
|
2014-02-26 02:12:47 +00:00
|
|
|
* Base API module for Thanks
|
2013-04-05 23:47:49 +00:00
|
|
|
*
|
|
|
|
* @ingroup API
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
2014-02-26 02:12:47 +00:00
|
|
|
abstract class ApiThank extends ApiBase {
|
|
|
|
protected function dieIfEchoNotInstalled() {
|
2013-03-18 19:56:12 +00:00
|
|
|
if ( !class_exists( 'EchoNotifier' ) ) {
|
|
|
|
$this->dieUsage( 'Echo is not installed on this wiki', 'echonotinstalled' );
|
|
|
|
}
|
2013-11-03 11:13:03 +00:00
|
|
|
}
|
2013-03-18 19:56:12 +00:00
|
|
|
|
2014-02-26 02:12:47 +00:00
|
|
|
protected function dieOnBadUser( User $user ) {
|
2013-11-03 11:13:03 +00:00
|
|
|
if ( $user->isAnon() ) {
|
2013-03-18 19:56:12 +00:00
|
|
|
$this->dieUsage( 'Anonymous users cannot send thanks', 'notloggedin' );
|
2013-11-03 11:13:03 +00:00
|
|
|
} elseif ( $user->pingLimiter( 'thanks-notification' ) ) {
|
2013-03-18 19:56:12 +00:00
|
|
|
$this->dieUsageMsg( array( 'actionthrottledtext' ) );
|
2013-11-03 11:13:03 +00:00
|
|
|
} elseif ( $user->isBlocked() ) {
|
2013-03-18 19:56:12 +00:00
|
|
|
$this->dieUsageMsg( array( 'blockedtext' ) );
|
|
|
|
}
|
2013-11-03 11:13:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 02:12:47 +00:00
|
|
|
protected function dieOnBadRecipient( User $user, User $recipient ) {
|
2013-11-24 06:45:12 +00:00
|
|
|
global $wgThanksSendToBots;
|
|
|
|
|
2014-02-26 02:12:47 +00:00
|
|
|
if ( $user->getId() === $recipient->getId() ) {
|
2013-11-24 06:45:12 +00:00
|
|
|
$this->dieUsage( 'You cannot thank yourself', 'invalidrecipient' );
|
|
|
|
} elseif ( !$wgThanksSendToBots && in_array( 'bot', $recipient->getGroups() ) ) {
|
|
|
|
$this->dieUsage( 'Bots cannot be thanked', 'invalidrecipient' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 04:28:10 +00:00
|
|
|
protected function markResultSuccess( $recipientName ) {
|
|
|
|
$this->getResult()->addValue( null, 'result', array(
|
|
|
|
'success' => 1,
|
|
|
|
'recipient' => $recipientName,
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2014-02-26 02:12:47 +00:00
|
|
|
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' );
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function needsToken() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-23 07:47:54 +00:00
|
|
|
// Writes to the Echo database and sometimes log tables.
|
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
public function getTokenSalt() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|