diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index 526347f952..5b57832522 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -624,6 +624,7 @@ var Zotero_Citation_Dialog = new function () { } return false; } + item.ignoreRetraction = true; break; } } diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index f012662dcb..1a332ac531 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -742,6 +742,8 @@ var Zotero_QuickFormat = new function () { Zotero_QuickFormat.showInLibrary(parseInt(citationItem.id)); } return false; + } else { + citationItem.ignoreRetraction = true; } } diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index b297baee26..15cb0a11ae 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -967,6 +967,13 @@ Zotero.Integration.Fields.prototype.updateSession = Zotero.Promise.coroutine(fun this._session.regenAll = true; } yield this._processFields(); + try { + yield this._session.handleRetractedItems(); + } + catch (e) { + Zotero.debug('Retracted item handling failed'); + Zotero.logError(e); + } this._session.regenAll = false; var updateTime = timer.stop(); @@ -1928,6 +1935,69 @@ Zotero.Integration.Session.prototype.getItems = function() { return Zotero.Cite.getItem(Object.keys(this.citationsByItemID)); } +Zotero.Integration.Session.prototype.handleRetractedItems = async function () { + const dealWithRetracted = (citedItem, inLibrary) => { + let dontPromptAgain = this.promptForRetraction(citedItem, inLibrary); + if (dontPromptAgain) { + for (let citation of this.citationsByItemID[citedItem.id]) { + for (let item of citation.citationItems) { + item.ignoreRetraction = true; + } + } + } + }; + let zoteroItems = this.getItems(); + let embeddedZoteroItems = []; + for (let zoteroItem of zoteroItems) { + let itemID = zoteroItem.id || zoteroItem.cslItemID; + let citation = this.citationsByItemID[itemID][0]; + let citationItem = citation.citationItems.find(i => i.id == itemID); + if (!citationItem.ignoreRetraction) { + if (zoteroItem.cslItemID) { + embeddedZoteroItems.push(zoteroItem); + } + else if (Zotero.Retractions.isRetracted(zoteroItem)) { + dealWithRetracted(zoteroItem, true); + } + } + } + try { + var retractedIndices = await Zotero.Retractions.getRetractionsFromJSON( + embeddedZoteroItems.map(item => item.toJSON())); + } catch (e) { + Zotero.debug("Retraction for embedded docs lookup failed"); + Zotero.logError(e); + } + for (let index of retractedIndices) { + dealWithRetracted(embeddedZoteroItems[index]); + } +}; + +Zotero.Integration.Session.prototype.promptForRetraction = function (citedItem, inLibrary) { + let ps = Services.prompt; + let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_OK); + // Cannot use citedItem.firstCreator since embedded items do not have that + let creator = citedItem.getCreator(0); + let itemString = (creator ? creator.lastName + ", " : "") + + citedItem.getField('year') + ", " + + citedItem.getDisplayTitle(); + let promptText = Zotero.getString('retraction.citedItemWarning') + + "\n\n" + + itemString; + if (inLibrary) { + promptText += "\n\n" + Zotero.getString('retraction.citeWarning.text2'); + } + let checkbox = { value: false }; + ps.confirmEx(null, + Zotero.getString('general.warning'), + promptText, + buttonFlags, + null, null, null, + Zotero.getString('retraction.citedItemWarning.dontWarn'), checkbox); + + return checkbox.value; +} + /** * Edits integration bibliography @@ -2720,7 +2790,7 @@ Zotero.Integration.Citation = class { toJSON() { const saveProperties = ["custom", "unsorted", "formattedCitation", "plainCitation", "dontUpdate", "noteIndex"]; const saveCitationItemKeys = ["locator", "label", "suppress-author", "author-only", "prefix", - "suffix"]; + "suffix", "ignoreRetraction"]; var citation = {}; diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 5cb7b904e5..23e6221716 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -1211,3 +1211,5 @@ retraction.details = More details: retraction.credit = Data from %S retraction.citeWarning.text1 = The item you are citing has been retracted. Do you still want to add it to your document? retraction.citeWarning.text2 = You can view the item in your library for further details on the retraction. +retraction.citedItemWarning = A cited item in your document has been retracted: +retraction.citedItemWarning.dontWarn = Don’t warn me about this item again