「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年5月1日 (月) 12:50(UTC)より
template>K-iczn (en:Module:Wd 2017年4月17日 (月) 11:47(UTC)より) |
template>K-iczn (en:Module:Wd 2017年5月1日 (月) 12:50(UTC)より) |
||
67行目: | 67行目: | ||
cfg.separators = { | cfg.separators = { | ||
-- use tables so that we can pass by reference | -- use tables so that we can pass by reference | ||
["sep"] | ["sep"] = {defaultSeparators["sep"]}, | ||
["sep%s"] | ["sep%s"] = {defaultSeparators["sep%s"]}, | ||
["sep%q"] | ["sep%q"] = {defaultSeparators["sep%q"]}, | ||
["sep%r"] | ["sep%r"] = {defaultSeparators["sep%r"]}, | ||
["punc"] | ["punc"] = {defaultSeparators["punc"]} | ||
} | } | ||
160行目: | 160行目: | ||
end | end | ||
-- used to create the final output string when it's all done, | -- used to create the final output string when it's all done, so that for references the | ||
-- | -- function extensionTag("ref", ...) is only called when they really ended up in the final output | ||
function concatValues(valuesArray) | function concatValues(valuesArray) | ||
local outString = "" | local outString = "" | ||
local j, skip | |||
for i = 1, #valuesArray do | for i = 1, #valuesArray do | ||
-- check if this is a reference | |||
if valuesArray[i].refHash then | if valuesArray[i].refHash then | ||
-- add <ref> tag with the reference's hash as its name (to deduplicate references) | j = i - 1 | ||
skip = false | |||
-- skip this reference if it is part of a continuous row of references that already contains the exact same reference | |||
while valuesArray[j] and valuesArray[j].refHash do | |||
if valuesArray[i].refHash == valuesArray[j].refHash then | |||
skip = true | |||
break | |||
end | |||
j = j - 1 | |||
end | |||
if not skip then | |||
-- add <ref> tag with the reference's hash as its name (to deduplicate references) | |||
outString = outString .. mw.getCurrentFrame():extensionTag("ref", valuesArray[i][1], {name = "wikidata-" .. valuesArray[i].refHash}) | |||
end | |||
else | else | ||
outString = outString .. valuesArray[i][1] | outString = outString .. valuesArray[i][1] | ||
533行目: | 549行目: | ||
function getShortName(itemID) | function getShortName(itemID) | ||
return p._property({itemID, aliasesP.shortName}) -- "property" is single | if itemID then | ||
return p._property({itemID, aliasesP.shortName}) -- "property" is single | |||
else | |||
return p._property({aliasesP.shortName}) -- "property" is single | |||
end | |||
end | end | ||
function getLabel(ID) | function getLabel(ID) | ||
return p._label({ID}) | if ID then | ||
return p._label({ID}) | |||
else | |||
return p._label({}) | |||
end | |||
end | end | ||
1,201行目: | 1,225行目: | ||
if v.param then | if v.param then | ||
valuesArray = mergeArrays(valuesArray, result[v.str]) | valuesArray = mergeArrays(valuesArray, result[v.str]) | ||
elseif v.str ~= "" then | |||
valuesArray[#valuesArray + 1] = {v.str} | valuesArray[#valuesArray + 1] = {v.str} | ||
end | end | ||
1,229行目: | 1,253行目: | ||
if #valuesArray > 0 then | if #valuesArray > 0 then | ||
valuesArray[#valuesArray + 1] = {sep} | if sep ~= "" then | ||
out = | valuesArray[#valuesArray + 1] = {sep} | ||
end | |||
out = mergeArrays(valuesArray, out) | |||
end | end | ||
end | end | ||
1,293行目: | 1,320行目: | ||
-- if there is already some output, then add the separator | -- if there is already some output, then add the separator | ||
if #out > 0 then | if #out > 0 and sep ~= "" then | ||
out[#out + 1] = {sep} | out[#out + 1] = {sep} | ||
end | end | ||
1,724行目: | 1,751行目: | ||
_.curState = State.new(_) | _.curState = State.new(_) | ||
local ID | local ID = nil | ||
local label = "" | local label = "" | ||
local title = nil | local title = nil | ||
1,737行目: | 1,764行目: | ||
if nextArg then | if nextArg then | ||
ID = mw.text.trim(nextArg) | |||
if ID == "" then | |||
ID = nil | |||
end | |||
end | end | ||
if ID then | |||
if ID | |||
if aliasesP[ID] then | if aliasesP[ID] then | ||
ID = aliasesP[ID] | ID = aliasesP[ID] | ||
1,756行目: | 1,783行目: | ||
end | end | ||
if _.curState.rawValue then | if _.curState.rawValue and not _.pageTitle then | ||
if mw.wikibase.getEntity(ID) or mw.wikibase.resolvePropertyId(ID) then | if mw.wikibase.getEntity(ID) or mw.wikibase.resolvePropertyId(ID) then | ||
if _.curState.linked then | if _.curState.linked then | ||
1,768行目: | 1,795行目: | ||
end | end | ||
end | end | ||
else | |||
return label | |||
end | |||
else | |||
if _.curState.rawValue and not _.pageTitle then | |||
label = mw.wikibase.getEntityIdForCurrentPage() or "" | |||
if _.curState.linked and label ~= "" then | |||
label = "[[d:" .. label .. "|" .. label .. "]]" | |||
end | end | ||
return label | |||
end | end | ||
end | |||
if _. | |||
label = mw.wikibase. | if ID and ID:sub(1,1) == "P" then | ||
if not _.pageTitle then | |||
label = mw.wikibase.label(ID) or "" | |||
if _.curState.linked and label ~= "" then | if _.curState.linked and label ~= "" then | ||
label = "[[d:" .. | label = "[[d:Property:" .. ID .. "|" .. label .. "]]" | ||
end | end | ||
else | end | ||
else | |||
if not _.pageTitle then | |||
if _.curState.shortName then | |||
label = getShortName(ID) | |||
label = | |||
end | end | ||
if | -- at this point, 'label' will be a string and not nil | ||
if label == "" then | |||
label = mw.wikibase.label(ID) | |||
end | end | ||
else | |||
if _.curState.linked then | -- set 'label' to nil so 'title' will always prevail | ||
label = nil | |||
end | |||
-- at this point, 'label' will be nil or a non-empty string | |||
if _.curState.linked or label == nil then | |||
if ID then | |||
title = mw.wikibase.sitelink(ID) | |||
else | else | ||
title = mw.title.getCurrentTitle().prefixedText | |||
end | end | ||
end | |||
if _.curState.linked and title then | |||
label = "[[" .. title .. "|" .. (label or title) .. "]]" | |||
else | |||
label = label or title or "" | |||
end | end | ||
end | end |