var archiveName = wgPageName + '/Archive' + 110; //+ archiveNum;
$('span.mw-headline').each(function(index, value){
var section = index;
if ($(this).parent().prop("tagName") == 'H2'){
var sectionTitle = $(this).html();
$(this).parent('h2').append('<a id="' + section + '" href="#archiverLink" class="archiverLink">' + 'Archive' + '</a>');
$(this).parent('h2').find('a.archiverLink').click(function(){
var request4 = {
action:"query",
titles: wgPageName,
prop: "revisions|info",
intoken: "edit",
rvprop: "content",
indexpageids: 1,
dataType: "xml",
format: "xml"
};
$.get(mw.config.get("wgScriptPath")+"/api.php", request4, function(response4){
var content = $(response4).find('rev').text();
var regexObject2 = new RegExp( '((^|\n)={1,5} ?.**?)\n={1,5}' , 'g');
var matches = ;
while (match = regexObject2.exec(content)) {
matches.push(match);
regexObject2.lastIndex = regexObject2.lastIndex - 5;
}
if (matches != null){
var contentMatch = matches;
//window.open("data:text/html," + encodeURIComponent(matches), "_blank", "width=200,height=100");
}
var request1 = {
action:"edit",
title: archiveName,
appendtext: contentMatch,
summary: 'adding ' + sectionTitle,
token: mw.user.tokens.get("editToken")
};
$.post(mw.config.get("wgScriptPath")+"/api.php", request1, function(response1){
var request2 = {
action:"edit",
section: section + 1,
title: wgPageName,
text: "",
summary: 'archived ' + sectionTitle,
token: mw.user.tokens.get("editToken")
};
$.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response1){
location.reload();
});
});
});
});
}
});