Better validate Wikipedia links
This commit is contained in:
parent
609931eb26
commit
d295e16049
|
@ -482,6 +482,28 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a Wikipedia link.
|
||||
*
|
||||
* @param string $id ID to validate.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function validateWikipediaId(string $id):string|false {
|
||||
|
||||
$validation = strtr($id, [
|
||||
'https://de.wikipedia.org/wiki/' => '',
|
||||
'https://en.wikipedia.org/wiki/' => '',
|
||||
'https://sv.wikipedia.org/wiki/' => '',
|
||||
'https://ru.wikipedia.org/wiki/' => '',
|
||||
]);
|
||||
|
||||
if (str_contains($validation, "/")) return false;
|
||||
|
||||
return $validation;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an ID.
|
||||
*
|
||||
|
@ -532,7 +554,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||
'http://viaf.org/viaf/',
|
||||
]),
|
||||
self::wikidata => self::validateWikidataId($id),
|
||||
self::wikipedia => str_replace('https://de.wikipedia.org/wiki/', '', $id),
|
||||
self::wikipedia => self::validateWikipediaId($id),
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user