Module:Sourdant/sandbox

Èn årtike di Wiccionaire.
I gn a nén co di dzo-pådje /doc pol notule d’ esplikêyes. Clitchîz cial po l’ ahiver.
--{{#invoke:Sourdant|p.display_info|E89}} to display information about ref E89
 
local p = {}
local base = require("Module:Base")

-- return the table of a reference
-- or false if reference doesn't exist
function p.get_reference(refID)	
	local ref = base.load_data("Sourdant/" .. refID)
	if not ref then
		return false
	end
	
	return ref
end

-- Display informations about a reference
-- Used in Sourdant namespace (not yet a namespace)
function p.display_info(frame)
	
	local refID = p.get_refID(frame)
	
	if not refID then
		return base.error_msg("i gn a pont d' limero d' sourdant")
	end
	
	local ref = p.get_reference(refID)
	
	if not ref then
		return base.error_msg("nole dinêye pol sourdant «"..refID.."»")
	end
	
	-- cover
	local cover = "Book important2.svg"
	local is_def_cover = true
	if ref.cover ~= nil and ref.cover ~= "" then
		local cover_name = mw.title.makeTitle("File", ref.cover)
		
		if cover_name.fileExists then
			cover = cover_name.text
			is_def_cover = false
		end
	end
	
	-- author(s)
	local div_author = mw.html.create( 'div' )
	div_author:css({
			["margin-bottom"] = "0.5em"
		})
	if ref.authors ~= nil and ref.authors ~="" then 
		local authors = frame:newParserValue( ref.authors )
		div_author:wikitext( authors.expand() )
	else
		div_author:wikitext( "[[:w:".. ref.author .."|".. ref.author .."]]" )
	end
	
	-- title
	local div_title = mw.html.create( 'div' )
	div_title:wikitext( "''".. ref.title .."''" )
	
	-- publication
	local div_pub = mw.html.create( 'div' )
	div_pub:css({
			["margin-top"] = "0.5em"
		})
	if ref.year ~= nil and ref.year ~= "" then
		div_pub:wikitext( "Eplaidî e ".. ref.year )
		if ref.publication ~= nil and ref.publication ~= "" then
			local pub = frame:newParserValue( ref.publication )
			div_pub:wikitext( " (".. pub.expand() ..")" )
		end
	elseif ref.alt_publication ~= nil and ref.alt_publication ~= "" then
		local pub = frame:newParserValue( ref.alt_publication )
		div_pub:wikitext( pub.expand() )
	end
	
		
	-- ref id
	local li_num = mw.html.create( 'li' )
	local span_num_link = mw.html.create( 'span' )
	span_num_link:css({
			["font-size"] = "0.8em"
		})
		:wikitext( " ([[Sourdants:Djivêye des motîs do walon|Cwè çki c' est ?]])" )
	li_num:wikitext( "Rahouca : '''".. ref.id .."'''" )
	li_num:node( span_num_link )
		
	-- left column
	local div_col_left = mw.html.create( 'div' )
	div_col_left	
		:css({
			["margin-bottom"] = "1em",
			float = "left",
			width = "45%",
			["min-width"] = "300px"
		})
		:node( div_author )
		:node( div_title )
		:node( div_pub )
	
	-- right column
	local ul_col_right = mw.html.create( 'ul' )
	ul_col_right
		:css({
			["margin-left"] = "3%",
			float = "left",
			width = "45%",
			["min-width"] = "300px",
			["list-style"] = "square"
		})
		:node( li_num )
		
	-- aliases
	if(ref.aliases ~= nil) then
		local li_aliases = mw.html.create( 'li' )
		li_aliases:wikitext( "Alias : " )
		for k, a in pairs(ref.aliases) do
			if k > 1 then
				li_aliases:wikitext( " ; ")
			end
			li_aliases:wikitext( "'''"..a.id.."'''")
			if a.description ~= nil then
				li_aliases:wikitext( " ("..a.description..")")
			end
		end
		ul_col_right:node(li_aliases)
	end
	
	-- isbn
	if(ref.isbn13 ~= nil or ref.isbn10 ~= nil) then
		local isbn = ""
		if ref.isbn13 ~= nil then
			isbn = ref.isbn13
		else
			isbn = ref.isbn10
		end
		local li_isbn = mw.html.create( 'li' )
		li_isbn:wikitext( "ISBN : [[Special:BookSources/"..isbn.."|"..isbn.."]]" )
		ul_col_right:node(li_isbn)
	end
		
	-- wikipedia
	if ref.wikipedia ~= nil and ref.wikipedia.title ~= nil then	
		local li_wikipedia = mw.html.create( 'li' )
		li_wikipedia:wikitext( "Wikipedia : [[:w:".. ref.wikipedia.lang ..":".. ref.wikipedia.title .."|".. ref.wikipedia.title .."]]" )
		ul_col_right:node( li_wikipedia )		
	end
	
	-- wikisource
	if ref.wikisource ~= nil and ref.wikisource.book ~= nil then
		local li_wikisource = mw.html.create( 'li' )
		li_wikisource:wikitext( "Wikisourd : [[:s:Index:".. ref.wikisource.lang ..":".. ref.wikisource.book .."|".. ref.wikisource.book .."]]" )
		ul_col_right:node( li_wikisource )
		
		-- cover from book
		if is_def_cover and ref.wikisource.coverpage ~= nil then
			cover = ref.wikisource.book .. '|page='..ref.wikisource.coverpage
		end
				
	end
	
	-- wikidata
	if ref.wikidata ~= nil and ref.wikidata ~= "" then	
		local li_wikidata = mw.html.create( 'li' )
		li_wikidata:wikitext( "Wikidata : [[:d:".. ref.wikidata .."|".. ref.wikidata .."]]")
		ul_col_right:node( li_wikidata)		
	end
	
	-- extarnal ressource
	if ref.external ~= nil and ref.external.link ~= nil then
		local li_external = mw.html.create( 'li' )
		li_external:css({
				["word-break"] = "break-all"
			})
			:wikitext( "Sol daegntoele : [".. ref.external.link .." " ..ref.external.link .."]")
		ul_col_right:node( li_external )		
	end
		
	-- cover link
	cover = '[[File:'..cover..'|left|128px]]'
	
	-- columns container
	local div_columns = mw.html.create( 'div' )	
	div_columns
		:css({
			["margin-left"] = "150px",
			overflow = "auto"
		})
		:node( div_col_left )
		:node( ul_col_right )
		
	-- categories container
	local div_cats = mw.html.create( 'div' )	
	div_cats
		:css({
			clear = "both",
			["border-top"] = "solid 1px #d1d2b2",
			["font-size"] = "0.8em",
			padding = "1em 2em 0"
		})
		:wikitext( "Tos les mots di ci [[sourdant]] ci k' ont ddja stî [[rahoukî]]s sol Wiccionaire sont dins ''[[:Categoreye:Mots ki sont dins ".. ref.id .."|cisse categoreye cial]]''." )

	local cat_name_prov = mw.title.makeTitle("Categoreye", "Spots ki sont dins ".. ref.id .."")
	if cat_name_prov.exists then
		div_cats:wikitext( " Po les [[spot|spots]] loukîz dins ''[[:Categoreye:Spots ki sont dins ".. ref.id .."|cisse categoreye cial]]''." )
	end
	
	-- main container
	local div = mw.html.create( 'div' )	
	div	:attr( 'class', 'info-sourdant')
		:css({
			border = "solid 1px #d1d2b2",
			background = "beige",
			padding = "1.5em",
			overflow = "auto"
		})
		:wikitext( cover )
		:node( div_columns )
		:node( div_cats )
		
	return tostring( div )
end

-- return first arg of frame considered as refID
function p.get_refID(frame)
	
	-- get args from parent modele
	local modele = mw.getCurrentFrame():getParent()
	local args = modele.args
	
	if args[1] ~= nil then
		return args[1]			
	else
		return false
	end
end

return p