Module:Sandbox/Hike395/CommonsLink explained
local getArgs = require('Module:Arguments').getArgslocal p =
function p.test(frame) local args = getArgs(frame) return p._test(args)end
function p._test(args) local qid = mw.wikibase.getEntityIdForTitle(args[1]) if not qid then return nil end local result = '
'..args[1]..' | ' local P935 = mw.wikibase.getBestStatements(qid, "P935")[1] result = result..'' local interesting = false local gallery = nil if P935 and P935.mainsnak.datavalue then gallery = P935.mainsnak.datavalue.value result = result..gallery end if not gallery then interesting = true end result = result..' | ' local category = nil local P373 = mw.wikibase.getBestStatements(qid, "P373")[1] if P373 and P373.mainsnak.datavalue then category = 'Category:'..P373.mainsnak.datavalue.value result = result..category end if not category then interesting = true end result = result..' | ' local commonsSitelink = mw.wikibase.getSitelink(qid,"commonswiki") local sitelinkCat = false if commonsSitelink then local comparison if mw.ustring.sub(commonsSitelink,1,9)
"Category:" then comparison = category sitelinkCat = true else comparison = gallery end if commonsSitelink ~= comparison then result = result..''..commonsSitelink..'' interesting = true else result = result..commonsSitelink end else interesting = true end result = result..' | ' local P910 = mw.wikibase.getBestStatements(qid, "P910")[1] if P910 then local tmcid = P910.mainsnak.datavalue and P910.mainsnak.datavalue.value.id local sitelink = mw.wikibase.getSitelink(tmcid, "commonswiki") if sitelink then if not sitelinkCat and sitelink ~= category then result = result..''..sitelink..'' interesting = true else result = result..sitelink end end end result = result..' |
' if (args.interesting or args.int) and not interesting then return nil end return resultend
return p