From f6e7cf83fac6273d96368045696cfcb0219430e3 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 8 Aug 2012 01:56:25 -0400 Subject: [PATCH 01/11] Add ability to search for item by key from quick search bar Matches beginning of key only, and only when search string is >= 2 chars --- chrome/content/zotero/xpcom/search.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index b0bdb82c2..84835d111 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -410,6 +410,11 @@ Zotero.Search.prototype.addCondition = function(condition, operator, value, requ for each(var part in parts) { this.addCondition('blockStart'); + + if (operator == 'contains' && part.text.length > 1) { + this.addCondition('key', 'beginsWith', part.text, false); + } + if (condition == 'quicksearch-titleCreatorYear') { this.addCondition('title', operator, part.text, false); this.addCondition('year', operator, part.text, false); @@ -2180,6 +2185,19 @@ Zotero.SearchConditions = new function(){ noLoad: true }, + { + name: 'key', + operators: { + is: true, + isNot: true, + beginsWith: true + }, + table: 'items', + field: 'key', + special: true, + noLoad: true + }, + { name: 'annotation', operators: { From 7dad7bcd5ab508e1fe72282522125da3a0eafae5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 8 Aug 2012 03:17:14 -0400 Subject: [PATCH 02/11] Require exact 8-character, uppercase item key for quick search --- chrome/content/zotero/xpcom/search.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index 84835d111..3cbdc711d 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -411,8 +411,9 @@ Zotero.Search.prototype.addCondition = function(condition, operator, value, requ for each(var part in parts) { this.addCondition('blockStart'); - if (operator == 'contains' && part.text.length > 1) { - this.addCondition('key', 'beginsWith', part.text, false); + // If search string is 8 characters, see if this is a item key + if (operator == 'contains' && part.text.length == 8) { + this.addCondition('key', 'is', part.text, false); } if (condition == 'quicksearch-titleCreatorYear') { From e599a207a13077196d795db268f6e534d5c6f63f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 14 Aug 2012 18:30:11 -0400 Subject: [PATCH 03/11] Some additional debug output for file syncing --- chrome/content/zotero/xpcom/storage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/storage.js b/chrome/content/zotero/xpcom/storage.js index 4d90fc323..e6f87ec82 100644 --- a/chrome/content/zotero/xpcom/storage.js +++ b/chrome/content/zotero/xpcom/storage.js @@ -2524,6 +2524,8 @@ Zotero.Sync.Storage.StreamListener.prototype = { onStateChange: function (wp, request, stateFlags, status) { Zotero.debug("onStateChange"); + Zotero.debug(stateFlags); + Zotero.debug(status); if ((stateFlags & Components.interfaces.nsIWebProgressListener.STATE_START) && (stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK)) { @@ -2577,7 +2579,7 @@ Zotero.Sync.Storage.StreamListener.prototype = { // Private methods // _onStart: function (request) { - //Zotero.debug('Starting request'); + Zotero.debug('Starting request'); if (this._data && this._data.onStart) { var data = this._getPassData(); this._data.onStart(request, data); @@ -2591,6 +2593,7 @@ Zotero.Sync.Storage.StreamListener.prototype = { }, _onDone: function (request, status) { + Zotero.debug('Request ended with status ' + status); var cancelled = status == 0x804b0002; // NS_BINDING_ABORTED if (!cancelled && request instanceof Components.interfaces.nsIHttpChannel) { From f60bceffac53e91222d455c3301aac7c43564b75 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 14 Aug 2012 20:07:38 -0400 Subject: [PATCH 04/11] Don't show empty close button --- chrome/skin/default/zotero/standalone.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/skin/default/zotero/standalone.css b/chrome/skin/default/zotero/standalone.css index 86070d281..01c16f53d 100644 --- a/chrome/skin/default/zotero/standalone.css +++ b/chrome/skin/default/zotero/standalone.css @@ -1,4 +1,4 @@ #zotero-tb-item-from-page, #zotero-tb-snapshot-from-page, #zotero-tb-link-from-page, -#zotero-tb-fullscreen, #zotero-fullscreen-close-separator { +#zotero-tb-fullscreen, #zotero-fullscreen-close-separator, #zotero-close-button { display: none; } \ No newline at end of file From ade715ff045ebdba71d4d9e98b4c923909b29c69 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 15 Aug 2012 06:01:47 -0400 Subject: [PATCH 05/11] Fixes #155, Slow offline syncs Don't reload all data for failed /login and /updated requests --- chrome/content/zotero/xpcom/sync.js | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index c1ded5e91..de594f232 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -1277,20 +1277,20 @@ Zotero.Sync.Server = new function () { Zotero.Sync.Runner.setSyncStatus(Zotero.getString('sync.status.loggingIn')); Zotero.HTTP.doPost(url, body, function (xmlhttp) { - _checkResponse(xmlhttp); + _checkResponse(xmlhttp, true); var response = xmlhttp.responseXML.childNodes[0]; if (response.firstChild.tagName == 'error') { if (response.firstChild.getAttribute('code') == 'INVALID_LOGIN') { var e = new Zotero.Error(Zotero.getString('sync.error.invalidLogin'), "INVALID_SYNC_LOGIN"); - _error(e); + _error(e, true); } - _error(response.firstChild.firstChild.nodeValue); + _error(response.firstChild.firstChild.nodeValue, true); } if (_sessionID) { - _error("Session ID already set in Zotero.Sync.Server.login()") + _error("Session ID already set in Zotero.Sync.Server.login()", true) } // [abcdefg0-9]{32} @@ -1299,7 +1299,7 @@ Zotero.Sync.Server = new function () { var re = /^[abcdefg0-9]{32}$/; if (!re.test(_sessionID)) { _sessionID = null; - _error('Invalid session ID received from server'); + _error('Invalid session ID received from server', true); } @@ -1373,7 +1373,7 @@ Zotero.Sync.Server = new function () { Zotero.HTTP.doPost(url, body, function (xmlhttp) { Zotero.debug(xmlhttp.responseText); - _checkResponse(xmlhttp); + _checkResponse(xmlhttp, !restart); if (_invalidSession(xmlhttp)) { Zotero.debug("Invalid session ID -- logging in"); @@ -1795,13 +1795,10 @@ Zotero.Sync.Server = new function () { } - function _checkResponse(xmlhttp) { + function _checkResponse(xmlhttp, noReloadOnFailure) { if (!xmlhttp.responseText) { - // Check SSL cert var channel = xmlhttp.channel; - if (!channel instanceof Ci.nsIChannel) { - _error('No HTTPS channel available'); - } + // Check SSL cert var secInfo = channel.securityInfo; if (secInfo instanceof Ci.nsITransportSecurityInfo) { secInfo.QueryInterface(Ci.nsITransportSecurityInfo); @@ -1817,14 +1814,19 @@ Zotero.Sync.Server = new function () { Zotero.debug(e); } // TODO: localize - _error("SSL certificate error connecting to " + host + "\n\nSee http://zotero.org/support/kb/ssl_certificate_error for more information."); + _error("SSL certificate error connecting to " + host + + "\n\nSee http://zotero.org/support/kb/ssl_certificate_error for more information.", + false, noReloadOnFailure); } else if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_BROKEN) == Ci.nsIWebProgressListener.STATE_IS_BROKEN) { - _error("SSL connection error"); + _error("SSL connection error", false, noReloadOnFailure); } } // TODO: localize - _error('Empty response from server. Please try again in a few minutes.'); + if (xmlhttp.status === 0) { + _error('Error connecting to server. Check your Internet connection.', false, noReloadOnFailure); + } + _error('Empty response from server. Please try again in a few minutes.', false, noReloadOnFailure); } if (!xmlhttp.responseXML || !xmlhttp.responseXML.childNodes[0] || @@ -1832,7 +1834,7 @@ Zotero.Sync.Server = new function () { !xmlhttp.responseXML.childNodes[0].firstChild) { Zotero.debug(xmlhttp.responseText); // TODO: localize - _error('Invalid response from server. Please try again in a few minutes.', xmlhttp.responseText); + _error('Invalid response from server. Please try again in a few minutes.', xmlhttp.responseText, noReloadOnFailure); } var firstChild = xmlhttp.responseXML.firstChild.firstChild; @@ -1851,7 +1853,7 @@ Zotero.Sync.Server = new function () { else { var timeStr = time.toLocaleString(); } - _error("Auto-syncing disabled until " + timeStr); + _error("Auto-syncing disabled until " + timeStr, false, noReloadOnFailure); } if (firstChild.localName == 'error') { @@ -2267,7 +2269,7 @@ Zotero.Sync.Server = new function () { } - function _error(e, extraInfo) { + function _error(e, extraInfo, skipReload) { if (e.name && e.name == 'ZOTERO_ERROR') { switch (e.error) { case Zotero.Error.ERROR_MISSING_OBJECT: @@ -2360,7 +2362,9 @@ Zotero.Sync.Server = new function () { _syncInProgress = false; Zotero.DB.rollbackAllTransactions(); - Zotero.reloadDataObjects(); + if (!skipReload) { + Zotero.reloadDataObjects(); + } Zotero.Sync.EventListener.resetIgnored(); _callbacks.onError(e); From d9ea6d3647c8d66b2d9d176cd9064bae9f13f35c Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 16 Aug 2012 21:10:59 -0400 Subject: [PATCH 06/11] Add useJournalAbbreviation export option for BibTeX (see https://github.com/zotero/translators/pull/436) --- chrome/locale/en-US/zotero/zotero.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 1fc73357d..7034184cb 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -551,6 +551,7 @@ fulltext.indexState.partial = Partial exportOptions.exportNotes = Export Notes exportOptions.exportFileData = Export Files +exportOptions.useJournalAbbreviation = Use Journal Abbreviation charset.UTF8withoutBOM = Unicode (UTF-8 without BOM) charset.autoDetect = (auto detect) From 9ca142c4f607c5d683491c89ab3a03e51021d18a Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 19 Aug 2012 12:39:49 -0400 Subject: [PATCH 07/11] Fix a situation under which Zotero could fail to embed item data in a document --- chrome/content/zotero/xpcom/integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index c40f6576e..46a2c52c4 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -2193,7 +2193,7 @@ Zotero.Integration.Session.prototype.getCitationField = function(citation) { // add itemData only if requested if(this.data.prefs.storeReferences) { - serializeCitationItem.itemData = citationItem.item; + serializeCitationItem.itemData = Zotero.Cite.System.retrieveItem(citationItem.id); addSchema = true; } } From c81c9478d9fc3cb71b482edcd89e5ec6ce19d923 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 19 Aug 2012 19:06:05 -0400 Subject: [PATCH 08/11] Make Zotero Standalone use the browser's user agent string when making requests on its behalf via connectors In conjunction with a change to the translator, this fixes the issue reported at http://forums.zotero.org/discussion/22409/ --- chrome/content/zotero/xpcom/cookieSandbox.js | 9 ++++++++- chrome/content/zotero/xpcom/server.js | 5 ++++- chrome/content/zotero/xpcom/server_connector.js | 14 +++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/cookieSandbox.js b/chrome/content/zotero/xpcom/cookieSandbox.js index b54d38069..e17a7423f 100755 --- a/chrome/content/zotero/xpcom/cookieSandbox.js +++ b/chrome/content/zotero/xpcom/cookieSandbox.js @@ -31,8 +31,9 @@ * @param {String|nsIURI} uri URI of page to manage cookies for (cookies for domains that are not * subdomains of this URI are ignored) * @param {String} cookieData Cookies with which to initiate the sandbox + * @param {String} userAgent User agent to use for sandboxed requests */ -Zotero.CookieSandbox = function(browser, uri, cookieData) { +Zotero.CookieSandbox = function(browser, uri, cookieData, userAgent) { this._observerService = Components.classes["@mozilla.org/observer-service;1"]. getService(Components.interfaces.nsIObserverService); @@ -54,6 +55,8 @@ Zotero.CookieSandbox = function(browser, uri, cookieData) { } } + if(userAgent) this.userAgent = userAgent; + Zotero.CookieSandbox.Observer.register(); if(browser) { this.attachToBrowser(browser); @@ -206,6 +209,10 @@ Zotero.CookieSandbox.Observer = new function() { return; } + if(trackedBy.userAgent) { + channel.setRequestHeader("User-Agent", trackedBy.userAgent, false); + } + // add cookies to be sent to this domain channel.setRequestHeader("Cookie", trackedBy.cookieString, false); Zotero.debug("CookieSandbox: Added cookies for request to "+channelURI, 5); diff --git a/chrome/content/zotero/xpcom/server.js b/chrome/content/zotero/xpcom/server.js index 1d7867c6b..172a86c46 100755 --- a/chrome/content/zotero/xpcom/server.js +++ b/chrome/content/zotero/xpcom/server.js @@ -361,9 +361,12 @@ Zotero.Server.DataListener.prototype._processEndpoint = function(method, postDat // pass to endpoint if((endpoint.init.length ? endpoint.init.length : endpoint.init.arity) === 3) { + const uaRe = /[\r\n]User-Agent: +([^\r\n]+)/i; + var m = uaRe.exec(this.header); var url = { "pathname":this.pathname, - "query":this.query ? Zotero.Server.decodeQueryString(this.query.substr(1)) : {} + "query":this.query ? Zotero.Server.decodeQueryString(this.query.substr(1)) : {}, + "userAgent":m && m[1] }; endpoint.init(url, decodedData, sendResponseCallback); diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js index 644d76435..7875f677b 100755 --- a/chrome/content/zotero/xpcom/server_connector.js +++ b/chrome/content/zotero/xpcom/server_connector.js @@ -98,7 +98,7 @@ Zotero.Server.Connector.Detect.prototype = { * @param {Object} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { this.sendResponse = sendResponseCallback; this._parsedPostData = data; @@ -115,7 +115,7 @@ Zotero.Server.Connector.Detect.prototype = { var pageShowCalled = false; var me = this; this._translate.setCookieSandbox(new Zotero.CookieSandbox(this._browser, - this._parsedPostData["uri"], this._parsedPostData["cookie"])); + this._parsedPostData["uri"], this._parsedPostData["cookie"], url.userAgent)); this._browser.addEventListener("DOMContentLoaded", function() { try { if(me._browser.contentDocument.location.href == "about:blank") return; @@ -283,7 +283,7 @@ Zotero.Server.Connector.SaveItem.prototype = { * @param {Object} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { // figure out where to save var libraryID = null; var collectionID = null; @@ -293,8 +293,8 @@ Zotero.Server.Connector.SaveItem.prototype = { var collection = zp.getSelectedCollection(); } catch(e) {} - var cookieSandbox = data["uri"] && data["cookie"] ? new Zotero.CookieSandbox(null, data["uri"], - data["cookie"]) : null; + var cookieSandbox = data["uri"] ? new Zotero.CookieSandbox(null, data["uri"], + data["cookie"] || "", url.userAgent) : null; // save items var itemSaver = new Zotero.Translate.ItemSaver(libraryID, @@ -339,12 +339,12 @@ Zotero.Server.Connector.SaveSnapshot.prototype = { * @param {String} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { Zotero.Server.Connector.Data[data["url"]] = ""+data["html"]+""; var browser = Zotero.Browser.createHiddenBrowser(); var pageShowCalled = false; - var cookieSandbox = new Zotero.CookieSandbox(browser, data["url"], data["cookie"]); + var cookieSandbox = new Zotero.CookieSandbox(browser, data["url"], data["cookie"], url.userAgent); browser.addEventListener("pageshow", function() { if(browser.contentDocument.location.href == "about:blank" || browser.contentDocument.readyState !== "complete") return; From addfaa75f7d0905d79d1dd7e5122620bcfd03e8b Mon Sep 17 00:00:00 2001 From: aurimasv Date: Mon, 3 Sep 2012 04:46:36 -0500 Subject: [PATCH 09/11] Fix bug in item.complete() --- chrome/content/zotero/xpcom/translation/translate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 839a06693..b62cb7607 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1371,7 +1371,7 @@ Zotero.Translate.Base.prototype = { "for(var key in this) {"+ "if("+createArrays+".indexOf(key) !== -1) {"+ "for each(var item in this[key]) {"+ - "for(var key2 in item[key2]) {"+ + "for(var key2 in item) {"+ "if(typeof item[key2] === 'xml') {"+ "item[key2] = item[key2].toString();"+ "}"+ From 4e1f6f63a03c060a3bf021bef469b6176f698f0b Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 9 Sep 2012 17:33:30 -0400 Subject: [PATCH 10/11] Fix clearing bibliography when all citations have been removed from the document --- chrome/content/zotero/xpcom/integration.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 46a2c52c4..aa0841a82 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -2533,6 +2533,8 @@ Zotero.Integration.Session.prototype.deleteCitation = function(index) { Zotero.Integration.Session.prototype.getBibliography = function() { this.updateUncitedItems(); + if(Zotero.Utilities.isEmpty(this.citationsByItemID)) return false; + // generate bibliography var bib = this.style.makeBibliography(); From e1159b98389944edf8a3efadc1f218f74196c5c0 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 10 Sep 2012 16:51:13 -0400 Subject: [PATCH 11/11] Update submodules, and point CSL locales to 1.0.1 for now --- chrome/content/zotero/locale/csl | 2 +- translators | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/locale/csl b/chrome/content/zotero/locale/csl index 42426e1d7..36d26a584 160000 --- a/chrome/content/zotero/locale/csl +++ b/chrome/content/zotero/locale/csl @@ -1 +1 @@ -Subproject commit 42426e1d786f766144e143894c3829d8f11c285c +Subproject commit 36d26a584ac869f2dfbdd528f57141a3bbcf016f diff --git a/translators b/translators index cda5ac5ef..af463b24e 160000 --- a/translators +++ b/translators @@ -1 +1 @@ -Subproject commit cda5ac5ef0f6c59d359e49d61fb8846c859ef6c0 +Subproject commit af463b24e40f0b426a40b55cf5f0d74dcab0d5b0