Benutzer:J*/lib/nulledit.js: Unterschied zwischen den Versionen
< Benutzer:J* | lib
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) |
J* (Diskussion | Beiträge) |
||
Zeile 53: | Zeile 53: | ||
var cont = $xml.find("query-continue categorymembers").attr("cmcontinue"); | var cont = $xml.find("query-continue categorymembers").attr("cmcontinue"); | ||
if (cont) | if (cont) | ||
− | window.setTimeout(function () {categoryNulledit(category,cont)}, | + | window.setTimeout(function () {categoryNulledit(category,cont)}, 10000); |
} | } | ||
Version vom 24. November 2010, 23:43 Uhr
/*
* libnulledit
*
* do nulledits to a page or members of a category
*/
function pageNulledit(page)
{
getNulleditTokens([page]);
}
function multipageNulledit(pages)
{
getNulleditTokens(pages);
}
function categoryNulledit(category,cont)
{
if(!cont)
cont = "";
jQuery.ajax({
url: "/api.php",
data: {
action: "query",
list: "categorymembers",
cmtitle: category,
format: "xml",
cmcontinue: cont
},
context: {category: category},
dataType: "xml",
success: parseCategoryNulleditMembers
});
}
function parseCategoryNulleditMembers(xml)
{
var $xml = jQuery(xml);
var category = this.category;
var $members = $xml.find("api query categorymembers cm");
var titles = [];
$members.each( function () {
$this = jQuery(this);
title = $this.attr("title");
titles.push(title);
});
multipageNulledit(titles);
var cont = $xml.find("query-continue categorymembers").attr("cmcontinue");
if (cont)
window.setTimeout(function () {categoryNulledit(category,cont)}, 10000);
}
function getNulleditTokens(pages)
{
var titlearray = [];
for(var i=0; i<pages.length; i++)
{
titlearray.push(pages[i]);
}
var titlestring = titlearray.join("|");
jQuery.ajax({
url: "/api.php",
data: {
action: "query",
prop: "info",
intoken: "edit",
titles: titlestring,
format: "xml"
},
dataType: "xml",
success: parseNulleditTokens
});
}
function parseNulleditTokens(xml)
{
var $xml = jQuery(xml);
$xml.find("api query pages page").each( function () {
var $this = jQuery(this);
var token = $this.attr("edittoken");
if(token)
doNulledit($this.attr("title"),token);
})
}
function doNulledit(page,token)
{
console.log([page,token]);
jQuery.ajax({
url: "/api.php",
type: "POST",
data: {
action: "edit",
appendtext: "",
token: token,
title: page,
nocreate: "1",
format: "xml"
},
dataType: "xml",
});
}
//categoryNulledit(wgPageName);
//pageNulledit(wgPageName);