Benutzer:J*/lib/nulledit.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Zeile 4: Zeile 4:
 
  * do nulledits to a page or members of a category
 
  * do nulledits to a page or members of a category
 
  */
 
  */
 
+
 
+
 
function pageNulledit(page)
 
function pageNulledit(page)
 
{
 
{
 
     getNulleditTokens([page]);
 
     getNulleditTokens([page]);
 
}
 
}
 
+
 
function multipageNulledit(pages)
 
function multipageNulledit(pages)
 
{
 
{
 
     getNulleditTokens(pages);
 
     getNulleditTokens(pages);
 
}
 
}
 
+
 
function categoryNulledit(category,cont)
 
function categoryNulledit(category,cont)
 
{
 
{
 
if(!cont)
 
if(!cont)
 
cont = "";
 
cont = "";
 
+
 
jQuery.ajax({
 
jQuery.ajax({
 
url: "/api.php",
 
url: "/api.php",
Zeile 35: Zeile 35:
 
});
 
});
 
}
 
}
 
+
 
function parseCategoryNulleditMembers(xml)
 
function parseCategoryNulleditMembers(xml)
 
{
 
{
 
var $xml = jQuery(xml);
 
var $xml = jQuery(xml);
 
var category = this.category;
 
var category = this.category;
 
+
 
var $members = $xml.find("api query categorymembers cm");
 
var $members = $xml.find("api query categorymembers cm");
 
+
 +
        var titles = [];
 
$members.each( function () {
 
$members.each( function () {
 
$this = jQuery(this);
 
$this = jQuery(this);
 
title = $this.attr("title");
 
title = $this.attr("title");
console.log(title);
+
titles.push(title);
 
});
 
});
 
+
        multipageNulledit(titles);
 +
 
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)}, 2000);
+
window.setTimeout(function () {categoryNulledit(category,cont)}, 5000);
 
}
 
}
 
+
 
function getNulleditTokens(pages)
 
function getNulleditTokens(pages)
 
{
 
{
Zeile 59: Zeile 61:
 
for(var i=0; i<pages.length; i++)
 
for(var i=0; i<pages.length; i++)
 
{
 
{
titlearray.push(encodeURIComponent(pages[i]));
+
titlearray.push(pages[i]);
 
}
 
}
 
var titlestring = titlearray.join("|");
 
var titlestring = titlearray.join("|");
 
+
 
jQuery.ajax({
 
jQuery.ajax({
 
url: "/api.php",
 
url: "/api.php",
Zeile 75: Zeile 77:
 
success: parseNulleditTokens
 
success: parseNulleditTokens
 
});
 
});
 
+
 
}
 
}
 
+
 
function parseNulleditTokens(xml)
 
function parseNulleditTokens(xml)
 
{
 
{
Zeile 83: Zeile 85:
 
$xml.find("api query pages page").each( function () {
 
$xml.find("api query pages page").each( function () {
 
var $this = jQuery(this);
 
var $this = jQuery(this);
doNulledit($this.attr("title"),$this.attr("edittoken"));
+
                var token = $this.attr("edittoken");
 +
                if(token)
 +
        doNulledit($this.attr("title"),token);
 
})
 
})
 
}
 
}
 
+
 
function doNulledit(page,token)
 
function doNulledit(page,token)
 
{
 
{
 
console.log([page,token]);
 
console.log([page,token]);
 
+
 
jQuery.ajax({
 
jQuery.ajax({
 
url: "/api.php",
 
url: "/api.php",
Zeile 105: Zeile 109:
 
});
 
});
 
}
 
}
 
+
//categoryNulledit("Kategorie:Commons: Kamel");
+
//categoryNulledit(wgPageName);
pageNulledit("Hauptseite")
+
//pageNulledit(wgPageName);

Version vom 24. November 2010, 23:42 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)}, 5000);
}
 
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);