Module:WikidataIB and Module:WikidataIB/sandbox: Difference between pages

From HandWiki
(Difference between pages)
Page 1
Page 2
imported>Jworkorg
m (1 revision imported)
 
imported>Jworkorg
m (1 revision imported)
 
Line 1: Line 1:
-- Version: 2020-11-08
-- Version: 2020-11-26
-- Module to implement use of a blacklist and whitelist for infobox fields
-- Module to implement use of a blacklist and whitelist for infobox fields
-- Can take a named parameter |qid which is the Wikidata ID for the article
-- Can take a named parameter |qid which is the Wikidata ID for the article
Line 802: Line 802:
-- createicon assembles the "Edit at Wikidata" pen icon.
-- createicon assembles the "Edit at Wikidata" pen icon.
-- It returns a wikitext string inside a span class="penicon"
-- It returns a wikitext string inside a span class="penicon"
-- if entityID is nil or empty, the ID associated with current page is used
-- langcode and propertyID may be nil or empty
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: i18n[];
-- Dependencies: i18n[];
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
local createicon = function(langcode, entityID, propertyID)
local createicon = function(langcode, entityID, propertyID)
langcode = langcode or ""
if not entityID or entityID == "" then entityID= mw.wikibase.getEntityIdForCurrentPage() end
propertyID = propertyID or ""
local icon = "&nbsp;<span class='penicon'>[["
local icon = "&nbsp;<span class='penicon'>[["
-- "&nbsp;<span data-bridge-edit-flow='overwrite' class='penicon'>[[" -> enable Wikidata Bridge
-- "&nbsp;<span data-bridge-edit-flow='overwrite' class='penicon'>[[" -> enable Wikidata Bridge
Line 812: Line 817:
.. i18n["editonwikidata"]
.. i18n["editonwikidata"]
.. "|link=https://www.wikidata.org/wiki/" .. entityID
.. "|link=https://www.wikidata.org/wiki/" .. entityID
.. "?uselang=" .. langcode
if langcode ~= "" then icon = icon .. "?uselang=" .. langcode end
if propertyID then icon = icon .. "#" .. propertyID end
if propertyID ~= "" then icon = icon .. "#" .. propertyID end
icon = icon .. "|" .. i18n["editonwikidata"] .. "]]</span>"
icon = icon .. "|" .. i18n["editonwikidata"] .. "]]</span>"
return icon
return icon
Line 822: Line 827:
-- assembleoutput takes the sequence table containing the property values
-- assembleoutput takes the sequence table containing the property values
-- and formats it according to switches given. It returns a string or nil.
-- and formats it according to switches given. It returns a string or nil.
-- It needs the entityID and propertyID to create a link in the pen icon.
-- It uses the entityID (and optionally propertyID) to create a link in the pen icon.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Dependencies: parseParam();
-- Dependencies: parseParam();
Line 2,737: Line 2,742:
if not (whitelist == 'ALL' or whitelist:find(fieldname)) then return nil end
if not (whitelist == 'ALL' or whitelist:find(fieldname)) then return nil end


local qid = mw.text.trim(args.qid or "")
local qid = args.qid
if qid == "" then qid = nil end
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
if qid and not mw.wikibase.entityExists(qid) then return nil end
if not entity then return nil end
 
local aliases = entity.aliases
local aliases = mw.wikibase.getEntity(qid).aliases
if not aliases then return nil end
if not aliases then return nil end
if not qid then qid= mw.wikibase.getEntityIdForCurrentPage() end


args.langobj = findLang(args.lang)
args.langobj = findLang(args.lang)
Line 3,251: Line 3,255:
if qid == "" then qid = nil end
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
if qid and not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end
if not entity then return i18n["entity-not-found"] end


local labels = entity.labels
local labels = mw.wikibase.getEntity(qid).labels
if not labels then return i18n["labels-not-found"] end
if not labels then return i18n["labels-not-found"] end


Line 3,278: Line 3,281:
if qid == "" then qid = nil end
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
if qid and not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end
if not entity then return i18n["entity-not-found"] end


local descriptions = entity.descriptions
local descriptions = mw.wikibase.getEntity(qid).descriptions
if not descriptions then return i18n["descriptions-not-found"] end
if not descriptions then return i18n["descriptions-not-found"] end


Line 3,305: Line 3,307:
if qid == "" then qid = nil end
if qid == "" then qid = nil end


local entity = mw.wikibase.getEntity(qid)
if qid and not mw.wikibase.entityExists(qid) then return i18n["entity-not-found"] end
if not entity then return i18n["entity-not-found"] end


local aliases = entity.aliases
local aliases = mw.wikibase.getEntity(qid).aliases
if not aliases then return i18n["aliases-not-found"] end
if not aliases then return i18n["aliases-not-found"] end