Compare commits

..

11 Commits

4 changed files with 109 additions and 4 deletions

View File

@@ -24,6 +24,7 @@ final class NodaBlacklistedTerms {
'versch.',
'verschiedenes',
'unbekannt',
'_',
'weitere',
'weiteres',
@@ -40,12 +41,22 @@ final class NodaBlacklistedTerms {
'AA',
'BB',
'CC',
'KK',
'K.A',
'S',
'N) (generell',
'DD',
'EE',
'FF',
'GG',
'HH',
'Generell) (+ Variante',
'LL',
'Von unbestimmbarer Gattung',
'Ohne andere Personen',
'Andere Darstellungen, denen der NAME einer historischen Person beigegeben werden kann',
'Andere Konzepte',
'Andere Systeme oder Kanons',
'-',
'?',
],

View File

@@ -10,14 +10,14 @@ declare(strict_types = 1);
* Provides functions for easily logging updates to the main noda DB tables.
*/
final class NodaLogEdit {
const ACTION_WHITELIST = [
public const ACTION_WHITELIST = [
'insert',
'update',
'merge',
'delete',
];
const SECTION_WHITELIST = [
public const SECTION_WHITELIST = [
'base',
'addition',
'noda_link',
@@ -32,6 +32,7 @@ final class NodaLogEdit {
'status',
'translation',
'group',
'note',
];
/**

View File

@@ -11,7 +11,7 @@ declare(strict_types = 1);
*/
final class NodaValidationHelper {
const ACTOR_DESCRIPTION_REQUIRED_DISTINCT_CHARS = 3;
private const ACTOR_DESCRIPTION_REQUIRED_DISTINCT_CHARS = 3;
/**
* Validates an actor description for completeness. Of course, only an informed
@@ -120,4 +120,93 @@ final class NodaValidationHelper {
}
}
/**
* Checks if an actor name is valid.
* Returns 0 if the actor can be added as a new one / actor name can be used as a new one.
* Returns the ID for already known actors.
* Throws an exception if the actor is blacklisted.
*
* @param MDMysqli $mysqli_noda DB connection to vocabulary.
* @param string $lang User language.
* @param string $persinst_name Actor name.
* @param string $persinst_name_en Actor name (short).
* @param string $persinst_geburtsjahr Birth year.
* @param string $persinst_sterbejahr Death year.
* @param string $context_identifier Context / instance identifier.
* @param integer $institution_id Institution ID.
*
* @return integer
*/
public static function checkPersinstNameIsUsable(MDMysqli $mysqli_noda, string $lang, string $persinst_name, string $persinst_name_en, string $persinst_geburtsjahr, string $persinst_sterbejahr, string $context_identifier, int $institution_id):int {
if ($storedType = NodaDistinctlyTypedStrings::lookup($mysqli_noda, $lang, $persinst_name_en)) {
if ($storedType !== 'persinst') {
throw new MDpageParameterMissingException("This term is marked to be distinctly a " . $storedType);
}
}
// Special case: ? or "unbekannt" as a given name.
if (str_starts_with($persinst_name_en, '? ') || str_starts_with(strtolower($persinst_name_en), 'unbekannt ') ) {
throw new MDBlacklistedInputException("Term is blacklisted");
}
// Check if the place name is in the current language's blacklist.
if (NodaBlacklistedTerms::checkPersinstBlacklistedInDb($mysqli_noda, $lang, $persinst_name) === true) {
throw new MDBlacklistedInputException("Term is blacklisted");
}
if (NodaBlacklistedTerms::checkPersinstBlacklistedInDb($mysqli_noda, $lang, $persinst_name_en) === true) {
throw new MDBlacklistedInputException("Term is blacklisted");
}
if ($existingPersinstId = NodaIDGetter::getPersinstIDByNamesAndRewrites($mysqli_noda, $lang, $persinst_name_en, $persinst_geburtsjahr, $persinst_sterbejahr, $context_identifier, $institution_id)) {
return $existingPersinstId;
}
if ($existingPersinstId = NodaIDGetter::getPersinstIDByNamesAndRewrites($mysqli_noda, $lang, $persinst_name, $persinst_geburtsjahr, $persinst_sterbejahr, $context_identifier, $institution_id)) {
return $existingPersinstId;
}
return 0;
}
/**
* Checks if an place name is valid.
* Returns 0 if the place can be added as a new one / place name can be used as a new one.
* Returns the ID for already known places.
* Throws an exception if the place is blacklisted.
*
* @param MDMysqli $mysqli_noda DB connection to vocabulary.
* @param string $lang User language.
* @param string $place_name Place name.
* @param string $context_identifier Context / instance identifier.
* @param integer $institution_id Institution ID.
*
* @return integer
*/
public static function checkPlaceNameIsUsable(MDMysqli $mysqli_noda, string $lang, string $place_name, string $context_identifier, int $institution_id):int {
if ($storedType = NodaDistinctlyTypedStrings::lookup($mysqli_noda, $lang, $place_name)) {
if ($storedType !== 'orte') {
throw new MDpageParameterMissingException("This term is marked to be distinctly a " . $storedType);
}
}
// Check if the place name is in the current language's blacklist.
if (NodaBlacklistedTerms::checkPlaceBlacklistedInDb($mysqli_noda, $lang, $place_name) === true) {
throw new MDBlacklistedInputException("Term is blacklisted");
}
if ($existingPlaceId = NodaIDGetter::getPlaceIDByNamesAndRewrites($mysqli_noda, $lang, $place_name, $context_identifier, $institution_id)) {
return $existingPlaceId;
}
return 0;
}
}

View File

@@ -138,7 +138,7 @@ final class NodaWikidataFetcher {
return '';
}
$firstPageId = array_keys($json_decoded['query']['pages'])[0];
$datafromwiki = strval($json_decoded['query']['pages'][$firstPageId]['extract']);
$datafromwiki = strval($json_decoded['query']['pages'][$firstPageId]['extract'] ?? "");
return self::_cleanInputSimple($datafromwiki);
@@ -436,6 +436,10 @@ final class NodaWikidataFetcher {
$url = 'https://query.wikidata.org/sparql?query=' . urlencode($sparqlQuery);
$result = MD_STD::runCurl($url, 100000000, self::WIKIDATA_FETCH_HEADERS);
if (json_validate($result) === false) {
throw new MDhttpFailedException("Failed to run SPARQL query");
}
return json_decode($result, true);
}