Module:Official website
Appearance
![]() | This Lua module is used on approximately 331,000 pages, or roughly 1% 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 uses the Wikidata property:
official website (P856) (see uses)
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module implements {{Official website}}. Please see the template page for documentation.
Tracking categories
- Category:Official website missing URL (171)
- Category:Official website different in Wikidata and Wikipedia (96,875)
- Category:Official website not in Wikidata (52,787)
See also
local makeUrl = require('Module:URL')._url
local p = {}
local function makeCategory(s)
return string.format('[[Category:%s]]', s)
end
local function quickPcall(func)
local success, result = pcall(func)
if success then
return result
end
end
local fetchWikidataUrl
fetchWikidataUrl = function()
local url = quickPcall(function ()
return mw.wikibase.getEntityObject().claims.P856[1].mainsnak.datavalue.value
end)
fetchWikidataUrl = function ()
return url
end
return url
end
local function formatUrl(options)
local ret = {}
ret[#ret + 1] = string.format(
'<span class="official-website">%s</span>',
makeUrl(options.url, options.display)
)
if options.format == 'flash' then
ret[#ret + 1] = mw.getCurrentFrame():expandTemplate{
title = 'Link note',
args = {note = 'Requires [[Adobe Flash player]]'}
}
end
if options.mobile then
ret[#ret + 1] = '(' .. makeUrl(options.mobile, 'Mobile') .. ')'
end
return table.concat(ret, ' ')
end
local function renderTrackingCategory(url)
if mw.title.getCurrentTitle().namespace ~= 0 then
return ''
end
local category
if fetchWikidataUrl() then
if url and url ~= fetchWikidataUrl() then
category = 'Official website different in Wikidata and Wikipedia'
end
else
category = 'Official website not in Wikidata'
end
return category and makeCategory(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 = formatUrl{
url = url,
display = args[2] or args.name or 'Official website',
mobile = args.mobile,
format = args.format
}
return formattedUrl .. renderTrackingCategory(url)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Official website'
})
return p._main(args)
end
return p