Module:Official website
- Afrikaans
- العربية
- Արեւմտահայերէն
- تۆرکجه
- Basa Bali
- বাংলা
- Bikol Central
- Bosanski
- Буряад
- Cebuano
- Corsu
- Dagbanli
- Dansk
- الدارجة
- डोटेली
- Eesti
- Ελληνικά
- فارسی
- Føroyskt
- Français
- Gaeilge
- Gaelg
- ગુજરાતી
- 한국어
- Hausa
- Հայերեն
- हिन्दी
- Ilokano
- Bahasa Indonesia
- Íslenska
- Italiano
- עברית
- Jawa
- ಕನ್ನಡ
- Kurdî
- ລາວ
- Latviešu
- Lietuvių
- Македонски
- മലയാളം
- मराठी
- مصرى
- Bahasa Melayu
- Nederlands
- नेपाली
- 日本語
- Norsk nynorsk
- ଓଡ଼ିଆ
- Oʻzbekcha / ўзбекча
- ਪੰਜਾਬੀ
- Português
- Qaraqalpaqsha
- Sakizaya
- संस्कृतम्
- ᱥᱟᱱᱛᱟᱲᱤ
- سرائیکی
- Setswana
- සිංහල
- Simple English
- سنڌي
- Slovenščina
- کوردی
- Српски / srpski
- Srpskohrvatski / српскохрватски
- Suomi
- Tagalog
- ไทย
- Türkçe
- اردو
- Vahcuengh
- Tiếng Việt
- Winaray
- 吴语
- 粵語
- 中文
Appearance
From Wikipedia, the free encyclopedia
Warning This Lua module is used on approximately 338,000 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.
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 state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
This module implements {{Official website }}. Please see the template page for documentation.
Tracking categories
- Category:Official website missing URL (0)
- Category:Official website different in Wikidata and Wikipedia (99,875)
- Category:Official website not in Wikidata (56,056)
See also
The above documentation is transcluded from Module:Official website/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
localmakeUrl=require('Module:URL')._url localp={} -- Wrapper for pcall which returns nil on failure. localfunctionquickPcall(func) localsuccess,result=pcall(func) ifsuccessthen returnresult end end -- Gets the rank for a Wikidata property table. Returns 1, 0 or -1, in -- order of rank. localfunctiongetRank(prop) localrank=prop.rank ifrank=='preferred'then return1 elseifrank=='normal'then return0 elseifrank=='deprecated'then return-1 else -- No rank or undefined rank is treated as "normal". return0 end end -- Finds whether a Wikidata property is qualified as being in English. localfunctionisEnglish(prop) localret=quickPcall(function() fori,langinipairs(prop.qualifiers.P407)do iflang.datavalue.value['numeric-id']==1860then returntrue end end returnfalse end) returnret==true end -- Fetches the official website URL from Wikidata. localfetchWikidataUrl fetchWikidataUrl=function() -- Get objects for all official sites on Wikidata. localwebsites=quickPcall(function() returnmw.wikibase.getAllStatements(mw.wikibase.getEntityIdForCurrentPage(),'P856') end) -- 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)do website._index=i end -- 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~=r2then returnr1>r2 end locale1=isEnglish(ws1) locale2=isEnglish(ws2) ife1~=e2then returne1 end returnws1._index<ws2._index end) localurl=quickPcall(function() returnwebsites[1].mainsnak.datavalue.value end) -- Cache the result so that we only do the heavy lifting once per #invoke. fetchWikidataUrl=function() returnurl end returnurl end -- Render the URL link, plus other visible output. localfunctionrenderUrl(options) ifnotoptions.urlandnotoptions.wikidataurlthen localqid=mw.wikibase.getEntityIdForCurrentPage() localresult='<strong class="error">'.. 'No URL found. Please specify a URL here or add one to Wikidata.'.. '</strong>' ifqidthen result=result..' [[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=Edit this at Wikidata |link=https://www.wikidata.org/wiki/'..qid..'#P856|Edit this at Wikidata]]' end returnresult end localret={} ret[#ret+1]=string.format( '<span class="official-website">%s</span>', makeUrl(options.urloroptions.wikidataurl,options.display) ) ifoptions.wikidataurlandnotoptions.urlthen localqid=mw.wikibase.getEntityIdForCurrentPage() ifqidthen ret[#ret+1]='[[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=Edit this at Wikidata |link=https://www.wikidata.org/wiki/'..qid..'#P856|Edit this at Wikidata]]' end end returntable.concat(ret,' ') end -- Render the tracking category. localfunctionrenderTrackingCategory(url,wikidataurl) ifmw.title.getCurrentTitle().namespace~=0then return'' end localcategory ifnoturlandnotwikidataurlthen category='Official website missing URL' elseifnoturlandwikidataurlthen return'' elseifurlandwikidataurlthen ifurl:gsub('/%s*$','')~=wikidataurl:gsub('/%s*$','')then category='Official website different in Wikidata and Wikipedia' end else category='Official website not in Wikidata' end returncategoryandstring.format('[[Category:%s]]',category)or'' end functionp._main(args) localurl=args[1]orargs.URLorargs.url localwikidataurl=fetchWikidataUrl() localformattedUrl=renderUrl{ url=url, wikidataurl=wikidataurl, display=args[2]orargs.nameor'Official website' } returnformattedUrl..renderTrackingCategory(url,wikidataurl) end functionp.main(frame) localargs=require('Module:Arguments').getArgs(frame,{ wrappers='Template:Official website' }) returnp._main(args) end returnp