Module:Taxonbar/confdoc: Difference between revisions

Content deleted Content added
add examples
use require('strict') instead of require('Module:No globals')
 
(8 intermediate revisions by 3 users not shown)
Line 1:
require('Module:No globalsstrict')
 
local conf = require( "Module:Taxonbar/conf" ) -- configuration module
Line 6:
function p.confdoc( frame )
local wikitable = '{| class="wikitable sortable"\n' mw.html. create('table')
wikitable:addClass('wikitable sortable')
'|-\n' ..
:tag('caption')
'! Parameter !! data-sort-type=number style="white-space: nowrap;"|Wikidata ID !! Authority !! Description'
: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 param = mw.ustring.lower(db[1])
local prop = db[3]
if type(prop) == 'number' and prop > 0 then
local param = mw.ustring.lower(db[1])
local TaxonbarProperty = frame:expandTemplate{ title = 'Taxonbar/Property', args = { prop } }
wikitablelocal row = wikitable mw.html. create('\ntr' .. )
row
'|-\n' ..
:tag('td')
'|' .. param .. '||' .. TaxonbarProperty
:wikitext(param)
:tag('td')
:attr('data-sort-value', prop)
:wikitext(format('[[d:Property:P%d|P%d]]', prop, prop))
-- {{#statements:P1629|from=P{{{1|}}}}}
:tag('td')
:wikitext(frame:callParserFunction{
name = '#statements:P1629',
args = { from = 'P' .. prop }
})
:tag('td')
:wikitext(mw.wikibase.getDescription('P' .. prop))
wikitable:node(row)
end
end
return wikitable .. '\n|}'
end
--[[ p.wikidataInfo( frame )
-function to show formatURL and id for taxonomic databases
]]
local counterCOUNTER_MAX = 10390
local counter = 0 --expensive parser function counter
 
function p.wikidataInfo( frame )
counter = frame.args['counter'] or 50COUNTER_MAX -- prevent too preventmanymany expensive calls
local start = frame.args['start'] or "a"
local finish = frame.args['finish'] or "zzz"
local wikitable = '{| class="wikitable sortable"\n' ..
'|-\n' ..
'! Parameter !! data-sort-type=number style="white-space: nowrap;"|Wikidata ID !! Database !! Examples !! datatype !! formatterURL (or alternative) and examples'
for _, db in pairs( conf.databases ) do
Line 45 ⟶ 79:
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
Line 60 ⟶ 95:
if subjectItem then
local officialWebsite = mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1]
counter = counter - 1
if officialWebsite then
url = url .. '<br/>website: ' .. officialWebsite.mainsnak.datavalue.value
Line 85 ⟶ 121:
.. '\n|' .. examples
.. '\n|' .. datatype
.. '\n|' .. url .. ('\n{{smalldiv|1=' .. links or "").. '}}'
end
end
Line 94 ⟶ 130:
function p.getExamples( propItem , prop, formatterURL, datatype)
counter = counter -1
if counter < 0 then return "count exceeded" end
Line 100 ⟶ 136:
local links = ""
local exampleStatements = propItem:getBestStatements('P1855')
local nExamples = 0
--local statement = statements[1]
for _, statement in pairs( exampleStatements ) do
if nExamples == 3 then break end -- don't show more than 3 examples
if statement.mainsnak and statement.mainsnak.datavalue and statement.mainsnak.datavalue.value then
local examplesValue = statement.mainsnak.datavalue.value
if examplesValue and examplesValue.id then
local exampleID = examplesValue.id
--examples = examples .. '\n*[[:d:' .. exampleID .. '|' .. exampleID ..']] <br/>'
local label = mw.wikibase.getLabel( exampleID )
examples = examples .. '\n*[[' .. label .. ']] ([[:d:' .. exampleID .. '|' .. exampleID ..']])'
 
-- 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 .. '<br/><small>id=<code>' .. id .. '</code></small>'
local link = formatterURL:gsub('$1', id)
if (datatype == "url") then link = id end
links = links .. '\n*' .. link .. ''
end
 
 
--[==[ -- this method is expensive as it calls getEntity
 
local item = mw.wikibase.getEntity(exampleID)
counter = counter - 1
nExamples = nExamples + 1
'|-\n' ..
if item and item ~= "" then
--datatype = item.datatype
Line 124 ⟶ 189:
links = links .. '\n*' .. link .. ''
end
end
]==]
else
examples = examples .. "No example"