Repository: internetarchive/openlibrary

Issue:
Add a UI for adding identifiers to authors
Related: #144 on the backend -- this added the following fields to Authors, in JSON:
```
remote_ids: {
   viaf: "305232897",
   wikidata: "Q888254",
   isni: "0000000027362838"
}
```

Which are displayed and formatted as links currently on the Author pages, e.g. https://openlibrary.org/authors/OL1102082A under the heading "Links (outside Open Library)"

The missing piece is a field in the Author edit form for users to add these ids.




Discussion:
@mekarpeles I would like to work on this. Can you please explain a little bit more?
@ayushshivani 
There are several things that could play into this. It doesn't need to be perfect to be an improvement, but here are some things I'd suggest from a librarian-user perspective:

The manual editing interface presently allows the user to paste or drag/drop generic html links to these sources. Such links should be automatically recognized and stripped down, to store just the identifier. 

It should also be possible to simply paste the identifier into a form, including over an existing value. 

Before storing an id (or deleting a previous value) there should be a check that the target record exists and that it corresponds to the OLID author record (at least one name in common to both records, and non-conflicting lifespan dates, perhaps with some slop allowed). 

The fetched ISNI records fetched usually include the corresponding VIAF and Wikidata ids. If these do not conflict with an existing value at the OLID target, then they should also be stored there.

The ISNI record will provide variant names for the author. These should be added to the OLID target as a.k.a. entries. This will eventually greatly aid author merging.

Ultimately much of this could be done as a bot cleanup task, but for now making the manual approach work better will be a great help.

Thank you for taking this on.
@LeadSongDog This ticket has a slightly smaller focus (renamed accordingly). The error checking would be useful, but I think this is just for the first step of adding a UI.

Currently, when you edit an edition, you get the option to add identifiers to other sites:

