Allow using Wikidata links for fetching information for actors
This commit is contained in:
@ -82,6 +82,54 @@ final class NodaWikidataFetcher {
|
||||
/** @var MDMysqli */
|
||||
private MDMysqli $_mysqli_noda;
|
||||
|
||||
/**
|
||||
* Attempts to fetch a Wikidata ID from a provided URL.
|
||||
*
|
||||
* @param string $linkUrl Link to a page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getWikidataIdFromLink(string $linkUrl):string {
|
||||
|
||||
if (!filter_var($linkUrl, FILTER_VALIDATE_URL)) {
|
||||
throw new MDExpectedException("Invalid URL");
|
||||
}
|
||||
|
||||
if (strpos($linkUrl, "https://www.wikidata.org/wiki/") !== false) {
|
||||
if ($output = self::getWikidataIdFromWikidataLink($linkUrl)) {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($linkUrl, ".wikipedia.org/") !== false) {
|
||||
if ($output = self::getWikidataIdFromWikipedia($linkUrl)) {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to fetch a Wikidata ID from a provided URL.
|
||||
*
|
||||
* @param string $linkUrl Link to a Wikidata page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getWikidataIdFromWikidataLink(string $linkUrl):string {
|
||||
|
||||
if (strpos($linkUrl, "https://www.wikidata.org/wiki/") === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$linkUrl = trim($linkUrl, '/ ');
|
||||
$parts = explode('/', $linkUrl);
|
||||
return end($parts);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to fetch a Wikidata ID from a provided URL.
|
||||
*
|
||||
@ -91,8 +139,8 @@ final class NodaWikidataFetcher {
|
||||
*/
|
||||
public static function getWikidataIdFromWikipedia(string $linkUrl):string {
|
||||
|
||||
if (!filter_var($linkUrl, FILTER_VALIDATE_URL)) {
|
||||
throw new MDExpectedException("Invalid URL");
|
||||
if (strpos($linkUrl, ".wikipedia.org/") === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$wikipedia_cont = MD_STD::runCurl($linkUrl);
|
||||
|
Reference in New Issue
Block a user