Modulo:Plain sister
Aspetto
La documentazione per questo modulo può essere creata in Modulo:Plain sister/man
local p = {}
local function wrapper(project, number, content, main)
local projectlogo = {
wikipedia = 'Wikipedia-logo-v2.svg',
wiktionary = 'Notification-icon-Wiktionary-logo.svg',
wikiquote = 'Notification-icon-Wikiquote.svg',
wikibooks = 'Notification-icon-Wikibooks-logo.svg',
wikisource = 'Notification-icon-Wikisource-logo.svg',
wikinews = 'Notification-icon-Wikinews-logo.svg',
wikiversity = 'Notification-icon-Wikiversity-logo.svg',
wikispecies = 'Notification-icon-Wikispecies-logo.svg',
wikidata = 'Notification-icon-Wikidata-logo.svg',
commons = 'Notification-icon-Commons-logo.svg',
wikivoyage = 'Notification-icon-Wikivoyage-logo.svg'
}
local div = mw.html.create( 'div' )
if project == 'wikidata' then
div
:wikitext( '[[File:' .. projectlogo[project] .. '|20px|link=]] [[d:' .. content .. '|' .. project .. ']]' )
elseif main ~= '' then
if number == 0 then
div
:wikitext( '[[File:' .. projectlogo[project] .. '|20px|link=]] ' .. project .. ' <b>' .. main .. '</b>' )
else
div
:attr( 'class', 'mw-collapsible mw-collapsed' )
:attr( 'data-expandtext', '+' .. number )
:wikitext( '[[File:' .. projectlogo[project] .. '|20px|link=]] ' .. project .. ' <b>' .. main .. '</b>' )
:tag( 'div' )
:attr( 'class', 'mw-collapsible-content' )
:wikitext( '\n:' .. content )
end
elseif number == 1 then
div
:wikitext( '[[File:' .. projectlogo[project] .. '|20px|link=]] ' .. project .. ' <b>' .. content .. '</b>' )
else
div
:attr( 'class', 'mw-collapsible mw-collapsed' )
:attr( 'data-expandtext', '+' .. number)
:wikitext( '[[File:' .. projectlogo[project] .. '|20px|link=]] ' .. project )
:tag( 'div' )
:attr( 'class', 'mw-collapsible-content' )
:wikitext( '\n:' .. content )
end
return tostring(div)
end
local function langfix(langcode)
local fixlist = {
als = 'gsw',
bat_smg = 'sgs',
be_x_old = 'be-tarask',
fiu_vro = 'vro',
no = 'nb',
roa_rup = 'rup',
zh_classical = 'lzh',
zh_min_nan = 'nan',
zh_yue = 'yue'
}
return mw.ustring.gsub(fixlist[langcode] or langcode, "_", "-")
end
local function makelink(prefix, lang, title)
return '[[' .. prefix .. ':' .. lang .. ':' .. title .. '|' .. lang .. ']]'
end
function p.links(frame)
local q = frame.args.qid or frame:getParent().args.qid
local mainlang = frame.args.mainlang or frame:getParent().args.mainlang
local s = {}
local wikipedias = {}
local wiktionaries = {}
local wikiquotes = {}
local wikibookses = {}
local wikisources = {}
local wikinewses = {}
local wikiversities = {}
local wikivoyages = {}
if q then
local entity = mw.wikibase.getEntity(q)
if entity and entity.sitelinks then
for i, j in pairs(entity.sitelinks) do
if mw.ustring.sub( j.site, -#'wiki' ) == 'wiki' and j.site ~= 'wikidatawiki' and j.site ~= 'commonswiki' and j.site ~= 'specieswiki' and j.site ~= 'metawiki' and j.site ~= 'mediawikiwiki' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wiki' ))
if langcode == mainlang then
wikipedias['main'] = makelink('w', langcode, j.title)
else
table.insert(wikipedias, makelink('w', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wiktionary' ) == 'wiktionary' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wiktionary' ))
if langcode == mainlang then
wiktionaries['main'] = makelink('wikt', langcode, j.title)
else
table.insert(wiktionaries, makelink('wikt', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wikiquote' ) == 'wikiquote' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wikiquote' ))
if langcode == mainlang then
wikiquotes['main'] = makelink('q', langcode, j.title)
else
table.insert(wikiquotes, makelink('q', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wikibooks' ) == 'wikibooks' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wikibooks' ))
if langcode == mainlang then
wikibookses['main'] = makelink('b', langcode, j.title)
else
table.insert(wikibookses, makelink('b', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wikisource' ) == 'wikisource' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wikisource' ))
if langcode == mainlang then
wikisources['main'] = makelink('', langcode, j.title)
else
table.insert(wikisources, makelink('', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wikinews' ) == 'wikinews' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wikinews' ))
if langcode == mainlang then
wikinewses['main'] = makelink('n', langcode, j.title)
else
table.insert(wikinewses, makelink('n', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wikiversity' ) == 'wikiversity' and j.site ~= 'betawikiversity' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wikiversity' ))
if langcode == mainlang then
wikiversities['main'] = makelink('v', langcode, j.title)
else
table.insert(wikiversities, makelink('v', langcode, j.title))
end
elseif mw.ustring.sub( j.site, -#'wikivoyage' ) == 'wikivoyage' then
local langcode = langfix(mw.ustring.sub( j.site, 1, #j.site-#'wikivoyage' ))
if langcode == mainlang then
wikivoyages['main'] = makelink('voy', langcode, j.title)
else
table.insert(wikivoyages, makelink('voy', langcode, j.title))
end
end
end
end
end
local function addlinks(project, t)
if #t > 0 or t['main'] then
table.sort(t)
table.insert(s, wrapper(project, #t, table.concat(t, ' · '), t['main'] or ''))
end
end
addlinks( 'wikipedia', wikipedias )
addlinks( 'wiktionary', wiktionaries )
addlinks( 'wikiquote', wikiquotes )
addlinks( 'wikibooks', wikibookses )
addlinks( 'wikinews', wikinewses )
addlinks( 'wikiversity', wikiversities )
addlinks( 'wikivoyage', wikivoyages )
table.insert(s, wrapper('wikidata', 1, q, ''))
return table.concat(s)
end
return p