「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年5月25日 (木) 18:25(UTC)より
template>K-iczn (en:Module:Wd 2017年5月20日 (土) 11:08(UTC)より) |
template>K-iczn (en:Module:Wd 2017年5月25日 (木) 18:25(UTC)より) |
||
331行目: | 331行目: | ||
end | end | ||
function | function datePrecedesDate(aY, aM, aD, bY, bM, bD) | ||
if aY == nil or bY == nil then | |||
return nil | |||
end | |||
aM = aM or 1 | |||
aD = aD or 1 | |||
bM = bM or 1 | |||
bD = bD or 1 | |||
if aY < bY then | |||
return true | |||
end | |||
if | if aY > bY then | ||
return | return false | ||
end | end | ||
if aM < bM then | |||
return true | |||
end | |||
if | if aM > bM then | ||
return false | |||
end | |||
if aD < bD then | |||
return true | |||
end | end | ||
return | return false | ||
end | end | ||
function | function getHookName(param, index) | ||
if | if hookNames[param] then | ||
return | return hookNames[param][index] | ||
elseif | elseif string.len(param) > 2 then | ||
return 2 | return hookNames[string.sub(param, 1, 2).."\\d"][index] | ||
else | else | ||
return | return nil | ||
end | end | ||
end | end | ||
function alwaysTrue() | |||
return true | |||
end | |||
-- The following function parses a format string. | |||
-- | |||
-- The example below shows how a parsed string is structured in memory. | |||
-- Variables other than 'str' and 'child' are left out for clarity's sake. | |||
-- | |||
-- Example: | |||
-- "A %p B [%s[%q1]] C [%r] D" | |||
-- | |||
-- Structure: | |||
-- [ | |||
-- { | |||
-- str = "A " | |||
-- }, | |||
-- { | |||
-- str = "%p" | |||
-- }, | |||
-- { | |||
-- str = " B ", | |||
-- child = | |||
-- [ | |||
-- { | |||
-- str = "%s", | |||
-- child = | |||
-- [ | |||
-- { | |||
-- str = "%q1" | |||
-- } | |||
-- ] | |||
-- } | |||
-- ] | |||
-- }, | |||
-- { | |||
-- str = " C ", | |||
-- child = | |||
-- [ | |||
-- { | |||
-- str = "%r" | |||
-- } | |||
function alwaysTrue() | -- ] | ||
return true | |||
end | |||
-- The following function parses a format string. | |||
-- | |||
-- The example below shows how a parsed string is structured in memory. | |||
-- Variables other than 'str' and 'child' are left out for clarity's sake. | |||
-- | |||
-- Example: | |||
-- "A %p B [%s[%q1]] C [%r] D" | |||
-- | |||
-- Structure: | |||
-- [ | |||
-- { | |||
-- str = "A " | |||
-- }, | -- }, | ||
-- { | -- { | ||
-- str = " D" | |||
-- str = " D" | |||
-- } | -- } | ||
-- ] | -- ] | ||
562行目: | 512行目: | ||
return root, params | return root, params | ||
end | |||
function convertRank(rank) | |||
if rank == "preferred" then | |||
return 1 | |||
elseif rank == "normal" then | |||
return 2 | |||
elseif rank == "deprecated" then | |||
return 3 | |||
else | |||
return 4 -- default (in its literal sense) | |||
end | |||
end | end | ||
595行目: | 557行目: | ||
return p._label({}) | return p._label({}) | ||
end | end | ||
end | |||
function Config:convertUnit(unit, link) | |||
link = link or false | |||
local itemID, label, lang, title | |||
if unit == "" or unit == "1" then | |||
return nil | |||
end | |||
itemID = parseWikidataURL(unit) | |||
if itemID then | |||
if itemID == aliasesQ.percentage then | |||
return "%" | |||
else | |||
label, lang = mw.wikibase.getLabelWithLang(itemID) | |||
-- don't allow language fallback | |||
if lang ~= self.langCode then | |||
label = nil | |||
end | |||
title = nil | |||
if link or label == nil then | |||
title = mw.wikibase.sitelink(itemID) | |||
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 | |||
return " " .. unit | |||
end | end | ||
657行目: | 663行目: | ||
value = addDelimiters(value) | value = addDelimiters(value) | ||
local unit = convertUnit(snak.datavalue.value['unit'], link) | local unit = self:convertUnit(snak.datavalue.value['unit'], link) | ||
if unit then | if unit then | ||
1,000行目: | 1,006行目: | ||
return value | return value | ||
elseif snak.datavalue.type == 'wikibase-entityid' then | elseif snak.datavalue.type == 'wikibase-entityid' then | ||
local lang | |||
local value = "" | local value = "" | ||
local title = nil | local title = nil | ||
1,017行目: | 1,024行目: | ||
if value == "" then | if value == "" then | ||
value = mw.wikibase. | value, lang = mw.wikibase.getLabelWithLang(itemID) | ||
-- don't allow language fallback | |||
if lang ~= self.langCode then | |||
value = nil | |||
end | |||
end | end | ||
1,911行目: | 1,923行目: | ||
local label = "" | local label = "" | ||
local title = nil | local title = nil | ||
local lang | |||
local nextArg = args[1] | local nextArg = args[1] | ||
1,986行目: | 1,999行目: | ||
if label == "" then | if label == "" then | ||
label = mw.wikibase. | label, lang = mw.wikibase.getLabelWithLang(ID) | ||
-- don't allow language fallback | |||
if lang ~= _.langCode then | |||
label = nil | |||
end | |||
end | end | ||
else | else |