summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Thanks/includes/ApiThank.php')
-rw-r--r--Thanks/includes/ApiThank.php49
1 files changed, 42 insertions, 7 deletions
diff --git a/Thanks/includes/ApiThank.php b/Thanks/includes/ApiThank.php
index 8b6cdf8b..9e99711f 100644
--- a/Thanks/includes/ApiThank.php
+++ b/Thanks/includes/ApiThank.php
@@ -1,4 +1,7 @@
<?php
+
+use MediaWiki\MediaWikiServices;
+
/**
* Base API module for Thanks
*
@@ -11,19 +14,47 @@ abstract class ApiThank extends ApiBase {
$this->dieWithError( 'thanks-error-notloggedin', 'notloggedin' );
} elseif ( $user->pingLimiter( 'thanks-notification' ) ) {
$this->dieWithError( [ 'thanks-error-ratelimited', $user->getName() ], 'ratelimited' );
- } elseif ( $user->isBlocked() ) {
- $this->dieBlocked( $user->getBlock() );
} elseif ( $user->isBlockedGlobally() ) {
$this->dieBlocked( $user->getGlobalBlock() );
}
}
- protected function dieOnBadRecipient( User $user, User $recipient ) {
- global $wgThanksSendToBots;
+ /**
+ * Check whether the user is blocked from this title. (This is not the same
+ * as checking whether they are sitewide blocked, because a sitewide blocked
+ * user may still be allowed to thank on their own talk page.)
+ *
+ * This is separate from dieOnBadUser because we need to know the title.
+ *
+ * @param User $user
+ * @param Title $title
+ */
+ protected function dieOnBlockedUser( User $user, Title $title ) {
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+ if ( $permissionManager->isBlockedFrom( $user, $title ) ) {
+ $this->dieBlocked( $user->getBlock() );
+ }
+ }
+ /**
+ * Check whether the user is sitewide blocked.
+ *
+ * This is separate from dieOnBlockedUser because we need to know if the thank
+ * is related to a revision. (If it is, then use dieOnBlockedUser instead.)
+ *
+ * @param User $user
+ */
+ protected function dieOnSitewideBlockedUser( User $user ) {
+ $block = $user->getBlock();
+ if ( $block && $block->isSitewide() ) {
+ $this->dieBlocked( $block );
+ }
+ }
+
+ protected function dieOnBadRecipient( User $user, User $recipient ) {
if ( $user->getId() === $recipient->getId() ) {
$this->dieWithError( 'thanks-error-invalidrecipient-self', 'invalidrecipient' );
- } elseif ( !$wgThanksSendToBots && $recipient->isBot() ) {
+ } elseif ( !$this->getConfig()->get( 'ThanksSendToBots' ) && $recipient->isBot() ) {
$this->dieWithError( 'thanks-error-invalidrecipient-bot', 'invalidrecipient' );
}
}
@@ -66,8 +97,7 @@ abstract class ApiThank extends ApiBase {
* when checking for duplicate thanks
*/
protected function logThanks( User $user, User $recipient, $uniqueId ) {
- global $wgThanksLogging;
- if ( !$wgThanksLogging ) {
+ if ( !$this->getConfig()->get( 'ThanksLogging' ) ) {
return;
}
$logEntry = new ManualLogEntry( 'thanks', 'thank' );
@@ -77,6 +107,11 @@ abstract class ApiThank extends ApiBase {
$logEntry->setTarget( $target );
$logId = $logEntry->insert();
$logEntry->publish( $logId, 'udp' );
+
+ if ( ExtensionRegistry::getInstance()->isLoaded( 'CheckUser' ) ) {
+ $recentChange = $logEntry->getRecentChange();
+ CheckUserHooks::updateCheckUserData( $recentChange );
+ }
}
public function needsToken() {