Better validate Wikipedia links

This commit is contained in:
Joshua Ramon Enslin 2023-09-26 01:30:40 +02:00
parent 609931eb26
commit d295e16049
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -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),
};
}