credits: "Tekijät",
network: "Verkko",
station: "Asema",
airdate: "Lähetyspäivä",
began: "Aloituspäivä",
ended: "Lopetuspäivä",
season: "Kauden numero",
seriesno: "Kauden numero",
number: "Numero",
minutes: "Minuutit",
transcript: "Puhtaaksi kirjoitettu teksti",
transcripturl: "Puhtaaksikirjoitetun osoite",
video: "Video",
people: "Ihmiset",
medium: "Tuotantomedia",
language: "Kieli",
time: "Aika",
oclc: "OCLC",
ref: "Ankkurin ID-tunnus"
}
},  
/**
- Optional preference to specify default date format for new references.
- If set, it overrides the general date preference from Special:Preferences.
-
- @type {String} supported date format string
- /
dateFormatString: null,  
/**
- Singleton used to format dates according to user preference
-
- @type DateFormatter
- /
dateFormatter: null,  
/**
- Gets the effective preference for date format. If there is no ProveIt-specific
- preference already at proveit.dateFormatString, it will determine the correct preference
- from MW user preferences. Then, it will store that value to proveit.dateFormatString
-
- @return {String} format string to use for dates
- /
getDatePreference: function {
if (this.dateFormatString === null) {
this.dateFormatString = mw.user.options.get('date');
}  
return this.dateFormatString;
},  
/**
- Returns descriptions for the current language.
- @return {Object} descriptions
- /
getDescriptions: function
{
//this could be made Cite-specific if needed.
return this.descriptions[proveit.LANG];
},  
/**
- String added to logs for easy search
- @type String
- /
LOG_MARKER: "[ProveIt] ",  
/**
- Convenience log function
- @param {...Object} var_args objects (including strings) to log
- /
log: function
{
var args = Array.prototype.slice.call(arguments);
args.unshift(this.LOG_MARKER);
mw.log.apply(mw, args);
},  
/**
- Log error object if possible, using error (preferable), or log, if available.
- @param {Error} ex error object
- /
logException: function(ex)
{
var args = [ex, ex.stack];
if(typeof(console) === "object" && $.isFunction(console.error))
{
args.unshift(this.LOG_MARKER);
console.error.apply(null, args);
}
else
{
this.log.apply(this, args);
}
},  
/**
- Returns true if the page has an edit box
-
- @return {Boolean} true if the page has an edit box, false otherwise
- /
isEditPage: function
{
return mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit';
},  
/**
- Returns true if the page is likely to contain references
- @return {Boolean} true if page is supported, false otherwise
- /
isSupportedPage: function
{
// "Regular" article, userspace, or Wikipedia:Sandbox (exception for testing).
return (mw.config.get('wgCanonicalNamespace') == '' || mw.config.get('wgCanonicalNamespace') == 'User' || mw.config.get('wgPageName') == 'Wikipedia:Sandbox');
},  
/**
- Convenience function. Returns the refbox element.
- @return {$Node} reference box
- /
getRefBox: function
{
return $("#refs");
},  
/**
- Provides the x and y (top) offsets to a given element. From QuirksMode (http://www.quirksmode.org/js/findpos.html), a freely available site by Peter-Paul Koch
- @param {Node} node any HTML node
- @return {Object} offsets to node, as object with and top properties.
- /
getPosition: function(node)
{
var = 0, top = 0;
do
{
+= node.offsetLeft;
top += node.offsetTop;
} while (node = node.offsetParent);
return {"": , "top": top};
},  
/**
- Highlights a given length of text, at a particular index.
- @param {Number} startInd start index in Wikipedia edit box
- @param {Number} length length of string to highlight
- @return {Boolean} always true
- /
highlightLengthAtIndex: function(startInd, length)
{
if(startInd < 0 || length < 0)
{
this.log("highlightStringAtIndex: invalid negative arguments");
}
var box = this.getMWEditBox;
var origText = box.value;
var editTop = this.getPosition(box).top;
box.value = origText.substring(0, startInd);
box.focus;
box.scrollTop = 1000000; //Larger than any real textarea (hopefully)
var curScrollTop = box.scrollTop;
box.value += origText.substring(startInd);
if(curScrollTop > 0)
{
box.scrollTop = curScrollTop + this.HALF_EDIT_BOX_HEIGHT;
}
$(box).focus.textSelection('setSelection',
{
start: startInd,
end: startInd + length
});
editTop = this.getPosition(box).top;
window.scroll(0, editTop);
return true;
},  
/**
- Highlights the first instance of a given string in the MediaWiki edit box.
- @param {String} targetStr the string in the edit box to highlight
- @return {Boolean} true if successful, false otherwise
- /
highlightTargetString: function(targetStr)
{
var origText = this.getMWEditValue;
var startInd = origText.indexOf(targetStr);
if(startInd == -1)
{
this.log("Target string \"" + targetStr + "\" not found.");
return false;
}
return this.highlightLengthAtIndex(startInd, targetStr.length);
},  
/**
- Convenience function. Returns the raw MediaWiki textarea element.
- @return {Node} the edit box element
- /
getMWEditBox: function
{
return $("#wpTextbox1")[0];
},  
/**
- Provides value of edit box with CR normalization
-
- @return {String} value of edit box with CRs stripped if document.selection exists
- /
getMWEditValue: function
{
var box = this.getMWEditBox;
var value = box.value;
if(!box.selectionStart && document.selection) // IE 8-like behavior
{
value = value.replace(/\r\n/g, "\n");
}
return value;
},  
/**
- Returns raw edit form element, which contains MWEditBox, among other things.
- @return {Node} the edit form element
- /
getMWEditForm: function
{
return $("#editform")[0];
},  
/**
- Runs a given function on submission of edit form
- @param {Function} subFunc function to run on submission
- /
addOnsubmit: function(subFunc)
{
var form = this.getMWEditForm;
if(!form)
{
throw new Error("No edit form, possibly due to protected page.");
}
form.addEventListener("submit", subFunc, false);
},  
/**
- Returns the raw MW edit summary element
- @return {Node} the edit summary element
- /
getEditSummary: function
{
return $("#wpSummary")[0];
},  
/**
- Keep track of whether we have already added an onsubmit function to include ProveIt in the summary.
- This guarantees the function will not be run twice.
- @type Boolean
- /
summaryFunctionAdded: false,  
/**
- Does the user want us to ever add "Edited by ProveIt" summary?
- @type Boolean
- /
shouldAddSummary: true,  
/**
- ProveIt should be visible on load (rather than requiring toolbar button click) on supported edit pages
- @type Boolean
- /
loadVisible: true,  
/**
- Maximize ProveIt when it first becomes visible. If false, it will start minimized. This has no effect on when it becomes visible.
- @type Boolean
- /
loadMaximized: false,  
/**
- Specifies to include ProveIt edit summary on next save.
- Can be disabled by modifying shouldAddSummary
- /
includeProveItEditSummary: function
{
if(this.shouldAddSummary && !this.summaryFunctionAdded)
{
try
{
var thisproveit = this;
this.addOnsubmit(function
{
var summary = thisproveit.getEditSummary;  
if(summary.value.indexOf("ProveIt") == -1)
{
summary.value += " (edited with ProveIt)";
}
});
this.summaryFunctionAdded = true;
}
catch(e)
{
this.log("Failed to add onsubmit handler. e.message: " + e.message);
}
}
},  
/**
- Setup button so users can load ProveIt on demand
- /
setupButton: function
{
var $box = $(this.getMWEditBox);  
// Ensures wikiEditor is loaded
$box.on('wikiEditor-toolbar-buildSection-main', function(event, section)
{
delete section.groups.insert.tools.reference;  
section.groups.insert.tools.proveit = {
label: 'ProveIt',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons//1/19/ProveIt_logo_for_user_boxes.svg/-ProveIt_logo_for_user_boxes.svg.png',
action: {
type: 'callback',
execute: function
{
proveit.toggleVisibility;
}
}
};
});
},  
/**
- Sets up ProveIt if we're on an edit page. This includes setting up the toolbar button. Depending on configuration and the current page, it may also call load to show ProveIt.
- /
setup: function
{
if(this.isEditPage)
{
if(this.loadVisible && this.isSupportedPage)
{
this.load;
}