Merge branch '3.0'
This commit is contained in:
commit
df2b3b11ef
|
@ -644,7 +644,7 @@
|
|||
|
||||
if (result && newName.value) {
|
||||
// Add other ids with same tag
|
||||
var ids = Zotero.Tags.getIDs(oldName);
|
||||
var ids = Zotero.Tags.getIDs(oldName, this.libraryID);
|
||||
|
||||
for (var i=0; i<ids.length; i++) {
|
||||
if (tagIDs.indexOf(ids[i]) == -1) {
|
||||
|
@ -691,7 +691,7 @@
|
|||
Zotero.DB.beginTransaction();
|
||||
|
||||
// Add other ids with same tag
|
||||
var ids = Zotero.Tags.getIDs(oldName);
|
||||
var ids = Zotero.Tags.getIDs(oldName, this.libraryID);
|
||||
for each(var id in ids) {
|
||||
if (tagIDs.indexOf(id) == -1) {
|
||||
tagIDs.push(id);
|
||||
|
|
|
@ -313,21 +313,21 @@ var Zotero_QuickFormat = new function () {
|
|||
Zotero.debug("Searched cited items");
|
||||
}
|
||||
|
||||
_updateItemList(citedItemsMatchingSearch, searchResultIDs, isAsync);
|
||||
_updateItemList(citedItems, citedItemsMatchingSearch, searchResultIDs, isAsync);
|
||||
});
|
||||
|
||||
if(!completed) {
|
||||
// We are going to have to wait until items have been retrieved from the document.
|
||||
// Until then, show item list without cited items.
|
||||
Zotero.debug("Getting cited items asynchronously");
|
||||
_updateItemList(false, searchResultIDs);
|
||||
_updateItemList(false, false, searchResultIDs);
|
||||
isAsync = true;
|
||||
} else {
|
||||
Zotero.debug("Got cited items synchronously");
|
||||
}
|
||||
} else {
|
||||
// No search conditions, so just clear the box
|
||||
_updateItemList([], []);
|
||||
_updateItemList([], [], []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ var Zotero_QuickFormat = new function () {
|
|||
/**
|
||||
* Updates the item list
|
||||
*/
|
||||
function _updateItemList(citedItems, searchResultIDs, preserveSelection) {
|
||||
function _updateItemList(citedItems, citedItemsMatchingSearch, searchResultIDs, preserveSelection) {
|
||||
var selectedIndex = 1, previousItemID;
|
||||
|
||||
// Do this so we can preserve the selected item after cited items have been loaded
|
||||
|
@ -366,13 +366,8 @@ var Zotero_QuickFormat = new function () {
|
|||
selectedIndex = 2;
|
||||
} else if(citedItems.length) {
|
||||
// We have cited items
|
||||
referenceBox.appendChild(_buildListSeparator(Zotero.getString("integration.cited")));
|
||||
for(var i=0, n=citedItems.length; i<n; i++) {
|
||||
var citedItem = citedItems[i];
|
||||
if(i < 50) {
|
||||
referenceBox.appendChild(_buildListItem(citedItem));
|
||||
}
|
||||
|
||||
// Tabulate number of items in document for each library
|
||||
if(!citedItem.cslItemID) {
|
||||
var libraryID = citedItem.libraryID ? citedItem.libraryID : 0;
|
||||
|
@ -383,6 +378,14 @@ var Zotero_QuickFormat = new function () {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(citedItemsMatchingSearch && citedItemsMatchingSearch.length) {
|
||||
referenceBox.appendChild(_buildListSeparator(Zotero.getString("integration.cited")));
|
||||
for(var i=0; i<Math.min(citedItemsMatchingSearch.length, 50); i++) {
|
||||
var citedItem = citedItemsMatchingSearch[i];
|
||||
referenceBox.appendChild(_buildListItem(citedItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also take into account items cited in this citation. This means that the sorting isn't
|
||||
|
@ -400,7 +403,7 @@ var Zotero_QuickFormat = new function () {
|
|||
}
|
||||
}
|
||||
|
||||
if(searchResultIDs.length && (!citedItems || citedItems.length < 50)) {
|
||||
if(searchResultIDs.length && (!citedItemsMatchingSearch || citedItemsMatchingSearch.length < 50)) {
|
||||
var items = Zotero.Items.get(searchResultIDs);
|
||||
|
||||
items.sort(function _itemSort(a, b) {
|
||||
|
@ -437,7 +440,7 @@ var Zotero_QuickFormat = new function () {
|
|||
});
|
||||
|
||||
var previousLibrary = -1;
|
||||
for(var i=0, n=Math.min(items.length, citedItems ? 50-citedItems.length : 50); i<n; i++) {
|
||||
for(var i=0, n=Math.min(items.length, citedItemsMatchingSearch ? 50-citedItemsMatchingSearch.length : 50); i<n; i++) {
|
||||
var item = items[i], libraryID = item.libraryID;
|
||||
|
||||
if(previousLibrary != libraryID) {
|
||||
|
@ -456,7 +459,7 @@ var Zotero_QuickFormat = new function () {
|
|||
}
|
||||
|
||||
_resize();
|
||||
if((citedItems && citedItems.length) || searchResultIDs.length) {
|
||||
if((citedItemsMatchingSearch && citedItemsMatchingSearch.length) || searchResultIDs.length) {
|
||||
referenceBox.selectedIndex = selectedIndex;
|
||||
referenceBox.ensureIndexIsVisible(selectedIndex);
|
||||
}
|
||||
|
|
|
@ -245,8 +245,6 @@ Zotero_RecognizePDF.Recognizer = function () {}
|
|||
Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, callback, captchaCallback) {
|
||||
const MAX_PAGES = 3;
|
||||
|
||||
const lineRe = /^\s*([^\s]+(?: [^\s]+)+)/;
|
||||
|
||||
this._libraryID = libraryID;
|
||||
this._callback = callback;
|
||||
//this._captchaCallback = captchaCallback;
|
||||
|
@ -257,10 +255,6 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
|
|||
cacheFile.remove(false);
|
||||
}
|
||||
|
||||
Zotero.debug('Running pdftotext -enc UTF-8 -nopgbrk '
|
||||
+ '-l ' + MAX_PAGES + ' "' + file.path + '" "'
|
||||
+ cacheFile.path + '"');
|
||||
|
||||
var proc = Components.classes["@mozilla.org/process/util;1"].
|
||||
createInstance(Components.interfaces.nsIProcess);
|
||||
var exec = Zotero.getZoteroDirectory();
|
||||
|
@ -269,6 +263,8 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
|
|||
|
||||
var args = ['-enc', 'UTF-8', '-nopgbrk', '-layout', '-l', MAX_PAGES];
|
||||
args.push(file.path, cacheFile.path);
|
||||
|
||||
Zotero.debug('Running pdftotext '+args.join(" "));
|
||||
try {
|
||||
if (!Zotero.isFx36) {
|
||||
proc.runw(true, args, args.length);
|
||||
|
@ -297,15 +293,13 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
|
|||
intlStream.QueryInterface(Components.interfaces.nsIUnicharLineInputStream);
|
||||
|
||||
// get the lines in this sample
|
||||
var lines = [];
|
||||
var lineLengths = [];
|
||||
var str = {};
|
||||
var lines = [],
|
||||
cleanedLines = [],
|
||||
cleanedLineLengths = [],
|
||||
str = {};
|
||||
while(intlStream.readLine(str)) {
|
||||
var line = lineRe.exec(str.value);
|
||||
if(line) {
|
||||
lines.push(line[1]);
|
||||
lineLengths.push(line[1].length);
|
||||
}
|
||||
var line = str.value.trim();
|
||||
if(line) lines.push(line);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
|
@ -319,13 +313,23 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
|
|||
this._DOI = m[0];
|
||||
}
|
||||
|
||||
// Use only first column from multi-column lines
|
||||
const lineRe = /^\s*([^\s]+(?: [^\s]+)+)/;
|
||||
for(var i=0; i<lines.length; i++) {
|
||||
var m = lineRe.exec(lines[i]);
|
||||
if(m) {
|
||||
cleanedLines.push(m[1]);
|
||||
cleanedLineLengths.push(m[1].length);
|
||||
}
|
||||
}
|
||||
|
||||
// get (not quite) median length
|
||||
var lineLengthsLength = lineLengths.length;
|
||||
var lineLengthsLength = cleanedLineLengths.length;
|
||||
if(lineLengthsLength < 20
|
||||
|| lines[0] === "This is a digital copy of a book that was preserved for generations on library shelves before it was carefully scanned by Google as part of a project") {
|
||||
|| cleanedLines[0] === "This is a digital copy of a book that was preserved for generations on library shelves before it was carefully scanned by Google as part of a project") {
|
||||
this._callback(false, "recognizePDF.noOCR");
|
||||
} else {
|
||||
var sortedLengths = lineLengths.sort();
|
||||
var sortedLengths = cleanedLineLengths.sort();
|
||||
var medianLength = sortedLengths[Math.floor(lineLengthsLength/2)];
|
||||
|
||||
// pick lines within 4 chars of the median (this is completely arbitrary)
|
||||
|
@ -333,9 +337,9 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
|
|||
var uBound = medianLength + 4;
|
||||
var lBound = medianLength - 4;
|
||||
for (var i=0; i<lineLengthsLength; i++) {
|
||||
if(lineLengths[i] > lBound && lineLengths[i] < uBound) {
|
||||
if(cleanedLineLengths[i] > lBound && cleanedLineLengths[i] < uBound) {
|
||||
// Strip quotation marks so they don't mess up search query quoting
|
||||
var line = lines[i].replace('"', '');
|
||||
var line = cleanedLines[i].replace('"', '');
|
||||
this._goodLines.push(line);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ if (!Array.indexOf) {
|
|||
};
|
||||
}
|
||||
var CSL = {
|
||||
PROCESSOR_VERSION: "1.0.342",
|
||||
STATUTE_SUBDIV_GROUPED_REGEX: /((?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/g,
|
||||
STATUTE_SUBDIV_PLAIN_REGEX: /(?:(?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/,
|
||||
STATUTE_SUBDIV_STRINGS: {
|
||||
|
@ -2204,7 +2205,7 @@ CSL.DateParser = function () {
|
|||
};
|
||||
CSL.Engine = function (sys, style, lang, forceLang) {
|
||||
var attrs, langspec, localexml, locale;
|
||||
this.processor_version = "1.0.339";
|
||||
this.processor_version = CSL.PROCESSOR_VERSION;
|
||||
this.csl_version = "1.0";
|
||||
this.sys = sys;
|
||||
this.sys.xml = new CSL.System.Xml.Parsing();
|
||||
|
@ -8113,6 +8114,10 @@ CSL.Node.text = {
|
|||
if (!this.decorations.length || this.decorations[0][0] !== "@" + this.variables[0]) {
|
||||
this.decorations = [["@" + this.variables[0], "true"]].concat(this.decorations);
|
||||
}
|
||||
} else {
|
||||
if (this.decorations.length && this.decorations[0][0] === "@" + this.variables[0]) {
|
||||
this.decorations = this.decorations.slice(1);
|
||||
}
|
||||
}
|
||||
state.output.append(value, this, false, false, true);
|
||||
}
|
||||
|
@ -9362,7 +9367,7 @@ CSL.Transform = function (state) {
|
|||
}
|
||||
return function (state, Item, item, usedOrig) {
|
||||
var primary, secondary, tertiary, primary_tok, group_tok, key;
|
||||
if (!variables[0]) {
|
||||
if (!variables[0] || (!Item[variables[0]] && !Item[alternative_varname])) {
|
||||
return null;
|
||||
}
|
||||
var slot = {primary:false, secondary:false, tertiary:false};
|
||||
|
@ -11404,19 +11409,17 @@ CSL.Output.Formatters.sentence = function (state, string) {
|
|||
return CSL.Output.Formatters.undoppelString(str);
|
||||
};
|
||||
CSL.Output.Formatters["capitalize-all"] = function (state, string) {
|
||||
var str, strings, len, pos;
|
||||
str = CSL.Output.Formatters.doppelString(string, CSL.TAG_ESCAPE);
|
||||
strings = str.string.split(" ");
|
||||
len = strings.length;
|
||||
for (pos = 0; pos < len; pos += 1) {
|
||||
if (strings[pos].length > 1) {
|
||||
var str = CSL.Output.Formatters.doppelString(string, CSL.TAG_ESCAPE);
|
||||
var strings = str.string.split(" ");
|
||||
for (var i = 0, ilen = strings.length; i < ilen; i += 1) {
|
||||
if (strings[i].length > 1) {
|
||||
if (state.opt.development_extensions.allow_force_lowercase) {
|
||||
strings[pos] = strings[pos].slice(0, 1).toUpperCase() + strings[pos].substr(1).toLowerCase();
|
||||
strings[i] = strings[i].slice(0, 1).toUpperCase() + strings[i].substr(1).toLowerCase();
|
||||
} else {
|
||||
strings[pos] = strings[pos].slice(0, 1).toUpperCase() + strings[pos].substr(1);
|
||||
strings[i] = strings[i].slice(0, 1).toUpperCase() + strings[i].substr(1);
|
||||
}
|
||||
} else if (strings[pos].length === 1) {
|
||||
strings[pos] = strings[pos].toUpperCase();
|
||||
} else if (strings[i].length === 1) {
|
||||
strings[i] = strings[i].toUpperCase();
|
||||
}
|
||||
}
|
||||
str.string = strings.join(" ");
|
||||
|
@ -11964,18 +11967,11 @@ CSL.Registry.prototype.renumber = function () {
|
|||
for (pos = 0; pos < len; pos += 1) {
|
||||
item = this.reflist[pos];
|
||||
item.seq = (pos + 1);
|
||||
var hasTaints = false;
|
||||
for (var key in this.state.tmp.taintedItemIDs) {
|
||||
hasTaints = true;
|
||||
break;
|
||||
if (this.state.opt.update_mode === CSL.NUMERIC && item.seq != this.oldseq[item.id]) {
|
||||
this.state.tmp.taintedItemIDs[item.id] = true;
|
||||
}
|
||||
if (hasTaints && item.seq != this.oldseq[item.id]) {
|
||||
if (this.state.opt.update_mode === CSL.NUMERIC) {
|
||||
this.state.tmp.taintedItemIDs[item.id] = true;
|
||||
}
|
||||
if (this.state.opt.bib_mode === CSL.NUMERIC) {
|
||||
this.return_data.bibchange = true;
|
||||
}
|
||||
if (this.state.opt.bib_mode === CSL.NUMERIC && item.seq != this.oldseq[item.id]) {
|
||||
this.return_data.bibchange = true;
|
||||
}
|
||||
}
|
||||
if (this.state.opt.citation_number_sort_direction === CSL.DESCENDING
|
||||
|
|
|
@ -2655,6 +2655,7 @@ Zotero.Integration.Session.prototype.updateCitations = function(callback) {
|
|||
index = parseInt(index);
|
||||
|
||||
var citation = this.citationsByIndex[index];
|
||||
if(!citation) continue;
|
||||
if(citation.properties.delete) {
|
||||
deleteCitations[index] = true;
|
||||
continue;
|
||||
|
|
|
@ -758,7 +758,7 @@ $rdf.Serializer = function () {
|
|||
|
||||
var attrs = '';
|
||||
if(subject.termType == 'bnode') {
|
||||
if(sz.incoming[subject].length != 1) { // not an anonymous bnode
|
||||
if(!sz.incoming[subject] || sz.incoming[subject].length != 1) { // not an anonymous bnode
|
||||
attrs = ' rdf:nodeID="' + subject.toNT().slice(2) + '"';
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1399,7 +1399,7 @@ Zotero.Utilities = {
|
|||
var isZoteroItem = item instanceof Zotero.Item, zoteroType;
|
||||
|
||||
for(var type in CSL_TYPE_MAPPINGS) {
|
||||
if(CSL_TYPE_MAPPINGS[zoteroType] == item.type) {
|
||||
if(CSL_TYPE_MAPPINGS[type] == cslItem.type) {
|
||||
zoteroType = type;
|
||||
break;
|
||||
}
|
||||
|
@ -1484,11 +1484,37 @@ Zotero.Utilities = {
|
|||
if(Zotero.ItemFields.isValidForType(fieldID, itemTypeID)) {
|
||||
var date = "";
|
||||
if(cslDate.literal) {
|
||||
date = cslDate.literal;
|
||||
} else if(cslDate.year) {
|
||||
if(cslDate.month) cslDate.month--;
|
||||
date = Zotero.Date.formatDate(cslDate);
|
||||
if(cslDate.season) date = cslDate.season+date;
|
||||
if(variable === "accessed") {
|
||||
date = strToISO(cslDate.literal);
|
||||
} else {
|
||||
date = cslDate.literal;
|
||||
}
|
||||
} else {
|
||||
var newDate = Zotero.Utilities.deepCopy(cslDate);;
|
||||
if(cslDate.dateParts && typeof cslDate.dateParts == "object") {
|
||||
if(cslDate.dateParts[0]) newDate.year = cslDate.dateParts[0];
|
||||
if(cslDate.dateParts[1]) newDate.month = cslDate.dateParts[1];
|
||||
if(cslDate.dateParts[2]) newDate.day = cslDate.dateParts[2];
|
||||
}
|
||||
|
||||
if(newDate.year) {
|
||||
if(variable === "accessed") {
|
||||
// Need to convert to SQL
|
||||
var date = Zotero.Utilities.lpad(newDate.year, "0", 4);
|
||||
if(newDate.month) {
|
||||
date += "-"+Zotero.Utilities.lpad(newDate.month+1, "0", 2);
|
||||
if(newDate.day) {
|
||||
date += "-"+Zotero.Utilities.lpad(newDate.day, "0", 2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(newDate.month) newDate.month--;
|
||||
date = Zotero.Date.formatDate(newDate);
|
||||
if(newDate.season) {
|
||||
date = newDate.season+" "+date;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isZoteroItem) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user