From a812f8a63b7a921fc9b3264c384119b8e8a9d7a6 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 5 Oct 2026 13:51:38 +0200 Subject: [PATCH] Update NodaValidationHelper --- src/NodaValidationHelper.php | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/NodaValidationHelper.php b/src/NodaValidationHelper.php index 8807071..799267e 100644 --- a/src/NodaValidationHelper.php +++ b/src/NodaValidationHelper.php @@ -70,6 +70,47 @@ final class NodaValidationHelper { } + /** + * Checks if an tag name is valid. + * Returns 0 if the tag can be added as a new one / tag name can be used as a new one. + * Returns the ID for already known tags. + * Throws an exception if the place is blacklisted. + * + * @param MDMysqli $mysqli_noda DB connection to vocabulary. + * @param string $lang User language. + * @param string $tag_name Tag name. + * @param string $context_identifier Context / instance identifier. + * @param integer $institution_id Institution ID. + * + * @return integer + */ + public static function checkTagNameIsUsable(MDMysqli $mysqli_noda, string $lang, string $tag_name, string $context_identifier, int $institution_id):int { + + if (strlen($tag_name) < 3) { + throw new MDBlacklistedInputException("This tag has been blacklisted"); + } + + if ($storedType = NodaDistinctlyTypedStrings::lookup($mysqli_noda, $lang, $tag_name)) { + + if ($storedType !== 'tag') { + throw new MDpageParameterMissingException("This term is marked to be distinctly a " . $storedType); + } + + } + + // Check if the tag name is in the current language's blacklist. + if (NodaBlacklistedTerms::tagIsInBlacklist($lang, $tag_name) === true) { + throw new MDBlacklistedInputException("This tag has been blacklisted"); + } + + if ($existingTagId = NodaIDGetter::getTagIDByNamesAndRewrites($mysqli_noda, $lang, $tag_name, $context_identifier, $institution_id)) { + return $existingTagId; + } + + return 0; + + } + /** * Validates an actor description for completeness. Of course, only an informed * guess based on the length and character composition of the description can be @@ -199,6 +240,10 @@ final class NodaValidationHelper { */ public static function checkPlaceNameIsUsable(MDMysqli $mysqli_noda, string $lang, string $place_name, string $context_identifier, int $institution_id):int { + if (strlen($place_name) < 3) { + throw new MDBlacklistedInputException("This place has been blacklisted"); + } + if ($storedType = NodaDistinctlyTypedStrings::lookup($mysqli_noda, $lang, $place_name)) { if ($storedType !== 'orte') {