User:Theleekycauldron/Prep tools.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Theleekycauldron/Prep tools. |
// <nowiki>
preptools = async function (e){
let preppage = await get_pages(Morebits.pageNameNorm,"user|content",null,"older");
await preppage;
let preptext = preppage[0].revisions[0].slots.main.content;
e.preventDefault();
var Window = new Morebits.simpleWindow(500, 400);
Window.setTitle("The prep set's half-assed workbench (PSHAW)");
Window.addFooterLink("DYK promoter's rules", "WP:DYKSG#Rules of thumb for preparing updates");
var form = new Morebits.quickForm();
function show(){
result = form.render();
Window.setContent(result);
Window.display();
}
async function promote(){
if (!mw.config.get('wgUserGroups').includes("sysop")){
alert("Might I suggest [[Wikipedia:Requests for adminship]] first?");
return;
}
let pqnum = preppage[0].title.slice(-1)
let queuepagetitle = "Template:Did you know/Queue/"+pqnum;
let nextpreppagetitle = "Template:Did you know/Queue/NextPrep";
form.root.childs = [];
form.append({
type: 'div',
name: 'queuemove',
label: `moving to [[${queuepagetitle}]]... `
});
form.append({
type: 'div',
name: 'prepclear',
label: `clearing [[${preppage[0].title}]]... `
});
form.append({
type: 'div',
name: 'updatecounter',
label: `updating [[Template:Did you know/Queue/NextPrep]]... `
});
show();
let clearpage = await get_pages("Template:Did you know/Clear","user|content",null,"older");
let nextpreppage = await get_pages(nextpreppagetitle,"user|content",null,"older");
let queuepage = await get_pages(queuepagetitle,"user|content",null,"older");
await clearpage;
await nextpreppage;
await queuepage
let cleartext = clearpage[0].revisions[0].slots.main.content;
let nextpreptext = nextpreppage[0].revisions[0].slots.main.content;
let queuetext = `{{DYKbotdo|~~~}}\n${preptext}`
if (queuepage[0].revisions[0].slots.main.content.length > 100){
alert("You sure that queue's empty?");
return;
}
if (nextpreptext[0] != pqnum){
alert("Promote your queues in order, I can't clean up all your messes!");
return;
}
console.log(nextpreptext[0],nextpreptext[0]%7,nextpreptext[0]%7+1,(parseInt(nextpreptext[0])%7+1).toString()+nextpreptext.slice(1));
nextpreptext = (parseInt(nextpreptext[0])%7+1).toString()+nextpreptext.slice(1);
var params = {
action: 'edit',
title: queuepagetitle, //queue
summary: `promoting from [[${preppage[0].title}|prep ${pqnum}]] ([[User:Theleekycauldron/DYK promoter|PSHAW]])`,
text: queuetext,
format: 'json'
}
api.postWithToken( 'csrf', params ).done( function ( data ) {
form.root.childs[0].data.label += 'done! :)';
console.log( data );
show();
//location.reload(true);
} );
var params = {
action: 'edit',
title: preppage[0].title,
summary: `rake to [[${queuepagetitle}|queue ${pqnum}]] ([[User:Theleekycauldron/DYK promoter|PSHAW]])`,
text: cleartext,
format: 'json'
}
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log(data);
form.root.childs[1].data.label += 'done! :)';
console.log(form.root.childs[1]);
show();
} );
var params = {
action: 'edit',
title: nextpreppagetitle,
summary: `updating counter ([[User:Theleekycauldron/DYK promoter|PSHAW]])`,
text: nextpreptext,
format: 'json'
}
api.postWithToken('csrf', params).done( function ( data ) {
console.log(data);
form.root.childs[2].data.label += 'done! :)';
console.log(form.root.childs[2]);
show();
} );
}
form.append({
type: 'div',
name: 'underdevelopment',
label: "this tool is still under development :)"
})
form.append({
type: 'button',
name: 'promoter',
label: 'Move to queue',
style: 'float: right',
event: function p(){promote()}
})
function pull_hook(slotnum){
var dykpage = new Morebits.wiki.page("Template talk:Did you know", 'Adding nomination to Template talk:Did you know'); //shamelessly stolen from SD0001
var nompage = ""
dykpage.load(function addNomToTTDYK(dykpage) {
var pageText = dykpage.getPageText();
var re = new RegExp('==Pulled nominations==\n^.*?$');
var newPageText = pageText.replace(re, '$&\n{{Template:Did you know nominations/' + nompage + '}}');
dykpage.setPageText(newPageText);
dykpage.setEditSummary(`/* Pulled nominations */ adding [[Template:Did you know nominations/${nompage}']] ([[User:Theleekycauldron/DYK promoter|PSHAW]])`);
dykpage.setMaxConflictRetries(3);
dykpage.save();
});
}
show();
}
// </nowiki>