diff --git a/wcfsetup/install/files/lib/form/ContactForm.class.php b/wcfsetup/install/files/lib/form/ContactForm.class.php
index f1f8ff23863..fc2e6da6b06 100644
--- a/wcfsetup/install/files/lib/form/ContactForm.class.php
+++ b/wcfsetup/install/files/lib/form/ContactForm.class.php
@@ -15,6 +15,7 @@
use wcf\system\form\builder\field\CaptchaFormField;
use wcf\system\form\builder\field\EmailFormField;
use wcf\system\form\builder\field\FileProcessorFormField;
+use wcf\system\form\builder\field\ICensorshipFormField;
use wcf\system\form\builder\field\IFormField;
use wcf\system\form\builder\field\SelectFormField;
use wcf\system\form\builder\field\TextFormField;
@@ -51,6 +52,7 @@ protected function createForm()
TextFormField::create('name')
->label('wcf.contact.sender')
->required()
+ ->censorship()
->value(WCF::getUser()->username ?: ''),
EmailFormField::create('email')
->label('wcf.user.email')
@@ -226,6 +228,10 @@ protected function getOptionFormFields(): array
$formField->required();
}
+ if ($formField instanceof ICensorshipFormField) {
+ $formField->censorship();
+ }
+
$formFields[] = $formField;
}
diff --git a/wcfsetup/install/files/lib/system/form/builder/field/ICensorshipFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/ICensorshipFormField.class.php
new file mode 100644
index 00000000000..8b254c654bd
--- /dev/null
+++ b/wcfsetup/install/files/lib/system/form/builder/field/ICensorshipFormField.class.php
@@ -0,0 +1,29 @@
+
+ * @since 6.2
+ */
+interface ICensorshipFormField extends IFormField
+{
+ /**
+ * Sets whether the censorship function should be applied to this field.
+ */
+ public function censorship(bool $censorship = true): static;
+
+ /**
+ * Returns `true` if the censorship function should be applied to this field.
+ */
+ public function hasCensorship(): bool;
+
+ /**
+ * Validates whether the text contains censored words.
+ */
+ public function validateCensorship(string $text): void;
+}
diff --git a/wcfsetup/install/files/lib/system/form/builder/field/TCensorshipFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/TCensorshipFormField.class.php
new file mode 100644
index 00000000000..1807255a4d8
--- /dev/null
+++ b/wcfsetup/install/files/lib/system/form/builder/field/TCensorshipFormField.class.php
@@ -0,0 +1,54 @@
+
+ * @since 6.2
+ */
+trait TCensorshipFormField
+{
+ protected bool $censorship = false;
+
+ #[\Override]
+ public function censorship(bool $censorship = true): static
+ {
+ $this->censorship = $censorship;
+
+ return $this;
+ }
+
+ #[\Override]
+ public function hasCensorship(): bool
+ {
+ return $this->censorship;
+ }
+
+ #[\Override]
+ public function validateCensorship(string $text): void
+ {
+ if (!$this->hasCensorship()) {
+ return;
+ }
+
+ if (!($this instanceof IFormField)) {
+ return;
+ }
+
+ $censoredWords = Censorship::getInstance()->test($text);
+ if ($censoredWords) {
+ $this->addValidationError(new FormFieldValidationError(
+ 'censoredWords',
+ 'wcf.message.error.censoredWordsFound',
+ ['censoredWords' => $censoredWords]
+ ));
+ }
+ }
+}
diff --git a/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php
index 59e67d3eb3a..bc2275dd988 100644
--- a/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php
+++ b/wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php
@@ -18,6 +18,7 @@ class TextFormField extends AbstractFormField implements
IAttributeFormField,
IAutoCompleteFormField,
IAutoFocusFormField,
+ ICensorshipFormField,
ICssClassFormField,
II18nFormField,
IImmutableFormField,
@@ -30,6 +31,7 @@ class TextFormField extends AbstractFormField implements
use TInputAttributeFormField;
use TTextAutoCompleteFormField;
use TAutoFocusFormField;
+ use TCensorshipFormField;
use TCssClassFormField;
use TImmutableFormField;
use TInputModeFormField;
@@ -115,6 +117,7 @@ protected function validateText($text, ?Language $language = null)
{
$this->validateMinimumLength($text, $language);
$this->validateMaximumLength($text, $language);
+ $this->validateCensorship($text);
}
/**
diff --git a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php
index 3c477097309..5b55f2d8bd5 100644
--- a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php
+++ b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php
@@ -6,8 +6,10 @@
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
use wcf\system\form\builder\field\AbstractFormField;
use wcf\system\form\builder\field\IAttributeFormField;
+use wcf\system\form\builder\field\ICensorshipFormField;
use wcf\system\form\builder\field\IMaximumLengthFormField;
use wcf\system\form\builder\field\IMinimumLengthFormField;
+use wcf\system\form\builder\field\TCensorshipFormField;
use wcf\system\form\builder\field\TInputAttributeFormField;
use wcf\system\form\builder\field\TMaximumLengthFormField;
use wcf\system\form\builder\field\TMinimumLengthFormField;
@@ -17,7 +19,6 @@
use wcf\system\form\builder\TObjectTypeFormNode;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\html\upcast\HtmlUpcastProcessor;
-use wcf\system\message\censorship\Censorship;
use wcf\system\message\quote\MessageQuoteManager;
use wcf\system\WCF;
use wcf\util\StringUtil;
@@ -32,10 +33,12 @@
*/
final class WysiwygFormField extends AbstractFormField implements
IAttributeFormField,
+ ICensorshipFormField,
IMaximumLengthFormField,
IMinimumLengthFormField,
IObjectTypeFormNode
{
+ use TCensorshipFormField;
use TInputAttributeFormField {
getReservedFieldAttributes as private inputGetReservedFieldAttributes;
}
@@ -89,6 +92,12 @@ final class WysiwygFormField extends AbstractFormField implements
*/
protected $templateName = 'shared_wysiwygFormField';
+ public function __construct()
+ {
+ // WYSIWYG form fields use the censorship function by default for backward compatibility reasons.
+ $this->censorship();
+ }
+
/**
* Sets the identifier used to autosave the field value and returns this field.
*
@@ -372,14 +381,7 @@ public function validate()
$this->validateMaximumLength($message);
if (empty($this->getValidationErrors())) {
- $censoredWords = Censorship::getInstance()->test($message);
- if ($censoredWords) {
- $this->addValidationError(new FormFieldValidationError(
- 'censoredWords',
- 'wcf.message.error.censoredWordsFound',
- ['censoredWords' => $censoredWords]
- ));
- }
+ $this->validateCensorship($message);
}
}
}
diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml
index b3f63e057a2..6204ee60b09 100644
--- a/wcfsetup/install/lang/de.xml
+++ b/wcfsetup/install/lang/de.xml
@@ -4341,7 +4341,7 @@ Erlaubte Dateiendungen: gif, jpg, jpeg, png, webp]]>
- - 1} ({#$number}×){/if}{/implode}]]>
+ - 1} ({#$number}×){/if}{/implode}]]>
diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml
index dbbaf2b1b3a..6fbd786d4f3 100644
--- a/wcfsetup/install/lang/en.xml
+++ b/wcfsetup/install/lang/en.xml
@@ -4287,7 +4287,7 @@ Allowed extensions: gif, jpg, jpeg, png, webp]]>
- - 1} ({#$number}×){/if}{/implode}.]]>
+ - 1} ({#$number}×){/if}{/implode}.]]>