Nothing Special   »   [go: up one dir, main page]

User:Equazcion/OneClickArchiver.js: Difference between revisions

Content deleted Content added
No edit summary
Stop requesting inprop=edit when tokens are got from mw.user.tokens.get("csrfToken")
 
(26 intermediate revisions by 5 users not shown)
Line 1:
if ((($('#ca-addsection').length > 0) || (mw.config.get('wgPageName') == 'Wikipedia:Administrators\'_noticeboard/Edit_warring')) && (mw.config.get('wgAction') == 'view')){
$('span.mw-headline').each(function(index, value){
var editSectionUrl = $(this).parent().find('.mw-editsection a:first').attr('href');
var section = index;
var sectionReg = /&section=(.*)/;
if ($(this).parent().prop("tagName") == 'H2'){
var sectionTitlesectionRaw = $(this)sectionReg.htmlexec(editSectionUrl);
if ((sectionRaw != null) && (sectionRaw[1].indexOf('T') < 0)){
$(this).parent('h2').append(' <div style="font-size:.6em;font-weight:bold;float:right"> | <a id="' + section + '" href="#archiverLink" class="archiverLink">' + 'Archive' + '</a></div>');
var section = parseInt(sectionRaw[1]);
$(this).parent('h2').find('a.archiverLink').click(function(){
if ($(this).parent().prop("tagName") == 'H2'){
var request4 = {
action:"query",
$(this).parent('h2').append(' <div style="font-size:.6em;font-weight:bold;float:right"> | <a id="' + section +
titles: wgPageName,
'" href="#archiverLink" class="archiverLink">' + 'Archive' + '</a></div>');
rvsection: 0,
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();
$(this).parent('h2').find('a.archiverLink').click(function(){
var regexObject3 = new RegExp('\\|counter ?= ?(\\d+)');
var counter = regexObject3.exec(content);
if ((counter == null) || (typeof counter == 'undefined')){
alert("No archive counter was detected on this page, so archiving was aborted.<br />See User:Equazcion/OneClickArchiver for details.");
} else {
var archiveNum = counter[1];
var mHeaders = '<span style="color:#454545;">Retrieving headers...</span>';
var archiveNameReg = /\|archive ?= ?(.*)\%\(counter\)d/;
var archiveNameRegMatchmSection = archiveNameReg.exec('retrieving section content)...';
var mPosting = '<span style="color:#004000">Content retrieved,</span> performing edits...';
if ((archiveNameRegMatch == null) || (typeof archiveNameRegMatch == 'undefined')){
var mPosted = '<span style="color:#008000">Archive appended...</span>';
alert("No archive name was detected on this page, so archiving was aborted.<br />See User:Equazcion/OneClickArchiver for details.");
var mCleared = '<span style="color:#008000">Section cleared...</span>';
} else {
var mReloading = '<span style="color:#00008C">All done! </span>Reloading...';
var archiveName = archiveNameRegMatch[1];
$('body').append('<div class="overlay" style="background-color:#000;opacity:.4;position:fixed;' +
'top:0;left:0;width:100%;height:100%;z-index:500;"></div>');
$('body').prepend('<div class="arcProg" style="font-weight:bold;box-shadow: 7px 7px 5px #000;font-size:0.9em;line-height:1.5em;' +
var request5 = {
'z-index:501;opacity:1;position:fixed;width:50%;left:25%;top:30%;background:#F7F7F7;border:#222 ridge 1px;padding:20px;"></div>');
action:"query",
titles: wgPageName,
$('.arcProg').append('<div>' + mHeaders + '</div>');
rvsection: section + 1,
prop: "revisions|info",
intoken:var "edit",request4 = {
rvpropaction: "contentquery",
titles: mw.config.get('wgPageName'),
indexpageids: 1,
dataTypervsection: "xml"0,
formatprop: "xmlrevisions|info",
};rvprop: "content",
indexpageids: 1,
dataType: "xml",
$.get(mw.config.get("wgScriptPath")+"/api.php", request5, function(response5){
format: "xml"
var contentSection = $(response5).find('rev').text();
};
$.get(mw.config.get("wgScriptPath")+"/api.php", request4, function(response4){
var content = $(response4).find('rev').text();
var regexObject3 = new RegExp('\\|counter ?= ?(\\d+)');
var counter = regexObject3.exec(content);
if ((counter == null) || (typeof counter == 'undefined')){
$('.arcProg').remove();
$('.overlay').remove();
alert("No archive counter was detected on this page, so archiving was aborted. See User:Equazcion/OneClickArchiver for details.");
} else {
var archiveNum = counter[1];
var archiveNameReg = /(\| *archive *= *.*\%\(counter\)d.*?) *(-->)?/;
var request1 = {
var archiveNameRegMatch = archiveNameReg.exec(content);
action:"edit",
if ((archiveNameRegMatch == null) || (typeof archiveNameRegMatch == 'undefined')){
title: archiveName + archiveNum,
appendtext: contentSection, $('.arcProg').remove();
$('.overlay').remove();
summary: '[[User:Equazcion/OneClickArchiver|OneClickArchiver]] adding ' + sectionTitle,
alert("No archive name was detected on this page, so archiving was aborted. See User:Equazcion/OneClickArchiver for details.");
token: mw.user.tokens.get("editToken")
} else {
var monthNames = ["january", "february", "march", "april", "may", "june",
"july", "august", "september", "october", "november", "december"];
var shortMonthNames = ["jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec"];
var year = new Date().getFullYear();
var month = new Date().getMonth();
var archiveName = archiveNameRegMatch[1]
.replace(/\|archive ?= ?/, '')
.replace(/\%\(year\)d/g, year)
.replace(/\%\(month\)d/g, month)
.replace(/\%\(monthname\)s/g, monthNames[month])
.replace(/\%\(monthnameshort\)s/g, shortMonthNames[month])
.replace(/\%\(counter\)d/g, archiveNum);
//https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Albert_Einstein&rvprop=size&format=xml
$('.arcProg').append('<div>' + 'Archive name <span style="font-weight:normal;color:#003366;">' + archiveName +
'</span> <span style="darkgreen">found</span>, ' + mSection + '</div>');
var request5 = {
action:"query",
titles: mw.config.get('wgPageName'),
rvsection: section,
prop: "revisions",
rvprop: "content",
indexpageids: 1,
dataType: "xml",
format: "xml"
};
$.postget(mw.config.get("wgScriptPath")+"/api.php", request1request5, function(response1response5){
$('.arcProg').append('<div>' + mPosting + '</div>');
var contentSection = '\r\r' + $(response5).find('rev').text();
var request1 = {
action:"edit",
title: archiveName,
appendtext: contentSection,
summary: '[[User:Equazcion/OneClickArchiver|OneClickArchiver]] adding 1 discussion',
token: mw.user.tokens.get("csrfToken")
};
var request2 = {
action:"edit",
section: section + 1,
title: mw.config.get('wgPageName'),
text: "",
summary: '[[User:Equazcion/OneClickArchiver|OneClickArchiver]] archived 1 discussion to [[' + sectionTitlearchiveName + ']]',
token: mw.user.tokens.get("editTokencsrfToken")
};
$.when(
$.post(mw.config.get("wgScriptPath")+"/api.php", request2request1, function(response1){
$('.arcProg').append('<div class="archiverPosted">' + mPosted + '</div>'); }),
$.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
location.reload();
$('.arcProg').append('<div class="archiverCleared">' + mCleared + '</div>'); })
});
).done(function() {
$('.arcProg').append('<div>' + mReloading + '</div>');
location.reload();
});
});
});
}
});
});
});
}
});