Module:WdIk
Voorkoms
Dokumentasie vir hierdie module kan geskep word by: Module:WdIk/doc
require('strict') -- force strict type checks, and block use of global variables
local p = {}; --All Lua modules on Wikipedia must begin by defining a variable
--that will hold their externally accessible functions.
--Such variables can have whatever name you want and may
--also contain various data as well as functions.
-- local functions must go at the top (before you call them) otherwise the interpretor thinks they are not defined
local function toSentenceCase(string)
return string:gsub("^%l", string.upper)
end
p.kas = function(frame) --Add a function to "p".
--Such functions are callable in Wikipedia
--via the #invoke command.
--"frame" will contain the data that Wikipedia
--sends this function when it runs.
-- 'kas' is a name of your choice. The same name needs to be referred to when the module is used.
local args = frame:getParent().args -- an array of the args to the function (start with 1)
local itemId = nil
if args.item then
itemId = args.item
end
if itemId == nil then
mw.addWarning("Wikidata itemID not found, defaulting to Q42")
itemId = 'Q42'
end
local item = mw.wikibase.getEntity(itemId)
if item == nil then
mw.addWarning("Wikidata item not found")
return ''
end
local title = toSentenceCase(item:getLabel()) or toSentenceCase(mw.title.getCurrentTitle().text)
local test_img = '[[Lêer:Test.svg|200px|beeld onderskrif]]'
local images = item:getBestStatements('P18')
local image1 = test_img
if #images == 1 then
image1 = '[[Lêer:' .. images[1].mainsnak.datavalue.value .. '|frameless|300px]]'
end
local image_desc = 'beeld onderskrif'
-- reference docs : https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#mw.html:wikitext
local kas_root = mw.html.create('table')
:addClass('infobox')
-- :attr( 'class', 'infobox' )
:css( 'width', '300px' ) -- el problemo | how to handle content wrapping?
-- First row with merged columns | Title
local tr1 = kas_root:tag('tr')
tr1
:tag('td')
:attr('colspan', 2) -- merges 2 columns into 1 cell
:css({
['text-align'] = 'center',
['background-color'] = '#ffdd00',
['font-weight'] = 'bold',
})
:wikitext(title)
-- Second row | Image
local tr2 = kas_root:tag('tr')
tr2
:tag('td')
:attr('colspan', 2) -- merges 2 columns into 1 cell
:css('text-align','center')
:wikitext(image1 .. image_desc)
-- Third row | data | Geboortenaam
local tr3 = kas_root:tag('tr')
tr3
:tag('td')
:css('font-weight','bold')
:wikitext('Geboortenaam')
:tag('td')
:wikitext(frame:preprocess('{{#statements:P1477}}'))
:wikitext('[[Lêer:Blue pencil.svg|wysig|10px|text-top|class=noviewer|link=https://www.wikidata.org/wiki/' .. item.id .. '#' .. 'P1477' .. ']]')
-- Fourth row | data | Geboortedatum
local tr4 = kas_root:tag('tr')
tr4:tag('td'):css('font-weight','bold'):wikitext('Geboortedatum')
tr4:tag('td'):wikitext(frame:preprocess('{{#statements:P569}}'))
:wikitext('[[Lêer:Blue pencil.svg|wysig|10px|text-top|class=noviewer|link=https://www.wikidata.org/wiki/' .. item.id .. '#' .. 'P569' .. ']]')
local geboortedatum = frame:preprocess('{{#statements:P569|from=Q42}}') -- parser functions and other special text must run through frame:preprocess otherwise it will be treated as plain text
return tostring(kas_root)
end -- end of function
return p --All modules end by returning the variable containing their functions to Wikipedia.