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

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
(AZ: Die Seite wurde neu angelegt.)
 
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)
+
if(!cont)
        cont = "";
+
cont = "";
  
    jQuery.ajax({
+
jQuery.ajax({
        url: "/api.php",
+
url: "/api.php",
        data: {
+
data: {
            action: "query",
+
action: "query",
            list: "categorymembers",
+
list: "categorymembers",
            cmtitle: category,
+
cmtitle: category,
            format: "xml",
+
format: "xml",
            cmcontinue: cont
+
cmcontinue: cont
        },
+
},
        context: {category: category},
+
context: {category: category},
        dataType: "xml",
+
dataType: "xml",
        success: parseCategoryNulleditMembers
+
success: parseCategoryNulleditMembers
    });
+
});
 
}
 
}
  
 
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");
  
    $members.each( function () {
+
$members.each( function () {
        $this = jQuery(this);
+
$this = jQuery(this);
        title = $this.attr("title");
+
title = $this.attr("title");
        console.log(title);
+
console.log(title);
    });
+
});
  
    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)}, 2000);
 
}
 
}
  
 
function getNulleditTokens(pages)
 
function getNulleditTokens(pages)
 
{
 
{
    action=query&prop=info&intoken=edit&titles=Hauptseite
+
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");
getNulleditTokens(["Hauptseite","Test"]);
+
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")