Module:Official website: Difference between revisions

Content deleted Content added
add code to detect the rank of URLs from Wikidata
move tracking category for no URL into the renderTrackingCategory function; this prevents it from being output in namespaces other than the main namespace
Line 2:
 
local p = {}
 
-- Makes a category from a string s.
local function makeCategory(s)
return string.format('[[Category:%s]]', s)
end
 
-- Wrapper for pcall which returns nil on failure.
Line 48 ⟶ 43:
-- Render the URL link, plus other visible output.
local function renderUrl(options)
if not options.url then
return '<strong class="error">' ..
'No URL found. Please specify a URL here or add one to Wikidata.' ..
'</strong>' ..
end
local ret = {}
ret[#ret + 1] = string.format(
Line 71:
end
local category
if fetchWikidataUrl()not url then
makeCategory(category = 'Official website missing URL')
elseif fetchWikidataUrl() then
if url and url ~= fetchWikidataUrl() then
category = 'Official website different in Wikidata and Wikipedia'
Line 78 ⟶ 80:
category = 'Official website not in Wikidata'
end
return category and makeCategorystring.format('[[Category:%s]]', category) or ''
end
 
function p._main(args)
local url = args[1] or args.___URL or fetchWikidataUrl()
if not url then
return '<strong class="error">' ..
'No URL found. Please specify a URL here or add one to Wikidata.' ..
'</strong>' ..
makeCategory('Official website missing URL')
end
local formattedUrl = renderUrl{
url = url,