MediaWiki:Skin/Artikelbaukasten.js

/* Artikelbaukasten */

addOnloadHook(ab_prepare);

/* globale variablen */ var ab_opts = {}; var ab_finish = null; var ab_redlinks = ""; var ab_artname = "";

function ab_entities(text) {       return jQuery(' ').text(text).html; }

function ab_prepare {	document.getElementById("Startlink").onclick = ab_init; }

function ab_init {	var temp_opts = {}; /* alle wichtigen Daten zuerst auslesen und verarbeiten */ var data = document.getElementById("data").innerHTML.replace(/&lt;br( | )*\/?&gt;/g, " ").replace(/(\r|\n|\f)+/g, "\n").split("\n"); for (line=0; line<data.length; line++) {		var elements; var struct = {}; if ( data[line].indexOf("|") == -1 ) elements = [ data[line] ]; else {			elements = data[line].split("|");

for (element=1; element<elements.length; element++) {				if ( elements[element].indexOf("=") == -1 ) continue; var pair; pair = elements[element].split("=", 2); struct[pair[0]]=pair[1].replace(/[¦]/g, "|"); }		}		switch ( elements[0] ) {			case "option": if ( temp_opts["options"] == null ) temp_opts["options"] = []; temp_opts["options"].push( struct ); break; case "flush": ab_opts[temp_opts.label.name] = temp_opts; temp_opts = new Object; break; case "comment": break; case "redlinks": ab_redlinks += ( ab_redlinks == "" ? "" : "|" ) + ( struct.names != null ? struct.names : "" ); break; default: temp_opts[elements[0]] = struct; break; }

}

/* http-request vortäuschen */ setTimeout("ab_init2", 1000); }

function ab_init2 {	/* GaGA/HW/... weg */ if ( document.getElementById("versteckdas") != null ) document.getElementById("versteckdas").style.display = "none";

jQuery("#empfohlene-seite-box").hide(0);

/* jetzt Spezial:Artikelbaukasten vortäuschen */ document.getElementById("Artikel").innerHTML=" "; document.getElementById("SuffixButtons").innerHTML = ' '+ ' '+ ''+ ' ';	ab_generate("default", "0"); ab_genWindow( "Spezial:Artikelbaukasten", "spezial" ); }

function ab_generate( labelId, optionId ) {	lastLabelObj = ab_opts[labelId];

label = lastLabelObj.options[optionId].next;

switch( lastLabelObj.options[optionId].action ) {		case "article" : ab_artname = lastLabelObj.options[optionId].text; setTimeout("ab_genWindow('Bearbeiten von „"+ab_artname+ "“', 'edit'); ab_generate2('"+label+"'); document.getElementById('Suffix').style.display = 'block';", 1000); break;

case "nothing": ab_generate2( label ); break;

default: document.getElementById("TextboxText").innerHTML += lastLabelObj.options[optionId].text + " "; ab_generate2( label ); break; } }

function ab_genWindow( artName, type ) {	if ( artName != null ) {		document.getElementsByTagName("H1")[0].innerHTML = artName; document.title = artName + " - Kamelopedia"; }

$maintab = jQuery("#ca-nstab-main"); if ( ! $maintab ) $maintab = jQuery("#ca-nstab-user"); //auch im Kamelbau zum Testen solls klappen $viewtab = jQuery("#ca-view"); $edittab = jQuery("#ca-edit"); $discusstab = jQuery("#ca-talk"); $historytab = jQuery("#ca-history"); $daumentab = jQuery("#ca-hw");

switch ( type ) {		case "edit": $maintab.find("a").text('Artikel'); $edittab.addClass('selected'); $viewtab.removeClass('selected'); $discusstab.addClass('new'); $historytab.show(0); $viewtab.show(0); $edittab.show(0); $daumentab.show(0); $discusstab.show(0); break; case "spezial": $maintab.find("a").text('Spezial'); $viewtab.hide(0); $edittab.hide(0); $historytab.hide(0); $discusstab.hide(0); $daumentab.hide(0); break; default: $maintab.find("a").text('Artikel'); $edittab.removeClass('selected'); $viewtab.addClass('selected'); $discusstab.addClass('new'); $viewtab.show(0); $edittab.show(0); $discusstab.show(0); $historytab.show(0); $daumentab.show(0); break;

}	self.scroll(0,0); }

function ab_generate2( label ) {	var out; out = ( ab_opts[label].label.text == null ?		ab_opts["default"].label.text : ab_opts[label].label.text ); if (ab_opts[label].options != null ) {		out += ""; for(opt=0; opt"+ab_opts[label].options[opt].text+""; }	out += "" }

if( ab_opts[label].setfinish != null ) ab_finish = ab_opts[label].setfinish;

if ( ab_finish != null ) {		out += " "+(ab_finish.text == null ? ab_opts["default"].setfinish.text : ab_finish.text).replace(/\[([^\]]+)\]/,"$1 ")+" "; }

if ( label != "start" ) {		out +=" "+ab_opts["default"].clear.text.replace(/\[([^\]]+)\]/g,"$1 ")+" ";

}	document.getElementById("Assistent").innerHTML = out; }

