「モジュール:Wd」の版間の差分

en:Module:Wd 2017年5月28日 (日) 18:42(UTC)より
template>K-iczn
(en:Module:Wd 2017年5月25日 (木) 18:25(UTC)より)
template>K-iczn
(en:Module:Wd 2017年5月28日 (日) 18:42(UTC)より)
543行目: 543行目:
end
end


function getShortName(itemID)
function getShortName(ID)
if itemID then
if ID then
return p._property({itemID, aliasesP.shortName})  -- "property" is single
return p._property({ID, aliasesP.shortName})  -- "property" is single
else
else
return p._property({aliasesP.shortName})  -- "property" is single
return p._property({aliasesP.shortName})  -- "property" is single
1,921行目: 1,921行目:
local ID = nil
local ID = nil
local label = ""
local label = nil
local title = nil
local title = nil
local prefix= ""
local lang
local lang
1,953行目: 1,954行目:
if not string.match(ID, '^[QP]%d+$') or tonumber(string.match(ID, '%d+')) > 2147483647 then
if not string.match(ID, '^[QP]%d+$') or tonumber(string.match(ID, '%d+')) > 2147483647 then
return ""
return ""
end
if _.curState.rawValue and not _.pageTitle then
if mw.wikibase.getEntity(ID) or mw.wikibase.resolvePropertyId(ID) then
if _.curState.linked then
if ID:sub(1,1) == "P" then
label = buildWikilink("d:Property:" .. ID, ID)
else
label = buildWikilink("d:" .. ID, ID)
end
else
label = ID
end
end
return label
end
else
if _.curState.rawValue and not _.pageTitle then
label = mw.wikibase.getEntityIdForCurrentPage() or ""
if _.curState.linked and label ~= "" then
label = buildWikilink("d:" .. label, label)
end
return label
end
end
end
end
if ID and ID:sub(1,1) == "P" then
if not _.curState.rawValue or _.pageTitle then
if not _.pageTitle then
label = mw.wikibase.label(ID) or ""
if _.curState.linked and label ~= "" then
label = buildWikilink("d:Property:" .. ID, label)
end
end
else
if not _.pageTitle then
if not _.pageTitle then
-- (1) try short name
if _.curState.shortName then
if _.curState.shortName then
label = getShortName(ID)
if ID and ID:sub(1,1) == "P" then
label = getShortName("Property:" .. ID)
else
label = getShortName(ID)
end
if label == "" then
label = nil
end
end
end
-- at this point, 'label' will be a string and not nil
-- (2) try label
if not label then
if label == "" then
label, lang = mw.wikibase.getLabelWithLang(ID)
label, lang = mw.wikibase.getLabelWithLang(ID)
2,006行目: 1,981行目:
end
end
end
end
else
-- set 'label' to nil so 'title' will always prevail
label = nil
end
end
-- at this point, 'label' will be nil or a non-empty string
-- (3) try sitelink/title
if not label or _.curState.linked then
if _.curState.linked or label == nil then
if not ID then
if ID then
title = mw.title.getCurrentTitle().prefixedText
elseif ID:sub(1,1) == "Q" then
title = mw.wikibase.sitelink(ID)
title = mw.wikibase.sitelink(ID)
else
elseif label then
title = mw.title.getCurrentTitle().prefixedText
-- properties have no sitelink, 'title = ID' should only be set
-- if there is a 'label' already and if it needs to be linked;
-- otherwise, it would be 'label = title == ID' even if '_.pageTitle' is set
title = ID
prefix = "d:Property:"
end
label = label or title
end
end
-- (4) try entity ID (i.e. raw value)
if not label and not _.pageTitle then
if not ID then
label = mw.wikibase.getEntityIdForCurrentPage()
elseif mw.wikibase.getEntity(ID) or mw.wikibase.resolvePropertyId(ID) then
label = ID
if ID:sub(1,1) == "P" then
prefix = "Property:"
end
end
end
end
if _.curState.linked and title then
prefix = "d:" .. prefix
label = buildWikilink(title, (label or title))
else
title = label
label = label or title or ""
end
end
if not label then
label = ""
end
-- add optional link
if _.curState.linked and title then
label = buildWikilink(prefix .. title, label)
end
end
匿名利用者