「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年8月28日 (月) 14:24(UTC)より
template>K-iczn (en:Module:Wd 2017年8月19日 (土) 20:45(UTC)より) |
template>K-iczn (en:Module:Wd 2017年8月28日 (月) 14:24(UTC)より) |
||
43行目: | 43行目: | ||
percentage = "Q11229", | percentage = "Q11229", | ||
prolepticJulianCalendar = "Q1985786" | prolepticJulianCalendar = "Q1985786" | ||
} | |||
local flags = { | |||
linked = "linked", | |||
raw = "raw", | |||
short = "short", | |||
multilanguage = "multilanguage", | |||
unit = "unit", | |||
mdy = "mdy", | |||
single = "single", | |||
sourced = "sourced", | |||
edit = "edit", | |||
editAtEnd = "edit@end", | |||
best = "best", | |||
preferred = "preferred", | |||
normal = "normal", | |||
deprecated = "deprecated", | |||
future = "future", | |||
current = "current", | |||
former = "former" | |||
} | } | ||
151行目: | 171行目: | ||
stt.shortName = false | stt.shortName = false | ||
stt.anyLanguage = false | stt.anyLanguage = false | ||
stt.unitOnly = false | |||
stt.singleValue = false | stt.singleValue = false | ||
564行目: | 585行目: | ||
end | end | ||
function getLabel(ID) | function getLabel(ID, args) | ||
args = args or {} | |||
if ID then | if ID then | ||
args[#args + 1] = ID | |||
end | end | ||
return p._label(args) | |||
end | end | ||
644行目: | 667行目: | ||
end | end | ||
function Config:convertUnit(unit, link) | function Config:convertUnit(unit, raw, link, short, unitOnly) | ||
raw = raw or false | |||
link = link or false | link = link or false | ||
local | short = short or false | ||
unitOnly = unitOnly or false | |||
local args = {} | |||
local space = " " | |||
local label = "" | |||
if unit == "" or unit == "1" then | if unit == "" or unit == "1" then | ||
return nil | return nil | ||
end | |||
if unitOnly then | |||
space = "" | |||
end | end | ||
658行目: | 690行目: | ||
return "%" | return "%" | ||
else | else | ||
if raw then | |||
args[#args + 1] = flags.raw | |||
end | |||
if | if link then | ||
args[#args + 1] = flags.linked | |||
end | |||
if short then | |||
args[#args + 1] = flags.short | |||
end | end | ||
label = getLabel(itemID, args) | |||
if | if label ~= "" then | ||
return space .. label | |||
end | end | ||
end | end | ||
end | end | ||
return " " | return "" | ||
end | end | ||
function Config:getValue(snak, raw, link, short, anyLang, noSpecial) | function Config:getValue(snak, raw, link, short, anyLang, unitOnly, noSpecial) | ||
raw = raw or false | raw = raw or false | ||
link = link or false | link = link or false | ||
short = short or false | short = short or false | ||
anyLang = anyLang or false | anyLang = anyLang or false | ||
unitOnly = unitOnly or false | |||
noSpecial = noSpecial or false | noSpecial = noSpecial or false | ||
707行目: | 731行目: | ||
elseif snak.datatype == 'commonsMedia' then | elseif snak.datatype == 'commonsMedia' then | ||
if link then | if link then | ||
return buildWikilink("c:File:" .. snak.datavalue.value, snak.datavalue.value) | |||
elseif not raw then | elseif not raw then | ||
return "[[File:" .. snak.datavalue.value .. "]]" | return "[[File:" .. snak.datavalue.value .. "]]" | ||
719行目: | 738行目: | ||
end | end | ||
elseif snak.datatype == 'geo-shape' and link then | elseif snak.datatype == 'geo-shape' and link then | ||
return buildWikilink("c:" .. snak.datavalue.value, snak.datavalue.value) | |||
elseif snak.datatype == 'math' and not raw then | elseif snak.datatype == 'math' and not raw then | ||
return mw.getCurrentFrame():extensionTag("math", snak.datavalue.value) | return mw.getCurrentFrame():extensionTag("math", snak.datavalue.value) | ||
739行目: | 753行目: | ||
end | end | ||
elseif snak.datavalue.type == 'quantity' then | elseif snak.datavalue.type == 'quantity' then | ||
local value = "" | |||
local value = | local unit | ||
if not raw then | if not unitOnly then | ||
-- get value and strip + signs from front | |||
value = mw.ustring.gsub(snak.datavalue.value['amount'], "^\+(.+)$", "%1") | |||
if raw then | |||
return value | |||
end | |||
-- replace decimal mark based on locale | -- replace decimal mark based on locale | ||
value = replaceDecimalMark(value) | value = replaceDecimalMark(value) | ||
748行目: | 769行目: | ||
-- add delimiters for readability | -- add delimiters for readability | ||
value = addDelimiters(value) | value = addDelimiters(value) | ||
end | |||
unit = self:convertUnit(snak.datavalue.value['unit'], raw, link, short, unitOnly) | |||
if unit then | |||
value = value .. unit | |||
end | end | ||
1,186行目: | 1,207行目: | ||
local rankPos | local rankPos | ||
if rank == | if rank == flags.best then | ||
self.bestRank = true | self.bestRank = true | ||
self.flagBest = true -- mark that 'best' flag was given | self.flagBest = true -- mark that 'best' flag was given | ||
1,192行目: | 1,213行目: | ||
end | end | ||
if rank:sub(1,9) == | if rank:sub(1,9) == flags.preferred then | ||
rankPos = 1 | rankPos = 1 | ||
elseif rank:sub(1,6) == | elseif rank:sub(1,6) == flags.normal then | ||
rankPos = 2 | rankPos = 2 | ||
elseif rank:sub(1,10) == | elseif rank:sub(1,10) == flags.deprecated then | ||
rankPos = 3 | rankPos = 3 | ||
else | else | ||
1,225行目: | 1,246行目: | ||
local periodPos | local periodPos | ||
if period == | if period == flags.future then | ||
periodPos = 1 | periodPos = 1 | ||
elseif period == | elseif period == flags.current then | ||
periodPos = 2 | periodPos = 2 | ||
elseif period == | elseif period == flags.former then | ||
periodPos = 3 | periodPos = 3 | ||
else | else | ||
1,251行目: | 1,272行目: | ||
end | end | ||
if flag == | if flag == flags.linked then | ||
self.curState.linked = true | self.curState.linked = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.raw then | ||
self.curState.rawValue = true | self.curState.rawValue = true | ||
1,263行目: | 1,284行目: | ||
return true | return true | ||
elseif flag == | elseif flag == flags.short then | ||
self.curState.shortName = true | self.curState.shortName = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.multilanguage then | ||
self.curState.anyLanguage = true | self.curState.anyLanguage = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.unit then | ||
self.curState.unitOnly = true | |||
return true | |||
elseif flag == flags.mdy then | |||
self.mdyDate = true | self.mdyDate = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.single then | ||
self.singleClaim = true | self.singleClaim = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.sourced then | ||
self.sourcedOnly = true | self.sourcedOnly = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.edit then | ||
self.editable = true | self.editable = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.editAtEnd then | ||
self.editable = true | self.editable = true | ||
self.editAtEnd = true | self.editAtEnd = true | ||
return true | return true | ||
elseif flag == | elseif flag == flags.best or flag:match('^'..flags.preferred..'[+-]?$') or flag:match('^'..flags.normal..'[+-]?$') or flag:match('^'..flags.deprecated..'[+-]?$') then | ||
self:setRank(flag) | self:setRank(flag) | ||
return true | return true | ||
elseif flag == | elseif flag == flags.future or flag == flags.current or flag == flags.former then | ||
self:setPeriod(flag) | self:setPeriod(flag) | ||
return true | return true | ||
1,540行目: | 1,564行目: | ||
-- level 1 hook | -- level 1 hook | ||
function State:getProperty(claim) | function State:getProperty(claim) | ||
local value = {self.conf:getValue(claim.mainsnak, self.rawValue, self.linked, self.shortName, self.anyLanguage)} -- create one value object | local value = {self.conf:getValue(claim.mainsnak, self.rawValue, self.linked, self.shortName, self.anyLanguage, self.unitOnly)} -- create one value object | ||
if #value > 0 then | if #value > 0 then | ||
1,565行目: | 1,589行目: | ||
-- level 2 hook | -- level 2 hook | ||
function State:getQualifier(snak) | function State:getQualifier(snak) | ||
local value = {self.conf:getValue(snak, self.rawValue, self.linked, self.shortName, self.anyLanguage)} -- create one value object | local value = {self.conf:getValue(snak, self.rawValue, self.linked, self.shortName, self.anyLanguage, self.unitOnly)} -- create one value object | ||
if #value > 0 then | if #value > 0 then | ||
1,639行目: | 1,663行目: | ||
-- not linked yet because we need the plain value for comparison first | -- not linked yet because we need the plain value for comparison first | ||
language = self:getReferenceDetail(statement.snaks, aliasesP.language | language = self:getReferenceDetail(statement.snaks, aliasesP.language, false, false, false, true) -- (noUnset = true) | ||
if language then | if language then | ||
-- not part of a "stated in"-source | -- not part of a "stated in"-source | ||
1,671行目: | 1,695行目: | ||
-- the next two may be part of a "stated in"-source, so retrieve them already so that they won't count as hasExtraParams | -- the next two may be part of a "stated in"-source, so retrieve them already so that they won't count as hasExtraParams | ||
title = self:getReferenceDetail(statement.snaks, aliasesP.title | title = self:getReferenceDetail(statement.snaks, aliasesP.title, false, false, true) -- anyLang = true | ||
statedIn = self:getReferenceDetail(statement.snaks, aliasesP.statedIn, false, true | statedIn = self:getReferenceDetail(statement.snaks, aliasesP.statedIn, false, true, false, true) -- link = true, (noUnset = true) | ||
-- (1) if both "reference URL" and "title" are present, then use the general template for citing web references | -- (1) if both "reference URL" and "title" are present, then use the general template for citing web references | ||
1,687行目: | 1,711行目: | ||
citeParams[i18n['cite']['archive-date']] = self:getReferenceDetail(statement.snaks, aliasesP.archiveDate) | citeParams[i18n['cite']['archive-date']] = self:getReferenceDetail(statement.snaks, aliasesP.archiveDate) | ||
citeParams[i18n['cite']['publisher']] = self:getReferenceDetail(statement.snaks, aliasesP.publisher, false, self.linked) -- link = true/false | citeParams[i18n['cite']['publisher']] = self:getReferenceDetail(statement.snaks, aliasesP.publisher, false, self.linked) -- link = true/false | ||
citeParams[i18n['cite']['quote']] = self:getReferenceDetail(statement.snaks, aliasesP.quote | citeParams[i18n['cite']['quote']] = self:getReferenceDetail(statement.snaks, aliasesP.quote, false, false, true) -- anyLang = true | ||
for i, v in ipairs(authors) do | for i, v in ipairs(authors) do | ||
1,714行目: | 1,738行目: | ||
-- retrieve the rest of the parameters and make them count as hasExtraParams | -- retrieve the rest of the parameters and make them count as hasExtraParams | ||
for i in pairs(statement.snaks) do | for i in pairs(statement.snaks) do | ||
params[i] = self:getReferenceDetail(statement.snaks, i, false, self.linked | params[i] = self:getReferenceDetail(statement.snaks, i, false, self.linked, true) -- link = true/false, anyLang = true | ||
hasExtraParams = true | hasExtraParams = true | ||
end | end | ||
1,786行目: | 1,810行目: | ||
-- gets a detail of one particular type for a reference | -- gets a detail of one particular type for a reference | ||
function State:getReferenceDetail(snaks, dType, raw, link | function State:getReferenceDetail(snaks, dType, raw, link, anyLang, noUnset) | ||
raw = raw or false | raw = raw or false | ||
link = link or false | link = link or false | ||
anyLang = anyLang or false | anyLang = anyLang or false | ||
noUnset = noUnset or false | noUnset = noUnset or false | ||
1,803行目: | 1,826行目: | ||
repeat | repeat | ||
for i, v in ipairs(snaks[dType]) do | for i, v in ipairs(snaks[dType]) do | ||
value = self.conf:getValue(v, raw, link, | value = self.conf:getValue(v, raw, link, false, anyLang and not switchLang, false, true) -- noSpecial = true | ||
if value then | if value then | ||
1,826行目: | 1,849行目: | ||
-- gets the details of one particular type for a reference | -- gets the details of one particular type for a reference | ||
function State:getReferenceDetails(snaks, dType, raw, link | function State:getReferenceDetails(snaks, dType, raw, link, anyLang, noUnset) | ||
raw = raw or false | raw = raw or false | ||
link = link or false | link = link or false | ||
anyLang = anyLang or false | anyLang = anyLang or false | ||
noUnset = noUnset or false | noUnset = noUnset or false | ||
1,841行目: | 1,863行目: | ||
for i, v in ipairs(snaks[dType]) do | for i, v in ipairs(snaks[dType]) do | ||
-- if nil is returned then it will not be added to the table | -- if nil is returned then it will not be added to the table | ||
values[#values + 1] = self.conf:getValue(v, raw, link, | values[#values + 1] = self.conf:getValue(v, raw, link, false, anyLang, false, true) -- noSpecial = true | ||
end | end | ||