closes #476, Add Wikipedia CSL/export format
This commit is contained in:
parent
6d452d44fd
commit
97850dabb3
|
@ -273,6 +273,17 @@ Zotero.Utilities.prototype.getCreatorsForType = function(type) {
|
||||||
return cleanTypes;
|
return cleanTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns a localized creatorType name
|
||||||
|
*/
|
||||||
|
Zotero.Utilities.prototype.getLocalizedCreatorType = function(type) {
|
||||||
|
try {
|
||||||
|
return Zotero.getString("creatorTypes."+type);
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cleans a title, capitalizing the proper words and replacing " :" with ":"
|
* Cleans a title, capitalizing the proper words and replacing " :" with ":"
|
||||||
*/
|
*/
|
||||||
|
|
299
scrapers.sql
299
scrapers.sql
|
@ -1,4 +1,4 @@
|
||||||
-- 199
|
-- 200
|
||||||
|
|
||||||
-- ***** BEGIN LICENSE BLOCK *****
|
-- ***** BEGIN LICENSE BLOCK *****
|
||||||
--
|
--
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
-- Set the following timestamp to the most recent scraper update date
|
-- Set the following timestamp to the most recent scraper update date
|
||||||
REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2007-03-22 19:45:00'));
|
REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2007-03-22 20:55:00'));
|
||||||
|
|
||||||
REPLACE INTO translators VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '1.0.0b4.r1', '', '2007-03-21 15:26:54', '1', '100', '4', 'Amazon.com', 'Sean Takats', '^https?://(?:www\.)?amazon',
|
REPLACE INTO translators VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '1.0.0b4.r1', '', '2007-03-21 15:26:54', '1', '100', '4', 'Amazon.com', 'Sean Takats', '^https?://(?:www\.)?amazon',
|
||||||
'function detectWeb(doc, url) {
|
'function detectWeb(doc, url) {
|
||||||
|
@ -10458,6 +10458,301 @@ function doImport() {
|
||||||
}
|
}
|
||||||
}');
|
}');
|
||||||
|
|
||||||
|
REPLACE INTO translators VALUES ('3f50aaac-7acc-4350-acd0-59cb77faf620', '1.0.0b4.r1', '', '2007-03-22 20:55:00', 1, 100, 2, 'Wikipedia', 'Simon Kornblith', '', NULL,
|
||||||
|
'var fieldMap = {
|
||||||
|
"url":"url",
|
||||||
|
edition:"edition",
|
||||||
|
publisher:"publisher",
|
||||||
|
doi:"DOI",
|
||||||
|
isbn:"ISBN",
|
||||||
|
issn:"ISSN",
|
||||||
|
conference:"conferenceName",
|
||||||
|
volume:"volume",
|
||||||
|
issue:"issue",
|
||||||
|
pages:"pages",
|
||||||
|
number:"epsiodeNumber"
|
||||||
|
};
|
||||||
|
|
||||||
|
var typeMap = {
|
||||||
|
book:"Cite book",
|
||||||
|
bookSection:"Cite book",
|
||||||
|
journalArticle:"Cite journal",
|
||||||
|
magazineArticle:"Cite news",
|
||||||
|
newspaperArticle:"Cite news",
|
||||||
|
thesis:"Cite paper",
|
||||||
|
letter:"Cite",
|
||||||
|
manuscript:"Cite book",
|
||||||
|
interview:"Cite interview",
|
||||||
|
film:"Cite video",
|
||||||
|
artwork:"Cite",
|
||||||
|
webpage:"Cite web",
|
||||||
|
report:"Cite conference",
|
||||||
|
bill:"Cite",
|
||||||
|
hearing:"Cite",
|
||||||
|
patent:"Cite",
|
||||||
|
statute:"Cite",
|
||||||
|
email:"Cite email",
|
||||||
|
map:"Cite",
|
||||||
|
blogPost:"Cite web",
|
||||||
|
instantMessage:"Cite",
|
||||||
|
forumPost:"Cite web",
|
||||||
|
audioRecording:"Cite",
|
||||||
|
presentation:"Cite paper",
|
||||||
|
videoRecording:"Cite video",
|
||||||
|
tvBroadcast:"Cite episode",
|
||||||
|
radioBroadcast:"Cite episode",
|
||||||
|
podcast:"Cite podcast",
|
||||||
|
computerProgram:"Cite",
|
||||||
|
conferencePaper:"Cite conference",
|
||||||
|
document:"Cite",
|
||||||
|
encyclopediaArticle:"Cite encyclopedia",
|
||||||
|
dictionaryEntry:"Cite encyclopedia"
|
||||||
|
};
|
||||||
|
|
||||||
|
function formatAuthors(authors, useTypes) {
|
||||||
|
var text = "";
|
||||||
|
for each(var author in authors) {
|
||||||
|
text += ", "+author.firstName;
|
||||||
|
if(author.firstName && author.lastName) text += " ";
|
||||||
|
text += author.lastName;
|
||||||
|
if(useTypes) text += " ("+Zotero.Utilities.getLocalizedCreatorType(author.creatorType)+")";
|
||||||
|
}
|
||||||
|
return text.substr(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatFirstAuthor(authors, useTypes) {
|
||||||
|
var firstCreator = authors.shift();
|
||||||
|
var field = firstCreator.lastName;
|
||||||
|
if(firstCreator.lastName && firstCreator.firstName) field += ", ";
|
||||||
|
field += firstCreator.firstName;
|
||||||
|
if(useTypes) field += " ("+Zotero.Utilities.getLocalizedCreatorType(firstCreator.creatorType)+")";
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(date) {
|
||||||
|
var date = date.substr(0, item.date.indexOf(" "));
|
||||||
|
if(date.substr(4, 3) == "-00") {
|
||||||
|
date = date.substr(0, 4);
|
||||||
|
} else if(date.substr(7, 3) == "-00") {
|
||||||
|
date = date.substr(0, 7);
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
function doExport() {
|
||||||
|
var first = true;
|
||||||
|
while(item = Zotero.nextItem()) {
|
||||||
|
// determine type
|
||||||
|
var type = typeMap[item.itemType];
|
||||||
|
if(!type) type = "Cite";
|
||||||
|
|
||||||
|
var properties = new Object();
|
||||||
|
|
||||||
|
for(var wikiField in fieldMap) {
|
||||||
|
var zoteroField = fieldMap[wikiField];
|
||||||
|
if(item[zoteroField]) properties[wikiField] = item[zoteroField];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.creators && item.creators.length) {
|
||||||
|
if(type == "Cite episode") {
|
||||||
|
// now add additional creators
|
||||||
|
properties.credits = formatAuthors(item.creators, true);
|
||||||
|
} else if(type == "Cite video") {
|
||||||
|
properties.people = "";
|
||||||
|
|
||||||
|
// make first creator first, last
|
||||||
|
properties.people = formatFirstAuthor(item.creators, true);
|
||||||
|
// now add additional creators
|
||||||
|
if(item.creators.length) properties.people += ", "+formatAuthors(item.creators, true);
|
||||||
|
|
||||||
|
// use type
|
||||||
|
if(item.type) {
|
||||||
|
properties.medium = item.type;
|
||||||
|
}
|
||||||
|
} else if(type == "Cite email") {
|
||||||
|
// get rid of non-authors
|
||||||
|
for(var i in item.creators) {
|
||||||
|
if(item.creators[i].creatorType != "author") {
|
||||||
|
// drop contributors
|
||||||
|
item.creators.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make first authors first, last
|
||||||
|
properties.author = formatFirstAuthor(item.creators);
|
||||||
|
// add supplemental authors
|
||||||
|
if(item.creators.length) {
|
||||||
|
properties.author += ", "+formatAuthors(item.creators);
|
||||||
|
}
|
||||||
|
} else if(type == "Cite interview") {
|
||||||
|
// check for an interviewer or translator
|
||||||
|
var interviewers = [];
|
||||||
|
var translators = [];
|
||||||
|
for(var i in item.creators) {
|
||||||
|
if(item.creators[i].creatorType == "translator") {
|
||||||
|
translators = translators.concat(item.creators.splice(i, 1));
|
||||||
|
} else if(item.creators[i].creatorType == "interviewer") {
|
||||||
|
interviewers = interviewers.concat(item.creators.splice(i, 1));
|
||||||
|
} else if(item.creators[i].creatorType == "contributor") {
|
||||||
|
// drop contributors
|
||||||
|
item.creators.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// interviewers
|
||||||
|
if(interviewers.length) {
|
||||||
|
properties.interviewer = formatAuthors([interviewers.shift()]);
|
||||||
|
if(interviewers.length) properties.cointerviewers = formatAuthors(interviewers);
|
||||||
|
}
|
||||||
|
// translators
|
||||||
|
if(translators.length) {
|
||||||
|
properties.cointerviewers = (properties.cointerviewers ? properties.cointerviewers+", " : "");
|
||||||
|
properties.cointerviewers += formatAuthors(translators);
|
||||||
|
}
|
||||||
|
// interviewees
|
||||||
|
if(item.creators.length) {
|
||||||
|
// take up to 4 interviewees
|
||||||
|
var i = 1;
|
||||||
|
while((interviewee = item.creators.shift()) && i <= 4) {
|
||||||
|
var lastKey = "last";
|
||||||
|
var firstKey = "first";
|
||||||
|
if(i != 1) {
|
||||||
|
lastKey += i;
|
||||||
|
firstKey += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
properties[lastKey] = interviewee.lastName;
|
||||||
|
properties[firstKey] = interviewee.firstName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// medium
|
||||||
|
if(item.medium) {
|
||||||
|
properties.type = item.medium
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// check for an editor or translator
|
||||||
|
var editors = [];
|
||||||
|
var translators = [];
|
||||||
|
for(var i in item.creators) {
|
||||||
|
if(item.creators[i].creatorType == "translator") {
|
||||||
|
translators = translators.concat(item.creators.splice(i, 1));
|
||||||
|
} else if(item.creators[i].creatorType == "editor") {
|
||||||
|
editors = editors.concat(item.creators.splice(i, 1));
|
||||||
|
} else if(item.creators[i].creatorType == "contributor") {
|
||||||
|
// drop contributors
|
||||||
|
item.creators.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// editors
|
||||||
|
var others = "";
|
||||||
|
if(editors.length) {
|
||||||
|
var editorText = formatAuthors(editors)+(editors.length == 1 ? " (ed.)" : " (eds.)");
|
||||||
|
if(item.itemType == "bookSection" || type == "Cite conference" || type == "Cite encyclopedia") {
|
||||||
|
// as per docs, use editor only for chapters
|
||||||
|
properties.editors = editorText;
|
||||||
|
} else {
|
||||||
|
others = editorText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// translators
|
||||||
|
if(translators.length) {
|
||||||
|
if(others) others += ", ";
|
||||||
|
others += formatAuthors(translators)+" (trans.)";
|
||||||
|
}
|
||||||
|
|
||||||
|
// pop off first author, if there is one
|
||||||
|
if(item.creators.length) {
|
||||||
|
var firstAuthor = item.creators.shift();
|
||||||
|
properties.last = firstAuthor.lastName;
|
||||||
|
properties.first = firstAuthor.firstName;
|
||||||
|
|
||||||
|
// add supplemental authors
|
||||||
|
if(item.creators.length) {
|
||||||
|
properties.coauthors = formatAuthors(item.creators);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach others
|
||||||
|
if(others) {
|
||||||
|
if(type == "Cite book") {
|
||||||
|
properties.others = others;
|
||||||
|
} else {
|
||||||
|
properties.coauthors = (properties.coauthors ? properties.coauthors+", " : "");
|
||||||
|
properties.coauthors += others;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.itemType == "bookSection") {
|
||||||
|
properties.title = item.publicationTitle;
|
||||||
|
properties.chapter = item.title;;
|
||||||
|
} else {
|
||||||
|
properties.title = item.title;
|
||||||
|
|
||||||
|
if(type == "Cite journal") {
|
||||||
|
properties.journal = item.publicationTitle;
|
||||||
|
} else if(type == "Cite conference") {
|
||||||
|
properties.booktitle = item.publicationTitle;
|
||||||
|
} else if(type == "Cite encyclopedia") {
|
||||||
|
properties.encyclopedia = item.publicationTitle;
|
||||||
|
} else {
|
||||||
|
properties.work = item.publicationTitle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == "Cite web" && item.type) {
|
||||||
|
properties.format = item.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.place) {
|
||||||
|
if(type == "Cite episode") {
|
||||||
|
properties.city = item.place;
|
||||||
|
} else {
|
||||||
|
properties.location = item.place;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.series) {
|
||||||
|
properties.series = item.series;
|
||||||
|
} else if(item.seriesTitle) {
|
||||||
|
properties.series = item.seriesTitle;
|
||||||
|
} else if(item.seriesText) {
|
||||||
|
properties.series = item.seriesText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.accessDate) {
|
||||||
|
properties.accessdate = formatDate(item.accessDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.date) {
|
||||||
|
if(type == "Cite email") {
|
||||||
|
properties.senddate = formatDate(item.date);
|
||||||
|
} else {
|
||||||
|
properties.date = formatDate(item.date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(item.runningTime) {
|
||||||
|
if(type == "Cite episode") {
|
||||||
|
properties.minutes = item.runningTime;
|
||||||
|
} else {
|
||||||
|
properties.time = item.runningTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write out properties
|
||||||
|
Zotero.write((first ? "" : "\r\n\r\n") + "{{"+type);
|
||||||
|
for(var key in properties) {
|
||||||
|
if(properties[key]) Zotero.write("\r\n| "+key+" = "+properties[key]);
|
||||||
|
}
|
||||||
|
Zotero.write("\r\n}}");
|
||||||
|
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}');
|
||||||
|
|
||||||
REPLACE INTO csl VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '2006-12-11 15:57:00', 'American Psychological Association',
|
REPLACE INTO csl VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '2006-12-11 15:57:00', 'American Psychological Association',
|
||||||
'<?xml version="1.0" encoding="UTF-8"?>
|
'<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<?oxygen RNGSchema="../schema/trunk/csl.rnc" type="compact"?>
|
<?oxygen RNGSchema="../schema/trunk/csl.rnc" type="compact"?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user