fix: some wikipedia images do not have a LicenseUrl eg for Branta canadensis, a public domain image. Set the licence url to the external link in that case
This commit is contained in:
+18
-10
@@ -408,8 +408,8 @@ class Wikipedia extends ImageProvider {
|
|||||||
protected $db_path = __ROOT__ . '/scripts/wikipedia.db';
|
protected $db_path = __ROOT__ . '/scripts/wikipedia.db';
|
||||||
|
|
||||||
protected function get_from_source($sci_name) {
|
protected function get_from_source($sci_name) {
|
||||||
$title = str_replace(' ', '_', $sci_name);
|
$page_title = str_replace(' ', '_', $sci_name);
|
||||||
$data = $this->get_json("https://en.wikipedia.org/api/rest_v1/page/summary/$title");
|
$data = $this->get_json("https://en.wikipedia.org/api/rest_v1/page/summary/$page_title");
|
||||||
if ($data == false or !isset($data['originalimage']))
|
if ($data == false or !isset($data['originalimage']))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -418,6 +418,9 @@ class Wikipedia extends ImageProvider {
|
|||||||
if ($metadata == false or !isset($metadata['query']['pages']))
|
if ($metadata == false or !isset($metadata['query']['pages']))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
$image_url = $data['originalimage']['source'];
|
||||||
|
$title = $data['title'];
|
||||||
|
|
||||||
foreach ($metadata['query']['pages'] as $page) {
|
foreach ($metadata['query']['pages'] as $page) {
|
||||||
$details = $page['imageinfo']['0']['extmetadata'];
|
$details = $page['imageinfo']['0']['extmetadata'];
|
||||||
$author = $details['Artist']['value'];
|
$author = $details['Artist']['value'];
|
||||||
@@ -427,13 +430,14 @@ class Wikipedia extends ImageProvider {
|
|||||||
} else {
|
} else {
|
||||||
$author_url = "https://en.wikipedia.org/wiki/File:$image_name";
|
$author_url = "https://en.wikipedia.org/wiki/File:$image_name";
|
||||||
}
|
}
|
||||||
|
if (isset($details['LicenseUrl'])) {
|
||||||
$license_url = $details['LicenseUrl']['value'];
|
$license_url = $details['LicenseUrl']['value'];
|
||||||
|
} else {
|
||||||
|
$license_url = $this->get_external_link($image_url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$engname = get_com_en_name($sci_name);
|
$engname = get_com_en_name($sci_name);
|
||||||
$image_url = $data['originalimage']['source'];
|
|
||||||
$title = $data['title'];
|
|
||||||
|
|
||||||
// $sci_name, $com_en_name, $image_url, $title, $id, $author_url, $license_url
|
// $sci_name, $com_en_name, $image_url, $title, $id, $author_url, $license_url
|
||||||
$this->set_image_in_db($sci_name, $engname, $image_url, $title, $sci_name, $author_url, $license_url);
|
$this->set_image_in_db($sci_name, $engname, $image_url, $title, $sci_name, $author_url, $license_url);
|
||||||
@@ -443,12 +447,16 @@ class Wikipedia extends ImageProvider {
|
|||||||
$image = parent::get_image($sci_name);
|
$image = parent::get_image($sci_name);
|
||||||
if ($image === false)
|
if ($image === false)
|
||||||
return false;
|
return false;
|
||||||
$image_name = substr($image['image_url'], strrpos($image['image_url'], '/') + 1);
|
|
||||||
// external link to photo
|
$image['photos_url'] = $this->get_external_link($image['image_url']);
|
||||||
$photos_url = "https://en.wikipedia.org/wiki/File:$image_name";
|
|
||||||
$image['photos_url'] = $photos_url;
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_external_link($image_url) {
|
||||||
|
$image_name = substr($image_url, strrpos($image_url, '/') + 1);
|
||||||
|
$photo_url = "https://en.wikipedia.org/wiki/File:$image_name";
|
||||||
|
return $photo_url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_info_url($sciname){
|
function get_info_url($sciname){
|
||||||
|
|||||||
Reference in New Issue
Block a user