-
- TODO:
- Use strings array here to find and update citations that are not main references. As is, they are orphaned.
- Both array and textbox should be updated.
- It may be enough to just set all non-main citations in text and array to this.getInsertionText(false).
- However, if they remove the name entirely (not recommended), that would be a problem.
- /
if(strings.length > 0) // This implies there was a name before
{
for(var i = 0; i < strings.length; i++)
{
// If we find the full citation as a citation, update to the new text.
if(strings[i] == this.orig)
{
// this.orig itself is updated in updateInText
strings[i] = newCiteText;
}
}
}
else if(this.name != null) // They have added a name, so we should have a main citation.
{
// Now that it has a name, it is a citation to itself.
strings.push(newCiteText);
}
};
/**
- &lt;ref name /&gt; for reference
- @type String
- /
this.name = argObj.name != "" ? argObj.name : null; // Save blank names as null  
/*
type of reference, e.g. cite web, cite news. Also used (including for CitationReference objects) to determine default fields.
- /
this.setType(argObj.type);  
//TODO: Re-examine whether both (or indeed either) of save or inMWEditBox are really necessary. Can it be determined from context?  
/**
- flag to determine whether citation must be saved. false indicates "dirty" citation that has yet to be updated in text and metadata.
- @type Boolean
- /
this.save = argObj.save;  
/**
- true if and only if the ref is in the MW edit box with the same value as this object's orig.
- @type Boolean
- /
this.inMWEditBox = argObj.inMWEditBox;  
/**
- original wikitext for reference
- @type String
- /
this.orig = argObj.orig;  
/**
- mapping of parameter names to values
- @type Object
- /
this.params = {};  
/**
- Convenience method. Returns sorter for parameters.
- @return {Function} sorter for parameters
- /
this.getSorter = function
{
var thisCite = this; // Make closure work as intended.
// Sorter uses paramSortKey first, then falls back on alphabetical order.
return function(paramA, paramB)
{
var aInd = thisCite.getSortIndex(paramA);
var bInd = thisCite.getSortIndex(paramB);
if(aInd != -1 && bInd != -1)
{
return aInd - bInd;
}
else
{
proveit.log('Parameter missing from getSortIndex, which causes the sort to be invalid. paramA: ', paramA, ', aInd: ', aInd, ', paramB: ', paramB, ', bInd: ', bInd);
if(paramA < paramB)
{
return -1;
}
else if(paramA == paramB)
{
return 0;
}
else
{
return 1;
}
}
};
};  
/**
- Returns true if this reference is valid, false otherwise.
- Assume all AbstractReference objects are valid. Can be overridden in subtypes.
- @return {Boolean} AbstractReference.isValid always returns true
- /
this.isValid = function{return true;};  
/**
- Generates label for reference using title, author, etc.
- @return {String} the label that was generated
- /
this.getLabel = function
{
var label = "";  
if (this.params.author)
{
label = this.params.author + "; ";
}
else if (this.params.last)
{
label = this.params.last;
if (this.params.first)
{
label += ", " + this.params.first;
}
label += "; ";
}  
if (this.params.title)
{
label += this.params.title;
}  
if(label == "")
{
var value;
for (value in this.params)
{
break;
}
if(value) // There could be no parameters
{
label = value;
}
}
return label;
};  
/**
- Gets insertion text (for edit box).
-
- TODO: Generate a regex object instead (getInsertionRegExp), so highlighting would not fail due to trivial changes (e.g. spacing).
- @param {Boolean} full If true, insert full text, otherwise ref name only
- @return {String} insertion text
- /
this.getInsertionText = function(full)
{
if(full)
{
return this.toString;
}
else
{
if(this.name)
{
return "";
return returnstring;
};  
/**
- Array of citation strings for this reference.
- @type Array
- /
this.citationStrings = [];  
/**
- Sets citationStrings to an array
- @param {Array} strings array of citation strings, not null
- /
this.setCitationStrings = function(strings)
{
this.citationStrings = strings;
};  
/**
- Gets array of citationStrings.
- @return {Array} (possibly empty) array of citation strings. Will not return null.
- /
this.getCitationStrings = function
{
return this.citationStrings;
};  
/**
- Get icon URL for reference
- @return {String} icon URL
- /
this.getIcon = function
{
return proveit.STATIC_BASE + "page_white.png";
};
},  
/**
- Constructor for CiteReference type.
- @class CiteReference
- @for proveit
- @constructor
- @extends AbstractReference
- @param {Object} argObj the argument object, with keys for each option
- /
CiteReference: function(argObj)
{
/* This is basically a fast representation of the template redirects, along with
- self-mappings.
- /
var typeNameMappings =
{
web: "web",
book: "book",
journal: "journal",
conference: "conference",
encyclopedia: "encyclopedia",
news: "news",
newsgroup: "newsgroup",
paper: "journal",
"press release": "press release",
"pressrelease": "press release",
interview: "interview",
episode: "episode",
"AV media": "AV media",
DVD: "AV media",
audio: "AV media",
"av media": "AV media",
cd: "AV media",
dvd: "AV media",
media: "AV media",
movie: "AV media",
"music video": "AV media",
video: "AV media",
visual: "AV media"
};  
// Sets the type (e.g. web for cite web), applying the mappings. This is up top because it is used in AbstractReference constructor.
this.setType = function(rawType)
{
var mappedType = typeNameMappings[rawType];
if(mappedType != null)
this.type = mappedType;
else
this.type = rawType; // Use naive type as fallback.
};  
/**
- Returns the type for display purposes, based on description messages. For example, for "AV media" it currently returns "Audiovisual work".
-
- @return {String} type for display
- /
this.getTypeForDisplay = function
{
return proveit.getDescriptions[this.type];
};  
proveit.AbstractReference.call(this, argObj);  
// TODO: Should CiteReference.getSortIndex and CitationReference.getSortIndex be merged into AbstractCitation? Less fine-grained, but simpler to maintain.
/**
- Returns the sort index for a given parameter
- @param {String} param parameter name
- @return {Number} sort index if found, otherwise -1
- /
this.getSortIndex = function(param)
{
// This is the order fields will be displayed or outputted.  
return $.inArray(param, [
"url",
"title",
"trans_title",
"encyclopedia",
"publisher",
"work",
"date",
"agency",
"accessdate",
"author",
"last",
"first",
"subject",
"subjectlink",
"inventor",
"editor",
"author2",
"last2",
"first2",
"subject2",
"subjectlink2",
"author3",
"last3",
"first3",
"subject3",
"subjectlink3",
"author4",
"last4",
"first4",
"subject4",
"author5",
"last5",
"first5",
"author6",
"last6",
"first6",
"author7",
"last7",
"first7",
"author8",
"last8",
"first8",
"author9",
"last9",
"first9",
"authorlink",
"coauthors",
"interviewer",
"cointerviewers",
"type",
"newsgroup",
"journal",
"booktitle",
"program",
"episodelink",
"series",
"serieslink",
"credits",
"network",
"station",
"callsign",
"city",
"airdate",
"began",
"ended",
"season",
"seriesno",
"number",
"minutes",
"transcript",
"transcripturl",
"people",
"year",
"month",
"article",
"contribution",
"format",
"medium",
"newspaper",
"conference",
"volume",
"edition",
"issue",
"location",
"pages",
"page",
"language",
"isbn",
"issn",
"oclc",
"doi",
"pmid",
"id",
"archiveurl",
"archivedate",
"deadurl",
"time",
"quote",
"ref"
]);
};  
/**
- Returns this reference as a string.
- @return {String} reference as string
- /
this.toString = function
{
return this.toStringInternal("cite", true);
};  
// References without these parameters will be flagged in red.
// True indicates required (null, or undefined, means not required)
var requiredParams =
{
web: { "url": true, "title": true},
book: { "title": true },
journal: { "title": true },
conference: { "title": true },
encyclopedia: { "title": true, "encyclopedia": true },
news: { "title": true, "work": true, "date": true },
newsgroup: { "title": true },
"press release" : { "title": true },