Jump to content

User:Theleekycauldron/Prep tools.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <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>