Modulo:Wikidata link: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
creazione modulo richiesto per voce Progetto:Wiki Loves Earth/Aree/Lombardia |
controllo entity |
||
(2 versioni intermedie di un altro utente non mostrate) | |||
Riga 1:
local p = {}
---
-- Check if a page exists
--
-- @return {boolean}
local page = mw.title.new( title )
return page and page.exists
end
---
Riga 9 ⟶ 19:
-- The label will be used as title in that case.
--
-- In the rare case that the page already exists but it's not a sitelink,
▲-- @param {string} entity Entity Q-ID
-- the 'disambiguation' parameter can be used to create a link like:
-- @return {string} Wikilink to the entity ID▼
-- "[[Wikidata Label Here (Disambiguation Text)]]"
▲function p._main( entity )
--
-- @param {string} entity Entity Q-ID
-- @param {string} disambiguation Optional disambiguation text
▲-- @return {string} Wikilink to the entity ID
function p._main( entity, disambiguation )
if not entity then return end
-- the default URL is just the entity Q-id, for further troubleshooting
local link = entity
-- get the sitelink of this entity
local siteLink = mw.wikibase.getSitelink( entity )
-- get the label of this entity
Riga 24 ⟶ 43:
else
if label then
-- if the page already exists, try a disambiguation
-- prepare a red link to an unexisting page▼
-- prepare a red link to an unexisting disambiguated page
link = string.format( '[[%s (%s)]]', label, disambiguation )
else
▲ -- prepare a red link to an unexisting page
link = string.format( '[[%s]]', label )
end
end
end
Riga 54 ⟶ 81:
-- anyway it's optional and the current page will be used if nil
local entity = args.id or args[1]
-- the page can be the arg 'disamb' or the 2st argument
local disambiguation = args.disamb or args[2]
-- see the p.main() function reference
return p._main( entity, disambiguation )
end
|