//Script to quickly get a list of all WikiProject Estonia articles
$(CollectButton);
function CollectButton() {
mw.util.addPortletLink("p-cactions", "javascript:allEst()", "wpe: allEst");
}
var estArticles = new Array();
var $content = $("#contentSub");
function allEst() {
$content.html("");
getAllEstonianArticles(null);
}
function getAllEstonianArticles(cmContinue) {
var url = cmContinue == null ?
"https://en.wikipedia.org/w/api.php?action=query&rawcontinue=&list=categorymembers&cmtitle=Category:WikiProject_Estonia_articles&cmlimit=500&cmprop=title&format=json"
: "https://en.wikipedia.org/w/api.php?action=query&rawcontinue=&list=categorymembers&cmtitle=Category:WikiProject_Estonia_articles&cmlimit=500&cmprop=title&format=json&cmcontinue=" + cmContinue;
$.ajax({
method: "GET",
dataType: "json",
url: url })
.done(function(data) {
$.each(data.query.categorymembers, function(i, v) {
estArticles.push(v.title);
});
//progressbar
$content.html(Array(Math.floor(estArticles.length / 50)).join("|") + " " + estArticles.length);
if (data == null) {
$content.html("Posting updates: " + estArticles.length);
updateEstArticles();
}
else {
var cmContinueC = data;
$content.html($content.html() + " " + cmContinueC);
getAllEstonianArticles(cmContinueC);
}
});
}
function updateEstArticles() {
var text = '';
var iPos = 0;
var article;
var prefix;
estArticles.sort();
for (i = 0; i < estArticles.length; i++) {
iPos = estArticles.indexOf(":");
prefix = estArticles.substring(0, iPos).split(" ");
if (prefix == "User") {
continue;
}
article = estArticles.substring(iPos + 1);
if (prefix == "Talk") {
article = "# ]·(])\r\n";
}
else {
article = "# ]·(])\r\n";
}
text = text + article;
}
text = estArticles.length + " articles found\r\n\r\n" + text + "\r\n\r\n]";
editPage({
title: 'Wikipedia:WikiProject Estonia/publicwatchlist',
text: text,
summary: 'Updating Estonia-related articles (' + estArticles.length + ')'
});
}
function editPage(info) {
$.ajax({
url: mw.util.wikiScript('api'),
type: 'POST',
dataType: 'json',
data: {
format: 'json',
action: 'edit',
title: info.title,
text: info.text,
summary: info.summary,
token: mw.user.tokens.get('editToken')
}
})
.complete(function() {
document.getElementById("contentSub").innerHTML = 'Update finished: ' + estArticles.length;
})
.error(function() {
alert('The AJAX edit request failed.');
});
}