Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Wikipedia links from Wikidata #9991

Merged
merged 15 commits into from
Nov 22, 2024
Merged

Conversation

RayBB
Copy link
Collaborator

@RayBB RayBB commented Nov 5, 2024

Closes #9360

This PR does three things:

  1. Add the (language aware) Wikipedia link
  2. Adds the Wikidata link
  3. Add the Google Scholar link

Originally, this was just going to be for Wikipedia but I quickly realized the code should be cleaned up and ready to handle multiple profiles since that's the main idea. We settled on Wikipedia because it's the most useful, Wikidata so it can point people where to edit, and Google Scholar because it's well known and only really applies to academics. It's a nice first step before we discuss what icons we want to show and the order.

Technical

  • We decided to statically host these few icons for now. However, we might do a cache from wikidata later when there are many more.
  • We also discussed using monochrome icons but our current iconsets don't have a lot of icons so we decided to punt on that decision until we figure out which profiles we want to show long term.

Testing

  • Add a Wikidata identifier to a profile and see the icons show up

Screenshot

Before After
image image

Stakeholders

@cdrini

@RayBB
Copy link
Collaborator Author

RayBB commented Nov 6, 2024

Dropping a bunch of profiles here we decided to leave out for the first version.


    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/5/5e/ResearchGate_icon_SVG.svg",
        "wikidata_property": "P2038",
        "label": "ResearchGate",
        "base_url": "https://www.researchgate.net/profile/",
    },
    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/0/06/ORCID_iD.svg",
        "wikidata_property": "P496",
        "label": "ORCID",
        "base_url": "https://orcid.org/",
    },
    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/c/c7/Google_Scholar_logo.svg",
        "wikidata_property": "P1960",
        "label": "Google Scholar",
        "base_url": "https://scholar.google.com/citations?user=",
    },
    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/6/66/Academia-logo-2021.svg",
        "wikidata_property": "P5715",
        "label": "Academia.edu",
        "base_url": "",
    },
    {
        "icon_url": "https://avatars.githubusercontent.com/u/2212508",
        "wikidata_property": "P6005",
        "label": "Muck Rack",
        "base_url": "https://muckrack.com/",
    },
    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Mastodon_logotype_%28simple%29_new_hue.svg",
        "wikidata_property": "P4033",
        "label": "Mastodon",
        "base_url": "https://fedirect.toolforge.org/?id=",
    },
    {
        "icon_url": "https://play-lh.googleusercontent.com/XXqfqs9irPSjphsMPcC-c6Q4-FY5cd8klw4IdI2lof_Ie-yXaFirqbNDzK2kJ808WXJk",
        "wikidata_property": "P4985",
        "label": "TMDB",
        "base_url": "https://www.themoviedb.org/person/",
    },
    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/c/cb/Cib-imdb_%28CoreUI_Icons_v1.0.0%29.svg",
        "wikidata_property": "P345",
        "label": "IMDb",
        "base_url": "https://www.imdb.com/name/",
    },
    {
        "icon_url": "https://upload.wikimedia.org/wikipedia/commons/c/ce/X_logo_2023.svg",
        "wikidata_property": "P2002",
        "label": "X (Twitter)",
        "base_url": "https://twitter.com/",
    },

openlibrary/core/wikidata.py Outdated Show resolved Hide resolved
openlibrary/templates/authors/infobox.html Outdated Show resolved Hide resolved
@RayBB RayBB changed the title add wikipedia links from wikidata add Wikipedia links from Wikidata Nov 6, 2024
@RayBB RayBB marked this pull request as ready for review November 6, 2024 19:23
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good overall; I can't quite test it until the http proxy is set up on our servers so that they can make the wikidata network call. That should be happening in the next day or so (CC @jimchamp ).

[
{
"url": f"{profile_config['base_url']}{value}",
"icon_url": f"/static/images/identifier_icons/{profile_config["icon_name"]}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"icon_url": f"/static/images/identifier_icons/{profile_config["icon_name"]}",
"icon_url": f"/static/images/identifier_icons/{profile_config['icon_name']}",

?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python 3.12+, this is actually ok! They rewrote the parser to make f-strings more resilient :) https://peps.python.org/pep-0701/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh. Neat!

@@ -32,14 +42,10 @@ class WikidataEntity:
labels: dict[str, str]
descriptions: dict[str, str]
aliases: dict[str, list[str]]
statements: dict[str, dict]
statements: dict[str, list[dict]]
sitelinks: dict[str, dict]
_updated: datetime # This is when we fetched the data, not when the entity was changed in Wikidata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is from a different PR, but would it make sense to call this _fetched or _last_fetched instead to avoid the ambiguity and need of the comment? (Probably also something for a different PR since, either way, it’s unrelated to adding Wikipedia links.)

Comment on lines +17 to +19
$def render_social_icon(url, icon_url, title):
<a href="$url" title="$_('View on %(site)s', site=title)">
<img class="profile-icon" src="$icon_url" alt="">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$def render_social_icon(url, icon_url, title):
<a href="$url" title="$_('View on %(site)s', site=title)">
<img class="profile-icon" src="$icon_url" alt="">
$def render_social_icon(url, icon_url, label):
<a href="$url" title="$_('View on %(site)s', site=label)">
<img class="profile-icon" src="$icon_url" alt="$label">

The alt property should describe/be a stand‐in for the image, so the social’s label is probably a good fit. (Also, changing the title to label to be consistent with how it’s named in the dict, since my first iteration of this had the function signature take an addition label property…)

Copy link
Collaborator

@cdrini cdrini Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, because we have the title tag on the above anchor element, the image can be seen as purely presentational, and doesn't require an alt tag (or more specifically requires an alt="" tag to denote it's presentational). E.g. screen readers will read the title tag, I believe. But this is a bit of an edge case, so not entirely sure.

@cdrini cdrini added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Nov 21, 2024
@@ -14,6 +14,11 @@
<td><span itemprop="$itemprop">$value</span></td>
</tr>

$def render_social_icon(url, icon_url, title):
<a href="$url" title="$_('View on %(site)s', site=title)">
Copy link
Collaborator

@cdrini cdrini Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<a href="$url" title="$_('View on %(site)s', site=title)">
<a href="$url" title="$_('View on %(site)s', site=title)" data-ol-link-track="AuthorSocialLink|$title">

For another PR: it would be nice to have analytics on this; can $title have spaces/etc we might need to strip?

Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is now working with @jimchamp 's latest PR changes ! 🥳

@cdrini cdrini merged commit 5fb3126 into master Nov 22, 2024
7 checks passed
@cdrini cdrini deleted the feature/9360-wikipedia-from-wikidata branch November 22, 2024 18:00
@alanvalenciagonzalez936
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Wikidata On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Wikipedia link to author page based on Wikidata
4 participants