「モジュール: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( | function getShortName(ID) | ||
if | if ID then | ||
return p._property({ | 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 | end | ||
end | end | ||
if not _.curState.rawValue or _.pageTitle then | |||
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 | ||
-- | -- (2) try label | ||
if not label then | |||
if label | |||
label, lang = mw.wikibase.getLabelWithLang(ID) | label, lang = mw.wikibase.getLabelWithLang(ID) | ||
2,006行目: | 1,981行目: | ||
end | end | ||
end | end | ||
end | end | ||
-- | -- (3) try sitelink/title | ||
if not label or _.curState.linked then | |||
if _.curState.linked | 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) | ||
elseif label then | |||
title = mw. | -- 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 | ||
title = label | |||
end | |||
if not label then | |||
label = "" | |||
end | |||
-- add optional link | |||
if _.curState.linked and title then | |||
label = buildWikilink(prefix .. title, label) | |||
end | end | ||