Merge branch '3.0'

This commit is contained in:
Simon Kornblith 2012-06-24 17:40:20 -04:00
commit df2b3b11ef
7 changed files with 93 additions and 63 deletions

View File

@ -644,7 +644,7 @@
if (result && newName.value) { if (result && newName.value) {
// Add other ids with same tag // 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++) { for (var i=0; i<ids.length; i++) {
if (tagIDs.indexOf(ids[i]) == -1) { if (tagIDs.indexOf(ids[i]) == -1) {
@ -691,7 +691,7 @@
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
// Add other ids with same tag // 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) { for each(var id in ids) {
if (tagIDs.indexOf(id) == -1) { if (tagIDs.indexOf(id) == -1) {
tagIDs.push(id); tagIDs.push(id);

View File

@ -313,21 +313,21 @@ var Zotero_QuickFormat = new function () {
Zotero.debug("Searched cited items"); Zotero.debug("Searched cited items");
} }
_updateItemList(citedItemsMatchingSearch, searchResultIDs, isAsync); _updateItemList(citedItems, citedItemsMatchingSearch, searchResultIDs, isAsync);
}); });
if(!completed) { if(!completed) {
// We are going to have to wait until items have been retrieved from the document. // We are going to have to wait until items have been retrieved from the document.
// Until then, show item list without cited items. // Until then, show item list without cited items.
Zotero.debug("Getting cited items asynchronously"); Zotero.debug("Getting cited items asynchronously");
_updateItemList(false, searchResultIDs); _updateItemList(false, false, searchResultIDs);
isAsync = true; isAsync = true;
} else { } else {
Zotero.debug("Got cited items synchronously"); Zotero.debug("Got cited items synchronously");
} }
} else { } else {
// No search conditions, so just clear the box // No search conditions, so just clear the box
_updateItemList([], []); _updateItemList([], [], []);
} }
} }
@ -348,7 +348,7 @@ var Zotero_QuickFormat = new function () {
/** /**
* Updates the item list * Updates the item list
*/ */
function _updateItemList(citedItems, searchResultIDs, preserveSelection) { function _updateItemList(citedItems, citedItemsMatchingSearch, searchResultIDs, preserveSelection) {
var selectedIndex = 1, previousItemID; var selectedIndex = 1, previousItemID;
// Do this so we can preserve the selected item after cited items have been loaded // 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; selectedIndex = 2;
} else if(citedItems.length) { } else if(citedItems.length) {
// We have cited items // We have cited items
referenceBox.appendChild(_buildListSeparator(Zotero.getString("integration.cited")));
for(var i=0, n=citedItems.length; i<n; i++) { for(var i=0, n=citedItems.length; i<n; i++) {
var citedItem = citedItems[i]; var citedItem = citedItems[i];
if(i < 50) {
referenceBox.appendChild(_buildListItem(citedItem));
}
// Tabulate number of items in document for each library // Tabulate number of items in document for each library
if(!citedItem.cslItemID) { if(!citedItem.cslItemID) {
var libraryID = citedItem.libraryID ? citedItem.libraryID : 0; 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 // 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); var items = Zotero.Items.get(searchResultIDs);
items.sort(function _itemSort(a, b) { items.sort(function _itemSort(a, b) {
@ -437,7 +440,7 @@ var Zotero_QuickFormat = new function () {
}); });
var previousLibrary = -1; 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; var item = items[i], libraryID = item.libraryID;
if(previousLibrary != libraryID) { if(previousLibrary != libraryID) {
@ -456,7 +459,7 @@ var Zotero_QuickFormat = new function () {
} }
_resize(); _resize();
if((citedItems && citedItems.length) || searchResultIDs.length) { if((citedItemsMatchingSearch && citedItemsMatchingSearch.length) || searchResultIDs.length) {
referenceBox.selectedIndex = selectedIndex; referenceBox.selectedIndex = selectedIndex;
referenceBox.ensureIndexIsVisible(selectedIndex); referenceBox.ensureIndexIsVisible(selectedIndex);
} }

View File

@ -245,8 +245,6 @@ Zotero_RecognizePDF.Recognizer = function () {}
Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, callback, captchaCallback) { Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, callback, captchaCallback) {
const MAX_PAGES = 3; const MAX_PAGES = 3;
const lineRe = /^\s*([^\s]+(?: [^\s]+)+)/;
this._libraryID = libraryID; this._libraryID = libraryID;
this._callback = callback; this._callback = callback;
//this._captchaCallback = captchaCallback; //this._captchaCallback = captchaCallback;
@ -257,10 +255,6 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
cacheFile.remove(false); 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"]. var proc = Components.classes["@mozilla.org/process/util;1"].
createInstance(Components.interfaces.nsIProcess); createInstance(Components.interfaces.nsIProcess);
var exec = Zotero.getZoteroDirectory(); 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]; var args = ['-enc', 'UTF-8', '-nopgbrk', '-layout', '-l', MAX_PAGES];
args.push(file.path, cacheFile.path); args.push(file.path, cacheFile.path);
Zotero.debug('Running pdftotext '+args.join(" "));
try { try {
if (!Zotero.isFx36) { if (!Zotero.isFx36) {
proc.runw(true, args, args.length); proc.runw(true, args, args.length);
@ -297,15 +293,13 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
intlStream.QueryInterface(Components.interfaces.nsIUnicharLineInputStream); intlStream.QueryInterface(Components.interfaces.nsIUnicharLineInputStream);
// get the lines in this sample // get the lines in this sample
var lines = []; var lines = [],
var lineLengths = []; cleanedLines = [],
var str = {}; cleanedLineLengths = [],
str = {};
while(intlStream.readLine(str)) { while(intlStream.readLine(str)) {
var line = lineRe.exec(str.value); var line = str.value.trim();
if(line) { if(line) lines.push(line);
lines.push(line[1]);
lineLengths.push(line[1].length);
}
} }
inputStream.close(); inputStream.close();
@ -319,13 +313,23 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
this._DOI = m[0]; 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 // get (not quite) median length
var lineLengthsLength = lineLengths.length; var lineLengthsLength = cleanedLineLengths.length;
if(lineLengthsLength < 20 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"); this._callback(false, "recognizePDF.noOCR");
} else { } else {
var sortedLengths = lineLengths.sort(); var sortedLengths = cleanedLineLengths.sort();
var medianLength = sortedLengths[Math.floor(lineLengthsLength/2)]; var medianLength = sortedLengths[Math.floor(lineLengthsLength/2)];
// pick lines within 4 chars of the median (this is completely arbitrary) // 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 uBound = medianLength + 4;
var lBound = medianLength - 4; var lBound = medianLength - 4;
for (var i=0; i<lineLengthsLength; i++) { 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 // 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); this._goodLines.push(line);
} }
} }

View File

@ -57,6 +57,7 @@ if (!Array.indexOf) {
}; };
} }
var CSL = { 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_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_PLAIN_REGEX: /(?:(?:^| )(?:art|ch|Ch|subch|p|pp|para|subpara|pt|r|sec|subsec|Sec|sch|tit)\.)/,
STATUTE_SUBDIV_STRINGS: { STATUTE_SUBDIV_STRINGS: {
@ -2204,7 +2205,7 @@ CSL.DateParser = function () {
}; };
CSL.Engine = function (sys, style, lang, forceLang) { CSL.Engine = function (sys, style, lang, forceLang) {
var attrs, langspec, localexml, locale; var attrs, langspec, localexml, locale;
this.processor_version = "1.0.339"; this.processor_version = CSL.PROCESSOR_VERSION;
this.csl_version = "1.0"; this.csl_version = "1.0";
this.sys = sys; this.sys = sys;
this.sys.xml = new CSL.System.Xml.Parsing(); 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]) { if (!this.decorations.length || this.decorations[0][0] !== "@" + this.variables[0]) {
this.decorations = [["@" + this.variables[0], "true"]].concat(this.decorations); 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); state.output.append(value, this, false, false, true);
} }
@ -9362,7 +9367,7 @@ CSL.Transform = function (state) {
} }
return function (state, Item, item, usedOrig) { return function (state, Item, item, usedOrig) {
var primary, secondary, tertiary, primary_tok, group_tok, key; var primary, secondary, tertiary, primary_tok, group_tok, key;
if (!variables[0]) { if (!variables[0] || (!Item[variables[0]] && !Item[alternative_varname])) {
return null; return null;
} }
var slot = {primary:false, secondary:false, tertiary:false}; 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); return CSL.Output.Formatters.undoppelString(str);
}; };
CSL.Output.Formatters["capitalize-all"] = function (state, string) { CSL.Output.Formatters["capitalize-all"] = function (state, string) {
var str, strings, len, pos; var str = CSL.Output.Formatters.doppelString(string, CSL.TAG_ESCAPE);
str = CSL.Output.Formatters.doppelString(string, CSL.TAG_ESCAPE); var strings = str.string.split(" ");
strings = str.string.split(" "); for (var i = 0, ilen = strings.length; i < ilen; i += 1) {
len = strings.length; if (strings[i].length > 1) {
for (pos = 0; pos < len; pos += 1) {
if (strings[pos].length > 1) {
if (state.opt.development_extensions.allow_force_lowercase) { 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 { } 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) { } else if (strings[i].length === 1) {
strings[pos] = strings[pos].toUpperCase(); strings[i] = strings[i].toUpperCase();
} }
} }
str.string = strings.join(" "); str.string = strings.join(" ");
@ -11964,20 +11967,13 @@ CSL.Registry.prototype.renumber = function () {
for (pos = 0; pos < len; pos += 1) { for (pos = 0; pos < len; pos += 1) {
item = this.reflist[pos]; item = this.reflist[pos];
item.seq = (pos + 1); item.seq = (pos + 1);
var hasTaints = false; if (this.state.opt.update_mode === CSL.NUMERIC && item.seq != this.oldseq[item.id]) {
for (var key in this.state.tmp.taintedItemIDs) {
hasTaints = true;
break;
}
if (hasTaints && item.seq != this.oldseq[item.id]) {
if (this.state.opt.update_mode === CSL.NUMERIC) {
this.state.tmp.taintedItemIDs[item.id] = true; this.state.tmp.taintedItemIDs[item.id] = true;
} }
if (this.state.opt.bib_mode === CSL.NUMERIC) { if (this.state.opt.bib_mode === CSL.NUMERIC && item.seq != this.oldseq[item.id]) {
this.return_data.bibchange = true; this.return_data.bibchange = true;
} }
} }
}
if (this.state.opt.citation_number_sort_direction === CSL.DESCENDING if (this.state.opt.citation_number_sort_direction === CSL.DESCENDING
&& this.state.opt.citation_number_sort_used) { && this.state.opt.citation_number_sort_used) {
this.reflist.reverse(); this.reflist.reverse();

View File

@ -2655,6 +2655,7 @@ Zotero.Integration.Session.prototype.updateCitations = function(callback) {
index = parseInt(index); index = parseInt(index);
var citation = this.citationsByIndex[index]; var citation = this.citationsByIndex[index];
if(!citation) continue;
if(citation.properties.delete) { if(citation.properties.delete) {
deleteCitations[index] = true; deleteCitations[index] = true;
continue; continue;

View File

@ -758,7 +758,7 @@ $rdf.Serializer = function () {
var attrs = ''; var attrs = '';
if(subject.termType == 'bnode') { 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) + '"'; attrs = ' rdf:nodeID="' + subject.toNT().slice(2) + '"';
} }
} else { } else {

View File

@ -1399,7 +1399,7 @@ Zotero.Utilities = {
var isZoteroItem = item instanceof Zotero.Item, zoteroType; var isZoteroItem = item instanceof Zotero.Item, zoteroType;
for(var type in CSL_TYPE_MAPPINGS) { for(var type in CSL_TYPE_MAPPINGS) {
if(CSL_TYPE_MAPPINGS[zoteroType] == item.type) { if(CSL_TYPE_MAPPINGS[type] == cslItem.type) {
zoteroType = type; zoteroType = type;
break; break;
} }
@ -1484,11 +1484,37 @@ Zotero.Utilities = {
if(Zotero.ItemFields.isValidForType(fieldID, itemTypeID)) { if(Zotero.ItemFields.isValidForType(fieldID, itemTypeID)) {
var date = ""; var date = "";
if(cslDate.literal) { if(cslDate.literal) {
if(variable === "accessed") {
date = strToISO(cslDate.literal);
} else {
date = cslDate.literal; date = cslDate.literal;
} else if(cslDate.year) { }
if(cslDate.month) cslDate.month--; } else {
date = Zotero.Date.formatDate(cslDate); var newDate = Zotero.Utilities.deepCopy(cslDate);;
if(cslDate.season) date = cslDate.season+date; 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) { if(isZoteroItem) {