Module:Official website/sandbox: Difference between revisions

Content deleted Content added
sync with main
testing language code addition
Line 40:
end
 
-- Fetches the official website URL/language from Wikidata.
local fetchWikidataUrlfetchWikidata
fetchWikidataUrlfetchWikidata = function()
-- Get objects for all official sites on Wikidata.
local websites = quickPcall(function ()
Line 76:
return websites[1].mainsnak.datavalue.value
end)
local iso639_3 = quickPcall(function()
local langItemId = websites[1].qualifiers.P407.datavalue.value.id
local langItem = mw.wikibase.getEntity(langItemId)
return langItem.claims.P220.mainsnak.datavalue.value
end)
 
local ret = {
url = url,
lang = iso639_3
}
 
-- Cache the result so that we only do the heavy lifting once per #invoke.
fetchWikidataUrlfetchWikidata = function ()
return urlret
end
 
return urlret
end
 
Line 105 ⟶ 115:
if options.mobile then
ret[#ret + 1] = '(' .. makeUrl(options.mobile, 'Mobile') .. ')'
end
if options.lang then
ret[#ret + 1] = ' ' .. frame:expandTemplate{
title = 'Link language',
args = { options.lang }
}
end
return table.concat(ret, ' ')
Line 117 ⟶ 133:
if not url and not wikidataurl then
category = 'Official website missing URL'
elseif not url and wikidataurl then
return ''
elseif url and wikidataurl then
Line 130 ⟶ 146:
 
function p._main(args)
local wikidataurlwikidata = fetchWikidataUrlfetchWikidata()
local url = args[1] or args.___URL or args.url or wikidataurlwikidata.url
local formattedUrl = renderUrl{
url = url,
display = args[2] or args.name or 'Official website',
mobile = args.mobile,
format = args.format,
lang = args.lang or wikidata.lang
}
return formattedUrl .. renderTrackingCategory(url, wikidataurlwikidata.url)
end