2010-07-06 09:02:35 +00:00
|
|
|
/*
|
|
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
2010-12-26 19:05:52 +00:00
|
|
|
Copyright © 2009 Center for History and New Media
|
2010-07-06 09:02:35 +00:00
|
|
|
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
|
2011-05-18 18:34:22 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2010-07-06 09:02:35 +00:00
|
|
|
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
|
2011-05-18 18:34:22 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2010-07-06 09:02:35 +00:00
|
|
|
|
2011-05-18 18:34:22 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2010-07-06 09:02:35 +00:00
|
|
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
Based on nsChromeExtensionHandler example code by Ed Anuff at
|
|
|
|
http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol
|
|
|
|
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
const ZOTERO_CONTRACTID = '@zotero.org/Zotero;1';
|
2006-10-02 23:15:27 +00:00
|
|
|
const ZOTERO_CLASSNAME = 'Zotero';
|
|
|
|
const ZOTERO_CID = Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}');
|
2007-10-23 07:11:59 +00:00
|
|
|
const ZOTERO_IID = Components.interfaces.chnmIZoteroService; //unused
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].
|
|
|
|
getService(Components.interfaces.nsIXULAppInfo);
|
2011-04-18 23:29:12 +00:00
|
|
|
if(appInfo.platformVersion[0] >= 2) {
|
2010-07-06 09:02:35 +00:00
|
|
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
}
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
// Assign the global scope to a variable to passed via wrappedJSObject
|
2006-10-02 23:15:27 +00:00
|
|
|
var ZoteroWrapped = this;
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Include the core objects to be stored within XPCOM
|
|
|
|
*********************************************************************/
|
|
|
|
|
2008-08-13 06:38:47 +00:00
|
|
|
var xpcomFiles = [
|
|
|
|
'zotero',
|
|
|
|
'annotate',
|
|
|
|
'attachments',
|
2010-05-30 11:25:25 +00:00
|
|
|
'cite',
|
2008-08-13 06:38:47 +00:00
|
|
|
'collectionTreeView',
|
2009-08-13 10:56:47 +00:00
|
|
|
'commons',
|
2010-09-23 04:14:19 +00:00
|
|
|
'connector',
|
2008-08-13 06:38:47 +00:00
|
|
|
'dataServer',
|
|
|
|
'data_access',
|
|
|
|
'data/dataObjects',
|
|
|
|
'data/cachedTypes',
|
|
|
|
'data/item',
|
|
|
|
'data/items',
|
|
|
|
'data/collection',
|
|
|
|
'data/collections',
|
|
|
|
'data/creator',
|
|
|
|
'data/creators',
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
'data/group',
|
|
|
|
'data/groups',
|
2008-08-13 06:38:47 +00:00
|
|
|
'data/itemFields',
|
|
|
|
'data/notes',
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
'data/libraries',
|
|
|
|
'data/relation',
|
|
|
|
'data/relations',
|
2008-08-13 06:38:47 +00:00
|
|
|
'data/tag',
|
|
|
|
'data/tags',
|
2010-10-27 00:36:20 +00:00
|
|
|
'date',
|
2008-08-13 06:38:47 +00:00
|
|
|
'db',
|
2009-08-10 16:44:15 +00:00
|
|
|
'debug',
|
2009-03-06 21:45:49 +00:00
|
|
|
'duplicate',
|
2008-08-13 06:38:47 +00:00
|
|
|
'enstyle',
|
2009-07-06 10:13:02 +00:00
|
|
|
'error',
|
2008-08-13 06:38:47 +00:00
|
|
|
'file',
|
|
|
|
'fulltext',
|
2010-10-25 00:58:47 +00:00
|
|
|
'http',
|
2008-08-13 06:38:47 +00:00
|
|
|
'id',
|
|
|
|
'integration',
|
2009-08-20 05:02:55 +00:00
|
|
|
'integration_compat',
|
2008-08-13 06:38:47 +00:00
|
|
|
'itemTreeView',
|
2011-02-09 03:22:06 +00:00
|
|
|
'locateManager',
|
2008-08-13 06:38:47 +00:00
|
|
|
'mime',
|
2008-09-16 19:14:52 +00:00
|
|
|
'mimeTypeHandler',
|
2008-08-13 06:38:47 +00:00
|
|
|
'notifier',
|
2010-10-27 00:36:20 +00:00
|
|
|
'openurl',
|
2008-08-13 06:38:47 +00:00
|
|
|
'progressWindow',
|
|
|
|
'proxy',
|
|
|
|
'quickCopy',
|
|
|
|
'report',
|
|
|
|
'schema',
|
|
|
|
'search',
|
2008-09-16 19:14:52 +00:00
|
|
|
'style',
|
2008-08-13 06:38:47 +00:00
|
|
|
'sync',
|
2008-08-31 23:36:01 +00:00
|
|
|
'storage',
|
Zotero File Storage megacommit
- Group file sync via Zotero File Storage
- Split file syncing into separate modules for ZFS and WebDAV
- Dragging items between libraries copies child notes, snapshots/files, and links based on checkboxes for each (enabled by default) in the Zotero preferences
- Sync errors now trigger an exclamation/error icon separate from the sync icon, with a popup window displaying the error and an option to report it
- Various errors that could cause perpetual sync icon spinning now stop the sync properly
- Zotero.Utilities.md5(str) is now md5(strOrFile, base64)
- doPost(), doHead(), and retrieveSource() now takes a headers parameter instead of requestContentType
- doHead() can now accept an nsIURI (with login credentials), is a background request, and isn't cached
- When library access or file writing access is denied during sync, display a warning and then reset local group to server version
- Perform additional steps (e.g., removing local groups) when switching sync users to prevent errors
- Compare hash as well as mod time when checking for modified local files
- Don't trigger notifications when removing groups from the client
- Clear relation links to items in removed groups
- Zotero.Item.attachmentHash property to get file MD5
- importFromFile() now takes libraryID as a third parameter
- Zotero.Attachments.getNumFiles() returns the number of files in the attachment directory
- Zotero.Attachments.copyAttachmentToLibrary() copies an attachment item, including files, to another library
- Removed Zotero.File.getFileHash() in favor of updated Zotero.Utilities.md5()
- Zotero.File.copyDirectory(dir, newDir) copies all files from dir into newDir
- Preferences shuffling: OpenURL to Advanced, import/export character set options to Export, "Include URLs of paper articles in references" to Styles
- Other stuff I don't remember
Suffice it to say, this could use testing.
2009-09-13 07:23:29 +00:00
|
|
|
'storage/session',
|
|
|
|
'storage/zfs',
|
|
|
|
'storage/webdav',
|
2008-08-13 06:38:47 +00:00
|
|
|
'timeline',
|
2010-11-02 21:39:54 +00:00
|
|
|
'translation/translator',
|
|
|
|
'translation/translate',
|
|
|
|
'translation/browser_firefox',
|
|
|
|
'translation/item_local',
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
'uri',
|
2008-08-13 06:38:47 +00:00
|
|
|
'utilities',
|
|
|
|
'zeroconf'
|
|
|
|
];
|
Initial Zotero 1.5 Megacommit
Apologies for the massive (and, due to data_access.js splitting, difficult-to-follow) commit. Please note that external code that accesses the data layer may need to be tweaked for compatibility. Here's a comprehensive-as-possible changelog:
- Added server sync functionality (incomplete)
- Overhaul of data layer
- Split data_access.js into separate files (item.js, items.js, creator.js, etc.)
- Made creators and collections first-class objects, similar to items
- Constructors now take id as first parameter, e.g. new Zotero.Item(1234, 'book'), to allow explicit id setting and id changing
- Made various data layer operations (including attachment fields) require a save() rather than making direct DB changes
- Better handling of unsaved objects
- Item.setCreator() now takes creator objects instead of creator ids, and Item.save() will auto-save unsaved creators
- clone() now works on unsaved objects
- Newly created object instances are now disabled after save() to force refetch of globally accessible instance using Zotero.(Items|Creators|etc.).get()
- Added secondary lookup key to data objects
- Deprecated getID() and getItemType() methods in favor of .id and .itemTypeID properties
- toArray() deprecated in favor of serialize(), which has a somewhat modified format
- Added support for multiple creators with identical data -- currently unimplemented in interface and most of data layer
- Added Item.diff() for comparing item metadata
- Database changes
- Added SQLite triggers to enforce foreign key constraints
- Added Zotero.DB.transactionVacuum flag to run a VACUUM after a transaction
- Added Zotero.DB.transactionDate, .transactionDateTime, and transactionTimestamp to retrieve consistent timestamps for entire transaction
- Properly store 64-bit integers
- Set PRAGMA locking_mode=EXCLUSIVE on database
- Set SQLite page size to 4096 on new databases
- Set SQLite page cache to 8MB
- Do some database cleanup and integrity checking on migration from 1.0 branch
- Removed IF NOT EXISTS from userdata.sql CREATE statements -- userdata.sql is now processed only on DB initialization
- Removed itemNoteTitles table and moved titles into itemNotes
- Abstracted metadata edit box and note box into flexible XBL bindings with various modes, including read-only states
- Massive speed-up of item tree view
- Several fixes from 1.0 branch for Fx3 compatibility
- Added Notifier observer to log delete events for syncing
- Zotero.Utilities changes
- New methods getSQLDataType() and md5()
- Removed onError from Zotero.Utilities.HTTP.doGet()
- Don't display more than 1024 characters in doPost() debug output
- Don't display passwords in doPost() debug output
- Added Zotero.Notifier.untrigger() -- currently unused
- Added Zotero.reloadDataObjects() to reset all in-memory objects
- Added |chars| parameter to Zotero.randomString(len, chars)
- Added Zotero.Date.getUnixTimestamp() and Date.toUnixTimestamp(JSDate)
- Adjusted zotero-service.js to simplify file inclusion
Various things (such as tags) are temporarily broken.
2008-05-04 08:32:48 +00:00
|
|
|
|
2010-05-30 11:25:25 +00:00
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFiles[0] + ".js");
|
|
|
|
|
|
|
|
// Load CiteProc into Zotero.CiteProc namespace
|
update to citeproc-js 1.0.88
From 1.0.82:
Fixes to cs:if and cs:else-if logic. Was failing to set the match
attribute on singleton nodes, among other things.
Treat greek letters as part of the "romanesque" character set, for
name formatting purposes.
If cs:number input has numbers separated by spaces, but also
extraneous non-comma, non-ampersand, non-hyphen characters, then
render as literal.
From 1.0.83:
Use en-dash rather than hyphen in formatted page range joins.
From 1.0.84:
Preserve explicit double spaces in HTML output.
From 1.0.85:
Pass full suite of double space suppression tests.
Language switching within a style works, for both localized dates and
terms. (This functionality is not yet valid in CSL.)
From 1.0.86:
Address bug that caused unreasonable delays with large namesets.
From 1.0.87:
Where et-al-min, et-al-subsequent-min or names-min are set to some
value larger than zero, and the number of names in a nameset exceeds
an arbitrary threshold of 50, truncate author lists that are longer
than the *-min value (plus a buffer value of 2), to raise performance
to a reasonable level with large namesets.
From 1.0.88:
Adjustments to language condition logic, to use only the base language
name for matching, while applying the full locale specified in the
conditional to node children.
Refinements to the recently introduced handling of brace-enclosed
leading characters as initialized form of names.
Adjustments to print statement arbitration, with a view to playing
nice with various systems.
2010-12-10 07:12:08 +00:00
|
|
|
Zotero.CiteProc = {"Zotero":Zotero};
|
2010-05-30 11:25:25 +00:00
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://zotero/content/xpcom/citeproc.js", Zotero.CiteProc);
|
|
|
|
|
|
|
|
for (var i=1; i<xpcomFiles.length; i++) {
|
2009-07-06 10:13:02 +00:00
|
|
|
try {
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFiles[i] + ".js");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError("Error loading " + xpcomFiles[i] + ".js");
|
|
|
|
throw (e);
|
|
|
|
}
|
Initial Zotero 1.5 Megacommit
Apologies for the massive (and, due to data_access.js splitting, difficult-to-follow) commit. Please note that external code that accesses the data layer may need to be tweaked for compatibility. Here's a comprehensive-as-possible changelog:
- Added server sync functionality (incomplete)
- Overhaul of data layer
- Split data_access.js into separate files (item.js, items.js, creator.js, etc.)
- Made creators and collections first-class objects, similar to items
- Constructors now take id as first parameter, e.g. new Zotero.Item(1234, 'book'), to allow explicit id setting and id changing
- Made various data layer operations (including attachment fields) require a save() rather than making direct DB changes
- Better handling of unsaved objects
- Item.setCreator() now takes creator objects instead of creator ids, and Item.save() will auto-save unsaved creators
- clone() now works on unsaved objects
- Newly created object instances are now disabled after save() to force refetch of globally accessible instance using Zotero.(Items|Creators|etc.).get()
- Added secondary lookup key to data objects
- Deprecated getID() and getItemType() methods in favor of .id and .itemTypeID properties
- toArray() deprecated in favor of serialize(), which has a somewhat modified format
- Added support for multiple creators with identical data -- currently unimplemented in interface and most of data layer
- Added Item.diff() for comparing item metadata
- Database changes
- Added SQLite triggers to enforce foreign key constraints
- Added Zotero.DB.transactionVacuum flag to run a VACUUM after a transaction
- Added Zotero.DB.transactionDate, .transactionDateTime, and transactionTimestamp to retrieve consistent timestamps for entire transaction
- Properly store 64-bit integers
- Set PRAGMA locking_mode=EXCLUSIVE on database
- Set SQLite page size to 4096 on new databases
- Set SQLite page cache to 8MB
- Do some database cleanup and integrity checking on migration from 1.0 branch
- Removed IF NOT EXISTS from userdata.sql CREATE statements -- userdata.sql is now processed only on DB initialization
- Removed itemNoteTitles table and moved titles into itemNotes
- Abstracted metadata edit box and note box into flexible XBL bindings with various modes, including read-only states
- Massive speed-up of item tree view
- Several fixes from 1.0 branch for Fx3 compatibility
- Added Notifier observer to log delete events for syncing
- Zotero.Utilities changes
- New methods getSQLDataType() and md5()
- Removed onError from Zotero.Utilities.HTTP.doGet()
- Don't display more than 1024 characters in doPost() debug output
- Don't display passwords in doPost() debug output
- Added Zotero.Notifier.untrigger() -- currently unused
- Added Zotero.reloadDataObjects() to reset all in-memory objects
- Added |chars| parameter to Zotero.randomString(len, chars)
- Added Zotero.Date.getUnixTimestamp() and Date.toUnixTimestamp(JSDate)
- Adjusted zotero-service.js to simplify file inclusion
Various things (such as tags) are temporarily broken.
2008-05-04 08:32:48 +00:00
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-06-24 20:42:41 +00:00
|
|
|
|
|
|
|
// Load RDF files into Zotero.RDF.AJAW namespace (easier than modifying all of the references)
|
|
|
|
var rdfXpcomFiles = [
|
|
|
|
'rdf/uri',
|
|
|
|
'rdf/term',
|
|
|
|
'rdf/identity',
|
|
|
|
'rdf/match',
|
|
|
|
'rdf/n3parser',
|
|
|
|
'rdf/rdfparser',
|
|
|
|
'rdf/serialize',
|
|
|
|
'rdf'
|
|
|
|
];
|
|
|
|
|
|
|
|
Zotero.RDF = {AJAW:{}};
|
|
|
|
|
|
|
|
for (var i=0; i<rdfXpcomFiles.length; i++) {
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://zotero/content/xpcom/" + rdfXpcomFiles[i] + ".js", Zotero.RDF.AJAW);
|
|
|
|
}
|
|
|
|
|
2006-08-25 19:15:03 +00:00
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://global/content/nsTransferable.js");
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
// Initialize the Zotero service
|
2006-05-27 00:20:27 +00:00
|
|
|
//
|
2006-10-02 23:15:27 +00:00
|
|
|
// This runs when ZoteroService is first requested.
|
2006-05-27 00:20:27 +00:00
|
|
|
// Calls to other XPCOM components must be in here rather than in top-level
|
|
|
|
// code, as other components may not have yet been initialized.
|
|
|
|
function setupService(){
|
2008-07-03 16:44:52 +00:00
|
|
|
try {
|
|
|
|
Zotero.init();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
var msg = typeof e == 'string' ? e : e.name;
|
|
|
|
dump(e + "\n\n");
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
2006-05-27 00:20:27 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
function ZoteroService(){
|
|
|
|
this.wrappedJSObject = ZoteroWrapped.Zotero;
|
2006-05-27 00:20:27 +00:00
|
|
|
setupService();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to replicate window.alert()
|
|
|
|
**/
|
2010-07-06 09:02:35 +00:00
|
|
|
// TODO: is this still used? if so, move to zotero.js
|
2006-05-27 00:20:27 +00:00
|
|
|
function alert(msg){
|
|
|
|
Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Ci.nsIPromptService)
|
|
|
|
.alert(null, "", msg);
|
|
|
|
}
|
|
|
|
|
2006-06-01 21:57:12 +00:00
|
|
|
/**
|
|
|
|
* Convenience method to replicate window.confirm()
|
|
|
|
**/
|
2010-07-06 09:02:35 +00:00
|
|
|
// TODO: is this still used? if so, move to zotero.js
|
2006-06-01 21:57:12 +00:00
|
|
|
function confirm(msg){
|
|
|
|
return Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Ci.nsIPromptService)
|
|
|
|
.confirm(null, "", msg);
|
|
|
|
}
|
2006-05-27 00:20:27 +00:00
|
|
|
|
Fulltext search support
There are currently two types of fulltext searching: an SQL-based word index and a file scanner. They each have their advantages and drawbacks.
The word index is very fast to search and is currently used for the find-as-you-type quicksearch. However, indexing files takes some time, so we should probably offer a preference to turn it off ("Index attachment content for quicksearch" or something). There's also an issue with Chinese characters (which are indexed by character rather than word, since there are no spaces to go by, so a search for a word with common characters could produce erroneous results). The quicksearch doesn't use a left-bound index (since that would probably upset German speakers searching for "musik" in "nachtmusik," though I don't know for sure how they think of words) but still seems pretty fast.
* Note: There will be a potentially long delay when you start Firefox with this revision as it builds a fulltext word index of your existing items. We obviously need a notification/option for this. *
The file scanner, used in the Attachment Content condition of the search dialog, offers phrase searching as well as regex support (both case-sensitive and not, and defaulting to multiline). It doesn't require an index, though it should probably be optimized to use the word index, if available, for narrowing the results when not in regex mode. (It does only scan files that pass all the other search conditions, which speeds it up considerably for multi-condition searches, and skips non-text files unless instructed otherwise, but it's still relatively slow.)
Both convert HTML to text before searching (with the exception of the binary file scanning mode).
There are some issues with which files get indexed and which don't that we can't do much about and that will probably confuse users immensely. Dan C. suggested some sort of indicator (say, a green dot) to show which files are indexed.
Also added (very ugly) charset detection (anybody want to figure out getCharsetFromString(str)?), a setTimeout() replacement in the XPCOM service, an arrayToHash() method, and a new header to timedtextarea.xml, since it's really not copyright CHNM (it's really just a few lines off from the toolkit timed-textbox binding--I tried to change it to extend timed-textbox and just ignore Return keypress events so that we didn't need to duplicate the Mozilla code, but timed-textbox's reliance on html:input instead of html:textarea made things rather difficult).
To do:
- Pref/buttons to disable/clear/rebuild fulltext index
- Hidden prefs to set maximum file size to index/scan
- Don't index words of fewer than 3 non-Asian characters
- MRU cache for saved searches
- Use word index if available to narrow search scope of fulltext scanner
- Cache attachment info methods
- Show content excerpt in search results (at least in advanced search window, when it exists)
- Notification window (a la scraping) to show when indexing
- Indicator of indexed status
- Context menu option to index
- Indicator that a file scanning search is in progress, if possible
- Find other ways to make it index the NYT front page in under 10 seconds
- Probably fix lots of bugs, which you will likely start telling me about...now.
2006-09-21 00:10:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to replicate window.setTimeout()
|
|
|
|
**/
|
2011-05-31 19:59:07 +00:00
|
|
|
function setTimeout(func, ms) {
|
|
|
|
Zotero.setTimeout(func, ms);
|
Fulltext search support
There are currently two types of fulltext searching: an SQL-based word index and a file scanner. They each have their advantages and drawbacks.
The word index is very fast to search and is currently used for the find-as-you-type quicksearch. However, indexing files takes some time, so we should probably offer a preference to turn it off ("Index attachment content for quicksearch" or something). There's also an issue with Chinese characters (which are indexed by character rather than word, since there are no spaces to go by, so a search for a word with common characters could produce erroneous results). The quicksearch doesn't use a left-bound index (since that would probably upset German speakers searching for "musik" in "nachtmusik," though I don't know for sure how they think of words) but still seems pretty fast.
* Note: There will be a potentially long delay when you start Firefox with this revision as it builds a fulltext word index of your existing items. We obviously need a notification/option for this. *
The file scanner, used in the Attachment Content condition of the search dialog, offers phrase searching as well as regex support (both case-sensitive and not, and defaulting to multiline). It doesn't require an index, though it should probably be optimized to use the word index, if available, for narrowing the results when not in regex mode. (It does only scan files that pass all the other search conditions, which speeds it up considerably for multi-condition searches, and skips non-text files unless instructed otherwise, but it's still relatively slow.)
Both convert HTML to text before searching (with the exception of the binary file scanning mode).
There are some issues with which files get indexed and which don't that we can't do much about and that will probably confuse users immensely. Dan C. suggested some sort of indicator (say, a green dot) to show which files are indexed.
Also added (very ugly) charset detection (anybody want to figure out getCharsetFromString(str)?), a setTimeout() replacement in the XPCOM service, an arrayToHash() method, and a new header to timedtextarea.xml, since it's really not copyright CHNM (it's really just a few lines off from the toolkit timed-textbox binding--I tried to change it to extend timed-textbox and just ignore Return keypress events so that we didn't need to duplicate the Mozilla code, but timed-textbox's reliance on html:input instead of html:textarea made things rather difficult).
To do:
- Pref/buttons to disable/clear/rebuild fulltext index
- Hidden prefs to set maximum file size to index/scan
- Don't index words of fewer than 3 non-Asian characters
- MRU cache for saved searches
- Use word index if available to narrow search scope of fulltext scanner
- Cache attachment info methods
- Show content excerpt in search results (at least in advanced search window, when it exists)
- Notification window (a la scraping) to show when indexing
- Indicator of indexed status
- Context menu option to index
- Indicator that a file scanning search is in progress, if possible
- Find other ways to make it index the NYT front page in under 10 seconds
- Probably fix lots of bugs, which you will likely start telling me about...now.
2006-09-21 00:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
//
|
|
|
|
// XPCOM goop
|
|
|
|
//
|
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
ZoteroService.prototype = {
|
|
|
|
contractID: ZOTERO_CONTRACTID,
|
|
|
|
classDescription: ZOTERO_CLASSNAME,
|
|
|
|
classID: ZOTERO_CID,
|
|
|
|
service: true,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports, ZOTERO_IID])
|
|
|
|
}
|
2006-05-27 00:20:27 +00:00
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
/**
|
|
|
|
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
|
|
|
|
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
|
|
|
|
*/
|
|
|
|
if (XPCOMUtils.generateNSGetFactory) {
|
|
|
|
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ZoteroService]);
|
|
|
|
} else {
|
|
|
|
var NSGetModule = XPCOMUtils.generateNSGetModule([ZoteroService]);
|
|
|
|
}
|