Update NodaValidationHelper

This commit is contained in:
jrenslin committed 2026-10-05 13:51:38 +02:00
1 parent 3d4e254eda
commit a812f8a63b
1 file changed
+45
+45
View File
@@ -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') {