function ab_generateFinish {	document.getElementById("TextboxText").innerHTML = " "+ (ab_finish.signature == null ? "" : " " + ab_finish.signature + " " ) + " " + document.getElementById("TextboxText").innerHTML; document.getElementById("Assistent").innerHTML = (ab_finish.text2 == null ? ab_opts["default"].setfinish.text2 : ab_finish.text2); ab_finish.inserted = ab_finish.template; }

function ab_clear {	ab_finish = null; document.getElementById('Suffix').style.display = 'none'; document.getElementById('TextboxText').innerHTML = ''; ab_init2;

}

function ab_display( fpt_save_or_preview ) {	ab_finish.fpt = fpt_save_or_preview;

if ( ab_finish.inserted == null ) {		ab_finish.html = ""; setTimeout("ab_finish.fpt;", 1000); }	else {		jQuery.ajax({			url: wgServer+wgScript+"/Vorlage:"+ab_finish.inserted,			data: "action=render",			success: function(html)			{				ab_finish.html = html.match(/<(div|table)(.|[\n])*<\/\1>/)[0];				ab_finish.fpt;			}		}); } }

function ab_save {	ab_render('Artikel', ab_artname); document.getElementById('preview').style.display = 'none'; document.getElementById('Suffix').style.display = 'none'; document.getElementById('n-Letzte-.C3.84nderungen').childNodes[0].onclick = ab_recentChanges; }

function ab_preview {	ab_render('previewRender'); document.getElementById('preview').style.display = 'block'; ab_genWindow( null, "edit" ); }

function ab_render( into, artname ) {	out = document.getElementById('TextboxText').innerHTML; /* Zuerst die Roten */ out = out.replace( new RegExp("\\[\\[("+ab_redlinks+")\\|([^\[\]|]+)\\]\\](\S*)", "g"), "$2$3"); out = out.replace( new RegExp("\\[\\[("+ab_redlinks+")\\]\\](\S*)", "g"), "$1$2"); out = out.replace(/\[\[([^\[\]|]+)\|([^\[\]|]+)\]\](\S*)/g, "$2$3"); out = out.replace(/\[\[([^\[\]|]+)\]\](\S*)/g, "$1$2");

sigtime = ab_genSigtime;

out = out.replace(/<br *?\/?>(.*?)[~]{4}<br *?\/?>/, " $1Kamel:"+wgUserName+"</a> "+sigtime+"  ");

out = out.replace(/\{\{.*\}\}/, ab_finish.html); document.getElementById(into).innerHTML = out; ab_genWindow( artname ); }

function ab_genSigtime {	datum = new Date; hrs = datum.getHours; min = datum.getMinutes; hrs_str = ( (hrs < 10) ? "0" + hrs : hrs ); min_str = ( (min < 10) ? "0" + min : min ); mon = datum.getMonth; day = datum.getDate; mon_str = [ "Jan.", "Feb.", "Mär.", "Apr.", "Mai", "Jun.", "Jul.", "Aug.", "Sep.", "Okt.", "Nov.", "Dez." ][mon]; yea = datum.getFullYear; return ( hrs_str + ":" + min_str + ", " + day + ". " + mon_str + " " + yea + " (CET)" ); }

function ab_recentChanges {	document.getElementById('n-Letzte-.C3.84nderungen').childNodes[0].onclick = function { return true; }; jQuery.ajax({		url:wgServer+wgScript+"/Spezial:Recentchanges",		data: {limit: 20, useskin: mw.config.get("skin")},		success: function(html)		{			datum = new Date;			hrs = datum.getHours;			min = datum.getMinutes;			hrs_str = ( (hrs < 10) ? "0" + hrs : hrs );			min_str = ( (min < 10) ? "0" + min : min );			chtime = ( hrs_str + ":" + min_str );			bytes = document.getElementById('TextboxText').innerHTML.length;			sigtime = ab_genSigtime;			begin = document.getElementById('TextboxText').innerHTML.replace(/<br *\/?>/g, " ").substr(0,150);			begin = begin.replace(/[~]{4}/, "Kamel:"+wgUserName+"</a> "+sigtime);

changes = '(Unterschied | ' + 				'Versionen</a>) . .   ' + 				'Neu ' +				''+ab_entities(ab_artname)+'</a>; '+chtime +				'. . (+'+bytes+' Bytes) . . ' + 				''+ab_entities(wgUserName) +				'</a> (Diskussion</a> ' + 				'| Beiträge</a>) ' +				' (Artikelbaukasten-Edit: "'+begin+'...") ';			body_begin = html.indexOf("<body"); body_begin = html.indexOf(">", body_begin); body_end  = html.indexOf(" "); html = html.substring( body_begin+1, body_end ); html = html.replace( //, "$1"+changes+"</li>"); ab_genWindow("Letzte Änderungen", "spezial");

content = jQuery(html).find("#bodyContent"); jQuery("#bodyContent").replaceWith(content); }	});	return false; }