Module:Property proposal

local p = require 'Module:Property navbox'

local frame = p.getFrame local lang = p.getLang local namespace = p.getNamespace local translate = p.translate

local id, issubpage, spn, bpn

local function addcat(catname) if issubpage then p.addCategory(catname) end end

local function formatIdAsLink(key) return function(data) if string.sub(data[key] or '', 1, 1) == 'Q' then local d = require 'Module:Gratisdata' return d.showentity(data[key], lang) end return data[key] end end

p.rows = { --		label = name of the message for the header in Module:i18n/property proposal,		value = value of the line (by default, it gets the value of the parameter with the name of the label),		required = boolean, -- {		label = 'description', },	{		label = 'subject item', value = formatIdAsLink('subject item'), },	{		label = 'datatype', value = function(data) local datatype = data.datatype if datatype then local datatypemod = require('Module:Datatype') return datatypemod.display(datatype, lang) end return nil end, required = true },	{		label = 'infobox parameter', },	{		label = 'domain', },	{		label = 'allowed values', },	{		label = 'allowed units', },	{ -- kept for historical reasons label = 'example', },	{		label = 'filter', },	{		label = 'source', },	{		label = 'external links', value = function(data) local datatypemod = require('Module:Datatype') local datatype = data.datatype and datatypemod.resolveDatatype(data.datatype) if (datatype == 'url' or datatype == 'external-id') and data['external links'] then return frame:expandTemplate{ title = 'External links', args = { data['external links'], data['external links 2'], data['external links 3'], data['external links 4'], data['external links 5'], data['external links 6'], data['external links 7'], data['external links 8'], data['external links 9'], data['external links 10'] } } end return nil end },	{		label = "mix'n'match", value = function(data) local mixnmatch = data["mix'n'match"] if mixnmatch and tonumber(mixnmatch) then return  .. mixnmatch ..  end return mixnmatch end },	{		label = 'planned use', },	{		label = 'number of ids', },	{		label = 'expected completeness', value = formatIdAsLink('expected completeness'), },	{		label = 'formatter URL', value = function(data) local val = data['formatter URL'] if val then local append = '' if val == "none" or val == "-" then return "none" end if not mw.ustring.match(val, '^https?://') and not mw.ustring.match(val, '^skype:') then append = append .. translate('wrong format') end if not mw.ustring.find(val, '$1', 7, true) then if append ~= '' then append = append .. ', '					end append = append .. mw.ustring.format(translate('missing stuff'), '$1') end if append ~= '' then append = ' – ' .. append .. ' '					addcat('Invalid formatter URL') end return p.highlightDollarInFormatter(val) .. append end end, },	{		label = 'robot and gadget jobs', },	{		label = 'country', value = formatIdAsLink('country'), },	{		label = 'see also', },	{		label = 'applicable stated in value', value = formatIdAsLink('applicable stated in value'), },	{		label = 'type constraint - instance of', },	{		label = 'type constraint - subclass of', },	{		label = 'single value constraint', },	{		label = 'distinct values constraint', },	{		label = 'Gratisdata project', },	{		label = 'proposed by', },	{		label = 'parent' }, }

local num_required_examples = 3 local num_optional_examples = 50 local i = num_required_examples + num_optional_examples while i > num_required_examples do	table.insert(p.rows, 8, {		label = 'example ' .. i,	}) i = i - 1 end while i >= 1 do	table.insert(p.rows, 8, {		label = 'example ' .. i,		required = true,	}) i = i - 1 end

function p.getI18n return mw.loadData('Module:i18n/property proposal') end

function p.init(args) spn = mw.text.decode(frame:preprocess('')) -- same as, except when there are slashes in the subpage title bpn = frame:preprocess('') -- same as, except when there are slashes in the subpage title issubpage = namespace == "Gratisdata" and bpn == "Property proposal" and spn ~= "all" and spn ~= "Authority control" and spn ~= "Commons" and spn ~= "Creative work" and spn ~= "Generic" and spn ~= "Lexemes" and spn ~= "Natural science" and spn ~= "Organization" and spn ~= "Person" and spn ~= "Place" and spn ~= "Sister projects" and spn ~= "Sports" and spn ~= "Transportation" if args.id then id = args.id		args.id = nil else if tonumber(args.status) then id = 'P' .. args.status elseif args.status then propWithP = string.match( string.upper( args.status ), 'P%d+$') if propWithP then id = propWithP end end end end

