From bc54320ff738ea2391026de23cd9ebd353194e53 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 10 Jun 2007 16:59:16 +0000 Subject: [PATCH] - improves HighWire regex - does not add shortTitle field to imported items (only items scraped via web) - fixes issues with ibid in Chicago Manual of Style (Note with Bibliography) - fixes issues with repeat parenthetical citations --- chrome/content/zotero/xpcom/cite.js | 46 ++++++++++++---------- chrome/content/zotero/xpcom/integration.js | 4 +- chrome/content/zotero/xpcom/translate.js | 4 +- scrapers.sql | 31 +++++++++++---- 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 37f725853..eac99d8bc 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -484,8 +484,9 @@ Zotero.CSL.prototype.createCitation = function(citation, format) { locator = citation.locators[i]; } + var position = (citation.citationType[i] == 1 ? "first" : "subsequent"); var citationString = this._getCitation(Zotero.Items.get(citation.itemIDs[i]), - (citation.citationType[i] == 1 ? "first" : "subsequent"), + position, locatorType, locator, format, this._cit); string.concat(citationString); @@ -1041,7 +1042,7 @@ Zotero.CSL.prototype._compareItem = function(a, b, opt) { * process creator objects; if someone had a creator model that handled * non-Western names better than ours, this would be the function to change */ -Zotero.CSL.prototype._processCreators = function(type, element, creators, format, bibCitElement) { +Zotero.CSL.prototype._processCreators = function(type, element, creators, format, bibCitElement, position) { var maxCreators = creators.length; if(!maxCreators) return false; @@ -1057,6 +1058,11 @@ Zotero.CSL.prototype._processCreators = function(type, element, creators, format return false; } + var etAl = bibCitElement.etAl; + if(position == "subsequent" && bibCitElement.subsequentEtAl) { + etAl = bibCitElement.subsequentEtAl; + } + for(var i in element.children) { var child = element.children[i]; var string = ""; @@ -1065,8 +1071,8 @@ Zotero.CSL.prototype._processCreators = function(type, element, creators, format var useEtAl = false; // figure out if we need to use "et al" - if(bibCitElement.etAl && maxCreators > bibCitElement.etAl.minCreators) { - maxCreators = bibCitElement.etAl.useFirst; + if(etAl && maxCreators >= etAl.minCreators) { + maxCreators = etAl.useFirst; useEtAl = true; } @@ -1122,15 +1128,16 @@ Zotero.CSL.prototype._processCreators = function(type, element, creators, format } authorStrings[maxCreators-1] = and+" "+authorStrings[maxCreators-1]; - // skip the comma if there are only two creators and no - // et al, and name as sort is no - if((maxCreators == 2 && child["delimiter-precedes-last"] != "always") || - (maxCreators > 2 && child["delimiter-precedes-last"] == "never")) { - var lastString = authorStrings.pop(); - authorStrings[maxCreators-2] = authorStrings[maxCreators-2]+" "+lastString; - } } } + + // check whether to use a serial comma + Zotero.debug(child["delimiter-precedes-last"]); + if((authorStrings.length == 2 && child["delimiter-precedes-last"] != "always") || + (authorStrings.length > 2 && child["delimiter-precedes-last"] == "never")) { + var lastString = authorStrings.pop(); + authorStrings[authorStrings.length-1] = authorStrings[authorStrings.length-1]+" "+lastString; + } } string = authorStrings.join(joinString); } else if(child.name == "label") { @@ -1154,19 +1161,18 @@ Zotero.CSL.prototype._processCreators = function(type, element, creators, format Zotero.CSL.prototype._getCitation = function(item, position, locatorType, locator, format, bibCitElement) { Zotero.debug("CSL: generating citation for item "+item.getID()); - if(!bibCitElement._types[position]) { - position = "first"; - } + // use true position if possible, otherwise "first" + var typePosition = (bibCitElement._types[position] ? position : "first"); // determine mapping - if(bibCitElement._types[position][0]) { + if(bibCitElement._types[typePosition][0]) { // only one element var typeName = 0; - var type = this._getTypeObject(position, typeName, bibCitElement); + var type = this._getTypeObject(typePosition, typeName, bibCitElement); } else { var typeNames = this._getTypeFromItem(item); for each(var typeName in typeNames) { - var type = this._getTypeObject(position, typeName, bibCitElement); + var type = this._getTypeObject(typePosition, typeName, bibCitElement); if(type) { break; } @@ -1208,13 +1214,13 @@ Zotero.CSL.prototype._getFieldValue = function(name, element, item, formattedStr // handle subsequent author substitute behavior dataAppended = formattedString.append(bibCitElement.subsequentAuthorSubstitute, element); } else { - var newString = this._processCreators(name, element, item._csl.authors, formattedString.format, bibCitElement); + var newString = this._processCreators(name, element, item._csl.authors, formattedString.format, bibCitElement, position); if(newString) dataAppended = formattedString.concat(newString, element); } } else if(name == "editor") { - dataAppended = formattedString.concat(this._processCreators(name, element, item._csl.editors, formattedString.format, bibCitElement), element); + dataAppended = formattedString.concat(this._processCreators(name, element, item._csl.editors, formattedString.format, bibCitElement, position), element); } else if(name == "translator") { - dataAppended = formattedString.concat(this._processCreators(name, element, item._csl.translators, formattedString.format, bibCitElement), element); + dataAppended = formattedString.concat(this._processCreators(name, element, item._csl.translators, formattedString.format, bibCitElement, position), element); } else if(name == "titles") { var data = new Zotero.CSL.FormattedString(this, formattedString.format); diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index b2124dd56..a7a21bac4 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -509,7 +509,7 @@ Zotero.Integration.SOAP = new function() { /* * sets document preferences * ACCEPTS: (sessionID)? - * RETURNS: sessionID, styleID, style-class + * RETURNS: sessionID, styleID, style-class, has-bibliography, use-endnotes */ function setDocPrefs(vars) { var io = new function() { @@ -549,7 +549,6 @@ Zotero.Integration.Session = function(styleID, useEndnotes) { } if(useEndnotes) { this.useEndnotes = useEndnotes; - Zotero.debug("the answer is "+useEndnotes); } this.citationSet = new Zotero.Integration.CitationSet(this.style); @@ -760,7 +759,6 @@ Zotero.Integration.CitationFactory.prototype.updateItems = function(citationSet, } } - Zotero.debug(disambiguation); this.style.preprocessItems(this.items); var tempCache = new Object(); diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js index 71ddd3e7a..0f67d2553 100644 --- a/chrome/content/zotero/xpcom/translate.js +++ b/chrome/content/zotero/xpcom/translate.js @@ -1193,7 +1193,9 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) { } // create short title - if(item.shortTitle === undefined && Zotero.ItemFields.isValidForType("shortTitle", typeID)) { + if(this.type == "web" && + item.shortTitle === undefined && + Zotero.ItemFields.isValidForType("shortTitle", typeID)) { // get field id var fieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(typeID, "title"); // get title diff --git a/scrapers.sql b/scrapers.sql index 8daf1cf11..a360ebe96 100644 --- a/scrapers.sql +++ b/scrapers.sql @@ -1,4 +1,4 @@ --- 231 +-- 232 -- ***** BEGIN LICENSE BLOCK ***** -- @@ -22,7 +22,7 @@ -- Set the following timestamp to the most recent scraper update date -REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2007-05-31 20:00:00')); +REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2007-06-10 16:54:12')); REPLACE INTO translators VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '1.0.0b4.r1', '', '2007-03-21 15:26:54', '1', '100', '4', 'Amazon.com', 'Sean Takats', '^https?://(?:www\.)?amazon', 'function detectWeb(doc, url) { @@ -6428,7 +6428,7 @@ function doWeb(doc, url) { } }'); -REPLACE INTO translators VALUES ('5eacdb93-20b9-4c46-a89b-523f62935ae4', '1.0.0b3.r1', '', '2007-05-15 22:00:00', '1', '100', '4', 'HighWire', 'Simon Kornblith', '^http://[^/]+/(?:cgi/searchresults|cgi/search|cgi/content/(?:abstract|full|short|summary)/[^/]+/[0-9]+/[0-9]+|current.dtl$|content/vol[0-9]+/issue[0-9]+/(?:index.dtl)?$)', +REPLACE INTO translators VALUES ('5eacdb93-20b9-4c46-a89b-523f62935ae4', '1.0.0b3.r1', '', '2007-06-10 16:54:12', '1', '100', '4', 'HighWire', 'Simon Kornblith', '^http://[^/]+/(?:cgi/searchresults|cgi/search|cgi/content/(?:abstract|full|short|summary)|current.dtl$|content/vol[0-9]+/issue[0-9]+/(?:index.dtl)?$)', 'function detectWeb(doc, url) { var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { @@ -10939,7 +10939,7 @@ function doExport() { } }'); -REPLACE INTO csl VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '2007-03-23 19:25:00', 'American Psychological Association', +REPLACE INTO csl VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '2007-06-10 16:54:12', 'American Psychological Association', ' '); -REPLACE INTO csl VALUES('http://www.zotero.org/namespaces/CSL/chicago-note-bibliography.csl', '2007-04-25 23:40:00', 'Chicago Manual of Style (Note with Bibliography)', +REPLACE INTO csl VALUES('http://www.zotero.org/namespaces/CSL/chicago-note-bibliography.csl', '2007-06-10 16:54:12', 'Chicago Manual of Style (Note with Bibliography)', '