Module:Sandbox/pietrasagh/Tohaomg
< Module:Sandbox | pietrasagh
local p = {} --create object (table) to be returned
function p.main(frame)
args = frame:getParent().args; --get all the parameters given in template call: {{Template|arg[1]|arg[2]|etc}}
res = {'{| class="wikitable"\n! Article\n! Good articles\n! Featured articles\n'} --table storing text, which this module returns
for k1, page_title in ipairs(args) do --iterate over each given argument
item = mw.wikibase.getEntity(mw.wikibase.getEntityIdForTitle(page_title), 'enwiki'); --get information from Wikidata item connected to the page
good, featured = {}, {} --create empty tables for good and featured articles
if item then --continue if item exists
for k2, site_info in pairs(item.sitelinks) do --iterate over each given site
x = mw.text.split(site_info.site, 'wiki') --split site name into two parts: before 'wiki' and after 'wiki'
language_code, tail = x[1], x[2] --'x' now is a table of two values, first is two-letter language code, the second is a tail after 'wiki'
language_code = language_code:gsub('_', '-') --replace underscores with dashes in language codes
if site_info.badges and tail=='' then --continue if page has any badges and it is wikipedia (not other project)
--if badge has values 'good article', 'good list' or 'recommended article', then add the page to the list of good articles
if (site_info.badges[1]=='Q17437798' or site_info.badges[1]=='Q51759403' or site_info.badges[1]=='Q17559452') then
table.insert(good, '[[:'..language_code..':'..site_info.title..'|'..language_code..']]')
--if badge has values 'featured article' or 'featured list', then add the page to the list of featured articles
elseif site_info.badges and (site_info.badges[1]=='Q17437796' or site_info.badges[1]=='Q17506997') then
table.insert(featured, '[[:'..language_code..':'..site_info.title..'|'..language_code..']]')
else end --if badge matches none of those values, just skip it
end
end
end
--make a row for the current page
table.insert(res, '|-\n| [[:en:'..page_title..']]\n| '..table.concat(good, ', ')..'\n| '..table.concat(featured, ', ')..'\n')
end
table.insert(res, '|}') --insert table ending
return frame:preprocess(table.concat(res)); --return the resulting string, which we get by joining all string in the 'res' table
end
return p; --return object