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

Update the URL of an item via wikidata P953 value #237

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/itemWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,14 @@ export default class ItemWrapper{
}

setPID(type, value, save=true) {
type = type.toUpperCase();

// the url field type as to be stay in lower case
if (type != 'url') {
type = type.toUpperCase();
}
switch (type) {
case 'DOI':
case 'ISBN':
case 'ISBN', 'url':
if (this.isValidField(type)) {
this.item.setField(type, value);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/wikidata.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const properties = {
'publicationDate': 'P577',
'statedIn': 'P248',
'refUrl': 'P854',
'citoIntention': 'P3712'
'citoIntention': 'P3712',
'openAccessUrl': 'P953'
};

// Fixme: have it as a global variable like this,
Expand Down
25 changes: 25 additions & 0 deletions src/zoteroOverlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SourceItemWrapper from './sourceItemWrapper';
import WikiciteChrome from './wikiciteChrome';
import Wikidata from './wikidata';
import wikicite from './wikicite';
import wikidata from './wikidata';

const TRANSLATORS_PATH = 'chrome://cita/content/translators/'
const TRANSLATOR_LABELS = [
Expand Down Expand Up @@ -401,6 +402,29 @@ const zoteroOverlay = {
}
},

/**
* Set the URL value of a Zotero item with the value of it's P953 wikidata element statement
*/
fetchOpenAccessUrls: async function(menuName) {
const items = await this.getSelectedItems(menuName);

for (const item of items) {
// get the QID of the item
const qid = item.getPID('QID');

debug('QID : ' + qid);

// fetch the value of the P953 of the element
const OpenAccessUrl = await Wikidata.getProperties(qid, 'openAccessUrl');
Futur3r marked this conversation as resolved.
Show resolved Hide resolved

debug('Open Access URL fetched as : ' + JSON.stringify(OpenAccessUrl));
// debug ex: Open Access URL fetched as : {"Q115183044":{"openAccessUrl":[]}}

// for each targetItem set the url field with the new Open Access url
item.setPID('url', OpenAccessUrl);
}
},

syncWithWikidata: async function(menuName) {
const items = await this.getSelectedItems(menuName);
if (items.length) {
Expand Down Expand Up @@ -1057,6 +1081,7 @@ const zoteroOverlay = {
createMenuItems: function(menuName, menuPopup, IDPrefix, elementsAreRoot, doc) {
const menuFunctions = [
'fetchQIDs',
'fetchOpenAccessUrls',
'syncWithWikidata',
'getFromCrossref',
'getFromOCC',
Expand Down
3 changes: 2 additions & 1 deletion static/chrome/locale/en-US/wikicite.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ wikicite.editor.title = Citation Editor
wikicite.extract.unsupported = Extracting citations from file attachments not yet supported.
wikicite.global.name = Cita
wikicite.global.unsupported = Unsupported
wikicite.item-menu.autolink-citations = Auto link citations with Zotero items
wikicite.item-menu.autolink-citations = Auto link citations with Zotero items
wikicite.item-menu.export-file = Export citations to file
wikicite.item-menu.export-croci = Export citations to CROCI
wikicite.item-menu.fetch-citation-qids = Fetch QIDs for cited items
Expand Down Expand Up @@ -146,6 +146,7 @@ wikicite.source-item.import.progress.error = Importing citations failed
wikicite.source-item.import.progress.loading = Importing citations...
wikicite.source-item.import.progress.none = No citations detected
wikicite.source-item.sync-single-citation.unsupported = Syncing individual citations with Wikidata not yet supported
wikicite.submenu.fetch-open-access-urls = Fetch open access url(s)
wikicite.submenu.add-as-citations = Add as citation(s) to...
wikicite.submenu.fetch-qids = Fetch QID(s)
wikicite.submenu.get-from-attachments = Extract citations from attachments
Expand Down
1 change: 1 addition & 0 deletions static/chrome/locale/fr/wikicite.properties
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ wikicite.source-item.import.progress.loading=Importation de citations...
wikicite.source-item.import.progress.none=Aucune citation détectée
wikicite.source-item.sync-single-citation.unsupported=Synchronisation de citations individuelles avec Wikidata non encore prise en charge
# Fuzzy
wikicite.submenu.fetch-open-access-urls=Obtenir urls en libre accès
wikicite.submenu.add-as-citations=Ajouter comme citations vers...
wikicite.submenu.fetch-qids=Obtenir les QID
wikicite.submenu.get-from-attachments=Extraire les citations des pièces jointes
Expand Down