Make use of the new spam check event
authorMarcel Werk <burntime@woltlab.com>
Tue, 4 Jun 2024 12:51:07 +0000 (14:51 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 4 Jun 2024 12:51:07 +0000 (14:51 +0200)
files/lib/data/conversation/message/ConversationMessageAction.class.php
files/lib/form/ConversationAddForm.class.php

index 05a370418477a49c188d35e50f15c0b696bae9ee..3f5cf5c20d14a3f65fc7ee4370ec34ad6583e09b 100644 (file)
@@ -11,6 +11,7 @@ use wcf\data\IAttachmentMessageQuickReplyAction;
 use wcf\data\IMessageInlineEditorAction;
 use wcf\data\IMessageQuoteAction;
 use wcf\data\smiley\SmileyCache;
+use wcf\event\message\MessageSpamChecking;
 use wcf\system\attachment\AttachmentHandler;
 use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\conversation\ConversationHandler;
@@ -305,6 +306,10 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements
             WCF::getSession()->getPermission('user.message.disallowedBBCodes')
         ));
         QuickReplyManager::getInstance()->validateParameters($this, $this->parameters, Conversation::class);
+
+        if ($this->messageIsProbablySpam()) {
+            throw new PermissionDeniedException();
+        }
     }
 
     /**
@@ -421,6 +426,10 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements
             $this->conversation,
             $this->getHtmlInputProcessor($this->parameters['data']['message'], $this->message->messageID)
         );
+
+        if ($this->messageIsProbablySpam()) {
+            throw new PermissionDeniedException();
+        }
     }
 
     /**
@@ -723,4 +732,21 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements
 
         return $this->htmlInputProcessor;
     }
+
+    /**
+     * This method triggers the event for the spam check and returns the result.
+     *
+     * @since 6.1
+     */
+    protected function messageIsProbablySpam(): bool
+    {
+        $event = new MessageSpamChecking(
+            $this->htmlInputProcessor,
+            WCF::getUser()->userID ? WCF::getUser() : null,
+            UserUtil::getIpAddress()
+        );
+        EventHandler::getInstance()->fire($event);
+
+        return $event->defaultPrevented();
+    }
 }
index ffd4778796acfa339daaa7c44e8fada81784aa37..f4723f5fab45174aa23873ab7c4d31a67ff84796 100644 (file)
@@ -256,6 +256,10 @@ class ConversationAddForm extends MessageForm
         }
 
         parent::validate();
+
+        if ($this->messageIsProbablySpam()) {
+            throw new PermissionDeniedException();
+        }
     }
 
     /**