「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年9月10日 (日) 18:05(UTC)より
template>K-iczn (en:Module:Wd 2017年9月9日 (土) 16:25(UTC)より) |
template>K-iczn (en:Module:Wd 2017年9月10日 (日) 18:05(UTC)より) |
||
268行目: | 268行目: | ||
function buildWikilink(target, label) | function buildWikilink(target, label) | ||
if target == label then | if not label or target == label then | ||
return "[[" .. target .. "]]" | return "[[" .. target .. "]]" | ||
else | else | ||
622行目: | 622行目: | ||
-- if ID == nil then item connected to current page is used | -- if ID == nil then item connected to current page is used | ||
function Config:getLabel(ID, raw, link, short | function Config:getLabel(ID, raw, link, short) | ||
raw = raw or false | raw = raw or false | ||
link = link or false | link = link or false | ||
short = short or false | short = short or false | ||
local label = nil | local label = nil | ||
633行目: | 632行目: | ||
local lang | local lang | ||
if | if raw then | ||
if not ID then | if not ID then | ||
label = mw.wikibase.getEntityIdForCurrentPage() | label = mw.wikibase.getEntityIdForCurrentPage() | ||
687行目: | 645行目: | ||
prefix = "d:" .. prefix | prefix = "d:" .. prefix | ||
title = label | title = label -- may be nil | ||
end | else | ||
-- try short name first if requested | |||
if short then | |||
label = getShortName(ID) | |||
if label == "" then | |||
label = nil | |||
end | |||
end | |||
-- get label | |||
if not label then | |||
label, lang = mw.wikibase.getLabelWithLang(ID) | |||
-- don't allow language fallback | |||
if lang ~= self.langCode then | |||
label = nil | |||
end | |||
end | |||
end | end | ||
if not label then | if not label then | ||
label = "" | label = "" | ||
elseif link then | |||
-- build a link if requested | |||
if not title then | |||
if not ID then | |||
title = mw.title.getCurrentTitle().prefixedText | |||
elseif ID:sub(1,1) == "Q" then | |||
title = mw.wikibase.sitelink(ID) | |||
elseif ID:sub(1,1) == "P" then | |||
-- properties have no sitelink, link to Wikidata instead | |||
title = ID | |||
prefix = "d:Property:" | |||
end | |||
end | |||
if title then | |||
label = buildWikilink(prefix .. title, label) | |||
end | |||
end | end | ||
729行目: | 718行目: | ||
if self.propertyID then | if self.propertyID then | ||
value = value .. "#" .. self.propertyID | value = value .. "#" .. self.propertyID | ||
elseif self.pageTitle then | |||
value = value .. "#sitelinks-wikipedia" | |||
end | end | ||
1,210行目: | 1,201行目: | ||
return value | return value | ||
elseif snak.datavalue.type == 'wikibase-entityid' then | elseif snak.datavalue.type == 'wikibase-entityid' then | ||
local label | |||
local itemID = snak.datavalue.value['numeric-id'] | local itemID = snak.datavalue.value['numeric-id'] | ||
1,220行目: | 1,212行目: | ||
end | end | ||
label = self:getLabel(itemID, raw, link, short) | |||
if label == "" then | |||
label = nil | |||
end | |||
return label | |||
else | else | ||
return '<strong class="error">' .. unknownDataTypeError(snak.datavalue.type) .. '</strong>' | return '<strong class="error">' .. unknownDataTypeError(snak.datavalue.type) .. '</strong>' | ||
2,326行目: | 2,324行目: | ||
local ID = nil | local ID = nil | ||
local label = | local label = nil | ||
local nextArg = args[1] | local nextArg = args[1] | ||
2,381行目: | 2,379行目: | ||
end | end | ||
label = _:getLabel(ID, _.curState.rawValue, _.curState.linked, _.curState.shortName | if _.pageTitle then | ||
-- "title" command was given | |||
if not ID then | |||
label = mw.title.getCurrentTitle().prefixedText | |||
elseif ID:sub(1,1) == "Q" then | |||
label = mw.wikibase.sitelink(ID) | |||
end | |||
if _.curState.linked and label then | |||
label = buildWikilink(label) | |||
end | |||
label = label or "" | |||
else | |||
-- "label" command was given | |||
label = _:getLabel(ID, _.curState.rawValue, _.curState.linked, _.curState.shortName) | |||
end | |||
if _.editable and label ~= "" then | if _.editable and label ~= "" then |