「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年5月17日 (水) 06:18(UTC)より
template>K-iczn (en:Module:Wd 2017年5月12日 (金) 08:40(UTC)より) |
template>K-iczn (en:Module:Wd 2017年5月17日 (水) 06:18(UTC)より) |
||
1行目: | 1行目: | ||
-- Original module located at [[:en:Module:Wd]]. | -- Original module located at [[:en:Module:Wd]] and [[:en:Module:Wd/i18n]]. | ||
local p = {} | local p = {} | ||
163行目: | 163行目: | ||
function extraRequiredParameterError(param) | function extraRequiredParameterError(param) | ||
return applyStringParams(i18n['errors']['extra-required-parameter'], param) | return applyStringParams(i18n['errors']['extra-required-parameter'], param) | ||
end | |||
function getOrdinalSuffix(num) | |||
return i18n.getOrdinalSuffix(num) | |||
end | |||
function addDelimiters(num) | |||
return i18n.addDelimiters(num) | |||
end | |||
function replaceDecimalMark(num) | |||
return mw.ustring.gsub(num, "[.]", i18n['numeric']['decimal-mark'], 1) | |||
end | |||
-- used for cleaner output when subst:ituting this module | |||
function replaceHTMLSpaces(str) | |||
return mw.ustring.gsub(str, " ", " ") | |||
end | |||
function buildWikilink(target, label) | |||
if target == label then | |||
return "[[" .. target .. "]]" | |||
else | |||
return "[[" .. target .. "|" .. label .. "]]" | |||
end | |||
end | end | ||
224行目: | 249行目: | ||
end | end | ||
function parseWikidataURL(url) | |||
local i, j | |||
if url:match('^http[s]?://') then | |||
i, j = url:find("Q") | |||
function parseWikidataURL(url) | |||
local i, j | |||
if url:match('^http[s]?://') then | |||
i, j = url:find("Q") | |||
if i then | if i then | ||
339行目: | 354行目: | ||
if link then | if link then | ||
if title then | if title then | ||
return " " .. | return " " .. buildWikilink(title, (label or title)) | ||
end | end | ||
if not label then | if not label then | ||
return " " .. " | return " " .. buildWikilink("d:" .. itemID, itemID) | ||
end | end | ||
end | end | ||
352行目: | 367行目: | ||
return " " .. unit | return " " .. unit | ||
end | end | ||
413行目: | 411行目: | ||
return false | return false | ||
end | |||
function getHookName(param, index) | |||
if hookNames[param] then | |||
return hookNames[param][index] | |||
elseif string.len(param) > 2 then | |||
return hookNames[string.sub(param, 1, 2).."\\d"][index] | |||
else | |||
return nil | |||
end | |||
end | end | ||
597行目: | 605行目: | ||
if snak.snaktype == 'value' then | if snak.snaktype == 'value' then | ||
if snak.datavalue.type == 'string' then | if snak.datavalue.type == 'string' then | ||
return snak.datavalue.value | if link and snak.datatype == 'url' then | ||
-- create link explicitly | |||
if raw then | |||
-- will render as a linked number like [1] | |||
return "[" .. snak.datavalue.value .. "]" | |||
else | |||
return "[" .. snak.datavalue.value .. " " .. snak.datavalue.value .. "]" | |||
end | |||
else | |||
return snak.datavalue.value | |||
end | |||
elseif snak.datavalue.type == 'monolingualtext' then | elseif snak.datavalue.type == 'monolingualtext' then | ||
if anyLang then | if anyLang then | ||
775行目: | 793行目: | ||
if not raw then | if not raw then | ||
if link then | if link then | ||
calendar = " ( | calendar = " ("..buildWikilink(i18n['datetime']['julian-calendar'], i18n['datetime']['julian'])..")" | ||
else | else | ||
calendar = " ("..i18n['datetime']['julian']..")" | calendar = " ("..i18n['datetime']['julian']..")" | ||
796行目: | 814行目: | ||
if ce then | if ce then | ||
if link then | if link then | ||
ce = | ce = buildWikilink(i18n['datetime']['common-era'], ce) | ||
end | end | ||
suffix = suffix .. " " .. ce | suffix = suffix .. " " .. ce | ||
966行目: | 984行目: | ||
if raw then | if raw then | ||
if link then | if link then | ||
return " | return buildWikilink("d:" .. itemID, itemID) | ||
else | else | ||
return itemID | return itemID | ||
986行目: | 1,004行目: | ||
if link then | if link then | ||
if title then | if title then | ||
value = | value = buildWikilink(title, (value or title)) | ||
elseif not value then | elseif not value then | ||
value = " | value = buildWikilink("d:" .. itemID, itemID) | ||
end | end | ||
elseif not value then | elseif not value then | ||
1,436行目: | 1,454行目: | ||
if snaks[aliasesP.archiveURL] then params[i18n['cite']['archive-url']] = self.conf:getValue(snaks[aliasesP.archiveURL]) end | if snaks[aliasesP.archiveURL] then params[i18n['cite']['archive-url']] = self.conf:getValue(snaks[aliasesP.archiveURL]) end | ||
if snaks[aliasesP.archiveDate] then params[i18n['cite']['archive-date']] = self.conf:getValue(snaks[aliasesP.archiveDate]) end | if snaks[aliasesP.archiveDate] then params[i18n['cite']['archive-date']] = self.conf:getValue(snaks[aliasesP.archiveDate]) end | ||
if snaks[aliasesP.author] then params[i18n['cite']['author']] = self.conf:getValue(snaks[aliasesP.author]) | if snaks[aliasesP.author] then params[i18n['cite']['author']] = self.conf:getValue(snaks[aliasesP.author], false, self.linked) end -- link = true/false | ||
if snaks[aliasesP.publisher] then params[i18n['cite']['publisher']] = self.conf:getValue(snaks[aliasesP.publisher]) | if snaks[aliasesP.publisher] then params[i18n['cite']['publisher']] = self.conf:getValue(snaks[aliasesP.publisher], false, self.linked) end -- link = true/false | ||
if snaks[aliasesP.quote] then params[i18n['cite']['quote']] = self.conf:getValue(snaks[aliasesP.quote], false, false, false, true) end -- anyLang = true | if snaks[aliasesP.quote] then params[i18n['cite']['quote']] = self.conf:getValue(snaks[aliasesP.quote], false, false, false, true) end -- anyLang = true | ||
if snaks[aliasesP.language] then | if snaks[aliasesP.language] then | ||
snakValue = self.conf:getValue(snaks[aliasesP.language]) | snakValue = self.conf:getValue(snaks[aliasesP.language], false, self.linked) -- link = true/false | ||
if self.conf.langName ~= snakValue then | if self.conf.langName ~= snakValue then | ||
1,462行目: | 1,480行目: | ||
if snaks[aliasesP.referenceURL] and snaks[aliasesP.title] then | if snaks[aliasesP.referenceURL] and snaks[aliasesP.title] then | ||
url = self.conf:getValue(snaks[aliasesP.referenceURL]) | url = self.conf:getValue(snaks[aliasesP.referenceURL]) | ||
title = self.conf:getValue(snaks[aliasesP.title], false, false, false, true) | title = self.conf:getValue(snaks[aliasesP.title], false, false, false, true) -- anyLang = true | ||
leadParams[#leadParams + 1] = "[" .. url .. " " .. title .. "]" | leadParams[#leadParams + 1] = "[" .. url .. " " .. title .. "]" | ||
1,475行目: | 1,493行目: | ||
if property ~= "" then | if property ~= "" then | ||
snakValue, lang = self.conf:getValue(v, false, (i == aliasesP.statedIn), false, true) -- link = true/false, anyLang = true | snakValue, lang = self.conf:getValue(v, false, self.linked or (i == aliasesP.statedIn) or (i == aliasesP.referenceURL), false, true) -- link = true/false, anyLang = true | ||
if lang and lang ~= self.conf.langCode then | if lang and lang ~= self.conf.langCode then | ||
1,894行目: | 1,912行目: | ||
if _.curState.linked then | if _.curState.linked then | ||
if ID:sub(1,1) == "P" then | if ID:sub(1,1) == "P" then | ||
label = " | label = buildWikilink("d:Property:" .. ID, ID) | ||
else | else | ||
label = " | label = buildWikilink("d:" .. ID, ID) | ||
end | end | ||
else | else | ||
1,910行目: | 1,928行目: | ||
if _.curState.linked and label ~= "" then | if _.curState.linked and label ~= "" then | ||
label = " | label = buildWikilink("d:" .. label, label) | ||
end | end | ||
1,922行目: | 1,940行目: | ||
if _.curState.linked and label ~= "" then | if _.curState.linked and label ~= "" then | ||
label = " | label = buildWikilink("d:Property:" .. ID, label) | ||
end | end | ||
end | end | ||
1,952行目: | 1,970行目: | ||
if _.curState.linked and title then | if _.curState.linked and title then | ||
label = | label = buildWikilink(title, (label or title)) | ||
else | else | ||
label = label or title or "" | label = label or title or "" |