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

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
K Schützte „Kamel:J*/lib/nulledit.js“ ([edit=sysop] (unbeschränkt) [move=sysop] (unbeschränkt) [protect=sysop] (unbeschränkt))
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
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,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)
cont = "";
cont = "";
 
jQuery.ajax({
jQuery.ajax({
url: "/api.php",
url: "/api.php",
Zeile 30: Zeile 30:
cmcontinue: cont
cmcontinue: cont
},
},
context: {category: category},
context: {category: category, notify: notify},
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");
 
        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,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)}, 2000);
window.setTimeout(function () {categoryNulledit(category,this.notify,cont)}, 10000);
}
}
 
function getNulleditTokens(pages)
function getNulleditTokens(pages,notify)
{
{
var titlearray = [];
var titlearray = [];
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("|");


        notify("Bereite Nulledits vor.",titlearray.length);
jQuery.ajax({
jQuery.ajax({
url: "/api.php",
url: "/api.php",
Zeile 73: Zeile 77:
},
},
dataType: "xml",
dataType: "xml",
context: {notify: notify},
success: parseNulleditTokens
success: parseNulleditTokens
});
});
 
}
}
 
function parseNulleditTokens(xml)
function parseNulleditTokens(xml)
{
{
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);
doNulledit($this.attr("title"),$this.attr("edittoken"));
                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)
function doNulledit(page,token,notify)
{
{
console.log([page,token]);
jQuery.ajax({
jQuery.ajax({
url: "/api.php",
url: "/api.php",
Zeile 103: Zeile 114:
},
},
dataType: "xml",
dataType: "xml",
context: {notify: notify},
success: reportNulledit
});
});
}
}


//categoryNulledit("Kategorie:Commons: Kamel");
function reportNulledit(xml)
pageNulledit("Hauptseite")
{
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]); } );

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]); } );