mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2025-01-05 18:04:06 +00:00
9a709e61b3
Simplify the code and add additional checks for invalid input. Change-Id: Ic1fe978730af7715c72f58cd7af46ab753e614e8
64 lines
1.7 KiB
PHP
64 lines
1.7 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 markResultSuccess( $recipientName ) {
|
|
$this->getResult()->addValue( null, 'result', array(
|
|
'success' => 1,
|
|
'recipient' => $recipientName,
|
|
) );
|
|
}
|
|
|
|
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 '';
|
|
}
|
|
}
|