User:ExtorcDev/rmMaster.js

//<nowiki>
$('<br><button class="closeButton">Close</button><button class="relistButton">Relist</button>').insertBefore('.tmbox-move');
$('<button class="rmTechButton">Raise Technical Move request</button>').insertBefore('.mw-archivedtalk');

var url = window.location.href.match(/Talk.*$/gm).toString().replace(/_/g, ' ');
if(url.match(/#/gm)){
	url = url.toString().replace(/#.*$/gm,'');
}
console.log(url);
$('.closeButton').click(function(){
	queryPage(function(result){
		sectionLog = result.split("==");
		for(let i = 0; i < sectionLog.length; i++){
			if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
				var section = sectionLog[i+1];
				section = section + '\n{{subst:RM bottom}}\n';
				var closeMSG = window.prompt("Close Message : ");
				var updatedSection;
				if(section.match(/multiple=yes/gm)){
					updatedSection = section.replace(/{{requested move.*multiple=yes\n.*/g,'{{subst:RM top|' + closeMSG + '|nac=yes}}');
				}
				else{
					updatedSection = section.replace(/{{requested move.*/g,'{{subst:RM top|' + closeMSG + '|nac=yes}}');
				}
				result = result.replace(sectionLog[i+1], updatedSection);
				console.log(result);
				editPage(url, result, 'Closed');
			}
		}	
	});
});

$('.relistButton').click(function(){
	console.log("Relisted");
	queryPage(function(result){
		sectionLog = result.split("==");
		for(let i = 0; i < sectionLog.length; i++){
			if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
				var section = sectionLog[i+1];
				console.log(section);
				if(section.match(/'''''Relisting.*>/gm)){
					console.log('Already relisted atleast once');
					var prevRelists = section.match(/'''''Relisting.*>/);
					var newRelists = prevRelists + '{{subst:relisting}}';
					var updatedSection = section.replace(prevRelists, newRelists);
					result = result.replace(section, updatedSection);
					console.log(result);
					editPage(url, result, 'Relisted');
				}
				else{
					var updatedSection = section.replace(section.match(/.UTC./m),'(UTC){{subst:relisting}}');
					result = result.replace(section, updatedSection);
					console.log(result);
					editPage(url, result, 'Relisted');
				}
			}
		}
	});
});

$('.rmTechButton').click(function(){
	queryPage(function(result){
		sectionLog = result.split("==");
		for(let i = 0; i < sectionLog.length; i++){
			if(sectionLog[i].match(/Requested move \d/gm)){
				var section = sectionLog[i+1];
				var moveFrom = window.prompt("Enter Move Source : ");
				var moveTo = window.prompt("Enter Move Destination : ");
				var reason = window.prompt("Request reason : ");
				var techReq = '{{subst:RMassist|'+ moveFrom +'|' + moveTo + '|reason=' + reason + '}}';
				
				var api2 = new mw.Api();
				api2.get( queryParams('Wikipedia:Requested moves/Technical requests') ).done( function ( data ) {
				    var page2;
					for (page2 in data.query.pages){
						result2 = data.query.pages[page2].revisions[0]['*'];
						var newMatch = result2.match(/=.* U.*\n.*>\n.*\n.*\n.*/gm).toString() + '\n' + techReq;
						console.log(newMatch);
						result2 = result2.replace(/=.* U.*\n.*>\n.*\n.*\n.*/gm, newMatch);
						console.log(result2);
						editPage('Wikipedia:Requested moves/Technical requests', result2, 'Raised Technical Request');
					}
				});
			}
		}	
	});
});

function editPage( loc , result , action) {
	var api2 = new mw.Api();
	api2.postWithToken("csrf", editParams(loc, result, action) ).done(function( data ) {
		alert( 'Page edited!' );
	} ).fail( function(code, data) {
		console.log( api.getErrorMessage( data ).text());
	} );
}

function queryParams(loc){ return { action: 'query', prop: 'revisions', rvprop: 'content', rvlimit: 1, titles: loc }; }
function editParams(loc, content, action){ return { action: 'edit', title: loc, text: content, summary: action + ' Request using [[User:ExtorcDev/rmMaster.js|rmMaster]]' }; }
function queryPage(onQuery){
	var api = new mw.Api();
	api.get( queryParams(url) ).done( function ( data ) {
	    var page;
		for (page in data.query.pages){
			result = data.query.pages[page].revisions[0]['*'];
			onQuery(result);
		}
	});
}
//</nowiki>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.