Module:Property navigation
Jump to navigation
Jump to search
Each submodule is a Lua table, and keys are:
Name | Top level only? | Function | Default |
---|---|---|---|
template | Yes | Name of the template without the Template: prefix. | NAME properties |
category | Yes | Categories that property talk pages using this navbox will be added to, without the Category: prefix. | same as template
|
template_cat | Yes | Categories that the navbox itself will be added to, without the Category: prefix. | Property by topic navigation templates |
topic | Yes | QID of the topic of a navbox. Can not be used together with name or q . This will automatically generate a title like "Wikidata properties related to TOPIC".
|
nil |
name | No | Name (title) of a navbox or a specific navbox group. Can be either a string or a table of translations. | nil |
q | No | If specified, the label of this specific item in the user language is used as name/title, unless overrided by name .
|
nil |
below | Yes | Optional text to appear below the navbox. Any templates will be expanded. | nil |
style | No | The style that this Lua table is displayed, one of "navbox" (displayed as a navbox), "child" (displayed as a child navbox), "list" (displayed as list), "list2" (displayed as a second-level list). |
|
separatorn | No | The separator before item n. Any templates will be expanded. (Ignored if style is navbox or child) | "\n*" (list); "\n**" (list2) |
prefixn | No | The prefix added before item n. Any templates will be expanded. (Ignored if style is navbox or child) | "" |
suffixn | No | The suffix added after item n. Any templates will be expanded. (Ignored if style is navbox or child) | "" |
unnamed parameter | No | Represents an element, which may be one of:
|
- Alabama
- Alaska
- Arizona
- Arkansas
- Berlin
- California
- Colorado
- Connecticut
- Delaware
- Florida
- Georgia
- Goodreads
- Han character
- Hawaii
- Idaho
- Illinois
- Indiana
- Iowa
- Kansas
- Kentucky
- London
- Louisiana
- Maine
- Maryland
- Massachusetts
- Michigan
- Minnesota
- Mississippi
- Missouri
- Montana
- MusicBrainz
- NIH
- Nebraska
- Nevada
- New Jersey
- New Mexico
- New York
- North Carolina
- Ohio
- Oklahoma
- Oregon
- Pennsylvania
- Puerto Rico
- Rhode Island
- South Carolina
- South Dakota
- Tennessee
- Texas
- U.S. regions
- Utah
- Virginia
- Washington
- West Virginia
- Wisconsin
- Wyoming
- anatomy
- authority control
- doc
- election
- games
- general topic
- i18n
- law
- location
- mathematics
- schools
- social networking service
- sports
Code
local p={i18n=mw.loadData("Module:Property navigation/i18n")}
local wdlabel=require('Module:Wikidata label')
local fb=require("Module:Fallback")
local lang = mw.getCurrentFrame():preprocess( "{{int:lang}}" )
local function navbox_render(data)
return (function() return prefix .. "[[" .. target .. "|" .. wdlabel._getLabel(q, nil, "-", "ucfirst") .. "]]" .. suffix
end)
end
function p.lang_switch(x) return fb._langSwitch(x, lang) end
function p.link_q(target, q, params)
params = params or {}
local prefix = params.bold and "'''" or ""
local suffix = prefix
return (function()
return prefix .. "[[" .. target .. "|" .. wdlabel._getLabel(q, nil, "-", "ucfirst") .. "]]" .. suffix
end)
end
function p.name(content)
local name
if type(content.name) == "table" then
name = content.name[lang] or (content.q and wdlabel._getLabel(content.q, nil, "-", "ucfirst") or nil) or fb._langSwitch(content.name, lang)
else
name = type(content.name) == "string" and content.name or (content.q and wdlabel._getLabel(content.q, nil, "-", "ucfirst") or nil)
end
if content.link then
name='[[' .. (content.link=='1' and content.q or content.link) .. '|' .. name ..']]'
end
return name
end
function p.render(content, style)
local style = content.style or style or "child"
if style=="navbox" then
local nav_data={
name = content.template,
listclass = "hlist",
style = "font: arial;",
bodystyle = "background: #CDDDDD; width: 100%; vertical-align: middle;",
titlestyle = "background: #CDDDDD; padding-left: 1em; padding-right: 1em; text-align: center; font-size: x-small;",
groupstyle = "background: #CDDDDD; padding-left: 1em; padding-right: 1em; text-align: right; font-size: 11px;",
liststyle = "background: #EFFFFF; text-align: left/center; font-size: 12px;",
state = "off",
navbar = "on",
}
if content.topic then
if type(content.topic)=="string" then
nav_data.title=mw.ustring.format(fb._langSwitch(p.i18n.properties_related, lang), wdlabel._getLabel(content.topic, nil, "wikidata"))
else
for _, v in ipairs(content.topic) do
nav_data.title=(nav_data.title and (nav_data.title .. '/') or '') .. wdlabel._getLabel(v, nil, "wikidata")
end
nav_data.title=mw.ustring.format(fb._langSwitch(p.i18n.properties_related, lang), nav_data.title)
end
else
nav_data.title=p.name(content)
end
for i, v in ipairs( content ) do
nav_data["group" .. i] = p.name(v)
nav_data["list" .. i] = p.render(v, type(v[1])=="table" and "child" or "list") .. "\n"
end
if content.below then
nav_data.below = mw.getCurrentFrame():preprocess(content.below)
end
return require("Module:Navbox")._navbox(nav_data)
elseif style=="child" then
local nav_data={"child"}
for i, v in ipairs( content ) do
nav_data["group" .. i] = p.name(v)
nav_data["list" .. i] = p.render(v, type(v[1])=="table" and (type(v[1][1])=="table" and "child" or "list") or "list") .. "\n"
end
return require("Module:Navbox")._navbox(nav_data)
elseif style=="list" or style=="list2" then
local result = ""
local item_prefix = style=="list2" and "\n**" or "\n*"
for i, v in ipairs( content ) do
local item = type(v)=="function" and v() or v
local prefix=content["prefix" .. i] and mw.getCurrentFrame():preprocess(content["prefix" .. i]) or ""
local separator=content["separator" .. i] and mw.getCurrentFrame():preprocess(content["separator" .. i]) or item_prefix
local suffix=content["suffix" .. i] and mw.getCurrentFrame():preprocess(content["suffix" .. i]) or ""
if type(item)=="string" then
if mw.ustring.match(item, "^P%d+$") then
result = result .. separator .. prefix .. wdlabel._getLabel(item, nil, "wikidata talk") .. suffix
elseif mw.ustring.match(item, "^Q%d+$") then
result = result .. separator .. prefix .. wdlabel._getLabel(item, nil, "wikidata") .. suffix
else
result = result .. separator .. prefix .. item .. suffix
end
else
result = result .. (item.name or item.q and (separator .. prefix .. p.name(item) .. suffix) or '') .. p.render(item, "list2")
end
end
return result
else
return "Unknown style:" .. str(style)
end
end
function p.navbox(name)
if type(name)=="table" then
name = name.args[1] or name:getParent().args[1]
end
if mw.ustring.sub(name, 1, 7) ~= "Module:" then
name = "Module:Property navigation/" .. name
end
local data=require(name)
local append=""
local template_name=data.template or mw.getContentLanguage():ucfirst(name:gsub("Module:Property navigation/","") .. " properties")
mw.log(template_name)
local category=data.category or template_name
local template_cat=data.template_cat or "Property by topic navigation templates"
if mw.title.getCurrentTitle().namespace==121 and category~="" then
append="[[Category:" .. category .. "]]"
elseif mw.title.getCurrentTitle().namespace==10 and mw.title.getCurrentTitle().text==template_name and template_cat~="" then
append=mw.getCurrentFrame():preprocess("{{Warning|To edit this navbox, please edit [[" .. name .. "]]}}") .. "[[Category:" .. template_cat .. "]]"
if category~="" then
append=append .. "[[Category:" .. category .. "|*]]"
end
end
return p.render(data, "navbox") .. append
end
return p