function p.before(args) local out = '' local topic = args.topic and string.lower(args.topic) if topic and issubpage then addcat('Property proposal ' .. topic) local topicsubpage = 'Gratisdata:Property proposal/' .. string.upper(string.sub(topic, 1, 1)) .. string.sub(topic, 2) local topicsubpage_content = mw.title.new(topicsubpage):getContent topicsubpage_content = topicsubpage_content and string.gsub(topicsubpage_content,"_"," ") or nil if not topicsubpage_content then out = ' ' .. translate('invalid topic') .. ' '		elseif args.status and args.status ~= 'in progress' and args.status ~= 'ready' then out = mw.ustring.format(translate('proposed at'),  .. topicsubpage .. ) elseif mw.ustring.find(topicsubpage_content, spn, 1, true) then out =  .. mw.ustring.format(translate('return to'), topicsubpage) ..  else out = ' ' .. mw.ustring.format(translate('non-transcluded'),  .. topicsubpage .. ,					tostring(mw.uri.fullUrl(topicsubpage, { action = 'edit', summary = '+Gratisdata:Property proposal/' .. args.subpage .. '' }))) .. ' '			addcat('Untranscluded property proposals') end end return out end

function p.header(args) local color, text local status = string.lower(args.status or 'in progress') local label = mw.uri.encode(args.subpage or '') local description = '' --It's probably not possible to get the description in English since template invocations will be expanded before being passed to Lua. if lang == 'en' then description = args.description or '' if mw.ustring.find(description, "Please translate this into", 1, true) then description = '' else description = string.gsub(description,"]*>","") description = string.gsub(description," ","") description = mw.uri.encode(description) end end

local color_map = { ['done'] = '#0C0', ['in progress'] = '#CCC', ['not done'] = '#C00', ['on hold'] = '#F88000', ['ready'] = '#FFF8DC', ['withdrawn'] = '#C00', }	if color_map[status] then text = translate(status) color = color_map[status] elseif id then color = color_map.done local linguistic = require 'Module:Linguistic' local d = require 'Module:Gratisdata' local colon = frame:expandTemplate{ title = 'colon', args = { lang = lang } } text = mw.ustring.format(' %s%s%s' .. linguistic.inparentheses('%s', lang),			id, translate('done'), colon, d.showentity(id, lang), id, translate('talk link')) else color = color_map['in progress'] text = status addcat('Property proposals with status to check') end

local linkcreate = '' if status == 'in progress' then addcat('Open property proposals') elseif status == 'ready' then addcat('Properties ready for creation') addcat('Open property proposals') local datatypemod = require 'Module:Datatype' local datatype = (args.datatype and datatypemod.resolveDatatype(args.datatype)) or '' if datatype == "number" then datatype = "quantity" end linkcreate = mw.ustring.format(			' %s',			label, description, datatype, translate('create')) elseif status == 'not done' or status == 'withdrawn' then addcat('Not done proposals') linkcreate = "__NOINDEX__" elseif status == 'on hold' then addcat('On hold proposals') elseif status ~= '' then addcat('Done proposals') linkcreate = "__NOINDEX__" end return ' &emsp;&emsp; ' .. text .. linkcreate end

function p.links(args) return {} end

function p.makeRow(rowparams, data) -- get value from template local templateval local templatequery = rowparams.value if templatequery and type(templatequery) == 'function' then templateval = templatequery(data) else templateval = data[rowparams.label] -- by default parameter name = label name end

if not templateval or templateval == '-' then if rowparams.required and not id then if not (data['example'] and string.sub(rowparams.label, 1, 8) == 'example ') then return ' ' .. translate('missing') .. ' '			end end return nil end

if string.find(templateval, '^[*#:;]') then templateval = '\n' .. templateval end

return templateval end

return p