Modulo:Wikidata link: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m added missing line
aggiunto supporto a disambiguante
Riga 1:
local p = {}
 
---
-- Check if a page exists
--
-- @param {string} entitytitle EntityPage Q-IDtitle
-- @return {boolean}
function p._mainpageExists( entitytitle )
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 )
 
-- the default URL is just the entity Q-id, for further troubleshooting
Riga 27 ⟶ 42:
else
if label then
-- if the page already exists, try a disambiguation
-- prepare a red link to an unexisting page
linkif =disambiguation string.formatand pageExists( '[[%s]]', label ) then
-- 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 57 ⟶ 80:
-- 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