This module tracks the Wikidata property: Lua error in Module:Uses_Wikidata at line 10: attempt to index field 'wikibase' (a nil value).
This module implements {{Official website}}. Please see the template page for documentation.
Tracking categories[]
Category:Official website missing URL
Category:Official website different in Wikidata and Wikipedia
Category:Official website not in Wikidata
localmakeUrl=require('Module:URL')._urllocalp={}-- Wrapper for pcall which returns nil on failure.localfunctionquickPcall(func)localsuccess,result=pcall(func)ifsuccessthenreturnresultendend-- Gets the rank for a Wikidata property table. Returns 1, 0 or -1, in-- order of rank.localfunctiongetRank(prop)localrank=prop.rankifrank=='preferred'thenreturn1elseifrank=='normal'thenreturn0elseifrank=='deprecated'thenreturn-1else-- No rank or undefined rank is treated as "normal".return0endend-- Finds whether a Wikidata property is qualified as being in English.localfunctionisEnglish(prop)localret=quickPcall(function()fori,langinipairs(prop.qualifiers.P2439)doiflang.datavalue.value['numeric-id']==1860thenreturntrueendendreturnfalseend)returnret==trueend-- Fetches the official website URL from Wikidata.localfetchWikidataUrlfetchWikidataUrl=function()-- Get objects for all official sites on Wikidata.localwebsites=quickPcall(function()returnmw.wikibase.getEntityObject().claims.P856end)-- Clone the objects in case other code needs them in their original order.websites=websitesandmw.clone(websites)or{}-- Add the table index to the objects in case it is needed in the sort.fori,websiteinipairs(websites)dowebsite._index=iend-- Sort the websites, first by highest rank, and then by websites in the-- English language, then by the website's original position in the-- property list. When we are done, get the URL from the highest-sorted-- object.table.sort(websites,function(ws1,ws2)localr1=getRank(ws1)localr2=getRank(ws2)ifr1~=r2thenreturnr1>r2endlocale1=isEnglish(ws1)locale2=isEnglish(ws2)ife1~=e2thenreturne1endreturnws1._index<ws2._indexend)localurl=quickPcall(function()returnwebsites[1].mainsnak.datavalue.valueend)-- Cache the result so that we only do the heavy lifting once per #invoke.fetchWikidataUrl=function()returnurlendreturnurlend-- Render the URL link, plus other visible output.localfunctionrenderUrl(options)ifnotoptions.urlthenreturn'<strong class="error">'..'No URL found. Please specify a URL here or add one to Wikidata.'..'</strong>'endlocalret={}ret[#ret+1]=string.format('<span class="official-website">%s</span>',makeUrl(options.url,options.display))ifoptions.format=='flash'thenret[#ret+1]=mw.getCurrentFrame():expandTemplate{title='Link note',args={note='Requires [[Adobe Flash Player]]'}}endifoptions.mobilethenret[#ret+1]='('..makeUrl(options.mobile,'Mobile')..')'endreturntable.concat(ret,' ')end-- Render the tracking category.localfunctionrenderTrackingCategory(url)ifmw.title.getCurrentTitle().namespace~=0thenreturn''endlocalcategoryifnoturlthencategory='Official website missing URL'elseiffetchWikidataUrl()thenifurlandurl~=fetchWikidataUrl()thencategory='Official website different in Wikidata and Wikipedia'endelsecategory='Official website not in Wikidata'endreturncategoryandstring.format('[[Category:%s]]',category)or''endfunctionp._main(args)localurl=args[1]orargs.URLorfetchWikidataUrl()localformattedUrl=renderUrl{url=url,display=args[2]orargs.nameor'Official website',mobile=args.mobile,format=args.format}returnformattedUrl..renderTrackingCategory(url)endfunctionp.main(frame)localargs=require('Module:Arguments').getArgs(frame,{wrappers='Template:Official website'})returnp._main(args)endreturnp