Modul:Dummy

Die Dokumentation für dieses Modul kann unter Modul:Dummy/Doku erstellt werden

-- Dieses Modul dient zum Testen diverser Mediawiki-spezifischer Funktionen

local p = {} 

-- Auslesen einer Seite. Parameter: 1=Namensraumnummer und 2= Seitenlemma (ohne Namensraum)
-- Rückgabe: Ein String mit dem Quelltext der Seite
function SeiteLesen(NR,Titel)
	local Seite = mw.title.makeTitle(NR, Titel)
	local Text;
	local Exist = Seite.exists
	if Exist then
		Text = Seite:getContent()
	else
		Text = '<span class="error">Seite existiert nicht!</span>'
	end
	return Exist, Text;
end

--split_newlines: Aufteilen des Seiteninhalts in eine Table mit den Zeilen
local function split_newlines(s)
	local ts = {}
	local str = s ..'\n'
	while 1 do
		local pos = mw.ustring.find(str,'\n',1,true);
		if pos then
			local line = mw.ustring.sub(str,1, pos-1)
			table.insert(ts,line)
			str = mw.ustring.sub(str,pos+1)
		else
			break;
		end
	end
	return ts
end

-- splitaline: Auftrennen einer Textzeile an den Stellen mit einem Separatorzeichen 
local function splitaline(str,Trenner)
	local sep = mw.ustring.sub(Trenner,1,1) or ';'
	local Data = {};
	local Teil = "";
	str = str .. sep;
	if mw.ustring.len(str) < 2 then return false, Data; end 	
	
	while 1 do
		pos = mw.ustring.find(str,sep,1,true);
		if pos then
			Teil = mw.ustring.sub(str,1,pos-1);
			table.insert(Data,Teil);
			str = mw.ustring.sub(str,pos+1)
		else
			break;
		end
	end
	return true, Data;
end

function p.ReadThePage(frame)
	local Namensraum = frame.args[1] or 0;
	local Seitenname = frame.args[2] or "";
	local Felder = {} 
	local isOk, Text  =SeiteLesen(Namensraum,Seitenname) 
	if not isOk then
		return Text;
	end
	local Zeilen = {}
	local Lines= split_newlines(Text,true);

	for i,v in ipairs(Lines) do
		isOk, Felder = splitaline(v,';');
		if isOk then
			table.insert(Zeilen,Felder);
		end
		isOk = false;
	end

--[=[
Hier liegt der Inhalt wie folgt vor:
	Eine Tabelle "Lines" mit den Zeilen als ein String
	Eine Tabelle "Zeilen", deren Elemente eine Tabelle "Felder" ist, welche die aufgetrennten Zeilen enthält.
	]=]
	-- Test: Ausgabe
	local Ausgabe = "";
	local Reihe = "";
	for i,v in ipairs(Zeilen) do
		Reihe = table.concat(Zeilen[i],'~')
		Ausgabe = Ausgabe .. Reihe .. \n'
	end
	return Ausgabe;
end

return p;

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.