「モジュール: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
return p._label({ID})
args[#args + 1] = ID
else
return p._label({})
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 itemID, label, lang, title
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
label, lang = mw.wikibase.getLabelWithLang(itemID)
if raw then
args[#args + 1] = flags.raw
-- don't allow language fallback
end
if lang ~= self.langCode then
if link then
label = nil
args[#args + 1] = flags.linked
end
if short then
args[#args + 1] = flags.short
end
end
title = nil
label = getLabel(itemID, args)
if link or label == nil then
if label ~= "" then
title = mw.wikibase.sitelink(itemID)
return space .. label
end
end
if link then
if title then
return " " .. buildWikilink(title, (label or title))
end
if not label then
return " " .. buildWikilink("d:" .. itemID, itemID)
end
end
return " " .. (label or title or itemID)
end
end
end
end
return " " .. unit
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
if raw then
return buildWikilink("c:File:" .. snak.datavalue.value, snak.datavalue.value)
-- will render as a linked number like [1]
return "[https://commons.wikimedia.org/wiki/File:" .. mw.ustring.gsub(snak.datavalue.value, " ", "_") .. "]"
else
return "[https://commons.wikimedia.org/wiki/File:" .. mw.ustring.gsub(snak.datavalue.value, " ", "_") .. " " .. snak.datavalue.value .. "]"
end
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
if raw then
return buildWikilink("c:" .. snak.datavalue.value, snak.datavalue.value)
-- will render as a linked number like [1]
return "[https://commons.wikimedia.org/wiki/" .. mw.ustring.gsub(snak.datavalue.value, " ", "_") .. "]"
else
return "[https://commons.wikimedia.org/wiki/" .. mw.ustring.gsub(snak.datavalue.value, " ", "_") .. " " .. snak.datavalue.value .. "]"
end
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
-- strip + signs from front
local value = ""
local value = mw.ustring.gsub(snak.datavalue.value['amount'], "^\+(.+)$", "%1")
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
local unit = self:convertUnit(snak.datavalue.value['unit'], link)
unit = self:convertUnit(snak.datavalue.value['unit'], raw, link, short, unitOnly)
if unit then
value = value .. unit
if unit then
end
value = value .. unit
end
end
1,186行目: 1,207行目:
local rankPos
local rankPos
if rank == "best" then
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) == "preferred" then
if rank:sub(1,9) == flags.preferred then
rankPos = 1
rankPos = 1
elseif rank:sub(1,6) == "normal" then
elseif rank:sub(1,6) == flags.normal then
rankPos = 2
rankPos = 2
elseif rank:sub(1,10) == "deprecated" then
elseif rank:sub(1,10) == flags.deprecated then
rankPos = 3
rankPos = 3
else
else
1,225行目: 1,246行目:
local periodPos
local periodPos
if period == "future" then
if period == flags.future then
periodPos = 1
periodPos = 1
elseif period == "current" then
elseif period == flags.current then
periodPos = 2
periodPos = 2
elseif period == "former" then
elseif period == flags.former then
periodPos = 3
periodPos = 3
else
else
1,251行目: 1,272行目:
end
end
if flag == "linked" then
if flag == flags.linked then
self.curState.linked = true
self.curState.linked = true
return true
return true
elseif flag == "raw" then
elseif flag == flags.raw then
self.curState.rawValue = true
self.curState.rawValue = true
1,263行目: 1,284行目:
return true
return true
elseif flag == "short" then
elseif flag == flags.short then
self.curState.shortName = true
self.curState.shortName = true
return true
return true
elseif flag == "multilanguage" then
elseif flag == flags.multilanguage then
self.curState.anyLanguage = true
self.curState.anyLanguage = true
return true
return true
elseif flag == "mdy" then
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 == "single" then
elseif flag == flags.single then
self.singleClaim = true
self.singleClaim = true
return true
return true
elseif flag == "sourced" then
elseif flag == flags.sourced then
self.sourcedOnly = true
self.sourcedOnly = true
return true
return true
elseif flag == "edit" then
elseif flag == flags.edit then
self.editable = true
self.editable = true
return true
return true
elseif flag == "edit@end" then
elseif flag == flags.editAtEnd then
self.editable = true
self.editable = true
self.editAtEnd = true
self.editAtEnd = true
return true
return true
elseif flag == "best" or flag:match('^preferred[+-]?$') or flag:match('^normal[+-]?$') or flag:match('^deprecated[+-]?$') then
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 == "future" or flag == "current" or flag == "former" then
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, false, false, false, false, true)  -- (noUnset = true)
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, false, false, false, true)  -- anyLang = true
title    = self:getReferenceDetail(statement.snaks, aliasesP.title, false, false, true)  -- anyLang = true
statedIn = self:getReferenceDetail(statement.snaks, aliasesP.statedIn, false, true, false, false, true)  -- link = true, (noUnset = 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, false, false, false, true)  -- anyLang = true
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, false, true)  -- link = true/false, anyLang = true
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, short, anyLang, noUnset)
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
short = short 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, short, anyLang and not switchLang, true)  -- noSpecial = true
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, short, anyLang, noUnset)
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
short = short 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, short, anyLang, true)  -- noSpecial = true
values[#values + 1] = self.conf:getValue(v, raw, link, false, anyLang, false, true)  -- noSpecial = true
end
end
匿名利用者