require('strict')
local conf = require("Module:Taxonbar/conf") -- configuration module
local p = function p.confdoc(frame) local wikitable = mw.html.create('table') wikitable:addClass('wikitable sortable') :tag('caption') :wikitext('Taxon identifiers by parameter name') :done :tag('tr') :tag('th') :wikitext('Parameter') :tag('th') :attr('data-sort-type', 'number') :css('white-space', 'nowrap') :wikitext('Wikidata ID') :tag('th') :wikitext('Authority') :tag('th') :wikitext('Description') local format = string.format for _, db in pairs(conf.databases) do local prop = db[3] if type(prop)
function p.wikidataInfo(frame) counter = frame.args['counter'] or COUNTER_MAX -- prevent too many expensive calls local start = frame.args['start'] or "a" local finish = frame.args['finish'] or "zzz" local wikitable = '
-\n' .. '! Parameter | Wikidata ID | Database | Examples | datatype | formatterURL (or alternative) and examples' for _, db in pairs(conf.databases) do local param = mw.ustring.lower(db[1]) local link = db[2] local prop = db[3] local id = 'id' local url = 'url' local datatype = "" local examples = "" local links = "" local formatterURL = "" if type(prop) 'number' and prop > 0 and param > start and param < finish then local item = mw.wikibase.getEntity('P'..prop) --('P5354') counter = counter - 1 if item and item ~= "" then datatype = item.datatype local statements = item:getBestStatements('P1630')[1] if statements and statements.mainsnak and statements.mainsnak.datavalue and statements.mainsnak.datavalue.value then formatterURL = statements.mainsnak.datavalue.value url = formatterURL else url = "No formatter URL (P1630)." if datatype"url" then url = url .. " The id of the external database is the url." end local subjectItem = item:getBestStatements('P1629')[1] if subjectItem then local officialWebsite = mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1] counter = counter - 1 if officialWebsite then url = url .. ' wikitable = wikitable .. '\n' .. ' | -' .. '\n | ' .. param .. '\n | ' .. 'P' .. prop .. '' .. '\n | ' .. link .. '\n | ' .. examples .. '\n | ' .. datatype .. '\n | ' .. url .. '\n' end end return wikitable .. '\n |
---|
function p.getExamples(propItem, prop, formatterURL, datatype) if counter < 0 then return "count exceeded" end local examples = "" local links = "" local exampleStatements = propItem:getBestStatements('P1855') local nExamples = 0 --local statement = statements[1] for _, statement in pairs(exampleStatements) do if nExamples
-- get information form qualifiers if statement.qualifiers then local qualifiers = statement['qualifiers'] local value = qualifiers['P'..prop][1] --['datavalue']['value'] --mw.addWarning (mw.wikibase.formatValues(qualifiers)) --mw.addWarning (mw.wikibase.renderSnaks(qualifiers)) -- mw.addWarning (mw.wikibase.formatValue(value)) --mw.addWarning (mw.wikibase.renderSnak(value)) local id = mw.wikibase.renderSnak(value) examples = examples .. '
id=' .. id .. '
' local link = formatterURL:gsub('$1', id) if (datatype
--[==[ -- this method is expensive as it calls getEntity local item = mw.wikibase.getEntity(exampleID) counter = counter - 1 nExamples = nExamples + 1 if item and item ~= "" then --datatype = item.datatype local statements = item:getBestStatements('P225')[1] -- taxon name if statements and statements.mainsnak and statements.mainsnak.datavalue and statements.mainsnak.datavalue.value then local taxon = statements.mainsnak.datavalue.value examples = examples .. ' ' .. taxon .. '' end local statements = item:getBestStatements('P'..prop)[1] -- the databas property if statements and statements.mainsnak and statements.mainsnak.datavalue and statements.mainsnak.datavalue.value then local id = statements.mainsnak.datavalue.value local link = formatterURL:gsub('$1', id) if (datatype
] else examples = examples .. "No example" end else examples = examples .. "No examples statements" end end
return examples, linksendreturn p