Module:Plain sister
Appearance
This Lua module is used on approximately 6,96,000 pages, or roughly 118% 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: |
This module provides one method, which lists sister links to the current page. It is used by {{plain sister}} and Module:Header structure.
local p = {}
local sites = {
-- interwiki prefix, parameter, label and site id (for Wikidata)
{ 'w', 'wikipedia', 'விக்கிப்பீடியக் கட்டுரை', 'tawiki' },
{ 'c', 'commons', 'பொதுவக காட்சியகம்', 'commonswiki' },
{ 'c:Category', 'commonscat', 'பொதுவக பகுப்பு', 'commonswiki' },
{ 'q', 'wikiquote', 'மேற்கோள்கள்', 'tawikiquote' },
{ 'n', 'wikinews', 'செய்திகள்', 'tawikinews' },
{ 'wikt', 'wiktionary', 'விளக்கம்', 'tawiktionary' },
{ 'b', 'wikibooks', 'நூல்', 'tawikibooks' },
{ 'v', 'wikiversity', 'course', 'tawikiversity' },
{ 'wikispecies', 'wikispecies', 'taxonomy', 'specieswiki' },
{ 'voy', 'wikivoyage', 'travel guide', 'tawikivoyage' },
{ 'd', 'wikidata', 'விக்கித்தரவு', 'wikidatawiki' },
{ 'bibliowiki', 'wikilivres', 'bibliowiki', '' }, -- wikilivres now bibliowiki
{ 'bibliowiki', 'bibliowiki', 'bibliowiki', '' },
{ 'm', 'meta', 'மேல்', 'metawiki' }
}
function p.interprojetPart( frame )
local frame = frame:getParent()
local item = mw.wikibase.getEntityObject()
local links = {}
for _, site in pairs( sites ) do
local val = frame.args[site[2]] -- link provided as input parameter
if val == '' then
val = nil;
end
if not val and site[4] ~= '' and item then -- fetch it from wikidata
val = item:getSitelink( site[4] )
if site[4] == 'wikidatawiki' then
val = item.id
elseif site[4] == 'commonswiki' and val then -- we have link to commons
local catFlag = (#val>9 and string.sub(val,1,9) == 'Category:')
if (site[2]=='commonscat' and catFlag==false) or (site[2]=='commons' and catFlag==true) then
val = nil -- link is to a wrong namespace so let's nuke it
elseif (site[2]=='commonscat' and catFlag==true) then
val = string.sub(val,10) -- trim 'Category:' from the front
end
end
end
if not val and site[2] == 'commons' and item then
local statements = item:getBestStatements('P935' ) -- get commons gallery page from P935 property
if statements[1] and statements[1].mainsnak.datavalue then
val = statements[1].mainsnak.datavalue.value
end
end
if not val and site[2] == 'commonscat' and item then
local statements = item:getBestStatements('P373' ) -- get commons category page from P373 property
if statements[1] and statements[1].mainsnak.datavalue then
val = statements[1].mainsnak.datavalue.value
end
end
if val then
table.insert( links, '[[' .. site[1] .. ':' .. val .. '|' .. site[3] .. ']]' )
end
end
if #links == 0 then -- links table length is zero
return ''
end
return '<li class="sisitem">'
.. '<span class="sisicon" style="padding-right:1ex;">[[Image:Wikimedia-logo.svg|frameless|18px|link=Special:sitematrix|alt=உடன் புறத்திட்டங்கள்.]]</span>'
.. '[[Special:sitematrix|உடன் புறத்திட்டங்கள்]]: ' .. table.concat( links, ', ' )
.. '.</li>'
end
return p