![image](https://user-images.githubusercontent.com/6251786/55238824-cbdeb980-520b-11e9-92ac-ebee18d76639.png)
([src](https://openlibrary.org/books/OL3020703M/Alice's_adventures_in_Wonderland/edit))

This scope of this ticket is to add a similar interface (ideally re-using as much of this code as possible) to author pages.
There is an edit interface for author links:
![authlinks](https://user-images.githubusercontent.com/11435431/55241643-df8d1e80-5211-11e9-9fd2-a776a31ccce5.jpg)

But the identifiers (as opposed to full urls) don't always show up there:
![author](https://user-images.githubusercontent.com/11435431/55241635-d9973d80-5211-11e9-91b9-21331cdf4003.jpg)

In the link box, I can copypaste the URL for an ISNI or VIAF page, and title it "ISNI" or "VIAF"
I'd like to see both kinds of edit work, with just the identifier needing to be stored.
For what it's worth, I just spoke with some editors at Wikimania (a Wikipedia/Wikimedia event) who are interested in contributing corrections to VIAF and Wikidata identifier linkages on Open Library.
> In the link box, I can copypaste the URL for an ISNI or VIAF page, and title it "ISNI" or "VIAF"
> I'd like to see both kinds of edit work, with just the identifier needing to be stored.

@LeadSongDog That's a good goal, but not the focus of this ticket. Let's avoid scope creep.

This ticket is about an identifier edit interface for 3 new author identifiers: Wikidata, VIAF, & ISNI.

Other possible, related, future tickets include:
* enhancing the edit link functionality to recognize links which should be converted to identifiers (#866)
* a data cleanup task to convert all existing links which should instead be identifiers
* a periodic sync/update job to track changes in one or more remote systems

> For what it's worth, I just spoke with some editors at Wikimania (a Wikipedia/Wikimedia event) who are interested in contributing corrections to VIAF and Wikidata identifier linkages on Open Library.

@bnewbold That's excellent, but I think the way that we maximize the efficiency of Wiki* volunteers is to allow them to work in familiar surroundings (ie Wikidata). If we use Wikidata as the central source of truth for all identifiers, we can focus everyone's effort on making sure that is correct. OpenLibrary can then import VIAF, ISNI, Wikipedia, ORCID, etc identifiers/links from there.

As a stopgap, in the interim, we'll have the edit interface proposed by this ticket.
@tfmorris ah, interesting. The way I had envisioned "wikidata as central source of identifier truth" working was that openlibrary entities would have a wikidata QID tag, and then an openlibrary bot/script would use that to do lookups (by wikidata QID), fetch identifiers (and other metadata), then update openlibrary. In this case the onus would be on openlibrary to maintain mappings to wikidata. But I guess you are saying the bot would do lookups based on the *openlibrary identifier* in wikidata and pull updates based on that. 

To clarify my above comment, I think the Wiki* editors were really mostly concerned/interested in pushing Wikidata identifier linkage, more than VIAF or other identifiers. Partially, as a mechanism to drive openlibrary visitors through to wikidata (and/or wikipedia articles) as a source of additional information about entities. This isn't possible if the mapping only exists on the wikidata side. I don't have any horse in that race.

Anyways, that's all a bit off topic. Regardless what the desired future workflow is, seems important to allow manual correction/editing of identifiers on openlibrary via the web interface.
I'm adding LCCN and OL to the ones mentioned. Would it be ok for someone to make a list of all the ones mentioned so far? Here it is:
Wikidata, ISNI, VIAF, LCCN, OLID, ORCID
what is "Classifications: RM666.T65, 616.12061" http://worldcat.org/identities/lccn-n82039404/ is this the VIAF?
@BrittanyBunk I've updated https://github.com/internetarchive/openlibrary/wiki/Guide-to-Identifiers for your reading pleasure, but it doesn't get into classifications.   

RM666.T65 is the LC Class for "Theraputics, Vitamin E" while 616.12061 is the Dewey Decimal Class for "Cardiopulmonary Drug Therapies" both of which would reasonably be applied to https://www.worldcat.org/title/vitamin-e-for-ailing-and-healthy-hearts/oclc/488728428

It's easy to tell DDC from LC Classifications, they're all-numeric.
Is this issue open or is it allotted to somebody as of now?
If it not allotted, I would like to contribute

@SudarshanHV I accidentally created a duplicate of this issue - so this is still open and an issue. You could tell that it still exists, because the layout for author pages is still a work in progress from when I last checked. You could see the issue I brought up #2786 to find out more. I think you're right though about working on this - so that'll be my next task.
Hey @BrittanyBunk! :wave: do you need any help with this?
> Hey @BrittanyBunk!  do you need any help with this?

Yes - the author roles are not alphabetized. It would also be nice if they're categorized. It's also sad that we can't add anymore role names. Why do we need a drop-down menu?

If you could remove the drop-down menu and instead let people fill in whatever they need to - that would be ideal!
Here is the code for how this currently works with editions:
https://github.com/internetarchive/openlibrary/blob/eddaa125d1ace42805ea1bc32fcd11d8aeff7603/openlibrary/templates/books/edit/edition.html#L443-L515

This is the file to edit to add the new code: https://github.com/internetarchive/openlibrary/blob/eddaa125d1ace42805ea1bc32fcd11d8aeff7603/openlibrary/templates/type/author/edit.html

I'm thinking of picking up this ticket and feel like it may be a good use case for Vue (which I am familiar with) since in some future we may want to parse IDs from URLs and giving visual feedback for that is nice. That being said, since #3828 I don't see many (any?) uses of Vue. I'm going to try to follow [this doc](https://github.com/cdrini/openlibrary/blob/9c1ad6dbb5c386ea3679b9dc48250be329f3c981/openlibrary/components/README.md) and see where I get.

Any tips, thoughts, or warnings? I'm going to try to keep it simple and just follow [this comment](https://github.com/internetarchive/openlibrary/issues/853#issuecomment-523593228) with the ability to add/change just three identifiers.

Resolving patch:
diff --git a/openlibrary/plugins/upstream/utils.py b/openlibrary/plugins/upstream/utils.py
--- a/openlibrary/plugins/upstream/utils.py
+++ b/openlibrary/plugins/upstream/utils.py
@@ -136,8 +136,9 @@ def render_component(name, attrs=None, json_encode=True):
     for (key, val) in attrs.items():
         if json_encode and isinstance(val, dict) or isinstance(val, list):
             val = json.dumps(val)
-        attrs_str += ' %s="%s"' % (key, val.replace('"', "'"))
-
+            # On the Vue side use decodeURIComponent to decode
+            val = urllib.parse.quote(val)
+        attrs_str += f' {key}="{val}"'
     html = ''
     included = web.ctx.setdefault("included-components", [])
 
@@ -557,6 +558,27 @@ def get_languages():
         _languages = sorted([web.storage(name=d.name, code=d.code, key=d.key) for d in web.ctx.site.get_many(keys)], key=lambda d: d.name.lower())
     return _languages
 
+
+@public
+def get_author_config():
+    return _get_author_config()
+
+
+@web.memoize
+def _get_author_config():
+    """Returns the author config.
+
+    The results are cached on the first invocation.
+    Any changes to /config/author page require restarting the app.
+
+    """
+    thing = web.ctx.site.get('/config/author')
+    if hasattr(thing, "identifiers"):
+        identifiers = [web.storage(t.dict()) for t in thing.identifiers if 'name' in t]
+    else:
+        identifiers = {}
+    return web.storage(identifiers=identifiers)
+
 @public
 def get_edition_config():
     return _get_edition_config()


Test patch: