diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 59cb81ae7..0da40148b 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -182,31 +182,6 @@ Zotero.CollectionTreeView.prototype.refresh = function() } } - if (this.hideSources.indexOf('commons') == -1 && Zotero.Commons.enabled) { - this._showRow(new Zotero.ItemGroup('separator', false)); - var header = { - id: "commons-header", - label: "Commons", // TODO: localize - expand: function (buckets) { - var show = function (buckets) { - for each(var bucket in buckets) { - self._showRow(new Zotero.ItemGroup('bucket', bucket), 1); - } - } - if (buckets) { - show(buckets); - } - else { - Zotero.Commons.getBuckets(show); - } - } - }; - this._showRow(new Zotero.ItemGroup('header', header), null, null, commonsExpand); - if (commonsExpand) { - header.expand(); - } - } - try { this._refreshHashMap(); } diff --git a/chrome/content/zotero/xpcom/commons.js b/chrome/content/zotero/xpcom/commons.js deleted file mode 100644 index 239d39297..000000000 --- a/chrome/content/zotero/xpcom/commons.js +++ /dev/null @@ -1,1421 +0,0 @@ -/* - ***** BEGIN LICENSE BLOCK ***** - - Copyright © 2009 Center for History and New Media - George Mason University, Fairfax, Virginia, USA - http://zotero.org - - This file is part of Zotero. - - Zotero is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Zotero is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with Zotero. If not, see . - - ***** END LICENSE BLOCK ***** -*/ - -//TODO localize -Zotero.Commons = new function() { - this.uri = 'http://www.archive.org/'; - this.apiUrl = 'http://s3.us.archive.org'; - this.postCreateBucketDelay = 2000; - - this.__defineGetter__('enabled', function () { - return Zotero.Prefs.get("commons.enabled"); - }); - - this.__defineSetter__('enabled', function (val) { - return Zotero.Prefs.set("commons.enabled", !!val); - }); - - this.__defineGetter__('userIdentifier', function () { - return Zotero.Prefs.get("commons.accessKey"); - }); - - this.__defineGetter__('accessKey', function () { - return Zotero.Prefs.get("commons.accessKey"); - }); - - this.__defineSetter__('accessKey', function (val) { - return Zotero.Prefs.set("commons.accessKey", val); - }); - - this.__defineGetter__('secretKey', function () { - return Zotero.Prefs.get("commons.secretKey"); - }); - - this.__defineSetter__('secretKey', function (val) { - // TODO: use login manager - return Zotero.Prefs.set("commons.secretKey", val); - }); - - this.__defineGetter__('userNameSlug', function () { - if (!_userNameSlug) { - throw ("Username not set in Zotero.Commons.userNameSlug getter"); - } - return _userNameSlug; - }); - - this.RDF_TRANSLATOR = { - 'label': 'Zotero RDF', - 'target': 'rdf', - 'translatorID': '14763d24-8ba0-45df-8f52-b8d1108e7ac9', - 'displayOptions': { - 'exportFileData': true, - 'exportNotes': true - } - }; - - this.RDF_IMPORT_TRANSLATOR = { - 'translatorID': '5e3ad958-ac79-463d-812b-a86a9235c28f', - } - - this.ERROR_BUCKET_EXISTS = 1; - - this.refreshNeeded = true; - - var _userName; - var _userNameSlug; - var _buckets = {}; - var _bucketsLoading = false; - var _bucketsLoaded = false; - var _requestingItems = false; - - - this.getBuckets = function (callback) { - if (!this.enabled) { - if (callback) { - callback(_buckets); - } - return; - } - - var accessKey = this.accessKey; - var secretKey = this.secretKey; - - if (_bucketsLoaded) { - if (callback) { - callback(_buckets); - } - return; - } - - if (_bucketsLoading) { - Zotero.debug("Already loading buckets"); - if (callback) { - callback(_buckets); - } - return; - } - - _bucketsLoading = true; - - var syncCallback = function (req) { - // Error - if (req.status != 200) { - Zotero.debug(req.status); - Zotero.debug(req.responseText); - - if (req.status == 503) { - alert("Unable to retrieve bucket list from the Internet Archive: server unavailable."); - } - else { - alert("Unable to retrieve bucket list from the Internet Archive: server error " + req.status); - } - - _bucketsLoading = false; - - return; - } - - Zotero.debug(req.responseText); - - _userName = req.responseXML.getElementsByTagName('DisplayName')[0].textContent; - _userNameSlug = Zotero.Commons.slugify(_userName); - - var currentBuckets = []; - var IABuckets = []; - - for (var name in _buckets) { - currentBuckets.push(name); - } - currentBuckets.sort(); - - Zotero.debug('=========='); - Zotero.debug("CURRENT BUCKETS"); - Zotero.debug(currentBuckets); - - - var buckets = req.responseXML.getElementsByTagName("Bucket"); - for (var i=0, len=buckets.length; i= maxTries) { - callback(0); - return; - } - - var delay = Zotero.Commons.postCreateBucketDelay * tries; - var seconds = delay / 1000; - Zotero.debug("Bucket " + self.name + " doesn't yet exist -- retrying in " + seconds + " seconds"); - - setTimeout(function () { - self.exists(callback, maxTries, tries); - }, delay); - return; - - default: - Zotero.debug(xmlhttp.status); - Zotero.debug(xmlhttp.responseText); - callback(-1); - return; - } - }); -} - - -Zotero.Commons.Bucket.prototype.getItems = function (callback) { - if (this._itemsLoading || - // Reload if data is too old - (this._itemsLoaded && (!this._lastLoad || (new Date - this._lastLoad) < (this.reloadSeconds * 1000)))) { - Zotero.debug("Using cached items"); - return this._getCachedItems(); - } - - Zotero.debug("Loading items from IA"); - - this._itemsLoading = true; - - var method = "GET"; - var uri = this.downloadURI + "/" + this.name + "_files.xml"; - - var self = this; - var progressWin = null; - var progressWinIcon = 'chrome://zotero/skin/treeitem-attachment-pdf.png'; - - var req = Zotero.HTTP.doGet(uri, function (xmlhttp) { - if (xmlhttp.status != 200) { - Zotero.debug(xmlhttp.status); - Zotero.debug(xmlhttp.responseText); - Zotero.debug("Commons: Error retrieving bucket contents", 2); - self._itemsLoading = false; - return; - } - - Zotero.debug(xmlhttp.responseText); - - try { - // Strip XML declaration and convert to E4X - var xml = new XML(xmlhttp.responseText.replace(/<\?xml.*\?>/, '')); - } - catch (e) { - Zotero.debug("Commons: Invalid response retrieving bucket contents", 2); - this._itemsLoading = false; - return; - } - - try { - var zipsXML = xml.file.(@source == 'original').(typeof format != 'undefined' && format == 'Zotero ZIP Item'); - } - catch (e) { - Zotero.debug("Commons: Invalid XML retrieving bucket contents", 2); - this._itemsLoading = false; - return; - } - - Zotero.debug(zipsXML); - - var zips = []; - - // Parse files XML to get RDF and OCRed PDFs - var ocrOriginals = {}; - var ocrPDFXML = xml.file.(@source == 'derivative').(format == 'Additional Text PDF').@name; - for each(var pdf in ocrPDFXML) { - var fn = pdf.toString().replace(/_text\.pdf$/, '.pdf'); - ocrOriginals[fn] = true; - } - - for each(var zipXML in zipsXML) { - var key = zipXML.@name.toString(); - var title = zipXML.title.toString(); - - var childrenXML = xml.file.(typeof zipsource != 'undefined').(zipsource == key); - var rdf; - var children = []; - for each(var childXML in childrenXML) { - var childKey = childXML.@name.toString(); - - // Pull out RDF filename - if (childXML.format == 'Zotero RDF') { - rdf = childKey; - continue; - } - - children.push({ - key: childKey, - title: childXML.title.toString(), - ocr: ocrOriginals[childKey] ? true : false - }); - } - -/* - // See if we already have this item - if (self._items[key]) { - continue; - } -*/ - zips.push({ - key: key, - title: title, - rdf: rdf, - children: children - }); - } - - self._itemsLoading = false; - self._itemsLoaded = true; - self._lastLoad = new Date; - - Zotero.debug(zips); - - Zotero.Notifier.trigger('refresh', 'bucket', self.id); - - // Get RDF for new items, pulling off a stack - var process = function (zips) { - if (!zips.length) { - Zotero.debug("Commons: No more ZIPs to process"); - - if (callback) { - callback(); - } - - return; - } - - let zip = zips.shift(); - - // See if we already have this item - if (self._items[zip.key]) { - process(zips); - return; - } - - var rdfURI = self.downloadURI + '/' + zip.rdf; - - Zotero.HTTP.doGet(rdfURI, function (xmlhttp) { - // If RDF not available, skip item - if (xmlhttp.status != 200) { - Zotero.debug("RDF not found at " + xmlhttp.channel.originalURI.spec); - process(zips); - return; - } - - if (!xmlhttp.responseText) { - Zotero.debug("RDF file is empty at " + xmlhttp.channel.originalURI.spec); - process(zips); - return; - } - - Zotero.debug(xmlhttp.responseText); - - var translate = new Zotero.Translate("import"); - translate.setString(xmlhttp.responseText); - translate.getTranslators() - translate.setTranslator(Zotero.Commons.RDF_IMPORT_TRANSLATOR.translatorID); - translate.setHandler("itemDone", function (translation, item) { - var typeID = Zotero.ItemTypes.getID(item.itemType); - var newItem = new Zotero.Item(typeID); - newItem.id = Zotero.ID.getBigInt(); - - // Add item data to virtual item - for (var field in item) { - // Skip empty fields - if (!item[field]) { - continue; - } - var fieldID = Zotero.ItemFields.getID(field); - if (!fieldID) { - continue; - } - - try { - newItem.setField(fieldID, item[field]); - } - catch (e) { - Zotero.debug(e); - } - } - - // Add creators to virtual item - for (var i=0; i 1) { - Zotero.debug("More than one local item linked to remote item " + uri, 2); - return false; - } - - var item = Zotero.URI.getURIItem(rels[0].subject); - if (!item) { - Zotero.debug("Linked local item not found for remote URI " + uri, 2); - return false; - } - - return item; -} - - -Zotero.Commons.Bucket.prototype._getCachedItems = function () { - var items = []; - for each(var item in this._items) { - items.push(item); - } - return items; -} - - -Zotero.Commons.Bucket.prototype._getIAKeyByItemID = function (id) { - for (var key in this._items) { - if (this._items[key].id == id) { - return key; - } - } - return false; -} - - - -// Implements nsIRequestObserver -Zotero.Commons.ZipWriterObserver = function (zipWriter, callback) { - this._zipWriter = zipWriter; - this._callback = callback; -} - -Zotero.Commons.ZipWriterObserver.prototype = { - onStartRequest: function () {}, - - onStopRequest: function(req, context, status) { - this._zipWriter.close(); - this._callback(); - } -} - - - -/* - * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined - * in FIPS PUB 180-1 - * Version 2.1a Copyright Paul Johnston 2000 - 2002. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for details. - */ -Zotero.Commons.SHA1 = new function() { - - // added by Ben Parr to expose function for Zotero - this.hex_sha1 = hex_sha1; - this.b64_sha1 = b64_sha1; - this.str_sha1 = str_sha1; - this.hex_hmac_sha1 = hex_hmac_sha1; - this.b64_hmac_sha1 = b64_hmac_sha1; - this.str_hmac_sha1 = str_hmac_sha1; - - - /* - * Configurable variables. You may need to tweak these to be compatible with - * the server-side, but the defaults work in most cases. - */ - var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ - var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ - var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ - - /* - * These are the functions you'll usually want to call - * They take string arguments and return either hex or base-64 encoded strings - */ - function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));} - function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));} - function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));} - function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));} - function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));} - function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));} - - /* - * Perform a simple self-test to see if the VM is working - */ - function sha1_vm_test() - { - return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d"; - } - - /* - * Calculate the SHA-1 of an array of big-endian words, and a bit length - */ - function core_sha1(x, len) - { - /* append padding */ - x[len >> 5] |= 0x80 << (24 - len % 32); - x[((len + 64 >> 9) << 4) + 15] = len; - - var w = Array(80); - var a = 1732584193; - var b = -271733879; - var c = -1732584194; - var d = 271733878; - var e = -1009589776; - - for(var i = 0; i < x.length; i += 16) - { - var olda = a; - var oldb = b; - var oldc = c; - var oldd = d; - var olde = e; - - for(var j = 0; j < 80; j++) - { - if(j < 16) w[j] = x[i + j]; - else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); - var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), - safe_add(safe_add(e, w[j]), sha1_kt(j))); - e = d; - d = c; - c = rol(b, 30); - b = a; - a = t; - } - - a = safe_add(a, olda); - b = safe_add(b, oldb); - c = safe_add(c, oldc); - d = safe_add(d, oldd); - e = safe_add(e, olde); - } - return Array(a, b, c, d, e); - - } - - /* - * Perform the appropriate triplet combination function for the current - * iteration - */ - function sha1_ft(t, b, c, d) - { - if(t < 20) return (b & c) | ((~b) & d); - if(t < 40) return b ^ c ^ d; - if(t < 60) return (b & c) | (b & d) | (c & d); - return b ^ c ^ d; - } - - /* - * Determine the appropriate additive constant for the current iteration - */ - function sha1_kt(t) - { - return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : - (t < 60) ? -1894007588 : -899497514; - } - - /* - * Calculate the HMAC-SHA1 of a key and some data - */ - function core_hmac_sha1(key, data) - { - var bkey = str2binb(key); - if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz); - - var ipad = Array(16), opad = Array(16); - for(var i = 0; i < 16; i++) - { - ipad[i] = bkey[i] ^ 0x36363636; - opad[i] = bkey[i] ^ 0x5C5C5C5C; - } - - var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz); - return core_sha1(opad.concat(hash), 512 + 160); - } - - /* - * Add integers, wrapping at 2^32. This uses 16-bit operations internally - * to work around bugs in some JS interpreters. - */ - function safe_add(x, y) - { - var lsw = (x & 0xFFFF) + (y & 0xFFFF); - var msw = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); - } - - /* - * Bitwise rotate a 32-bit number to the left. - */ - function rol(num, cnt) - { - return (num << cnt) | (num >>> (32 - cnt)); - } - - /* - * Convert an 8-bit or 16-bit string to an array of big-endian words - * In 8-bit function, characters >255 have their hi-byte silently ignored. - */ - function str2binb(str) - { - var bin = Array(); - var mask = (1 << chrsz) - 1; - for(var i = 0; i < str.length * chrsz; i += chrsz) - bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32); - return bin; - } - - /* - * Convert an array of big-endian words to a string - */ - function binb2str(bin) - { - var str = ""; - var mask = (1 << chrsz) - 1; - for(var i = 0; i < bin.length * 32; i += chrsz) - str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask); - return str; - } - - /* - * Convert an array of big-endian words to a hex string. - */ - function binb2hex(binarray) - { - var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; - var str = ""; - for(var i = 0; i < binarray.length * 4; i++) - { - str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + - hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8)) & 0xF); - } - return str; - } - - /* - * Convert an array of big-endian words to a base-64 string - */ - function binb2b64(binarray) - { - var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - var str = ""; - for(var i = 0; i < binarray.length * 4; i += 3) - { - var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16) - | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 ) - | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF); - for(var j = 0; j < 4; j++) - { - if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; - else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); - } - } - return str; - } -} - diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 4ad7c778e..7a272b225 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2069,21 +2069,7 @@ Zotero.Prefs = new function(){ return; } - var xml = new XML(str); - - var commonsEnable = xml.setting.(@id == 'commons-enable'); - if (commonsEnable == 'true') { - Zotero.Commons.enabled = true; - Zotero.Commons.accessKey = xml.setting.(@id == 'commons-accessKey').toString(); - Zotero.Commons.secretKey = xml.setting.(@id == 'commons-secretKey').toString(); - } - else if (commonsEnable == 'false') { - Zotero.Commons.enabled = false; - Zotero.Commons.accessKey = ''; - Zotero.Commons.secretKey = ''; - } - // This is kind of a hack - Zotero.Notifier.trigger('refresh', 'collection', []); + // TODO: parse settings XML } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index bf206d409..b85aad8b2 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -1685,137 +1685,6 @@ var ZoteroPane = new function() } } - this.createCommonsBucket = function () { - var self = this; - - Zotero.Commons.getBuckets(function () { - var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - - var invalid = false; - - while (true) { - if (invalid) { - // TODO: localize - ps.alert(null, "", "Invalid title. Please try again."); - invalid = false; - } - - var newTitle = {}; - var result = ps.prompt( - null, - "", - // TODO: localize - "Enter a title for this Zotero Commons collection:", - newTitle, - "", {} - ); - - if (!result) { - return; - } - - var title = Zotero.Utilities.trim(newTitle.value); - - if (!title) { - return; - } - - if (!Zotero.Commons.isValidBucketTitle(title)) { - invalid = true; - continue; - } - - break; - } - - invalid = false; - - var origName = title.toLowerCase(); - origName = origName.replace(/[^a-z0-9 ._-]/g, ''); - origName = origName.replace(/ /g, '-'); - origName = origName.substr(0, 32); - - while (true) { - if (invalid) { - // TODO: localize - var msg = "'" + testName + "' is not a valid Zotero Commons collection identifier.\n\n" - + "Collection identifiers can contain basic Latin letters, numbers, " - + "hyphens, and underscores and must be no longer than 32 characters. " - + "Spaces and other characters are not allowed."; - ps.alert(null, "", msg); - invalid = false; - } - - var newName = { value: origName }; - var result = ps.prompt( - null, - "", - // TODO: localize - "Enter an identifier for the collection '" + title + "'.\n\n" - + "The identifier will form the collection's URL on archive.org. " - + "Identifiers can contain basic Latin letters, numbers, hyphens, and underscores " - + "and must be no longer than 32 characters. " - + "Spaces and other characters are not allowed.\n\n" - + '"' + Zotero.Commons.userNameSlug + '-" ' - + "will be automatically prepended to your entry.", - newName, - "", {} - ); - - if (!result) { - return; - } - - var name = Zotero.Utilities.trim(newName.value); - - if (!name) { - return; - } - - var testName = Zotero.Commons.userNameSlug + '-' + name; - if (!Zotero.Commons.isValidBucketName(testName)) { - invalid = true; - continue; - } - - break; - } - - // TODO: localize - var progressWin = new Zotero.ProgressWindow(); - progressWin.changeHeadline("Creating Zotero Commons Collection"); - var icon = self.collectionsView.getImageSrc(self.collectionsView.selection.currentIndex); - progressWin.addLines(title, icon) - progressWin.show(); - - Zotero.Commons.createBucket(name, title, function () { - progressWin.startCloseTimer(); - }); - }); - } - - - this.refreshCommonsBucket = function() { - if (!this.collectionsView - || !this.collectionsView.selection - || this.collectionsView.selection.count != 1 - || this.collectionsView.selection.currentIndex == -1) { - return false; - } - - var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); - if (itemGroup && itemGroup.isBucket()) { - var self = this; - itemGroup.ref.refreshItems(function () { - self.itemsView.refresh(); - self.itemsView.sort(); - - // On a manual refresh, also check for new OCRed files - //Zotero.Commons.syncFiles(); - }); - } - } function editSelectedCollection() { diff --git a/components/zotero-service.js b/components/zotero-service.js index ed58fbe11..71fbed54c 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -56,7 +56,6 @@ const xpcomFilesLocal = [ 'annotate', 'attachments', 'cite', - 'commons', 'cookieSandbox', 'data_access', 'data/dataObjects', diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 18ba2dac0..e4b89dd1a 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -119,11 +119,6 @@ pref("extensions.zotero.httpServer.port", 23119); // ascii "ZO" // Zeroconf pref("extensions.zotero.zeroconf.server.enabled", false); -// Zotero Commons -pref("extensions.zotero.commons.enabled", false); -pref("extensions.zotero.commons.accessKey", ''); -pref("extensions.zotero.commons.secretKey", ''); - // Annotation settings pref("extensions.zotero.annotations.warnOnClose", true);