Benutzer:J*/lib/nulledit.js: Unterschied zwischen den Versionen
< Benutzer:J* | lib
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) (AZ: Die Seite wurde neu angelegt.) |
J* (Diskussion | Beiträge) |
||
Zeile 8: | Zeile 8: | ||
function pageNulledit(page) | function pageNulledit(page) | ||
{ | { | ||
− | + | getNulleditTokens([page]); | |
+ | } | ||
+ | |||
+ | function multipageNulledit(pages) | ||
+ | { | ||
+ | getNulleditTokens(pages); | ||
} | } | ||
function categoryNulledit(category,cont) | 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) | function parseCategoryNulleditMembers(xml) | ||
{ | { | ||
− | + | var $xml = jQuery(xml); | |
− | + | var category = this.category; | |
− | + | var $members = $xml.find("api query categorymembers cm"); | |
− | + | $members.each( function () { | |
− | + | $this = jQuery(this); | |
− | + | title = $this.attr("title"); | |
− | + | console.log(title); | |
− | + | }); | |
− | + | var cont = $xml.find("query-continue categorymembers").attr("cmcontinue"); | |
− | + | if (cont) | |
− | + | window.setTimeout(function () {categoryNulledit(category,cont)}, 2000); | |
} | } | ||
function getNulleditTokens(pages) | function getNulleditTokens(pages) | ||
{ | { | ||
− | + | var titlearray = []; | |
+ | for(var i=0; i<pages.length; i++) | ||
+ | { | ||
+ | titlearray.push(encodeURIComponent(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) | function parseNulleditTokens(xml) | ||
{ | { | ||
− | + | var $xml = jQuery(xml); | |
+ | $xml.find("api query pages page").each( function () { | ||
+ | var $this = jQuery(this); | ||
+ | doNulledit($this.attr("title"),$this.attr("edittoken")); | ||
+ | }) | ||
} | } | ||
function doNulledit(page,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("Kategorie:Commons: Kamel"); | //categoryNulledit("Kategorie:Commons: Kamel"); | ||
− | + | pageNulledit("Hauptseite") |
Version vom 24. November 2010, 23:29 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");
$members.each( function () {
$this = jQuery(this);
title = $this.attr("title");
console.log(title);
});
var cont = $xml.find("query-continue categorymembers").attr("cmcontinue");
if (cont)
window.setTimeout(function () {categoryNulledit(category,cont)}, 2000);
}
function getNulleditTokens(pages)
{
var titlearray = [];
for(var i=0; i<pages.length; i++)
{
titlearray.push(encodeURIComponent(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);
doNulledit($this.attr("title"),$this.attr("edittoken"));
})
}
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("Kategorie:Commons: Kamel");
pageNulledit("Hauptseite")