มีเดียวิกิ:RefToolbarLegacy.js

//'+
+
+
+
+
+
+
+
'\
\
\
\
\
';
document.getElementById('editform').insertBefore(citeselect, document.getElementById('editform').firstChild ) ;
}
var reftoolformarea = document.createElement( 'span' );
reftoolformarea.id = 'refToolFormArea';
$("#citeselect").append( reftoolformarea );
}
if (typeof EditTools == "object") {
var placeholder = document.getElementById("editpage-specialchars");
EditTools.createEditTools (placeholder);
}
}
function addOption(script, text) {
var option = document.createElement('input');
option.setAttribute('type', 'button');
option.setAttribute('onclick', script);
option.setAttribute("value", text);
return option;
}
function hideInitial() {
document.getElementById('citeselect').style.display = 'none';
oldFormHide();
}
function oldFormHide() {
//if (numforms != 0) {
//  document.getElementById('citediv'+numforms).style.display = 'none';
//}
document.getElementById('refToolFormArea').innerHTML = ;
if (document.getElementById('errorform') !== null) {
document.getElementById('citeselect').removeChild(document.getElementById('errorform'));
}
}
function showMore() {
	document.getElementById('citemore').style.display = ;
}
var months = 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December';
var citeGlobalDateFormat = "  ";
function getTime() {
var datestr = ;
if (citeUserDateFormat) {
datestr = citeUserDateFormat;
} else {
datestr = citeGlobalDateFormat;
}
var DT = new Date();
var zmonth = ;
var month = DT.getUTCMonth()+1;
if (month ', date);
datestr = datestr.replace(, month);
datestr = datestr.replace(, zdate);
datestr = datestr.replace(, zmonth);
datestr = datestr.replace(, monthsDT.getUTCMonth());
datestr = datestr.replace(, DT.getUTCFullYear().toString());
return (datestr);
}
function lastNameToRefname() {
//Note: This only works if field 'refname' comes after field 'last', but it always does
var lastName;
var fields = document.getElementById('citediv'+numforms).getElementsByTagName('input');
for (var i=0; i'+
+legend++
+
+
' URL: '+
+
' Title: '+
+
' Last name: '+
+
' First name: '+
+
' Coauthors: '+
+
' Publication date: '+
+
' ' + ((template == 'cite news') ? 'Newspaper' : 'Work') + ': '+
+
' Publisher: '+
+
' Pages: '+
+
' Language: '+
+
' Access date: '+
+
' Location: '+
;
if (template == 'cite web') {
form += ' Archive URL: '+
+
' Archive date: '+
;
}
form += ' Reference name: '+
+
+
' '+
	'  \
	'+
'Vertical form'+
'Template documentation'+
;
document.getElementById('refToolFormArea').innerHTML = form;
}
function citeBook() {
oldFormHide();
var template = "cite book";
numforms++;
var form = +
'Cite book source';
form += ' \
	Title:  \
	';
for (var i=1;i \
		Author'+i_str+' last name:  \
		 \
		 first name:  \
		 \
		 Authorlink:  \
		 \
		 \
		 \
		';
}
form += 'Coauthors:  \
	 \
	 Editor:  \
	 \
	 Others:  \
	 \
	 \
	 \
	Publisher:  \
	 \
	 Location:  \
	 \
	\
	Publication date or year:  \
	 \
	dmy \
	md, y \
	y-m-d \
	 \
	 Edition:  \
	 \
	\
	Series:  \
	 \
	 Volume:  \
	 \
	\
	Page number(s): \
	 \
	 Chapter:  \
	 \
	\
	ISBN:  \
	 \
	 Language:  \
	 \
	\
	URL:  \
	 \
	 Access date: \
	 \
	\
	Other fields: \
	 \
	 Ref name:  \
	 \
	 \
	 \
	\
	\{\{cite book}} doc \
	\{\{citation}} doc \
	plain wikicode (experimental) \
	Vertical form \
	Extra parameters \
	 \
	 \
	 \
	\
	';
document.getElementById('refToolFormArea').innerHTML = form;
}
function citeJournal() {
oldFormHide();
var template = "cite journal";
numforms++;
var form = +
'Cite journal'+
+
+
' Last name: '+
+
' First name: '+
+
' Coauthors: '+
+
' Publication date: '+
+
' Title: '+
+
' Journal: '+
+
' Publisher: '+
+
' Location: '+
+
' Volume: '+
+
' Issue: '+
+
' Pages: '+
+
' ISSN: '+
+
' OCLC: '+
+
' DOI: '+
+
' PMID: '+
+
' Quote: '+
+
' URL: '+
+
' Access date: '+
+
' Language: '+
+
' Reference name: '+
+
+
+
	'  \
	'+
'Vertical form'+
'Template documentation'+
;
document.getElementById('refToolFormArea').innerHTML = form;
}
function citeEncyclopedia() {
oldFormHide();
var template = "cite encyclopedia";
numforms++;
var form = +
'Cite encyclopedia source'+
+
+
' Last name: '+
+
' First name: '+
+
' Coauthors: '+
+
' Editors: '+
+
' Entry title: '+
+
' Encyclopedia: '+
+
' Publisher: '+
+
' Location: '+
+
' Year: '+
+
' Volume: '+
+
' Pages: '+
+
' ISBN: '+
+
' URL: '+
+
' Access date: '+
+
' Language: '+
+
' Reference name: '+
+
+
+
	'  \
	'+
'Vertical form'+
'Template documentation'+
;
document.getElementById('refToolFormArea').innerHTML = form;
}
function citePressRelease() {
oldFormHide();
var template = "cite press release";
numforms++;
var form = +
'Cite press release'+
+
+
' Title: '+
+
' Publisher: '+
+
' Date: '+
+
' Language: '+
+
' URL: '+
+
' Access date: '+
+
' Reference name: '+
+
+
+
	'  \
	'+
'Vertical form'+
'Template documentation'+
;
document.getElementById('refToolFormArea').innerHTML = form;
}
function citeMap() {
oldFormHide();
var template = "cite map";
numforms++;
var form = +
'Cite map'+
+
+
' Publisher: '+
+
' Title: '+
+
' URL: '+
+
' Access date: '+
+
' Edition: '+
+
' Date or year: '+
+
' Cartography: '+
+
' Scale: '+
+
' Series: '+
+
' Page: '+
+
' Section: '+
+
' Inset: '+
+
' ISBN: '+
+
' Reference name: '+
+
+
+
	'  \
	'+
'Vertical form'+
'Template documentation'+
;
document.getElementById('refToolFormArea').innerHTML = form;
}
function showRefSectionOptions() {
oldFormHide();
var template = "cite encyclopedia";
numforms++;
var form = +
'Add references section\
	Headline:\
	== References == \
	== Notes == \
	Type: \
	 \
	\{\{Reflist}} \
	\{\{Reflist|2}} \
	List-defined references (Info 1, Info 2)\
'+
;
document.getElementById('refToolFormArea').innerHTML = form;
}
function makeCiteCode() {
cites = document.getElementById('citediv'+numforms).getElementsByTagName('input');
var template = ;
var citebegin = '\{\{' + citevalue;
template = citevalue;
}
else {
if (citeid === "pages") {
if (citevalue.match(/^\w+$/) && template != 'cite encyclopedia') {
citeid = "page";    //Use page= instead of pages= if only one page. Makes p. 5 instead of pp. 5.
}
else {
citevalue = citevalue.replace(/-/g, "–");    //Replace hyphens with en dashes WP:ENDASH
}
}
else if (citeid == "date" && citevalue.match(/^\d\d\d\d$/)) {
citeid = "year";  // Use year= instead of date= if only the year is specified
}
citeinner += "|" + citeid + "=" + citevalue;
}
}
}
cite = citebegin + citename + citeinner + "}}";
return cite;
}
function addcites(template) {
var cite = makeCiteCode();
$("#wpTextbox1").focus();
mw.toolbar.insertTags(cite, , );
//document.getElementById('citediv'+numforms).style.display = 'none';
oldFormHide();
}
function addRefSection() {
	var wikicode = "\n";
	if (document.getElementById('references').checked) {
		wikicode += "== References ==\n";
	}
	else if (document.getElementById('notes').checked) {
		wikicode += "== Notes ==\n";
	}
	else {alert('No headline selected!');}
	
	if (document.getElementById('type-references').checked) {
		if (document.getElementById('ldr').checked) {
			wikicode += "\n\n\n";
		}
		else {
			wikicode += "\n";
		}
	}
	else if (document.getElementById('type-reflist').checked 
document.getElementById('type-reflist2').checked) {
		var col2 = document.getElementById('type-reflist2').checked ? '|2' :  ;
		if (document.getElementById('ldr').checked) {
			wikicode += "\{\{Reflist" + col2 + "|refs=\n\n}}\n";
		}
		else {
			wikicode += "\{\{Reflist" + col2 + "}}\n";
		}
	}
	else {alert('No type selected!');}
	$("#wpTextbox1").focus();
	mw.toolbar.insertTags(wikicode, , );
	document.getElementById('citediv'+numforms).innerHTML = ;
}
function getNamedRefs(calls) {
if (typeof(wikEdUseWikEd) != 'undefined') {
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
}
}
text = document.getElementById('wpTextbox1').value;
var regex;
if (calls) {
regex = //gi //'
} else {
regex = //gi //'
}
var namedrefs = new Array();
var i=0;
var nr=true;
do {
ref = regex.exec(text);
if(ref != null){
if (ref5) {
namedrefsi = ref5;
} else if (ref3) {
namedrefsi = ref3;
} else {
namedrefsi = ref6;
}
i++;
} else {
nr=false;
}
} while (nr==true);
return namedrefs;
}
function citeNamedRef() {
var namedrefs = getNamedRefs(false);
if (namedrefs == ) {
oldFormHide();
numforms++;
var out = +
'References in textThere are no named refs (';
$("#wpTextbox1").focus();
mw.toolbar.insertTags(ref, , );
document.getElementById('citediv'+numforms).style.display = 'none';
}
function getAllRefs() {
if (typeof(wikEdUseWikEd) != 'undefined') {
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
}
}
var text = document.getElementById('wpTextbox1').value;
var regex = /((.|\n)*?)/gim //"
var allrefs = new Array();
var i=0;
var nr=true;
do {
ref = regex.exec(text);
if(ref != null){
if (ref0.search(/^\s{150}/) != -1) {
ref0 = ref0.replace(/\|(^\s)/g, "| $1");
}
ref0 = ref0.replace(//g, ">");
allrefsi = ref0;
i++;
} else {
nr=false;
}
} while (nr==true);
return allrefs;
}
function NRcallError(namedrefs, refname) {
for (var i=0; i((.|\n)*?)/gim, "$8");  //"
}
var namedrefs = getNamedRefs(false);
var errorlist = new Array();
var q=0;
var unclosed = document.getElementById('unclosed').checked;
var samecontent = document.getElementById('samecontent').checked;
var templates = document.getElementById('templates').checked;
var repeated = document.getElementById('repeated').checked;
var undef = document.getElementById('undef').checked;
for (var i=0; i/) == -1 && unclosed) {
errorlistq = +allrefsi+;
errorlistq += 'Unclosed '+
' Unclosed '+
' References with the same content'+
' References not using a citation template'+
' Multiple references with the same name'+
' Usage of undefined named references'+
+
;
document.getElementById('citeselect').innerHTML += form;
}
function doErrorCheck() {
var errors = errorCheck();
document.getElementById('citeselect').removeChild(document.getElementById('errorform'));
if (errors == 0) {
if (numforms != 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
numforms++;
out = +
'Error checkingNo errors found.';
document.getElementById('citeselect').innerHTML += out;
}
else {
if (numforms != 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
numforms++;
form = +
'Error checking'+
;
for (var i=0; i'+
;
document.getElementById('citeselect').innerHTML += form;
}
}
function makeBookCitationCode(callback) {
var cite = '\{\{';

if (document.getElementById('cite_book').checked 
document.getElementById('plain').checked) {
cite += 'cite book';
}
else if (document.getElementById('citation').checked) {
cite += 'citation';
}
else {alert('No template selected.');}

var authorcite = ;
var prevauthor = 0;
for (var i=3;i>=1;i--) {
//var author = document.getElementById('author' + i).value;
var last = document.getElementById('last' + i).value;
var first = document.getElementById('first' + i).value;
var authorlink = document.getElementById('authorlink' + i).value;
if (i==1 && !prevauthor) { i = ; }
if (/\S/.test(authorlink)) {
authorcite = '|authorlink' + i + '=' + authorlink + authorcite;
}
if (/\S/.test(last)) {
authorcite = '|last' + i + '=' + last + '|first' + i + '=' + first + authorcite;
prevauthor = 1;
}
/*else if (/\S/.test(author)) {
authorcite = '|author' + i + '=' + author + authorcite;
prevauthor = 1;
}*/
}
cite += authorcite;
var simplefields = "coauthors", "editor", "others", "title", "url", "accessdate","edition","series","volume","date","publisher","location","language","isbn","pages","chapter";
for (var i=0;i";


if (document.getElementById('plain').checked) {
var match = /^(.*?)(\{\{.*}})(.*?)$/.exec(cite);
if (match) {
var citebeg = match1;
var citemid = match2;
var citeend = match3;
citemid = citemid.replace(/cite book/, "Vancite book");
//alert(citebeg + ':::' + citemid + ':::' + citeend);
//document.getElementById('fullcite').value = 'Updating...';
var url = 'api.php?action=expandtemplates&format=xml&text=' + encodeURIComponent(citemid);
document.getElementById('progress').style.visibility = "visible";
var xmlhttpExpand = new XMLHttpRequest();
xmlhttpExpand.onreadystatechange=function() {
		if(xmlhttpExpand.readyState==4) {	  
			if(xmlhttpExpand.status==200) {
				document.getElementById('progress').style.visibility = "hidden";
				var xmlDoc=xmlhttpExpand.responseXML.documentElement;
				var expanded = xmlDoc.getElementsByTagName("expandtemplates")0.textContent;
				if (expanded == undefined) {
					expanded = xmlDoc.getElementsByTagName("expandtemplates")0.childNodes0.nodeValue;
				}
				expanded = expanded.replace(//ig, );
				expanded = expanded.replace(//ig, );
				expanded = expanded.replace(//ig, );
				expanded = expanded.replace(/\&\#32\;/ig, ' ');
				expanded = expanded.replace(/\&\#59\;/ig, ';');
				expanded = expanded.replace(/\&\#91\;/ig, );
				expanded = expanded.replace(/\&\#93\;/ig, );
				
				plaincite = citebeg + expanded + citeend;
				//alert(plaincite);
				callback(plaincite);
			}
			else
				alert('The query returned an error.');
		}
}
xmlhttpExpand.open("GET",url,true);
xmlhttpExpand.send(null);
}
else {alert('Error A1');}
}
else {
if (document.getElementById('verbose').checked) {
cite = cite.replace(/\|/g, "\n|");
}
callback(cite);
}
}
function makeCiteBook() {
makeBookCitationCode(function(cite) { 
$("#wpTextbox1").focus();
mw.toolbar.insertTags(cite, , ); 
if (!refToolDebug) { oldFormHide(); }
});
}
function formatDate(datein, dateformat) {
if (dateformat == ) {return (datein);}
datein = datein.replace(/^\s*(.*?)\s*$/, "$1");  //Trim whitespace
var year = -1;
var month = -1;
var date = -1;
var match = /^(\d\d\d\d)-(\d\d?)(-(\d\d?))?$/.exec(datein);
if(match) {
//alert(' match1=' + match1 + ' match2=#' + match2 + '# match3=' + match3 + ' match4=' + match4  );
year = parseInt(match1, 10);	//10 forces decimal conversion
month = parseInt(match2, 10);
if (match4) {
date = parseInt(match4, 10);
}
}
else if (/^\d\d? \w+ \d\d\d\d$/.test(datein) 
/^\w+ \d\d?, \d\d\d\d$/.test(datein)) {
var DT = new Date(datein);
year = DT.getFullYear();
month = DT.getMonth()+1;
date = DT.getDate();
}
else if (datein == 'today') {
var DT = new Date();
year = DT.getUTCFullYear();
month = DT.getUTCMonth()+1;
date = DT.getUTCDate();
}
else {return (datein);}
//alert('datein=' + datein + ', y=' + year + ', m=' + month + ', d=' + date);
var zmonth = ;
if (month  -1) {
if (date ', date);
datestr = datestr.replace(, month);
datestr = datestr.replace(, zdate);
datestr = datestr.replace(, zmonth);
datestr = datestr.replace(, monthsmonth-1);
datestr = datestr.replace(, year.toString());
datestr = datestr.replace(/\s+/, ' ').replace(/^\s+/, ).replace(/(\D),/, '$1').replace(/-$/, );
return (datestr);
}
function getDateFormat() {
	var dateformat = ;
	if (document.getElementById('dmy')){
		if (document.getElementById('dmy').checked) {dateformat = '  '}
		else if (document.getElementById('mdy').checked) {dateformat = ' , '}
		else if (document.getElementById('ymd').checked) {dateformat = '--'}
	}
	else if (citeUserDateFormat) {
		dateformat = citeUserDateFormat;
	} else {
		dateformat = citeGlobalDateFormat;
	}
	return (dateformat);
}
function reformatDates() {
var dateformat = getDateFormat();
//alert(':' + dateformat + ':');
document.getElementById('accessdate').value = formatDate(document.getElementById('accessdate').value, dateformat);
document.getElementById('date').value = formatDate(document.getElementById('date').value, dateformat);
//document.getElementById('dateformat_hidden').value = getDateFormatShort();
}
/*function updateGetButton() {
	document.getElementById('urlget').disabled = document.getElementById('url').value == ;
}*/
function preview(wikitext) {
document.getElementById('progress').style.visibility = "visible";
wikitext += ;
var url = "api.php?action=parse&format=xml&prop=text&text=" + encodeURIComponent(wikitext);
var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState==4) {
			if(xmlhttp.status==200) {
				document.getElementById('progress').style.visibility = "hidden";
				var xmlDoc=xmlhttp.responseXML.documentElement;
				var previewHTML = xmlDoc.getElementsByTagName("text")0.textContent;
				if (previewHTML == undefined) {
					previewHTML = xmlDoc.getElementsByTagName("text")0.childNodes0.nodeValue;
				}
				//alert(previewHTML);
				previewHTML = previewHTML.replace(/href="\//gi, 'href="//en.wikipedia.org/');
				document.getElementById('previewSpan').innerHTML = 'Citation preview' + previewHTML + ;
			}
			else
				alert('The query returned an error.');
		}
};
xmlhttp.open("GET", url, true);
xmlhttp.send(null)
}
function previewCitationBook() {
makeBookCitationCode(preview);
}
function previewCitationDefault() {
	var wikitext = makeCiteCode();
	preview(wikitext);
}
function pullJs() {
	var book_url = document.getElementById('url').value;
	if (book_url) {
		document.getElementById('progress').style.visibility = "visible";
		var book_url_enc = encodeURIComponent(book_url);
		if(!refTagURL) {refTagURL = defaultRefTagURL;}
		var baseurl = refTagURL + 'googlebooksjs.py';
		var url = baseurl + '?book_url=' + book_url_enc + '&callback=setFormValues';
		/*var script = document.createElement("script");        
		script.setAttribute("src",url);
		script.setAttribute("type","text/javascript");                
		document.body.appendChild(script);*/
		JsonRequest(url);
	}else{
		alert('No URL.');
	}
}
function pullISBN() {
	var isbn = document.getElementById('isbn').value;
	isbn = isbn.replace(/^0-9/g,"");	//Digits only
	if (isbn) {
		document.getElementById('progress').style.visibility = "visible";
		if(!refTagURL) {refTagURL = defaultRefTagURL;}
		var baseurl = refTagURL + 'getdiberri.py';
		var url = baseurl + '?isbn=' + isbn + '&callback=useDiberriData';
		/*var script = document.createElement("script");
		script.setAttribute("src",url);
		script.setAttribute("type","text/javascript");
		document.body.appendChild(script);*/
		JsonRequest(url);
	}else{
		alert('No ISBN.');
	}
}
function pullDOI() {
	var doi = document.getElementById('doi').value;
	if (doi) {
		document.getElementById('progress').style.visibility = "visible";
		if(!refTagURL) {refTagURL = defaultRefTagURL;}
		var baseurl = refTagURL + 'doifetchjs.py';
		var url = baseurl + '?doi=' + encodeURIComponent(doi) + '&callback=useDoiData';
		JsonRequest(url);
	}else{
		alert('No DOI.');
	}
}
function pullPMID() {
	alert('Not implemented yet...');
	/*var doi = document.getElementById('doi').value;
	if (doi) {
		document.getElementById('progress').style.visibility = "visible";
		if(!refTagURL) {refTagURL = defaultRefTagURL;}
		var baseurl = refTagURL + 'doifetchjs.py';
		var url = baseurl + '?doi=' + encodeURIComponent(doi) + '&callback=useDoiData';
		JsonRequest(url);
	}else{
		alert('No DOI.');
	}*/
}
function pullURL() {
	var url = document.getElementById('url').value;
	if (url) {
		document.getElementById('progress').style.visibility = "visible";
		if(!refTagURL) {refTagURL = defaultRefTagURL;}
		var baseurl = refTagURL + 'urlfetchjs.py';
		var url = baseurl + '?url=' + encodeURIComponent(url) + '&callback=useUrlData';
		JsonRequest(url);
	}else{
		alert('No URl.');
	}
}
function JsonRequest(url) {
	//mw.loader.load(url)  //Bad: does not import the same script more than once
	var script = document.createElement("script");        
	script.setAttribute("src",url);
	script.setAttribute("type","text/javascript");                
	//document.body.appendChild(script);
	document.getElementsByTagName('head')0.appendChild(script);
}
function setFormValues(bookdata) {
	document.getElementById('progress').style.visibility = "hidden";
	//alert(bookdata);
	//alert(bookdata.page);
	if (bookdata.title.length != 0) { document.getElementById('title').value = bookdata.title; }
	if (bookdata.isbn.length != 0) { document.getElementById('isbn').value = bookdata.isbn; }
	if (bookdata.publisher.length != 0) { document.getElementById('publisher').value = bookdata.publisher; }
	if (bookdata.pages.length != 0) { 
		document.getElementById('pages').value = bookdata.pages; 
		document.getElementById('pages').style.backgroundColor = '#FFFF99';
	}
	if (bookdata.url.length != 0) { document.getElementById('url').value = bookdata.url; }
	if (bookdata.date.length != 0) { document.getElementById('date').value = bookdata.date; }
	for (var i=0;i