Module:Sister project logo
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This Lua module is used on approximately 1,230,000 pages, or roughly 2% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
| This module depends on the following other modules: |
Usage
{{#invoke:Sister project logo|main}}
Generates correct wiki image markup for the logo of a sister project.
- Parameters
- project: A project name (e.g., "commons") or prefix (e.g., "n") that specifies a sister project
- image: An image to use instead of the logo. "image=none" returns blank
- size: The size of the logo, using the same format as standard image wiki markup. defaults to "40x40px". When "size=large", produces correct sizing for Template:Wikipedia's sister projects
- class: One or more CSS classes to add to the logo. If more than one, they should be space-separated.
Logo filenames and other metadata are stored in Module:Sister project logo/data
require('strict')
local p = {}
-- Lazy-load logo file names and other metadata
local data = mw.loadData('Module:Sister project logo/data')
-- Convert table of arguments into wiki image markup
local function imageMarkup(args)
local x = {}
-- positional arguments first
for _, arg in ipairs(args) do
table.insert(x,arg)
end
-- named arguments converted to foo=bar
for k, v in pairs(args) do
if not tonumber(k) then
table.insert(x,k..'='..v)
end
end
return '[['..table.concat(x,'|')..']]'
end
function p._main(args)
local localArgs = {}
-- map possibly verbose project argument into canonical project string
local project = args.project and args.project:lower()
project = data.projectMap[project] or project
-- image=none means bail (for [[Template:Sister project]])
if args.image == 'none' then
return ''
-- if image specified, return it instead of stored logo (for [[Template:Sister project]])
elseif args.image then
return args.image
else
local logoImage = data.logo[project]
-- if project is unknown, use Wikimedia logo (for [[Template:Sister project]])
if not logoImage then
project = 'wm'
logoImage = data.logo['wm']
end
table.insert(localArgs,'File:'..logoImage)
end
-- size=large means use sizes from [[Template:Wikipedia's sister projects]]
-- size defaults to 40x40px (for [[Template:Sister project]])
table.insert(localArgs,args.size == 'large' and (data.largeSize[project] or '35px') or args.size or '40x40px')
-- if logo is PD, blank link and alt (to suppress from screen readers)
if data.PDicon[project] then
localArgs.link = ''
localArgs.alt = ''
else
localArgs.alt = data.logoAlt[project]
end
-- For dark mode, flip dark-on-light icons to be light-on-dark
-- Also: use editor-specified classes (for [[Template:Sister-inline]])
localArgs.class = "noviewer"..(data.darkOnLight[project] and " skin-invert-image" or "")
..(args.class and " "..args.class or "")
return imageMarkup(localArgs)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
return p._main(args) or ''
end
return p