Jump to content

User:Sander Säde/allest.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.
//Script to quickly get a list of all WikiProject Estonia articles
$(CollectButton);
function CollectButton() {
   addPortletLink( chooseBox( 'wpe: AllEstTest', TwinkleConfig.toolboxButtons ), "javascript:allEstTest()", "wpe: allEstTest", "", "", "");
   }
var estAjax;
var estArticles = new Array();

function allEstTest() 
{
	document.getElementById("contentSub").innerHTML = "";
	getAllEstonianArticles();
}

function getAllEstonianArticles()
{
	ajaxEstGet("http://wiki.riteme.site/w/api.php?action=query&list=categorymembers&cmtitle=Category:WikiProject_Estonia_articles&cmlimit=500&cmnamespace=1&cmprop=title&format=json");
}

function ajaxEstGet(url) {
	estAjax = sajax_init_object(null);
	estAjax.onreadystatechange = ajaxEstGetReceived;
	estAjax.open("GET", url, true);
	estAjax.send(null);
}

function ajaxEstGetReceived() {
 if (estAjax.readyState != 4) return;
	var response = eval('(' + estAjax.responseText + ')');
	
	for(i = 0; i < response["query"]["categorymembers"].length; i++) 
	{
		estArticles.push(response["query"]["categorymembers"][i]["title"].replace("Talk:", ""));
	}
	
	//nice progressbar
	var s = "";
	for(i = 0; i < Math.floor(estArticles.length / 30); i++)
	{
		s = s + "|";
	}
	document.getElementById("contentSub").innerHTML = s + " " + estArticles.length;
	
	if (response["query-continue"] == null) 
	{
		updateEstArticles();
		document.getElementById("contentSub").innerHTML = "Posting...";
	}
	else
	{
	document.getElementById("contentSub").innerHTML = document.getElementById("contentSub").innerHTML + " " + response["query-continue"]["categorymembers"]["cmcontinue"];
		ajaxEstGet("http://wiki.riteme.site/w/api.php?action=query&list=categorymembers&cmtitle=Category:WikiProject_Estonia_articles&cmlimit=500&cmnamespace=1&cmprop=title&format=json&cmcontinue=" + response["query-continue"]["categorymembers"]["cmcontinue"]);
	}
}

function updateEstArticles() {
	var getForm = sajax_init_object(null);
	getForm.overrideMimeType('text/xml');
	getForm.open( 'GET' , 'http://wiki.riteme.site/w/index.php?title=User:Sander_S%C3%A4de/WPEarticles&action=submit', true);
	getForm.onreadystatechange = function() {
		if(getForm.readyState != 4) return;
		doUpdateEstArticles(getForm.responseXML);
		};
	getForm.send(null)
}

function doUpdateEstArticles(pg) {
	form = pg.getElementById('editform');
	if(!form ) return;
	var text = '';
	
	for(i = 0; i < estArticles.length; i++) {
		text = text + " [[" + estArticles[i] + "]]·([[Talk:" + estArticles[i] + "|talk]]) | ";
		}
	text = estArticles.length + " articles found<br/>" + text;
	var summary = 'Updating Estonia-related articles';
	var postData = {
		'wpMinoredit': form.wpMinoredit.checked, 'wpWatchthis': form.wpWatchthis.checked, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': text};
	var postFormAjax = sajax_init_object();
	postFormAjax.overrideMimeType('text/xml');
	postFormAjax.open( 'POST' , "http://wiki.riteme.site/w/index.php?title=User:Sander_S%C3%A4de/WPEarticles&action=submit", true);
	postFormAjax.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	postFormAjax.onload = function() {
		return;
		}
	postFormAjax.send( QueryString.create(postData));
	document.getElementById("contentSub").innerHTML = "Update finished. " + estArticles.length + " articles found. <br />" + QueryString.create(postData) + "<br />" + text;
}