Benutzer:J*/lib/nulledit.js: Unterschied zwischen den Versionen
< Benutzer:J* | lib
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) (+ Notify) |
J* (Diskussion | Beiträge) K (Schützte „Kamel:J*/lib/nulledit.js“ ([edit=sysop] (unbeschränkt) [move=sysop] (unbeschränkt) [protect=sysop] (unbeschränkt))) |
(kein Unterschied)
|
Aktuelle Version vom 25. November 2010, 08:59 Uhr
/*
* libnulledit
*
* do nulledits to a page or members of a category
*/
function pageNulledit(page,notify)
{
getNulleditTokens([page],notify);
}
function multipageNulledit(pages,notify)
{
getNulleditTokens(pages,notify);
}
function categoryNulledit(category,notify,cont)
{
if(!cont)
cont = "";
jQuery.ajax({
url: "/api.php",
data: {
action: "query",
list: "categorymembers",
cmtitle: category,
format: "xml",
cmcontinue: cont
},
context: {category: category, notify: notify},
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,this.notify);
var cont = $xml.find("query-continue categorymembers").attr("cmcontinue");
if (cont)
window.setTimeout(function () {categoryNulledit(category,this.notify,cont)}, 10000);
}
function getNulleditTokens(pages,notify)
{
var titlearray = [];
for(var i=0; i<pages.length; i++)
{
titlearray.push(pages[i]);
}
var titlestring = titlearray.join("|");
notify("Bereite Nulledits vor.",titlearray.length);
jQuery.ajax({
url: "/api.php",
data: {
action: "query",
prop: "info",
intoken: "edit",
titles: titlestring,
format: "xml"
},
dataType: "xml",
context: {notify: notify},
success: parseNulleditTokens
});
}
function parseNulleditTokens(xml)
{
var $xml = jQuery(xml);
var context = this;
$xml.find("api query pages page").each( function () {
var $this = jQuery(this);
var token = $this.attr("edittoken");
if(token)
{
context.notify("Führe Nulledit für "+$this.attr("title")+" durch.", 0);
doNulledit($this.attr("title"),token,context.notify);
}
else
context.notify("Kein valides Token für "+ $this.attr("title"), -1);
})
}
function doNulledit(page,token,notify)
{
jQuery.ajax({
url: "/api.php",
type: "POST",
data: {
action: "edit",
appendtext: "",
token: token,
title: page,
nocreate: "1",
format: "xml"
},
dataType: "xml",
context: {notify: notify},
success: reportNulledit
});
}
function reportNulledit(xml)
{
this.notify("Ok.",-1);
}
//var count = 0
//pageNulledit(wgPageName, function (a,b) { count += b; console.log([a,count]); } );
//categoryNulledit(wgPageName, function (a,b) { count += b; console.log([a,count]); } );