2006-10-04 17:16:56 +00:00
|
|
|
|
/*
|
|
|
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2006 Center for History and New Media
|
|
|
|
|
George Mason University, Fairfax, Virginia, USA
|
|
|
|
|
http://chnm.gmu.edu
|
|
|
|
|
|
|
|
|
|
Licensed under the Educational Community License, Version 1.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.opensource.org/licenses/ecl1.php
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
const ZOTERO_CONFIG = {
|
2006-08-30 07:05:57 +00:00
|
|
|
|
GUID: 'zotero@chnm.gmu.edu',
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
DB_REBUILD: false, // erase DB and recreate from schema
|
2006-08-31 22:52:27 +00:00
|
|
|
|
REPOSITORY_URL: 'http://www.zotero.org/repo',
|
2006-07-31 03:38:02 +00:00
|
|
|
|
REPOSITORY_CHECK_INTERVAL: 86400, // 24 hours
|
2008-06-17 20:41:31 +00:00
|
|
|
|
REPOSITORY_RETRY_INTERVAL: 3600, // 1 hour
|
2008-06-18 08:47:38 +00:00
|
|
|
|
SYNC_URL: 'https://sync.zotero.org/'
|
2006-02-21 17:01:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Core functions
|
|
|
|
|
*/
|
2006-10-02 23:15:27 +00:00
|
|
|
|
var Zotero = new function(){
|
2006-05-27 00:20:27 +00:00
|
|
|
|
// Privileged (public) methods
|
2006-03-20 21:47:22 +00:00
|
|
|
|
this.init = init;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.stateCheck = stateCheck;
|
|
|
|
|
//this.shutdown = shutdown;
|
2006-07-27 08:45:48 +00:00
|
|
|
|
this.getProfileDirectory = getProfileDirectory;
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
this.getInstallDirectory = getInstallDirectory;
|
2006-10-02 23:15:27 +00:00
|
|
|
|
this.getZoteroDirectory = getZoteroDirectory;
|
2006-07-27 08:45:48 +00:00
|
|
|
|
this.getStorageDirectory = getStorageDirectory;
|
2006-10-02 23:15:27 +00:00
|
|
|
|
this.getZoteroDatabase = getZoteroDatabase;
|
2008-08-31 23:36:01 +00:00
|
|
|
|
this.getTempDirectory = getTempDirectory;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.chooseZoteroDirectory = chooseZoteroDirectory;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
this.debug = debug;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.log = log;
|
|
|
|
|
this.getErrors = getErrors;
|
|
|
|
|
this.getSystemInfo = getSystemInfo;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
this.varDump = varDump;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.safeDebug = safeDebug;
|
2006-05-27 00:20:27 +00:00
|
|
|
|
this.getString = getString;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.localeJoin = localeJoin;
|
|
|
|
|
this.getLocaleCollation = getLocaleCollation;
|
|
|
|
|
this.setFontSize = setFontSize;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
this.flattenArguments = flattenArguments;
|
Closes #259, auto-complete of tags
Addresses #260, Add auto-complete to search window
- New XPCOM autocomplete component for Zotero data -- can be used by setting the autocompletesearch attribute of a textbox to 'zotero' and passing a search scope with the autocompletesearchparam attribute. Additional parameters can be passed by appending them to the autocompletesearchparam value with a '/', e.g. 'tag/2732' (to exclude tags that show up in item 2732)
- Tag entry now uses more or less the same interface as metadata -- no more popup window -- note that tab isn't working properly yet, and there's no way to quickly enter multiple tags (though it's now considerably quicker than it was before)
- Autocomplete for tags, excluding any tags already set for the current item
- Standalone note windows now register with the Notifier (since tags needed item modification notifications to work properly), which will help with #282, "Notes opened in separate windows need item notification"
- Tags are now retrieved in alphabetical order
- Scholar.Item.replaceTag(oldTagID, newTag), with a single notify
- Scholar.getAncestorByTagName(elem, tagName) -- walk up the DOM tree from an element until an element with the specified tag name is found (also checks with 'xul:' prefix, for use in XBL), or false if not found -- probably shouldn't be used too widely, since it's doing string comparisons, but better than specifying, say, nine '.parentNode' properties, and makes for more resilient code
A few notes:
- Autocomplete in Minefield seems to self-destruct after using it in the same field a few times, taking down saving of the field with it -- this may or may not be my fault, but it makes Zotero more or less unusable in 3.0 at the moment. Sorry. (I use 3.0 myself for development, so I'll work on it.)
- This would have been much, much easier if having an autocomplete textbox (which uses an XBL-generated popup for the suggestions) within a popup (as it is in the independent note edit panes) didn't introduce all sorts of crazy bugs that had to be defeated with annoying hackery -- one side effect of this is that at the moment you can't close the tags popup with the Escape key
- Independent note windows now need to pull in itemPane.js to function properly, which is a bit messy and not ideal, but less messy and more ideal than duplicating all the dual-state editor and tabindex logic would be
- Hitting tab in a tag field not only doesn't work but also breaks things until the next window refresh.
- There are undoubtedly other bugs.
2006-09-07 08:07:48 +00:00
|
|
|
|
this.getAncestorByTagName = getAncestorByTagName;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
this.join = join;
|
2006-06-20 17:32:40 +00:00
|
|
|
|
this.inArray = inArray;
|
|
|
|
|
this.arraySearch = arraySearch;
|
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
|
|
|
|
this.arrayToHash = arrayToHash;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.hasValues = hasValues;
|
2006-06-01 19:46:57 +00:00
|
|
|
|
this.randomString = randomString;
|
2006-08-01 23:10:31 +00:00
|
|
|
|
this.moveToUnique = moveToUnique;
|
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
|
|
|
|
this.reloadDataObjects = reloadDataObjects;
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
|
// Public properties
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.initialized = false;
|
|
|
|
|
this.skipLoading = false;
|
|
|
|
|
this.__defineGetter__("startupError", function() { return _startupError; });
|
|
|
|
|
this.__defineGetter__("startupErrorHandler", function() { return _startupErrorHandler; });
|
2006-06-15 06:13:02 +00:00
|
|
|
|
this.version;
|
2006-08-30 19:18:43 +00:00
|
|
|
|
this.platform;
|
2006-09-06 07:04:02 +00:00
|
|
|
|
this.locale;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.dir; // locale direction: 'ltr' or 'rtl'
|
2006-08-30 21:56:52 +00:00
|
|
|
|
this.isMac;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.isWin;
|
|
|
|
|
this.initialURL; // used by Schema to show the changelog on upgrades
|
|
|
|
|
|
|
|
|
|
var _startupError;
|
|
|
|
|
var _startupErrorHandler;
|
|
|
|
|
var _zoteroDirectory = false;
|
|
|
|
|
var _debugLogging;
|
|
|
|
|
var _debugLevel;
|
|
|
|
|
var _debugTime;
|
|
|
|
|
var _debugLastTime;
|
|
|
|
|
//var _shutdown = false;
|
|
|
|
|
var _localizedStringBundle;
|
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
|
|
2006-02-21 17:01:06 +00:00
|
|
|
|
/*
|
|
|
|
|
* Initialize the extension
|
|
|
|
|
*/
|
2006-03-20 21:47:22 +00:00
|
|
|
|
function init(){
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (this.initialized || this.skipLoading) {
|
2006-05-27 00:20:27 +00:00
|
|
|
|
return false;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
}
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
2008-09-11 19:35:53 +00:00
|
|
|
|
var start = (new Date()).getTime()
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
// Register shutdown handler to call Zotero.shutdown()
|
2007-10-23 07:11:59 +00:00
|
|
|
|
/*
|
2006-08-01 18:01:56 +00:00
|
|
|
|
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
|
observerService.addObserver({
|
|
|
|
|
observe: function(subject, topic, data){
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.shutdown(subject, topic, data)
|
2006-08-01 18:01:56 +00:00
|
|
|
|
}
|
|
|
|
|
}, "xpcom-shutdown", false);
|
2007-10-23 07:11:59 +00:00
|
|
|
|
*/
|
2006-08-01 18:01:56 +00:00
|
|
|
|
|
2006-06-25 07:31:01 +00:00
|
|
|
|
// Load in the preferences branch for the extension
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Prefs.init();
|
2006-06-25 07:31:01 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
_debugLogging = Zotero.Prefs.get('debug.log');
|
|
|
|
|
_debugLevel = Zotero.Prefs.get('debug.level');
|
|
|
|
|
_debugTime = Zotero.Prefs.get('debug.time');
|
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
|
// Load in the extension version from the extension manager
|
|
|
|
|
var nsIUpdateItem = Components.interfaces.nsIUpdateItem;
|
|
|
|
|
var gExtensionManager =
|
|
|
|
|
Components.classes["@mozilla.org/extensions/manager;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIExtensionManager);
|
|
|
|
|
this.version
|
2006-10-02 23:15:27 +00:00
|
|
|
|
= gExtensionManager.getItemForID(ZOTERO_CONFIG['GUID']).version;
|
2006-05-27 00:20:27 +00:00
|
|
|
|
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
|
var appInfo =
|
|
|
|
|
Components.classes["@mozilla.org/xre/app-info;1"].
|
|
|
|
|
getService(Components.interfaces.nsIXULAppInfo)
|
|
|
|
|
this.isFx2 = appInfo.platformVersion.indexOf('1.8') === 0; // TODO: remove
|
|
|
|
|
this.isFx3 = appInfo.platformVersion.indexOf('1.9') === 0;
|
|
|
|
|
|
2006-08-30 19:18:43 +00:00
|
|
|
|
// OS platform
|
|
|
|
|
var win = Components.classes["@mozilla.org/appshell/appShellService;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIAppShellService)
|
|
|
|
|
.hiddenDOMWindow;
|
|
|
|
|
this.platform = win.navigator.platform;
|
2006-08-30 19:57:23 +00:00
|
|
|
|
this.isMac = (this.platform.substr(0, 3) == "Mac");
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.isWin = (this.platform.substr(0, 3) == "Win");
|
|
|
|
|
this.isLinux = (this.platform.substr(0, 5) == "Linux");
|
2006-07-27 08:45:48 +00:00
|
|
|
|
|
2006-09-06 07:04:02 +00:00
|
|
|
|
// Locale
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var ph = Components.classes["@mozilla.org/network/protocol;1?name=http"].
|
|
|
|
|
getService(Components.interfaces.nsIHttpProtocolHandler);
|
|
|
|
|
if (ph.language.length == 2) {
|
|
|
|
|
this.locale = ph.language + '-' + ph.language.toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.locale = ph.language;
|
|
|
|
|
}
|
2006-09-06 07:04:02 +00:00
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
|
// Load in the localization stringbundle for use by getString(name)
|
2006-10-02 23:15:27 +00:00
|
|
|
|
var src = 'chrome://zotero/locale/zotero.properties';
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'].
|
|
|
|
|
getService(Components.interfaces.nsILocaleService);
|
2006-05-27 00:20:27 +00:00
|
|
|
|
var appLocale = localeService.getApplicationLocale();
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
|
var stringBundleService =
|
|
|
|
|
Components.classes["@mozilla.org/intl/stringbundle;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIStringBundleService);
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
|
_localizedStringBundle = stringBundleService.createBundle(src, appLocale);
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// Set the locale direction to Zotero.dir
|
|
|
|
|
// DEBUG: is there a better way to get the entity from JS?
|
|
|
|
|
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
|
|
|
.createInstance();
|
|
|
|
|
xmlhttp.open('GET', 'chrome://global/locale/global.dtd', false);
|
Merged revisions 2190-2192,2194,2196-2199,2202-2205,2209,2212,2214-2215,2227-2228,2230,2232-2243,2245,2247-2256,2263-2272,2276,2278-2279,2281,2284-2286,2292,2296-2297,2299-2302,2304-2305,2309-2310,2314,2317-2323,2325-2329,2331-2337,2339,2341-2342,2344,2347-2366,2370-2371,2373-2377,2379-2391,2393-2402,2405-2410,2413,2415-2416,2418,2420-2421,2423,2427-2429,2431-2433,2437,2440-2441,2443-2450,2453,2455-2459,2461-2467,2471,2475-2480,2482-2490,2493,2495-2499,2501-2506,2511,2513-2519,2521,2525-2536,2540,2543-2553,2555-2559,2561-2576,2578,2580-2603,2606-2609,2611-2616,2618-2620,2624-2630,2632-2633 to trunk via svnmerge from 1.0 branch
2008-05-05 07:19:34 +00:00
|
|
|
|
xmlhttp.overrideMimeType('text/plain');
|
2007-10-23 07:11:59 +00:00
|
|
|
|
xmlhttp.send(null);
|
|
|
|
|
this.dir = xmlhttp.responseText.match(/(ltr|rtl)/)[0];
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.getZoteroDirectory();
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
// Zotero dir not found
|
|
|
|
|
if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
|
|
|
|
|
_startupError = Zotero.getString('dataDir.notFound');
|
|
|
|
|
_startupErrorHandler = function() {
|
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
|
var win = wm.getMostRecentWindow('navigator:browser');
|
|
|
|
|
|
|
|
|
|
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
|
createInstance(Components.interfaces.nsIPromptService);
|
|
|
|
|
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_OK)
|
|
|
|
|
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
|
|
|
|
|
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING);
|
|
|
|
|
var index = ps.confirmEx(win,
|
|
|
|
|
Zotero.getString('general.error'),
|
|
|
|
|
_startupError + '\n\n' +
|
|
|
|
|
Zotero.getString('dataDir.previousDir') + ' '
|
|
|
|
|
+ Zotero.Prefs.get('lastDataDir'),
|
|
|
|
|
buttonFlags, null,
|
|
|
|
|
Zotero.getString('dataDir.useProfileDir'),
|
|
|
|
|
Zotero.getString('general.locate'),
|
|
|
|
|
null, {});
|
|
|
|
|
|
|
|
|
|
// Revert to profile directory
|
|
|
|
|
if (index == 1) {
|
|
|
|
|
Zotero.chooseZoteroDirectory(false, true);
|
|
|
|
|
}
|
|
|
|
|
// Locate data directory
|
|
|
|
|
else if (index == 2) {
|
|
|
|
|
Zotero.chooseZoteroDirectory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// DEBUG: handle more startup errors
|
|
|
|
|
else {
|
|
|
|
|
throw (e);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize keyboard shortcuts
|
|
|
|
|
Zotero.Keys.init();
|
|
|
|
|
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
|
try {
|
|
|
|
|
Zotero.DB.test();
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
|
Components.utils.reportError(e);
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
|
this.skipLoading = true;
|
|
|
|
|
Zotero.DB.skipBackup = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// Add notifier queue callbacks to the DB layer
|
|
|
|
|
Zotero.DB.addCallback('begin', Zotero.Notifier.begin);
|
|
|
|
|
Zotero.DB.addCallback('commit', Zotero.Notifier.commit);
|
|
|
|
|
Zotero.DB.addCallback('rollback', Zotero.Notifier.reset);
|
|
|
|
|
|
|
|
|
|
Zotero.Fulltext.init();
|
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
|
// Trigger updating of schema and scrapers
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (Zotero.Schema.userDataUpgradeRequired()) {
|
|
|
|
|
var upgraded = Zotero.Schema.showUpgradeWizard();
|
|
|
|
|
if (!upgraded) {
|
|
|
|
|
this.skipLoading = true;
|
|
|
|
|
Zotero.DB.skipBackup = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// If no userdata upgrade, still might need to process system/scrapers
|
|
|
|
|
else {
|
|
|
|
|
try {
|
|
|
|
|
Zotero.Schema.updateSchema();
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
if (typeof e == 'string' && e.match('newer than SQL file')) {
|
|
|
|
|
_startupError = e;
|
|
|
|
|
}
|
2008-08-31 23:36:01 +00:00
|
|
|
|
else {
|
|
|
|
|
_startupError = "Database upgrade error";
|
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
Components.utils.reportError(_startupError);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Zotero.DB.startDummyStatement();
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Schema.updateScrapersRemote();
|
2006-06-15 06:13:02 +00:00
|
|
|
|
|
2006-08-30 00:16:07 +00:00
|
|
|
|
// Initialize integration web server
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Integration.init();
|
2006-08-30 00:16:07 +00:00
|
|
|
|
|
2008-06-03 05:26:30 +00:00
|
|
|
|
// Initialize data web server
|
|
|
|
|
Zotero.DataServer.init();
|
|
|
|
|
Zotero.Zeroconf.init();
|
|
|
|
|
|
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
|
|
|
|
Zotero.Sync.init();
|
2008-08-31 23:36:01 +00:00
|
|
|
|
Zotero.Sync.Runner.init();
|
|
|
|
|
Zotero.Sync.Storage.init();
|
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
|
|
|
|
|
2008-09-11 19:35:53 +00:00
|
|
|
|
Zotero.Proxies.init();
|
|
|
|
|
Zotero.Ingester.MIMEHandler.init();
|
|
|
|
|
Zotero.Cite.MIMEHandler.init();
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.initialized = true;
|
2008-09-11 19:35:53 +00:00
|
|
|
|
Zotero.debug("Initialized in "+((new Date()).getTime() - start)+" ms");
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check if a DB transaction is open and, if so, disable Zotero
|
|
|
|
|
*/
|
|
|
|
|
function stateCheck() {
|
|
|
|
|
if (Zotero.DB.transactionInProgress()) {
|
|
|
|
|
this.initialized = false;
|
|
|
|
|
this.skipLoading = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-27 00:20:27 +00:00
|
|
|
|
return true;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
}
|
2006-02-21 17:01:06 +00:00
|
|
|
|
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
/*
|
2006-08-01 18:01:56 +00:00
|
|
|
|
function shutdown(subject, topic, data){
|
|
|
|
|
// Called twice otherwise, for some reason
|
|
|
|
|
if (_shutdown){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2006-08-01 23:10:31 +00:00
|
|
|
|
return true;
|
2006-08-01 18:01:56 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
*/
|
2006-08-01 18:01:56 +00:00
|
|
|
|
|
|
|
|
|
|
2006-07-27 08:45:48 +00:00
|
|
|
|
function getProfileDirectory(){
|
|
|
|
|
return Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIProperties)
|
|
|
|
|
.get("ProfD", Components.interfaces.nsIFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
function getInstallDirectory() {
|
|
|
|
|
var id = ZOTERO_CONFIG.GUID;
|
|
|
|
|
var em = Components.classes["@mozilla.org/extensions/manager;1"].
|
|
|
|
|
getService(Components.interfaces.nsIExtensionManager);
|
|
|
|
|
var installDir = em.getInstallLocation(id).getItemLocation(id);
|
|
|
|
|
return installDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
function getZoteroDirectory(){
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (_zoteroDirectory != false) {
|
|
|
|
|
// Return a clone of the file pointer so that callers can modify it
|
|
|
|
|
return _zoteroDirectory.clone();
|
|
|
|
|
}
|
2006-07-27 08:45:48 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (Zotero.Prefs.get('useDataDir')) {
|
|
|
|
|
var file = Components.classes["@mozilla.org/file/local;1"].
|
|
|
|
|
createInstance(Components.interfaces.nsILocalFile);
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
try {
|
|
|
|
|
file.persistentDescriptor = Zotero.Prefs.get('dataDir');
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
Zotero.debug("Persistent descriptor in extensions.zotero.dataDir did not resolve", 1);
|
|
|
|
|
e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
|
|
|
|
throw (e);
|
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
var e = { name: "NS_ERROR_FILE_NOT_FOUND" };
|
|
|
|
|
throw (e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var file = Zotero.getProfileDirectory();
|
|
|
|
|
file.append('zotero');
|
2008-09-11 17:20:09 +00:00
|
|
|
|
Zotero.File.createDirectoryIfMissing(file);
|
2006-07-27 08:45:48 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
Zotero.debug("Using data directory " + file.path);
|
|
|
|
|
|
|
|
|
|
_zoteroDirectory = file;
|
2008-09-11 17:20:09 +00:00
|
|
|
|
return file.clone();
|
2006-07-27 08:45:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getStorageDirectory(){
|
2006-10-02 23:15:27 +00:00
|
|
|
|
var file = Zotero.getZoteroDirectory();
|
2006-07-27 08:45:48 +00:00
|
|
|
|
|
|
|
|
|
file.append('storage');
|
2008-09-11 17:20:09 +00:00
|
|
|
|
Zotero.File.createDirectoryIfMissing(file);
|
2006-07-27 08:45:48 +00:00
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
function getZoteroDatabase(name, ext){
|
|
|
|
|
name = name ? name + '.sqlite' : 'zotero.sqlite';
|
2006-08-01 23:10:31 +00:00
|
|
|
|
ext = ext ? '.' + ext : '';
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
var file = Zotero.getZoteroDirectory();
|
2007-10-23 07:11:59 +00:00
|
|
|
|
file.append(name + ext);
|
2006-08-01 23:10:31 +00:00
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-31 23:36:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return {nsIFile}
|
|
|
|
|
*/
|
|
|
|
|
function getTempDirectory() {
|
|
|
|
|
var tmp = this.getZoteroDirectory();
|
|
|
|
|
tmp.append('tmp');
|
2008-09-11 17:20:09 +00:00
|
|
|
|
Zotero.File.createDirectoryIfMissing(tmp);
|
2008-08-31 23:36:01 +00:00
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-11 17:20:09 +00:00
|
|
|
|
this.getStylesDirectory = function () {
|
|
|
|
|
var dir = this.getZoteroDirectory();
|
|
|
|
|
dir.append('styles');
|
|
|
|
|
Zotero.File.createDirectoryIfMissing(dir);
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.getTranslatorsDirectory = function () {
|
|
|
|
|
var dir = this.getZoteroDirectory();
|
|
|
|
|
dir.append('translators');
|
|
|
|
|
Zotero.File.createDirectoryIfMissing(dir);
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
function chooseZoteroDirectory(forceRestartNow, useProfileDir) {
|
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
|
var win = wm.getMostRecentWindow('navigator:browser');
|
2006-08-01 23:10:31 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIPromptService);
|
2006-08-01 23:10:31 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (useProfileDir) {
|
|
|
|
|
Zotero.Prefs.set('useDataDir', false);
|
2006-08-01 23:10:31 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
else {
|
|
|
|
|
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
|
|
|
while (true) {
|
|
|
|
|
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
|
|
|
.createInstance(nsIFilePicker);
|
|
|
|
|
fp.init(win, Zotero.getString('dataDir.selectDir'), nsIFilePicker.modeGetFolder);
|
|
|
|
|
fp.appendFilters(nsIFilePicker.filterAll);
|
|
|
|
|
if (fp.show() == nsIFilePicker.returnOK) {
|
|
|
|
|
var file = fp.file;
|
|
|
|
|
|
|
|
|
|
if (file.directoryEntries.hasMoreElements()) {
|
|
|
|
|
var dbfile = file.clone();
|
|
|
|
|
dbfile.append('zotero.sqlite');
|
|
|
|
|
// Warn if non-empty and no zotero.sqlite
|
|
|
|
|
if (!dbfile.exists()) {
|
|
|
|
|
var buttonFlags = ps.STD_YES_NO_BUTTONS;
|
|
|
|
|
var index = ps.confirmEx(win,
|
|
|
|
|
Zotero.getString('dataDir.selectedDirNonEmpty.title'),
|
|
|
|
|
Zotero.getString('dataDir.selectedDirNonEmpty.text'),
|
|
|
|
|
buttonFlags, null, null, null, null, {});
|
|
|
|
|
|
|
|
|
|
// Not OK -- return to file picker
|
|
|
|
|
if (index == 1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set new data directory
|
|
|
|
|
Zotero.Prefs.set('dataDir', file.persistentDescriptor);
|
|
|
|
|
Zotero.Prefs.set('lastDataDir', file.path);
|
|
|
|
|
Zotero.Prefs.set('useDataDir', true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-01 23:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING);
|
|
|
|
|
if (!forceRestartNow) {
|
|
|
|
|
buttonFlags += (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING);
|
2006-08-01 23:10:31 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var index = ps.confirmEx(win,
|
|
|
|
|
Zotero.getString('general.restartRequired'),
|
|
|
|
|
Zotero.getString('general.restartRequiredForChange'),
|
|
|
|
|
buttonFlags,
|
|
|
|
|
Zotero.getString('general.restartNow'),
|
|
|
|
|
forceRestartNow ? null : Zotero.getString('general.restartLater'),
|
|
|
|
|
null, null, {});
|
2006-08-01 23:10:31 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (index == 0) {
|
|
|
|
|
var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIAppStartup);
|
|
|
|
|
appStartup.quit(Components.interfaces.nsIAppStartup.eRestart);
|
|
|
|
|
appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
|
|
|
|
|
}
|
2006-08-01 23:10:31 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
return useProfileDir ? true : file;
|
2006-08-01 23:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-27 08:45:48 +00:00
|
|
|
|
|
2006-02-21 17:01:06 +00:00
|
|
|
|
/*
|
|
|
|
|
* Debug logging function
|
|
|
|
|
*
|
2007-10-23 07:11:59 +00:00
|
|
|
|
* Uses prefs e.z.debug.log and e.z.debug.level (restart required)
|
2006-02-21 17:01:06 +00:00
|
|
|
|
*
|
|
|
|
|
* Defaults to log level 3 if level not provided
|
|
|
|
|
*/
|
2006-03-20 21:47:22 +00:00
|
|
|
|
function debug(message, level) {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (!_debugLogging){
|
2006-02-21 17:01:06 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 18:43:44 +00:00
|
|
|
|
if (typeof message!='string'){
|
2006-10-02 23:15:27 +00:00
|
|
|
|
message = Zotero.varDump(message);
|
2006-06-01 18:43:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-02-21 17:01:06 +00:00
|
|
|
|
if (!level){
|
|
|
|
|
level = 3;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// If level above debug.level value, don't display
|
|
|
|
|
if (level > _debugLevel){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deltaStr = '';
|
|
|
|
|
if (_debugTime) {
|
|
|
|
|
var delta = 0;
|
|
|
|
|
var d = new Date();
|
|
|
|
|
if (_debugLastTime) {
|
|
|
|
|
delta = d - _debugLastTime;
|
|
|
|
|
}
|
|
|
|
|
_debugLastTime = d;
|
|
|
|
|
|
|
|
|
|
while (("" + delta).length < 7) {
|
|
|
|
|
delta = '0' + delta;
|
2006-03-22 18:53:26 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
deltaStr = '(+' + delta + ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dump('zotero(' + level + ')' + deltaStr + ': ' + message + "\n\n");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Log a message to the Mozilla JS error console
|
|
|
|
|
*
|
|
|
|
|
* |type| is a string with one of the flag types in nsIScriptError:
|
|
|
|
|
* 'error', 'warning', 'exception', 'strict'
|
|
|
|
|
*/
|
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
|
|
|
|
function log(message, type, sourceName, sourceLine, lineNumber, columnNumber) {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIConsoleService);
|
|
|
|
|
var scriptError = Components.classes["@mozilla.org/scripterror;1"]
|
|
|
|
|
.createInstance(Components.interfaces.nsIScriptError);
|
|
|
|
|
|
|
|
|
|
if (!type) {
|
|
|
|
|
type = 'warning';
|
2006-02-21 17:01:06 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var flags = scriptError[type + 'Flag'];
|
|
|
|
|
|
|
|
|
|
scriptError.init(
|
|
|
|
|
message,
|
|
|
|
|
sourceName ? sourceName : null,
|
|
|
|
|
sourceLine != undefined ? sourceLine : null,
|
|
|
|
|
lineNumber != undefined ? lineNumber : null,
|
|
|
|
|
columnNumber != undefined ? columnNumber : null,
|
|
|
|
|
flags,
|
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
|
|
|
|
'XUL javascript' // DEBUG: this doesn't seem to work
|
2007-10-23 07:11:59 +00:00
|
|
|
|
);
|
|
|
|
|
consoleService.logMessage(scriptError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getErrors(asStrings) {
|
|
|
|
|
var errors = [];
|
|
|
|
|
var cs = Components.classes["@mozilla.org/consoleservice;1"].
|
|
|
|
|
getService(Components.interfaces.nsIConsoleService);
|
|
|
|
|
var messages = {};
|
|
|
|
|
cs.getMessageArray(messages, {})
|
|
|
|
|
|
|
|
|
|
var skip = ['CSS Parser', 'content javascript'];
|
2006-02-21 17:01:06 +00:00
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
msgblock:
|
|
|
|
|
for each(var msg in messages.value) {
|
|
|
|
|
//Zotero.debug(msg);
|
|
|
|
|
try {
|
|
|
|
|
msg.QueryInterface(Components.interfaces.nsIScriptError);
|
|
|
|
|
//Zotero.debug(msg);
|
|
|
|
|
if (skip.indexOf(msg.category) != -1 || msg.flags & msg.warningFlag) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
|
|
var blacklist = [
|
|
|
|
|
"No chrome package registered for chrome://communicator",
|
|
|
|
|
'[JavaScript Error: "Components is not defined" {file: "chrome://nightly/content/talkback/talkback.js',
|
|
|
|
|
'[JavaScript Error: "document.getElementById("sanitizeItem")',
|
|
|
|
|
'No chrome package registered for chrome://piggy-bank',
|
Merged revisions 2190-2192,2194,2196-2199,2202-2205,2209,2212,2214-2215,2227-2228,2230,2232-2243,2245,2247-2256,2263-2272,2276,2278-2279,2281,2284-2286,2292,2296-2297,2299-2302,2304-2305,2309-2310,2314,2317-2323,2325-2329,2331-2337,2339,2341-2342,2344,2347-2366,2370-2371,2373-2377,2379-2391,2393-2402,2405-2410,2413,2415-2416,2418,2420-2421,2423,2427-2429,2431-2433,2437,2440-2441,2443-2450,2453,2455-2459,2461-2467,2471,2475-2480,2482-2490,2493,2495-2499,2501-2506,2511,2513-2519,2521,2525-2536,2540,2543-2553,2555-2559,2561-2576,2578,2580-2603,2606-2609,2611-2616,2618-2620,2624-2630,2632-2633 to trunk via svnmerge from 1.0 branch
2008-05-05 07:19:34 +00:00
|
|
|
|
'[JavaScript Error: "[Exception... "\'Component is not available\' when calling method: [nsIHandlerService::getTypeFromExtension',
|
|
|
|
|
'[JavaScript Error: "this._uiElement is null',
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
|
'Error: a._updateVisibleText is not a function',
|
|
|
|
|
'[JavaScript Error: "Warning: unrecognized command line flag -psn',
|
|
|
|
|
'LibX:',
|
|
|
|
|
'function skype_',
|
|
|
|
|
'[JavaScript Error: "uncaught exception: Permission denied to call method Location.toString"]'
|
2007-10-23 07:11:59 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<blacklist.length; i++) {
|
|
|
|
|
if (msg.message.indexOf(blacklist[i]) != -1) {
|
Merged revisions 2190-2192,2194,2196-2199,2202-2205,2209,2212,2214-2215,2227-2228,2230,2232-2243,2245,2247-2256,2263-2272,2276,2278-2279,2281,2284-2286,2292,2296-2297,2299-2302,2304-2305,2309-2310,2314,2317-2323,2325-2329,2331-2337,2339,2341-2342,2344,2347-2366,2370-2371,2373-2377,2379-2391,2393-2402,2405-2410,2413,2415-2416,2418,2420-2421,2423,2427-2429,2431-2433,2437,2440-2441,2443-2450,2453,2455-2459,2461-2467,2471,2475-2480,2482-2490,2493,2495-2499,2501-2506,2511,2513-2519,2521,2525-2536,2540,2543-2553,2555-2559,2561-2576,2578,2580-2603,2606-2609,2611-2616,2618-2620,2624-2630,2632-2633 to trunk via svnmerge from 1.0 branch
2008-05-05 07:19:34 +00:00
|
|
|
|
//Zotero.debug("Skipping blacklisted error: " + msg.message);
|
2007-10-23 07:11:59 +00:00
|
|
|
|
continue msgblock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (asStrings) {
|
|
|
|
|
errors.push(msg.message)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
errors.push(msg);
|
|
|
|
|
}
|
2006-02-21 17:01:06 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSystemInfo() {
|
|
|
|
|
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].
|
|
|
|
|
getService(Components.interfaces.nsIXULAppInfo);
|
|
|
|
|
|
|
|
|
|
var info = {
|
|
|
|
|
version: Zotero.version,
|
|
|
|
|
platform: Zotero.platform,
|
|
|
|
|
locale: Zotero.locale,
|
|
|
|
|
appName: appInfo.name,
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
appVersion: appInfo.version,
|
|
|
|
|
extensions: this.getInstalledExtensions().join(', ')
|
2007-10-23 07:11:59 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var str = '';
|
|
|
|
|
for (var key in info) {
|
|
|
|
|
str += key + ' => ' + info[key] + ', ';
|
2006-02-21 17:01:06 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
str = str.substr(0, str.length - 2);
|
|
|
|
|
return str;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
|
|
|
|
|
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return {String[]} Array of extension names and versions
|
|
|
|
|
*/
|
|
|
|
|
this.getInstalledExtensions = function () {
|
|
|
|
|
var em = Components.classes["@mozilla.org/extensions/manager;1"].
|
|
|
|
|
getService(Components.interfaces.nsIExtensionManager);
|
|
|
|
|
var installed = em.getItemList(
|
|
|
|
|
Components.interfaces.nsIUpdateItem.TYPE_ANY, {}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var addons = [];
|
|
|
|
|
for each(var addon in installed) {
|
|
|
|
|
switch (addon.id) {
|
|
|
|
|
case "zotero@chnm.gmu.edu":
|
|
|
|
|
case "{972ce4c6-7e08-4474-a285-3208198ce6fd}": // Default theme
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addons.push(addon.name + " (" + addon.version
|
|
|
|
|
+ (addon.type != 2 ? ", " + addon.type : "") + ")");
|
|
|
|
|
}
|
|
|
|
|
return addons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* PHP var_dump equivalent for JS
|
|
|
|
|
*
|
|
|
|
|
* Adapted from http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html
|
|
|
|
|
*/
|
2006-03-20 21:47:22 +00:00
|
|
|
|
function varDump(arr,level) {
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
var dumped_text = "";
|
|
|
|
|
if (!level){
|
|
|
|
|
level = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The padding given at the beginning of the line.
|
|
|
|
|
var level_padding = "";
|
|
|
|
|
for (var j=0;j<level+1;j++){
|
|
|
|
|
level_padding += " ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof(arr) == 'object') { // Array/Hashes/Objects
|
|
|
|
|
for (var item in arr) {
|
|
|
|
|
var value = arr[item];
|
|
|
|
|
|
|
|
|
|
if (typeof(value) == 'object') { // If it is an array,
|
|
|
|
|
dumped_text += level_padding + "'" + item + "' ...\n";
|
|
|
|
|
dumped_text += arguments.callee(value,level+1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (typeof value == 'function'){
|
|
|
|
|
dumped_text += level_padding + "'" + item + "' => function(...){...} \n";
|
|
|
|
|
}
|
2008-06-25 01:07:35 +00:00
|
|
|
|
else if (typeof value == 'number') {
|
|
|
|
|
dumped_text += level_padding + "'" + item + "' => " + value + "\n";
|
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
else {
|
|
|
|
|
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { // Stings/Chars/Numbers etc.
|
|
|
|
|
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
|
|
|
|
|
}
|
|
|
|
|
return dumped_text;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
function safeDebug(obj){
|
|
|
|
|
for (var i in obj){
|
|
|
|
|
try {
|
|
|
|
|
Zotero.debug(i + ': ' + obj[i]);
|
|
|
|
|
}
|
|
|
|
|
catch (e){
|
|
|
|
|
try {
|
|
|
|
|
Zotero.debug(i + ': ERROR');
|
|
|
|
|
}
|
|
|
|
|
catch (e){}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getString(name, params){
|
2006-06-26 20:41:09 +00:00
|
|
|
|
try {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (params != undefined){
|
|
|
|
|
if (typeof params != 'object'){
|
|
|
|
|
params = [params];
|
|
|
|
|
}
|
|
|
|
|
var l10n = _localizedStringBundle.formatStringFromName(name, params, params.length);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var l10n = _localizedStringBundle.GetStringFromName(name);
|
|
|
|
|
}
|
2006-06-26 20:41:09 +00:00
|
|
|
|
}
|
|
|
|
|
catch (e){
|
|
|
|
|
throw ('Localized string not available for ' + name);
|
|
|
|
|
}
|
|
|
|
|
return l10n;
|
2006-05-27 00:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
/*
|
|
|
|
|
* Join the elements of an array into a string using the appropriate
|
|
|
|
|
* locale direction
|
|
|
|
|
*
|
|
|
|
|
* |separator| defaults to a space (not a comma like Array.join()) if
|
|
|
|
|
* not specified
|
|
|
|
|
*
|
|
|
|
|
* TODO: Substitute localized characters (e.g. Arabic comma and semicolon)
|
|
|
|
|
*/
|
|
|
|
|
function localeJoin(arr, separator) {
|
|
|
|
|
if (typeof separator == 'undefined') {
|
|
|
|
|
separator = ' ';
|
|
|
|
|
}
|
|
|
|
|
if (this.dir == 'rtl') {
|
|
|
|
|
arr.reverse();
|
|
|
|
|
separator.split('').reverse().join('');
|
|
|
|
|
}
|
|
|
|
|
return arr.join(separator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getLocaleCollation() {
|
|
|
|
|
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
|
|
|
|
|
.getService(Components.interfaces.nsILocaleService);
|
|
|
|
|
var collationFactory = Components.classes["@mozilla.org/intl/collation-factory;1"]
|
|
|
|
|
.getService(Components.interfaces.nsICollationFactory);
|
|
|
|
|
return collationFactory.CreateCollation(localeService.getApplicationLocale());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sets font size based on prefs -- intended for use on root element
|
|
|
|
|
* (zotero-pane, note window, etc.)
|
|
|
|
|
*/
|
|
|
|
|
function setFontSize(rootElement) {
|
|
|
|
|
var size = Zotero.Prefs.get('fontSize');
|
|
|
|
|
rootElement.style.fontSize = size + 'em';
|
|
|
|
|
if (size <= 1) {
|
|
|
|
|
size = 'small';
|
|
|
|
|
}
|
|
|
|
|
else if (size <= 1.25) {
|
|
|
|
|
size = 'medium';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
size = 'large';
|
|
|
|
|
}
|
|
|
|
|
// Custom attribute -- allows for additional customizations in zotero.css
|
|
|
|
|
rootElement.setAttribute('zoteroFontSize', size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* Flattens mixed arrays/values in a passed _arguments_ object and returns
|
|
|
|
|
* an array of values -- allows for functions to accept both arrays of
|
|
|
|
|
* values and/or an arbitrary number of individual values
|
|
|
|
|
*/
|
2006-03-20 21:47:22 +00:00
|
|
|
|
function flattenArguments(args){
|
2006-06-02 20:51:34 +00:00
|
|
|
|
// Put passed scalar values into an array
|
2006-09-12 06:53:48 +00:00
|
|
|
|
if (typeof args!='object' || args===null){
|
2006-06-02 20:51:34 +00:00
|
|
|
|
args = [args];
|
|
|
|
|
}
|
|
|
|
|
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
var returns = new Array();
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<args.length; i++){
|
|
|
|
|
if (typeof args[i]=='object'){
|
2006-08-25 19:15:03 +00:00
|
|
|
|
if(args[i]) {
|
|
|
|
|
for (var j=0; j<args[i].length; j++){
|
|
|
|
|
returns.push(args[i][j]);
|
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
returns.push(args[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return returns;
|
2006-03-20 21:47:22 +00:00
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
|
|
|
|
|
|
Closes #259, auto-complete of tags
Addresses #260, Add auto-complete to search window
- New XPCOM autocomplete component for Zotero data -- can be used by setting the autocompletesearch attribute of a textbox to 'zotero' and passing a search scope with the autocompletesearchparam attribute. Additional parameters can be passed by appending them to the autocompletesearchparam value with a '/', e.g. 'tag/2732' (to exclude tags that show up in item 2732)
- Tag entry now uses more or less the same interface as metadata -- no more popup window -- note that tab isn't working properly yet, and there's no way to quickly enter multiple tags (though it's now considerably quicker than it was before)
- Autocomplete for tags, excluding any tags already set for the current item
- Standalone note windows now register with the Notifier (since tags needed item modification notifications to work properly), which will help with #282, "Notes opened in separate windows need item notification"
- Tags are now retrieved in alphabetical order
- Scholar.Item.replaceTag(oldTagID, newTag), with a single notify
- Scholar.getAncestorByTagName(elem, tagName) -- walk up the DOM tree from an element until an element with the specified tag name is found (also checks with 'xul:' prefix, for use in XBL), or false if not found -- probably shouldn't be used too widely, since it's doing string comparisons, but better than specifying, say, nine '.parentNode' properties, and makes for more resilient code
A few notes:
- Autocomplete in Minefield seems to self-destruct after using it in the same field a few times, taking down saving of the field with it -- this may or may not be my fault, but it makes Zotero more or less unusable in 3.0 at the moment. Sorry. (I use 3.0 myself for development, so I'll work on it.)
- This would have been much, much easier if having an autocomplete textbox (which uses an XBL-generated popup for the suggestions) within a popup (as it is in the independent note edit panes) didn't introduce all sorts of crazy bugs that had to be defeated with annoying hackery -- one side effect of this is that at the moment you can't close the tags popup with the Escape key
- Independent note windows now need to pull in itemPane.js to function properly, which is a bit messy and not ideal, but less messy and more ideal than duplicating all the dual-state editor and tabindex logic would be
- Hitting tab in a tag field not only doesn't work but also breaks things until the next window refresh.
- There are undoubtedly other bugs.
2006-09-07 08:07:48 +00:00
|
|
|
|
function getAncestorByTagName(elem, tagName){
|
|
|
|
|
while (elem.parentNode){
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
if (elem.tagName==tagName || elem.tagName=='xul:' + tagName){
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* A version of join() that operates externally for use on objects other
|
|
|
|
|
* than arrays (e.g. _arguments_)
|
|
|
|
|
*
|
|
|
|
|
* Note that this is safer than extending Object()
|
|
|
|
|
*/
|
2006-03-20 21:47:22 +00:00
|
|
|
|
function join(obj, delim){
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
var a = [];
|
|
|
|
|
for (var i=0, len=obj.length; i<len; i++){
|
|
|
|
|
a.push(obj[i]);
|
|
|
|
|
}
|
|
|
|
|
return a.join(delim);
|
2006-03-20 21:47:22 +00:00
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
|
|
|
|
|
|
2006-06-20 17:32:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* PHP's in_array() for JS -- returns true if a value is contained in
|
|
|
|
|
* an array, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
function inArray(needle, haystack){
|
|
|
|
|
for (var i in haystack){
|
|
|
|
|
if (haystack[i]==needle){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* PHP's array_search() for JS -- searches an array for a value and
|
|
|
|
|
* returns the key if found, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
function arraySearch(needle, haystack){
|
|
|
|
|
for (var i in haystack){
|
|
|
|
|
if (haystack[i]==needle){
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
function arrayToHash(array){
|
|
|
|
|
var hash = {};
|
|
|
|
|
|
|
|
|
|
for each(var val in array){
|
|
|
|
|
hash[val] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
/*
|
|
|
|
|
* Returns true if an object (or associative array) has at least one value
|
|
|
|
|
*/
|
|
|
|
|
function hasValues(obj) {
|
|
|
|
|
for (var i in obj) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-01 19:46:57 +00:00
|
|
|
|
/**
|
|
|
|
|
* Generate a random string of length 'len' (defaults to 8)
|
|
|
|
|
**/
|
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
|
|
|
|
function randomString(len, chars) {
|
|
|
|
|
if (!chars) {
|
|
|
|
|
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
|
|
|
|
|
}
|
|
|
|
|
if (!len) {
|
2006-06-01 19:46:57 +00:00
|
|
|
|
len = 8;
|
|
|
|
|
}
|
|
|
|
|
var randomstring = '';
|
|
|
|
|
for (var i=0; i<len; i++) {
|
|
|
|
|
var rnum = Math.floor(Math.random() * chars.length);
|
|
|
|
|
randomstring += chars.substring(rnum,rnum+1);
|
|
|
|
|
}
|
|
|
|
|
return randomstring;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-01 23:10:31 +00:00
|
|
|
|
function moveToUnique(file, newFile){
|
|
|
|
|
newFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644);
|
|
|
|
|
var newName = newFile.leafName;
|
|
|
|
|
newFile.remove(null);
|
|
|
|
|
|
|
|
|
|
// Move file to unique name
|
|
|
|
|
file.moveTo(newFile.parent, newName);
|
|
|
|
|
return file;
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function reloadDataObjects() {
|
2008-09-03 18:04:50 +00:00
|
|
|
|
Zotero.Tags.unloadAll();
|
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
|
|
|
|
Zotero.Collections.reloadAll();
|
2008-09-03 18:04:50 +00:00
|
|
|
|
Zotero.Creators.unloadAll();
|
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
|
|
|
|
Zotero.Items.reloadAll();
|
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2006-06-13 15:14:22 +00:00
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Prefs = new function(){
|
2006-06-25 07:31:01 +00:00
|
|
|
|
// Privileged methods
|
|
|
|
|
this.init = init;
|
|
|
|
|
this.get = get;
|
|
|
|
|
this.set = set;
|
|
|
|
|
|
|
|
|
|
this.register = register;
|
|
|
|
|
this.unregister = unregister;
|
|
|
|
|
this.observe = observe;
|
|
|
|
|
|
|
|
|
|
// Public properties
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.prefBranch;
|
2006-06-25 07:31:01 +00:00
|
|
|
|
|
|
|
|
|
function init(){
|
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
2006-10-02 23:15:27 +00:00
|
|
|
|
this.prefBranch = prefs.getBranch("extensions.zotero.");
|
2006-06-25 07:31:01 +00:00
|
|
|
|
|
|
|
|
|
// Register observer to handle pref changes
|
|
|
|
|
this.register();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a preference
|
|
|
|
|
**/
|
2007-10-23 07:11:59 +00:00
|
|
|
|
function get(pref, global){
|
2006-06-25 07:31:01 +00:00
|
|
|
|
try {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if (global) {
|
|
|
|
|
var service = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var service = this.prefBranch;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-25 07:31:01 +00:00
|
|
|
|
switch (this.prefBranch.getPrefType(pref)){
|
|
|
|
|
case this.prefBranch.PREF_BOOL:
|
|
|
|
|
return this.prefBranch.getBoolPref(pref);
|
|
|
|
|
case this.prefBranch.PREF_STRING:
|
|
|
|
|
return this.prefBranch.getCharPref(pref);
|
|
|
|
|
case this.prefBranch.PREF_INT:
|
|
|
|
|
return this.prefBranch.getIntPref(pref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (e){
|
|
|
|
|
throw ("Invalid preference '" + pref + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a preference
|
|
|
|
|
**/
|
|
|
|
|
function set(pref, value){
|
|
|
|
|
try {
|
|
|
|
|
switch (this.prefBranch.getPrefType(pref)){
|
|
|
|
|
case this.prefBranch.PREF_BOOL:
|
|
|
|
|
return this.prefBranch.setBoolPref(pref, value);
|
|
|
|
|
case this.prefBranch.PREF_STRING:
|
|
|
|
|
return this.prefBranch.setCharPref(pref, value);
|
|
|
|
|
case this.prefBranch.PREF_INT:
|
|
|
|
|
return this.prefBranch.setIntPref(pref, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (e){
|
|
|
|
|
throw ("Invalid preference '" + pref + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Methods to register a preferences observer
|
|
|
|
|
//
|
|
|
|
|
function register(){
|
|
|
|
|
this.prefBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
|
|
|
|
|
this.prefBranch.addObserver("", this, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unregister(){
|
|
|
|
|
if (!this.prefBranch){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.prefBranch.removeObserver("", this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function observe(subject, topic, data){
|
|
|
|
|
if(topic!="nsPref:changed"){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// subject is the nsIPrefBranch we're observing (after appropriate QI)
|
|
|
|
|
// data is the name of the pref that's been changed (relative to subject)
|
|
|
|
|
switch (data){
|
2006-06-25 07:34:03 +00:00
|
|
|
|
case "automaticScraperUpdates":
|
|
|
|
|
if (this.get('automaticScraperUpdates')){
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Schema.updateScrapersRemote();
|
2006-06-25 07:34:03 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Schema.stopRepositoryTimer();
|
2006-06-25 07:34:03 +00:00
|
|
|
|
}
|
2006-06-25 07:31:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
/*
|
|
|
|
|
* Handles keyboard shortcut initialization from preferences, optionally
|
|
|
|
|
* overriding existing global shortcuts
|
|
|
|
|
*
|
|
|
|
|
* Actions are configured in ZoteroPane.handleKeyPress()
|
|
|
|
|
*/
|
|
|
|
|
Zotero.Keys = new function() {
|
|
|
|
|
this.init = init;
|
|
|
|
|
this.windowInit = windowInit;
|
|
|
|
|
this.getCommand = getCommand;
|
|
|
|
|
|
Merged revisions 2640-2647,2651,2653-2654,2656-2658,2660-2667,2670-2672,2674-2677,2680,2683-2684,2687-2704,2707 to trunk via svnmerge from 1.0 branch
2008-05-16 09:14:11 +00:00
|
|
|
|
var _keys = {};
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Called by Zotero.init()
|
|
|
|
|
*/
|
|
|
|
|
function init() {
|
|
|
|
|
var actions = Zotero.Prefs.prefBranch.getChildList('keys', {}, {});
|
|
|
|
|
|
|
|
|
|
// Get the key=>command mappings from the prefs
|
|
|
|
|
for each(var action in actions) {
|
|
|
|
|
var action = action.substr(5); // strips 'keys.'
|
|
|
|
|
if (action == 'overrideGlobal') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
_keys[Zotero.Prefs.get('keys.' + action)] = action;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Called by ZoteroPane.onLoad()
|
|
|
|
|
*/
|
|
|
|
|
function windowInit(document) {
|
|
|
|
|
var useShift = Zotero.isMac;
|
|
|
|
|
|
|
|
|
|
// Zotero pane shortcut
|
|
|
|
|
var zKey = Zotero.Prefs.get('keys.openZotero');
|
|
|
|
|
var keyElem = document.getElementById('key_openZotero');
|
|
|
|
|
// Only override the default with the pref if the <key> hasn't been manually changed
|
|
|
|
|
// and the pref has been
|
|
|
|
|
if (keyElem.getAttribute('key') == 'Z' && keyElem.getAttribute('modifiers') == 'accel alt'
|
Merged revisions 2640-2647,2651,2653-2654,2656-2658,2660-2667,2670-2672,2674-2677,2680,2683-2684,2687-2704,2707 to trunk via svnmerge from 1.0 branch
2008-05-16 09:14:11 +00:00
|
|
|
|
&& (zKey != 'Z' || useShift)) {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
keyElem.setAttribute('key', zKey);
|
|
|
|
|
if (useShift) {
|
|
|
|
|
keyElem.setAttribute('modifiers', 'accel shift');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Zotero.Prefs.get('keys.overrideGlobal')) {
|
|
|
|
|
var keys = document.getElementsByTagName('key');
|
|
|
|
|
for each(var key in keys) {
|
|
|
|
|
try {
|
|
|
|
|
var id = key.getAttribute('id');
|
|
|
|
|
}
|
|
|
|
|
// A couple keys are always invalid
|
|
|
|
|
catch (e) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id == 'key_openZotero') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mods = key.getAttribute('modifiers').split(/[\,\s]/);
|
|
|
|
|
var second = useShift ? 'shift' : 'alt';
|
|
|
|
|
// Key doesn't match a Zotero shortcut
|
|
|
|
|
if (mods.length != 2 || !((mods[0] == 'accel' && mods[1] == second) ||
|
|
|
|
|
(mods[0] == second && mods[1] == 'accel'))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_keys[key.getAttribute('key')] || key.getAttribute('key') == zKey) {
|
Merged revisions 2640-2647,2651,2653-2654,2656-2658,2660-2667,2670-2672,2674-2677,2680,2683-2684,2687-2704,2707 to trunk via svnmerge from 1.0 branch
2008-05-16 09:14:11 +00:00
|
|
|
|
// Don't override Redo on Fx3 Mac, since Redo and Zotero can coexist
|
|
|
|
|
if (zKey == 'Z' && key.getAttribute('key') == 'Z'
|
|
|
|
|
&& id == 'key_redo' && Zotero.isFx3 && Zotero.isMac) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
Zotero.debug('Removing key ' + id + ' with accesskey ' + key.getAttribute('key'));
|
|
|
|
|
key.parentNode.removeChild(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getCommand(key) {
|
|
|
|
|
return _keys[key] ? _keys[key] : false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-13 15:14:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class for creating hash arrays that behave a bit more sanely
|
|
|
|
|
*
|
|
|
|
|
* Hashes can be created in the constructor by alternating key and val:
|
|
|
|
|
*
|
2006-10-02 23:15:27 +00:00
|
|
|
|
* var hasharray = new Zotero.Hash('foo','foovalue','bar','barvalue');
|
2006-06-13 15:14:22 +00:00
|
|
|
|
*
|
|
|
|
|
* Or using hasharray.set(key, val)
|
|
|
|
|
*
|
|
|
|
|
* _val_ defaults to true if not provided
|
|
|
|
|
*
|
|
|
|
|
* If using foreach-style looping, be sure to use _for (i in arr.items)_
|
|
|
|
|
* rather than just _for (i in arr)_, or else you'll end up with the
|
|
|
|
|
* methods and members instead of the hash items
|
|
|
|
|
*
|
|
|
|
|
* Most importantly, hasharray.length will work as expected, even with
|
|
|
|
|
* non-numeric keys
|
|
|
|
|
*
|
|
|
|
|
* Adapated from http://www.mojavelinux.com/articles/javascript_hashes.html
|
|
|
|
|
* (c) Mojavelinux, Inc.
|
|
|
|
|
* License: Creative Commons
|
|
|
|
|
**/
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Hash = function(){
|
2006-06-13 15:14:22 +00:00
|
|
|
|
this.length = 0;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.items = {};
|
2006-06-13 15:14:22 +00:00
|
|
|
|
|
|
|
|
|
// Public methods defined on prototype below
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < arguments.length; i += 2) {
|
|
|
|
|
if (typeof(arguments[i + 1]) != 'undefined') {
|
|
|
|
|
this.items[arguments[i]] = arguments[i + 1];
|
|
|
|
|
this.length++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Hash.prototype.get = function(in_key){
|
2006-08-26 05:33:44 +00:00
|
|
|
|
return this.items[in_key] ? this.items[in_key] : false;
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Hash.prototype.set = function(in_key, in_value){
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
// Default to a boolean hash if value not provided
|
|
|
|
|
if (typeof(in_value) == 'undefined'){
|
|
|
|
|
in_value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof(this.items[in_key]) == 'undefined') {
|
|
|
|
|
this.length++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.items[in_key] = in_value;
|
|
|
|
|
|
|
|
|
|
return in_value;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Hash.prototype.remove = function(in_key){
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
var tmp_value;
|
|
|
|
|
if (typeof(this.items[in_key]) != 'undefined') {
|
|
|
|
|
this.length--;
|
|
|
|
|
var tmp_value = this.items[in_key];
|
|
|
|
|
delete this.items[in_key];
|
2006-02-21 17:01:06 +00:00
|
|
|
|
}
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
|
|
|
|
|
return tmp_value;
|
2006-02-21 17:01:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Hash.prototype.has = function(in_key){
|
Renamed DB to scholar.sqlite, since that seems to be the current fashion
Added some new core functions:
- Scholar.varDump(), after PHP's var_dump()
- Scholar.flattenArguments(), to flatten mixed array/literal argument lists into a single array
- Scholar.join() -- a version of join() that operates externally, for use on, for example, the arguments object (safer than extending Object)
- Scholar.Hash, a slightly smarter associative array -- not perfect, but brings a proper length property and a few convenience methods (and allows for other additions) -- should probably be limited to places where the length property or other additional additions are needed, since its use is a little non-standard (e.g. you have to remember to do _for (i in arr.items)_ rather than just _for (i in arr)_, to use set(), etc.)
2006-03-14 11:45:19 +00:00
|
|
|
|
return typeof(this.items[in_key]) != 'undefined';
|
2006-06-13 14:53:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-02 05:45:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* Singleton for common text formatting routines
|
|
|
|
|
**/
|
|
|
|
|
Zotero.Text = new function() {
|
|
|
|
|
this.titleCase = titleCase;
|
|
|
|
|
|
|
|
|
|
var skipWords = ["but", "or", "yet", "so", "for", "and", "nor", "a", "an",
|
|
|
|
|
"the", "at", "by", "from", "in", "into", "of", "on", "to", "with", "up",
|
|
|
|
|
"down", "as"];
|
|
|
|
|
// this may only match a single character
|
|
|
|
|
var delimiterRegexp = /([ \/\-–—])/;
|
|
|
|
|
|
|
|
|
|
function titleCase(string) {
|
|
|
|
|
if (!string) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// split words
|
|
|
|
|
var words = string.split(delimiterRegexp);
|
|
|
|
|
var isUpperCase = string.toUpperCase() == string;
|
|
|
|
|
|
|
|
|
|
var newString = "";
|
|
|
|
|
var delimiterOffset = words[0].length;
|
|
|
|
|
var lastWordIndex = words.length-1;
|
|
|
|
|
var previousWordIndex = -1;
|
|
|
|
|
for(var i=0; i<=lastWordIndex; i++) {
|
|
|
|
|
// only do manipulation if not a delimiter character
|
|
|
|
|
if(words[i].length != 0 && (words[i].length != 1 || !delimiterRegexp.test(words[i]))) {
|
|
|
|
|
var upperCaseVariant = words[i].toUpperCase();
|
|
|
|
|
var lowerCaseVariant = words[i].toLowerCase();
|
|
|
|
|
|
|
|
|
|
// only use if word does not already possess some capitalization
|
|
|
|
|
if(isUpperCase || words[i] == lowerCaseVariant) {
|
|
|
|
|
if(
|
|
|
|
|
// a skip word
|
|
|
|
|
skipWords.indexOf(lowerCaseVariant.replace(/[^a-zA-Z]+/, "")) != -1
|
|
|
|
|
// not first or last word
|
|
|
|
|
&& i != 0 && i != lastWordIndex
|
|
|
|
|
// does not follow a colon
|
|
|
|
|
&& (previousWordIndex == -1 || words[previousWordIndex][words[previousWordIndex].length-1] != ":")
|
|
|
|
|
) {
|
|
|
|
|
words[i] = lowerCaseVariant;
|
|
|
|
|
} else {
|
|
|
|
|
// this is not a skip word or comes after a colon;
|
|
|
|
|
// we must capitalize
|
|
|
|
|
words[i] = upperCaseVariant[0] + lowerCaseVariant.substr(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
previousWordIndex = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newString += words[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newString;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-06-13 14:53:38 +00:00
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Date = new function(){
|
2006-06-13 15:07:08 +00:00
|
|
|
|
this.sqlToDate = sqlToDate;
|
2006-10-04 00:47:55 +00:00
|
|
|
|
this.dateToSQL = dateToSQL;
|
2006-08-30 23:21:49 +00:00
|
|
|
|
this.strToDate = strToDate;
|
2006-08-31 00:04:11 +00:00
|
|
|
|
this.formatDate = formatDate;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.strToISO = strToISO;
|
|
|
|
|
this.strToMultipart = strToMultipart;
|
|
|
|
|
this.isMultipart = isMultipart;
|
|
|
|
|
this.multipartToSQL = multipartToSQL;
|
|
|
|
|
this.multipartToStr = multipartToStr;
|
|
|
|
|
this.isSQLDate = isSQLDate;
|
|
|
|
|
this.isSQLDateTime = isSQLDateTime;
|
|
|
|
|
this.sqlHasYear = sqlHasYear;
|
|
|
|
|
this.sqlHasMonth = sqlHasMonth;
|
|
|
|
|
this.sqlHasDay = sqlHasDay;
|
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
|
|
|
|
this.getUnixTimestamp = getUnixTimestamp;
|
|
|
|
|
this.toUnixTimestamp = toUnixTimestamp;
|
2006-08-01 23:10:31 +00:00
|
|
|
|
this.getFileDateString = getFileDateString;
|
|
|
|
|
this.getFileTimeString = getFileTimeString;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
this.getLocaleDateOrder = getLocaleDateOrder;
|
|
|
|
|
|
|
|
|
|
var _localeDateOrder = null;
|
|
|
|
|
|
2006-06-13 15:07:08 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert an SQL date in the form '2006-06-13 11:03:05' into a JS Date object
|
|
|
|
|
*
|
|
|
|
|
* Can also accept just the date part (e.g. '2006-06-13')
|
|
|
|
|
**/
|
2006-08-14 03:19:01 +00:00
|
|
|
|
function sqlToDate(sqldate, isUTC){
|
2006-06-13 15:07:08 +00:00
|
|
|
|
try {
|
|
|
|
|
var datetime = sqldate.split(' ');
|
|
|
|
|
var dateparts = datetime[0].split('-');
|
|
|
|
|
if (datetime[1]){
|
|
|
|
|
var timeparts = datetime[1].split(':');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
timeparts = [false, false, false];
|
|
|
|
|
}
|
2006-08-14 03:19:01 +00:00
|
|
|
|
|
Cross-posting to BC for discussion: http://chnm.grouphub.com/projects/310105/msg/cat/2114872/3538662/comments
Changes as per my discussions with Dan:
- Separated snapshot functionality into two individual buttons, Create New Item From Current Page and Take Snapshot of Current page
- Updated schema to support primary, secondary and hidden item types (and future user customizations)
- Reorganized New Item menu, moving secondary items into sub-menu
- Removed ability to create link attachments, since it never really made much sense -- will simply use the webpage item type instead. Underlying functionality still exists for the time being, as people have existing links in their libraries--I think we're gonna have to just warn beta testers and delete them in a transition step, as converting nested links really wouldn't be worth the effort.
- Moved file link/add functions into new item menu and removed attachment drop-down
- Large, prominent View and Locate buttons in edit pane for going to an associated URL and looking up in OpenURL, respectively -- buttons gray out as appropriate
- New Item from Page stores the URL and access date (Item.save() checks for the string "CURRENT_TIMESTAMP" for accessDate and doesn't bind it as a string)
- "Website" to "Web Page" (do we prefer "Webpage"? they both look a bit funky in uppercase)
More coming.
Bugs/Known Issues:
- Since snapshots from the toolbar are now top-level in the current collection, there needs to be a way to drag them into items
- The camera icon for adding snapshots, despite being a famfamfam icon, really doesn't read too well (or perhaps just clashes with the rest of our icons). Anybody have a better one? (It also may be able to just be lightened up a bit.)
- Trying the large View/Locate buttons after discussions with Dan, but this approach may not work -- 1) a large View button for the URL makes a lot less sense when you have a parent item with a child snapshot, since people will end up clicking it all the time when they really want to view the snapshot, and 2) the Locate button is awfully big for something that only applies to certain types of items, may not get used very often when it does, and probably won't work when it is
- The access date is stored in UTC and displayed with toLocaleString() like Date Added and Date Modified, but, unlike those two, it's also user-editable. This is clearly a problem. Probably need to parse to Date on blur() with strToDate() and insert as UTC, discarding anything left over.
- Item type itself is still "website" -- should probably change that while we still can
Closes #253, OpenURL arrow should provide visual feedback on mouseover and/or look more button-like
Addresses #304, change references to "website" to "web page"
Addresses #207, openurl arrow functionality
2006-09-27 08:12:09 +00:00
|
|
|
|
// Invalid date part
|
|
|
|
|
if (dateparts.length==1){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-14 03:19:01 +00:00
|
|
|
|
if (isUTC){
|
|
|
|
|
return new Date(Date.UTC(dateparts[0], dateparts[1]-1, dateparts[2],
|
|
|
|
|
timeparts[0], timeparts[1], timeparts[2]));
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-14 16:59:29 +00:00
|
|
|
|
return new Date(dateparts[0], dateparts[1]-1, dateparts[2],
|
2006-06-13 15:07:08 +00:00
|
|
|
|
timeparts[0], timeparts[1], timeparts[2]);
|
|
|
|
|
}
|
|
|
|
|
catch (e){
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.debug(sqldate + ' is not a valid SQL date', 2)
|
2006-06-13 15:07:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-01 23:10:31 +00:00
|
|
|
|
|
2006-10-04 00:47:55 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a JS Date object to an SQL date in the form '2006-06-13 11:03:05'
|
|
|
|
|
*
|
|
|
|
|
* If _toUTC_ is true, creates a UTC date
|
|
|
|
|
**/
|
|
|
|
|
function dateToSQL(date, toUTC)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (toUTC){
|
|
|
|
|
var year = date.getUTCFullYear();
|
|
|
|
|
var month = date.getUTCMonth();
|
|
|
|
|
var day = date.getUTCDate();
|
|
|
|
|
var hours = date.getUTCHours();
|
|
|
|
|
var minutes = date.getUTCMinutes();
|
|
|
|
|
var seconds = date.getUTCSeconds();
|
|
|
|
|
}
|
|
|
|
|
else {
|
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
|
|
|
|
return date.toLocaleFormat('%Y-%m-%d %T');
|
2006-10-04 00:47:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var utils = new Zotero.Utilities();
|
|
|
|
|
year = utils.lpad(year, '0', 4);
|
|
|
|
|
month = utils.lpad(month + 1, '0', 2);
|
|
|
|
|
day = utils.lpad(day, '0', 2);
|
|
|
|
|
hours = utils.lpad(hours, '0', 2);
|
|
|
|
|
minutes = utils.lpad(minutes, '0', 2);
|
|
|
|
|
seconds = utils.lpad(seconds, '0', 2);
|
|
|
|
|
|
|
|
|
|
return year + '-' + month + '-' + day + ' '
|
|
|
|
|
+ hours + ':' + minutes + ':' + seconds;
|
|
|
|
|
}
|
|
|
|
|
catch (e){
|
|
|
|
|
Zotero.debug(date + ' is not a valid JS date', 2);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-31 23:36:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* Convert a JS Date object to an ISO 8601 UTC date/time
|
|
|
|
|
*
|
|
|
|
|
* @param {Date} date JS Date object
|
|
|
|
|
* @return {String} ISO 8601 UTC date/time
|
|
|
|
|
* e.g. 2008-08-15T20:00:00Z
|
|
|
|
|
*/
|
|
|
|
|
this.dateToISO = function (date) {
|
|
|
|
|
var year = date.getUTCFullYear();
|
|
|
|
|
var month = date.getUTCMonth();
|
|
|
|
|
var day = date.getUTCDate();
|
|
|
|
|
var hours = date.getUTCHours();
|
|
|
|
|
var minutes = date.getUTCMinutes();
|
|
|
|
|
var seconds = date.getUTCSeconds();
|
|
|
|
|
|
|
|
|
|
var utils = new Zotero.Utilities();
|
|
|
|
|
year = utils.lpad(year, '0', 4);
|
|
|
|
|
month = utils.lpad(month + 1, '0', 2);
|
|
|
|
|
day = utils.lpad(day, '0', 2);
|
|
|
|
|
hours = utils.lpad(hours, '0', 2);
|
|
|
|
|
minutes = utils.lpad(minutes, '0', 2);
|
|
|
|
|
seconds = utils.lpad(seconds, '0', 2);
|
|
|
|
|
|
|
|
|
|
return year + '-' + month + '-' + day + 'T'
|
|
|
|
|
+ hours + ':' + minutes + ':' + seconds + 'Z';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert an ISO 8601–formatted UTC date/time to a JS Date
|
|
|
|
|
*
|
|
|
|
|
* Adapted from http://delete.me.uk/2005/03/iso8601.html (AFL-licensed)
|
|
|
|
|
*
|
|
|
|
|
* @param {String} isoDate ISO 8601 date
|
|
|
|
|
* @return {Date} JS Date
|
|
|
|
|
*/
|
|
|
|
|
this.isoToDate = function (isoDate) {
|
|
|
|
|
var re8601 = /([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?/;
|
|
|
|
|
var d = isoDate.match(re8601);
|
|
|
|
|
|
|
|
|
|
var offset = 0;
|
|
|
|
|
var date = new Date(d[1], 0, 1);
|
|
|
|
|
|
|
|
|
|
if (d[3]) { date.setMonth(d[3] - 1); }
|
|
|
|
|
if (d[5]) { date.setDate(d[5]); }
|
|
|
|
|
if (d[7]) { date.setHours(d[7]); }
|
|
|
|
|
if (d[8]) { date.setMinutes(d[8]); }
|
|
|
|
|
if (d[10]) { date.setSeconds(d[10]); }
|
|
|
|
|
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
|
|
|
|
|
if (d[14]) {
|
|
|
|
|
offset = (Number(d[16]) * 60) + Number(d[17]);
|
|
|
|
|
offset *= ((d[15] == '-') ? 1 : -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset -= date.getTimezoneOffset();
|
|
|
|
|
var time = (Number(date) + (offset * 60 * 1000));
|
|
|
|
|
return new Date(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-30 23:21:49 +00:00
|
|
|
|
/*
|
|
|
|
|
* converts a string to an object containing:
|
|
|
|
|
* day: integer form of the day
|
|
|
|
|
* month: integer form of the month (indexed from 0, not 1)
|
|
|
|
|
* year: 4 digit year (or, year + BC/AD/etc.)
|
|
|
|
|
* part: anything that does not fall under any of the above categories
|
|
|
|
|
* (e.g., "Summer," etc.)
|
2007-10-23 07:11:59 +00:00
|
|
|
|
*
|
|
|
|
|
* Note: the returned object is *not* a JS Date object
|
2006-08-30 23:21:49 +00:00
|
|
|
|
*/
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var _slashRe = /^(.*?)\b([0-9]{1,4})(?:([\-\/\.\u5e74])([0-9]{1,2}))?(?:([\-\/\.\u6708])([0-9]{1,4}))?\b(.*?)$/
|
|
|
|
|
var _yearRe = /^(.*?)\b((?:circa |around |about |c\.? ?)?[0-9]{1,4}(?: ?B\.? ?C\.?(?: ?E\.?)?| ?C\.? ?E\.?| ?A\.? ?D\.?)|[0-9]{3,4})\b(.*?)$/i;
|
2006-09-06 07:04:02 +00:00
|
|
|
|
var _monthRe = null;
|
|
|
|
|
var _dayRe = null;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
2006-08-30 23:21:49 +00:00
|
|
|
|
function strToDate(string) {
|
|
|
|
|
var date = new Object();
|
|
|
|
|
|
|
|
|
|
// skip empty things
|
|
|
|
|
if(!string) {
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-31 01:49:46 +00:00
|
|
|
|
string = string.toString().replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s+/, " ");
|
2006-08-30 23:21:49 +00:00
|
|
|
|
|
2006-09-06 07:04:02 +00:00
|
|
|
|
// first, directly inspect the string
|
|
|
|
|
var m = _slashRe.exec(string);
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if(m &&
|
|
|
|
|
(!m[5] || m[3] == m[5] || (m[3] == "\u5e74" && m[5] == "\u6708")) && // require sane separators
|
|
|
|
|
((m[2] && m[4] && m[6]) || (!m[1] && !m[7]))) { // require that either all parts are found,
|
|
|
|
|
// or else this is the entire date field
|
2006-09-06 07:04:02 +00:00
|
|
|
|
// figure out date based on parts
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if(m[2].length == 3 || m[2].length == 4 || m[3] == "\u5e74") {
|
2006-09-06 07:04:02 +00:00
|
|
|
|
// ISO 8601 style date (big endian)
|
2007-10-23 07:11:59 +00:00
|
|
|
|
date.year = m[2];
|
|
|
|
|
date.month = m[4];
|
|
|
|
|
date.day = m[6];
|
2006-09-06 07:04:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
// local style date (middle or little endian)
|
2007-10-23 07:11:59 +00:00
|
|
|
|
date.year = m[6];
|
2006-10-02 23:15:27 +00:00
|
|
|
|
var country = Zotero.locale.substr(3);
|
2006-09-06 07:04:02 +00:00
|
|
|
|
if(country == "US" || // The United States
|
|
|
|
|
country == "FM" || // The Federated States of Micronesia
|
|
|
|
|
country == "PW" || // Palau
|
|
|
|
|
country == "PH") { // The Philippines
|
2007-10-23 07:11:59 +00:00
|
|
|
|
date.month = m[2];
|
|
|
|
|
date.day = m[4];
|
2006-09-06 07:04:02 +00:00
|
|
|
|
} else {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
date.month = m[4];
|
|
|
|
|
date.day = m[2];
|
2006-09-06 07:04:02 +00:00
|
|
|
|
}
|
2006-08-30 23:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if(date.year) date.year = parseInt(date.year, 10);
|
|
|
|
|
if(date.day) date.day = parseInt(date.day, 10);
|
|
|
|
|
if(date.month) {
|
|
|
|
|
date.month = parseInt(date.month, 10);
|
|
|
|
|
|
|
|
|
|
if(date.month > 12) {
|
|
|
|
|
// swap day and month
|
|
|
|
|
var tmp = date.day;
|
|
|
|
|
date.day = date.month
|
|
|
|
|
date.month = tmp;
|
|
|
|
|
}
|
2006-09-06 07:04:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if((!date.month || date.month <= 12) && (!date.day || date.day <= 31)) {
|
|
|
|
|
if(date.year && date.year < 100) { // for two digit years, determine proper
|
|
|
|
|
// four digit year
|
2006-09-06 07:04:02 +00:00
|
|
|
|
var today = new Date();
|
|
|
|
|
var year = today.getFullYear();
|
|
|
|
|
var twoDigitYear = year % 100;
|
|
|
|
|
var century = year - twoDigitYear;
|
|
|
|
|
|
|
|
|
|
if(date.year <= twoDigitYear) {
|
|
|
|
|
// assume this date is from our century
|
|
|
|
|
date.year = century + date.year;
|
|
|
|
|
} else {
|
|
|
|
|
// assume this date is from the previous century
|
|
|
|
|
date.year = century - 100 + date.year;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
if(date.month) date.month--; // subtract one for JS style
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.debug("DATE: retrieved with algorithms: "+date.toSource());
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
date.part = m[1]+m[7];
|
|
|
|
|
} else {
|
|
|
|
|
// give up; we failed the sanity check
|
|
|
|
|
Zotero.debug("DATE: algorithms failed sanity check");
|
|
|
|
|
date = {"part":string};
|
2006-09-06 07:04:02 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
Zotero.debug("DATE: could not apply algorithms");
|
|
|
|
|
date.part = string;
|
2006-08-30 23:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// couldn't find something with the algorithms; use regexp
|
|
|
|
|
// YEAR
|
|
|
|
|
if(!date.year) {
|
|
|
|
|
var m = _yearRe.exec(date.part);
|
|
|
|
|
if(m) {
|
|
|
|
|
date.year = m[2];
|
|
|
|
|
date.part = m[1]+m[3];
|
|
|
|
|
Zotero.debug("DATE: got year ("+date.year+", "+date.part+")");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MONTH
|
|
|
|
|
if(!date.month) {
|
|
|
|
|
// compile month regular expression
|
|
|
|
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
|
'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// If using a non-English bibliography locale, try those too
|
|
|
|
|
if (Zotero.CSL.Global.locale != 'en-US') {
|
|
|
|
|
months = months.concat(Zotero.CSL.Global.getMonthStrings("short"));
|
2006-09-08 22:26:59 +00:00
|
|
|
|
}
|
2006-09-06 07:04:02 +00:00
|
|
|
|
if(!_monthRe) {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
_monthRe = new RegExp("^(.*)\\b("+months.join("|")+")[^ ]*(?: (.*)$|$)", "i");
|
2006-09-06 07:04:02 +00:00
|
|
|
|
}
|
2006-08-31 00:04:11 +00:00
|
|
|
|
|
2006-09-06 07:04:02 +00:00
|
|
|
|
var m = _monthRe.exec(date.part);
|
2006-08-30 23:21:49 +00:00
|
|
|
|
if(m) {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// Modulo 12 in case we have multiple languages
|
|
|
|
|
date.month = months.indexOf(m[2][0].toUpperCase()+m[2].substr(1).toLowerCase()) % 12;
|
2006-08-30 23:21:49 +00:00
|
|
|
|
date.part = m[1]+m[3];
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.debug("DATE: got month ("+date.month+", "+date.part+")");
|
2007-10-23 07:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DAY
|
|
|
|
|
if(!date.day) {
|
|
|
|
|
// compile day regular expression
|
|
|
|
|
if(!_dayRe) {
|
|
|
|
|
var daySuffixes = Zotero.getString("date.daySuffixes").replace(/, ?/g, "|");
|
|
|
|
|
_dayRe = new RegExp("\\b([0-9]{1,2})(?:"+daySuffixes+")?\\b(.*)", "i");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var m = _dayRe.exec(date.part);
|
|
|
|
|
if(m) {
|
|
|
|
|
var day = parseInt(m[1], 10);
|
|
|
|
|
// Sanity check
|
|
|
|
|
if (day <= 31) {
|
|
|
|
|
date.day = day;
|
2006-09-11 01:05:26 +00:00
|
|
|
|
if(m.index > 0) {
|
|
|
|
|
date.part = date.part.substr(0, m.index);
|
|
|
|
|
if(m[2]) {
|
|
|
|
|
date.part += " "+m[2];;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
date.part = m[2];
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.debug("DATE: got day ("+date.day+", "+date.part+")");
|
2006-08-30 23:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
// clean up date part
|
2006-08-30 23:21:49 +00:00
|
|
|
|
if(date.part) {
|
|
|
|
|
date.part = date.part.replace(/^[^A-Za-z0-9]+/, "").replace(/[^A-Za-z0-9]+$/, "");
|
2006-09-06 04:45:19 +00:00
|
|
|
|
if(!date.part.length) {
|
|
|
|
|
date.part = undefined;
|
|
|
|
|
}
|
2006-08-30 23:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return date;
|
|
|
|
|
}
|
2006-08-01 23:10:31 +00:00
|
|
|
|
|
2008-06-20 06:40:05 +00:00
|
|
|
|
/**
|
2006-08-31 00:04:11 +00:00
|
|
|
|
* does pretty formatting of a date object returned by strToDate()
|
2007-10-23 07:11:59 +00:00
|
|
|
|
*
|
2008-06-20 06:40:05 +00:00
|
|
|
|
* @param {Object} date A date object, as returned from strToDate()
|
|
|
|
|
* @param {Boolean} shortFormat Whether to return a short (12/1/95) date
|
|
|
|
|
* @return A formatted date string
|
|
|
|
|
* @type String
|
|
|
|
|
**/
|
|
|
|
|
function formatDate(date, shortFormat) {
|
|
|
|
|
if(shortFormat) {
|
|
|
|
|
var localeDateOrder = getLocaleDateOrder();
|
|
|
|
|
var string = localeDateOrder[0]+"/"+localeDateOrder[1]+"/"+localeDateOrder[2];
|
|
|
|
|
return string.replace("y", (date.year !== undefined ? date.year : "00"))
|
|
|
|
|
.replace("m", (date.month !== undefined ? 1+date.month : "0"))
|
|
|
|
|
.replace("d", (date.day !== undefined ? date.day : "0"));
|
|
|
|
|
} else {
|
|
|
|
|
var string = "";
|
|
|
|
|
|
|
|
|
|
if(date.part) {
|
|
|
|
|
string += date.part+" ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var months = Zotero.CSL.Global.getMonthStrings("long");
|
|
|
|
|
if(date.month != undefined && months[date.month]) {
|
|
|
|
|
// get short month strings from CSL interpreter
|
|
|
|
|
string += months[date.month];
|
|
|
|
|
if(date.day) {
|
|
|
|
|
string += " "+date.day+", ";
|
|
|
|
|
} else {
|
|
|
|
|
string += " ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(date.year) {
|
|
|
|
|
string += date.year;
|
2006-08-31 00:04:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-31 23:36:01 +00:00
|
|
|
|
function strToISO(str) {
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var date = Zotero.Date.strToDate(str);
|
|
|
|
|
|
|
|
|
|
if(date.year) {
|
|
|
|
|
var dateString = Zotero.Utilities.prototype.lpad(date.year, "0", 4);
|
|
|
|
|
if(date.month) {
|
|
|
|
|
dateString += "-"+Zotero.Utilities.prototype.lpad(date.month+1, "0", 2);
|
|
|
|
|
if(date.day) {
|
|
|
|
|
dateString += "-"+Zotero.Utilities.prototype.lpad(date.day, "0", 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dateString;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function strToMultipart(str){
|
|
|
|
|
if (!str){
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var utils = new Zotero.Utilities();
|
|
|
|
|
|
|
|
|
|
var parts = strToDate(str);
|
|
|
|
|
parts.month = typeof parts.month != "undefined" ? parts.month + 1 : '';
|
|
|
|
|
|
|
|
|
|
var multi = (parts.year ? utils.lpad(parts.year, '0', 4) : '0000') + '-'
|
|
|
|
|
+ utils.lpad(parts.month, '0', 2) + '-'
|
|
|
|
|
+ (parts.day ? utils.lpad(parts.day, '0', 2) : '00')
|
|
|
|
|
+ ' '
|
|
|
|
|
+ str;
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Regexes for multipart and SQL dates
|
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
|
|
|
|
// Allow zeroes in multipart dates
|
|
|
|
|
var _multipartRE = /^\-?[0-9]{4}\-[0-9]{2}\-[0-9]{2} /;
|
|
|
|
|
//var _sqldateRE = /^\-?[0-9]{4}\-[0-9]{2}\-[0-9]{2}/;
|
|
|
|
|
//var _sqldatetimeRE = /^\-?[0-9]{4}\-[0-9]{2}\-[0-9]{2} ([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])/;
|
|
|
|
|
var _sqldateRE = /^\-?[0-9]{4}\-(0[1-9]|10|11|12)\-(0[1-9]|[1-2][0-9]|30|31)$/;
|
|
|
|
|
var _sqldatetimeRE = /^\-?[0-9]{4}\-(0[1-9]|10|11|12)\-(0[1-9]|[1-2][0-9]|30|31) ([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$/;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests if a string is a multipart date string
|
|
|
|
|
* e.g. '2006-11-03 November 3rd, 2006'
|
|
|
|
|
*/
|
|
|
|
|
function isMultipart(str){
|
|
|
|
|
return _multipartRE.test(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the SQL part of a multipart date string
|
|
|
|
|
* (e.g. '2006-11-03 November 3rd, 2006' returns '2006-11-03')
|
|
|
|
|
*/
|
|
|
|
|
function multipartToSQL(multi){
|
|
|
|
|
if (!multi){
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isMultipart(multi)){
|
|
|
|
|
return '0000-00-00';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return multi.substr(0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user part of a multipart date string
|
|
|
|
|
* (e.g. '2006-11-03 November 3rd, 2006' returns 'November 3rd, 2006')
|
|
|
|
|
*/
|
|
|
|
|
function multipartToStr(multi){
|
|
|
|
|
if (!multi){
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isMultipart(multi)){
|
|
|
|
|
return multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return multi.substr(11);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isSQLDate(str){
|
|
|
|
|
return _sqldateRE.test(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isSQLDateTime(str){
|
|
|
|
|
return _sqldatetimeRE.test(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sqlHasYear(sqldate){
|
|
|
|
|
return isSQLDate(sqldate) && sqldate.substr(0,4)!='0000';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sqlHasMonth(sqldate){
|
|
|
|
|
return isSQLDate(sqldate) && sqldate.substr(5,2)!='00';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sqlHasDay(sqldate){
|
|
|
|
|
return isSQLDate(sqldate) && sqldate.substr(8,2)!='00';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
function getUnixTimestamp() {
|
|
|
|
|
return Math.round(Date.now() / 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toUnixTimestamp(date) {
|
|
|
|
|
if (date === null || typeof date != 'object' ||
|
|
|
|
|
date.constructor.name != 'Date') {
|
|
|
|
|
throw ('Not a valid date in Zotero.Date.toUnixTimestamp()');
|
|
|
|
|
}
|
|
|
|
|
return Math.round(date.getTime() / 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-01 23:10:31 +00:00
|
|
|
|
function getFileDateString(file){
|
|
|
|
|
var date = new Date();
|
|
|
|
|
date.setTime(file.lastModifiedTime);
|
|
|
|
|
return date.toLocaleDateString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getFileTimeString(file){
|
|
|
|
|
var date = new Date();
|
|
|
|
|
date.setTime(file.lastModifiedTime);
|
|
|
|
|
return date.toLocaleTimeString();
|
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Figure out the date order from the output of toLocaleDateString()
|
|
|
|
|
*
|
|
|
|
|
* Returns a string with y, m, and d (e.g. 'ymd', 'mdy')
|
|
|
|
|
*/
|
|
|
|
|
function getLocaleDateOrder(){
|
|
|
|
|
if (_localeDateOrder) {
|
|
|
|
|
return _localeDateOrder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var date = new Date("October 5, 2006");
|
|
|
|
|
var parts = date.toLocaleDateString().match(/([0-9]+)[^0-9]+([0-9]+)[^0-9]+([0-9]+)/);
|
|
|
|
|
|
|
|
|
|
// The above only works on OS X and Linux,
|
|
|
|
|
// where toLocaleDateString() produces "10/05/2006"
|
|
|
|
|
if (!parts) {
|
|
|
|
|
var country = Zotero.locale.substr(3);
|
|
|
|
|
switch (country) {
|
|
|
|
|
// I don't know where this country list came from, but these
|
|
|
|
|
// are little-endian in Zotero.strToDate()
|
|
|
|
|
case 'US': // The United States
|
|
|
|
|
case 'FM': // The Federated States of Micronesia
|
|
|
|
|
case 'PW': // Palau
|
|
|
|
|
case 'PH': // The Philippines
|
|
|
|
|
return 'mdy';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 'dmy';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (parseInt(parts[1])){
|
|
|
|
|
case 2006:
|
|
|
|
|
var order = 'y';
|
|
|
|
|
break;
|
|
|
|
|
case 10:
|
|
|
|
|
var order = 'm';
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
var order = 'd';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch (parseInt(parts[2])){
|
|
|
|
|
case 2006:
|
|
|
|
|
order += 'y';
|
|
|
|
|
break;
|
|
|
|
|
case 10:
|
|
|
|
|
order += 'm';
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
order += 'd';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch (parseInt(parts[3])){
|
|
|
|
|
case 2006:
|
|
|
|
|
order += 'y';
|
|
|
|
|
break;
|
|
|
|
|
case 10:
|
|
|
|
|
order += 'm';
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
order += 'd';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_localeDateOrder = order;
|
|
|
|
|
|
|
|
|
|
return order;
|
|
|
|
|
}
|
2006-07-27 23:01:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
/**
|
|
|
|
|
* Functions for creating and destroying hidden browser objects
|
|
|
|
|
**/
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.Browser = new function() {
|
2006-07-27 23:01:55 +00:00
|
|
|
|
this.createHiddenBrowser = createHiddenBrowser;
|
|
|
|
|
this.deleteHiddenBrowser = deleteHiddenBrowser;
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
function createHiddenBrowser(win) {
|
|
|
|
|
if (!win) {
|
|
|
|
|
var win = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator)
|
|
|
|
|
.getMostRecentWindow("navigator:browser");
|
2006-07-27 23:01:55 +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
|
|
|
|
// Create a hidden browser
|
2007-10-23 07:11:59 +00:00
|
|
|
|
var hiddenBrowser = win.document.createElement("browser");
|
Merged revisions 2890,2895-2896,2898,2900-2901,2905,2909-2911,2913,2916-2917,2919,2922,2936-2937,2953-2954,2957,2959,2962-2965,2969-2970,2973-2975,2979-2980,2983 via svnmerge from 1.0 branch
2008-07-07 15:18:49 +00:00
|
|
|
|
hiddenBrowser.setAttribute('type', 'content');
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
|
hiddenBrowser.setAttribute('disablehistory', 'true');
|
2007-10-23 07:11:59 +00:00
|
|
|
|
win.document.documentElement.appendChild(hiddenBrowser);
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
// Disable some features
|
|
|
|
|
hiddenBrowser.docShell.allowImages = false;
|
|
|
|
|
hiddenBrowser.docShell.allowJavascript = false;
|
|
|
|
|
hiddenBrowser.docShell.allowMetaRedirects = false;
|
|
|
|
|
hiddenBrowser.docShell.allowPlugins = false;
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.debug("created hidden browser ("
|
2007-10-23 07:11:59 +00:00
|
|
|
|
+ win.document.getElementsByTagName('browser').length + ")");
|
|
|
|
|
return hiddenBrowser;
|
2006-07-27 23:01:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
function deleteHiddenBrowser(myBrowser) {
|
|
|
|
|
myBrowser.stop();
|
2006-07-27 23:01:55 +00:00
|
|
|
|
myBrowser.parentNode.removeChild(myBrowser);
|
2007-10-23 07:11:59 +00:00
|
|
|
|
myBrowser = null;
|
2006-10-02 23:15:27 +00:00
|
|
|
|
Zotero.debug("deleted hidden browser");
|
2006-07-27 23:01:55 +00:00
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Functions for disabling and enabling the unresponsive script indicator
|
|
|
|
|
**/
|
|
|
|
|
Zotero.UnresponsiveScriptIndicator = new function() {
|
|
|
|
|
this.disable = disable;
|
|
|
|
|
this.enable = enable;
|
|
|
|
|
|
|
|
|
|
// stores the state of the unresponsive script preference prior to disabling
|
|
|
|
|
var _unresponsiveScriptPreference, _isDisabled;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* disables the "unresponsive script" warning; necessary for import and
|
|
|
|
|
* export, which can take quite a while to execute
|
|
|
|
|
**/
|
|
|
|
|
function disable() {
|
|
|
|
|
// don't do anything if already disabled
|
|
|
|
|
if(_isDisabled) return;
|
|
|
|
|
|
|
|
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
|
|
|
|
|
getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
_unresponsiveScriptPreference = prefService.getIntPref("dom.max_chrome_script_run_time");
|
|
|
|
|
prefService.setIntPref("dom.max_chrome_script_run_time", 0);
|
|
|
|
|
|
|
|
|
|
_isDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* restores the "unresponsive script" warning
|
|
|
|
|
**/
|
|
|
|
|
function enable() {
|
|
|
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
|
|
|
|
|
getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
prefService.setIntPref("dom.max_chrome_script_run_time", _unresponsiveScriptPreference);
|
|
|
|
|
|
|
|
|
|
_isDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implements nsIWebProgressListener
|
|
|
|
|
*/
|
|
|
|
|
Zotero.WebProgressFinishListener = function(onFinish) {
|
|
|
|
|
this.onStateChange = function(wp, req, stateFlags, status) {
|
|
|
|
|
//Zotero.debug('onStageChange: ' + stateFlags);
|
|
|
|
|
if ((stateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
|
|
|
|
|
&& (stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK)) {
|
|
|
|
|
onFinish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.onProgressChange = function(wp, req, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
|
|
|
|
|
//Zotero.debug('onProgressChange');
|
|
|
|
|
//Zotero.debug('Current: ' + curTotalProgress);
|
|
|
|
|
//Zotero.debug('Max: ' + maxTotalProgress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.onLocationChange = function(wp, req, location) {}
|
|
|
|
|
this.onSecurityChange = function(wp, req, stateFlags, status) {}
|
|
|
|
|
this.onStatusChange = function(wp, req, status, msg) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Saves or loads JSON objects. Based on public domain code from
|
|
|
|
|
* http://www.json.org/json.js
|
|
|
|
|
*/
|
|
|
|
|
Zotero.JSON = new function() {
|
|
|
|
|
this.serialize = serialize;
|
|
|
|
|
this.unserialize = unserialize;
|
|
|
|
|
|
|
|
|
|
// m is a table of character substitutions.
|
|
|
|
|
var m = {
|
|
|
|
|
'\b': '\\b',
|
|
|
|
|
'\t': '\\t',
|
|
|
|
|
'\n': '\\n',
|
|
|
|
|
'\f': '\\f',
|
|
|
|
|
'\r': '\\r',
|
|
|
|
|
'"' : '\\"',
|
|
|
|
|
'\\': '\\\\'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Format integers to have at least two digits.
|
|
|
|
|
function f(n) {
|
|
|
|
|
return n < 10 ? '0' + n : n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceFunction(a) {
|
|
|
|
|
var c = m[a];
|
|
|
|
|
if (c) {
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
c = a.charCodeAt();
|
|
|
|
|
return '\\u00' +
|
|
|
|
|
Math.floor(c / 16).toString(16) +
|
|
|
|
|
(c % 16).toString(16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function serialize(arg) {
|
|
|
|
|
if(arg === null) {
|
|
|
|
|
return "null";
|
|
|
|
|
} else if(arg instanceof Array) {
|
|
|
|
|
var a = [], // The array holding the partial texts.
|
|
|
|
|
i, // Loop counter.
|
|
|
|
|
l = arg.length,
|
|
|
|
|
v; // The value to be stringified.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For each value in arg array...
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < l; i += 1) {
|
|
|
|
|
var out = serialize(arg[i]);
|
|
|
|
|
if(out !== undefined) {
|
|
|
|
|
a.push(out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Join all of the member texts together and wrap them in brackets.
|
|
|
|
|
|
|
|
|
|
return '[' + a.join(',') + ']';
|
|
|
|
|
} else if(typeof(arg) == "boolean") {
|
|
|
|
|
return String(arg);
|
|
|
|
|
} else if(arg instanceof Date) {
|
|
|
|
|
// Eventually, this method will be based on the date.toISOString method.
|
|
|
|
|
|
|
|
|
|
return '"' + arg.getUTCFullYear() + '-' +
|
|
|
|
|
f(arg.getUTCMonth() + 1) + '-' +
|
|
|
|
|
f(arg.getUTCDate()) + 'T' +
|
|
|
|
|
f(arg.getUTCHours()) + ':' +
|
|
|
|
|
f(arg.getUTCMinutes()) + ':' +
|
|
|
|
|
f(arg.getUTCSeconds()) + 'Z"';
|
|
|
|
|
} else if(typeof(arg) == "number") {
|
|
|
|
|
// JSON numbers must be finite. Encode non-finite numbers as null.
|
|
|
|
|
|
|
|
|
|
return isFinite(arg) ? String(arg) : 'null';
|
|
|
|
|
} else if(typeof(arg) == "string") {
|
|
|
|
|
if (/["\\\x00-\x1f]/.test(arg)) {
|
|
|
|
|
return '"' + arg.replace(/[\x00-\x1f\\"]/g, replaceFunction) + '"';
|
|
|
|
|
}
|
|
|
|
|
return '"' + arg + '"';
|
|
|
|
|
} else if(arg instanceof Object) {
|
|
|
|
|
var a = [], // The array holding the partial texts.
|
|
|
|
|
k, // The current key.
|
|
|
|
|
v; // The current value.
|
|
|
|
|
|
|
|
|
|
// Iterate through all of the keys in the object, ignoring the proto chain
|
|
|
|
|
// and keys that are not strings.
|
|
|
|
|
|
|
|
|
|
for (k in arg) {
|
|
|
|
|
if (typeof k === 'string' &&
|
|
|
|
|
Object.prototype.hasOwnProperty.apply(arg, [k])) {
|
|
|
|
|
var out = serialize(arg[k]);
|
|
|
|
|
if(out !== undefined) {
|
|
|
|
|
a.push(serialize(k) + ':' + out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Join all of the member texts together and wrap them in braces.
|
|
|
|
|
|
|
|
|
|
return '{' + a.join(',') + '}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function unserialize(arg) {
|
|
|
|
|
var j;
|
|
|
|
|
|
|
|
|
|
// Parsing happens in three stages. In the first stage, we run the text against
|
|
|
|
|
// a regular expression which looks for non-JSON characters. We are especially
|
|
|
|
|
// concerned with '()' and 'new' because they can cause invocation, and '='
|
|
|
|
|
// because it can cause mutation. But just to be safe, we will reject all
|
|
|
|
|
// unexpected characters.
|
|
|
|
|
|
|
|
|
|
// We split the first stage into 3 regexp operations in order to work around
|
|
|
|
|
// crippling deficiencies in Safari's regexp engine. First we replace all
|
|
|
|
|
// backslash pairs with '@' (a non-JSON character). Second we delete all of
|
|
|
|
|
// the string literals. Third, we look to see if only JSON characters
|
|
|
|
|
// remain. If so, then the text is safe for eval.
|
|
|
|
|
|
|
|
|
|
if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(arg.
|
|
|
|
|
replace(/\\./g, '@').
|
|
|
|
|
replace(/"[^"\\\n\r]*"/g, ''))) {
|
|
|
|
|
|
|
|
|
|
// In the second stage we use the eval function to compile the text into a
|
|
|
|
|
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
|
|
|
|
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
|
|
|
|
// in parens to eliminate the ambiguity.
|
|
|
|
|
|
|
|
|
|
j = eval('(' + arg + ')');
|
|
|
|
|
|
|
|
|
|
// In the optional third stage, we recursively walk the new structure, passing
|
|
|
|
|
// each name/value pair to a filter function for possible transformation.
|
|
|
|
|
|
|
|
|
|
return j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
|
|
|
|
|
|
|
|
|
throw new SyntaxError('parseJSON');
|
|
|
|
|
}
|
2006-06-06 19:53:27 +00:00
|
|
|
|
}
|