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) (+ Notify) |
||
Zeile 6: | Zeile 6: | ||
− | function pageNulledit(page) | + | function pageNulledit(page,notify) |
{ | { | ||
− | getNulleditTokens([page]); | + | getNulleditTokens([page],notify); |
} | } | ||
− | function multipageNulledit(pages) | + | function multipageNulledit(pages,notify) |
{ | { | ||
− | getNulleditTokens(pages); | + | getNulleditTokens(pages,notify); |
} | } | ||
− | function categoryNulledit(category,cont) | + | function categoryNulledit(category,notify,cont) |
{ | { | ||
if(!cont) | if(!cont) | ||
Zeile 30: | Zeile 30: | ||
cmcontinue: cont | cmcontinue: cont | ||
}, | }, | ||
− | context: {category: category}, | + | context: {category: category, notify: notify}, |
dataType: "xml", | dataType: "xml", | ||
success: parseCategoryNulleditMembers | success: parseCategoryNulleditMembers | ||
Zeile 49: | Zeile 49: | ||
titles.push(title); | titles.push(title); | ||
}); | }); | ||
− | multipageNulledit(titles); | + | multipageNulledit(titles,this.notify); |
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)}, 10000); | + | window.setTimeout(function () {categoryNulledit(category,this.notify,cont)}, 10000); |
} | } | ||
− | function getNulleditTokens(pages) | + | function getNulleditTokens(pages,notify) |
{ | { | ||
var titlearray = []; | var titlearray = []; | ||
Zeile 64: | Zeile 64: | ||
} | } | ||
var titlestring = titlearray.join("|"); | var titlestring = titlearray.join("|"); | ||
+ | |||
+ | notify("Bereite Nulledits vor.",titlearray.length); | ||
jQuery.ajax({ | jQuery.ajax({ | ||
Zeile 75: | Zeile 77: | ||
}, | }, | ||
dataType: "xml", | dataType: "xml", | ||
+ | context: {notify: notify}, | ||
success: parseNulleditTokens | success: parseNulleditTokens | ||
}); | }); | ||
Zeile 83: | Zeile 86: | ||
{ | { | ||
var $xml = jQuery(xml); | var $xml = jQuery(xml); | ||
+ | var context = this; | ||
$xml.find("api query pages page").each( function () { | $xml.find("api query pages page").each( function () { | ||
var $this = jQuery(this); | var $this = jQuery(this); | ||
var token = $this.attr("edittoken"); | var token = $this.attr("edittoken"); | ||
if(token) | if(token) | ||
− | doNulledit($this.attr("title"),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) | + | function doNulledit(page,token,notify) |
{ | { | ||
− | |||
− | |||
jQuery.ajax({ | jQuery.ajax({ | ||
url: "/api.php", | url: "/api.php", | ||
Zeile 107: | Zeile 114: | ||
}, | }, | ||
dataType: "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]); } ); |
Version vom 25. November 2010, 00:12 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]); } );