「モジュール: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"]     = {defaultSeparators["sep"]},
["sep"]   = {defaultSeparators["sep"]},
["sep%s"]   = {defaultSeparators["sep%s"]},
["sep%s"] = {defaultSeparators["sep%s"]},
["sep%q"]   = {defaultSeparators["sep%q"]},
["sep%q"] = {defaultSeparators["sep%q"]},
["sep%r"]   = {defaultSeparators["sep%r"]},
["sep%r"] = {defaultSeparators["sep%r"]},
["punc"]     = {defaultSeparators["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
-- so that extensionTag("ref") is only called when it's really in the final output
-- 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
outString = outString .. mw.getCurrentFrame():extensionTag("ref", valuesArray[i][1], {name = "wikidata-" .. valuesArray[i].refHash})
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])
else
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 = mergeTables(valuesArray, 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
nextArg = mw.text.trim(nextArg)
ID = mw.text.trim(nextArg)
else
nextArg = ""
if ID == "" then
ID = nil
end
end
end
ID = nextArg
if ID then
if ID ~= "" then
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
if ID:sub(1,1) == "P" then
return label
if not _.pageTitle then
end
label = mw.wikibase.label(ID) or ""
else
if _.curState.rawValue and not _.pageTitle then
if _.curState.linked and label ~= "" then
label = mw.wikibase.getEntityIdForCurrentPage() or ""
label = "[[d:Property:" .. ID .. "|" .. label .. "]]"
end
if _.curState.linked and label ~= "" then
end
label = "[[d:" .. label .. "|" .. label .. "]]"
else
if not _.pageTitle then
if _.curState.shortName then
label = getShortName(ID)
end
-- at this point, 'label' will be a string and not nil
if label == "" then
label = mw.wikibase.label(ID)
end
else
-- 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
title = mw.wikibase.sitelink(ID)
end
if _.curState.linked and title then
label = "[[" .. title .. "|" .. (label or title) .. "]]"
else
label = label or title or ""
end
end
end
return label
end
end
else
end
if _.curState.rawValue then
label = mw.wikibase.getEntityIdForCurrentPage() or ""
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 .. "|" .. label .. "]]"
label = "[[d:Property:" .. ID .. "|" .. label .. "]]"
end
end
else
end
if not _.pageTitle then
else
label = mw.wikibase.label()
if not _.pageTitle then
else
if _.curState.shortName then
-- set 'label' to nil so 'title' will always prevail
label = getShortName(ID)
label = nil
end
end
if _.curState.linked or label == nil then
-- at this point, 'label' will be a string and not nil
title = mw.title.getCurrentTitle().prefixedText
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 = "[[" .. title .. "|" .. (label or title) .. "]]"  -- not much use since it links to the current page, but does add wiki mark-up
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
label = label or title
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
匿名利用者