/*<nowiki>
Copyright (c) 2023 theleekycauldron
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
$.when(
mw.loader.using('ext.gadget.morebits'),
$.ready
).then(async function() {
console.log("queuer ready!");
if (mw.config.get('wgPageName').includes("Template:Did_you_know/Preparation_area")) {
$(mw.util.addPortletLink(window.DYKH_portlet || 'p-cactions', '#', 'Move to queue (PSHAW)', 'dyk-portlet')).click(moveToQueue);
}
});
moveToQueue = async function (e){
let prep = await Prep.create(mw.config.get('wgPageName'))
e.preventDefault();
var Window = new Morebits.simpleWindow(480, 270);
Window.setTitle("The prep set's half-assed workbench (PSHAW)");
Window.addFooterLink("Prep builder instructions", "Wikipedia:Did you know/Prep builder instructions");
Window.addFooterLink("Admin instructions", "Wikipedia:Did you know/Admin instructions");
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 ] first?");
return;
}
let pqnum = prep.title.slice(-1);
let queue = await Prep.create("Template:Did you know/Queue/"+pqnum);
let nextpreppagetitle = "Template:Did you know/Queue/NextPrep";
console.log(prep);
console.log(queue);
form.root.childs = ;
form.append({
type: 'div',
name: 'queuemove',
label: `moving to ]... `
});
form.append({
type: 'div',
name: 'prepclear',
label: `clearing ]... `
});
form.append({
type: 'div',
name: 'updatecounter',
label: `updating ]... `
});
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");
await clearpage;
await nextpreppage;
let cleartext = clearpage.revisions.slots.main.content;
let nextpreptext = nextpreppage.revisions.slots.main.content;
queue.content = `{{DYKbotdo|~~~}}\n${prep.content}`
prep.content = cleartext
if (nextpreptext != pqnum){
alert("Promote your queues in order, I can't clean up all your messes!");
return;
}
console.log(nextpreptext,nextpreptext%7,nextpreptext%7+1,(parseInt(nextpreptext)%7+1).toString()+nextpreptext.slice(1));
nextpreptext = (parseInt(nextpreptext)%7+1).toString()+nextpreptext.slice(1);
await queue.save(`promoting from ]`).done(function(data){
form.root.childs.data.label += 'done! :)';
console.log(data);
show();
});
await prep.save(`rake to ]`).done(function (data){
console.log(data);
form.root.childs.data.label += 'done! :)';
console.log(form.root.childs);
show();
});
var params = {
action: 'edit',
title: nextpreppagetitle,
summary: `updating counter`+tag,
text: nextpreptext,
format: 'json'
}
api.postWithToken('csrf', params).done( function ( data ) {
console.log(data);
form.root.childs.data.label += 'done! :)';
console.log(form.root.childs);
show();
location.replace("https://en.wikipedia.orghttps://wikines.com/en/"+queue.title);
} );
}
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 ] (])`);
dykpage.setMaxConflictRetries(3);
dykpage.save();
});
}
show();
}
// </nowiki>