删除的内容 添加的内容
enwiki>Janhrach
CaelLab-import​(留言 | 贡献)
本站无 Wikibase:入口函数统一返回空串,替代 mw.wikibase 报错
 
第1行:
-- Original module located at [[:en:Module:Wd]] and [[:en:Module:Wd/i18n]].
 
require("strict")
local p = {}
local module_argarg = ...
local i18n
local i18nPath
 
local function loadI18n(aliasesP, frame)
第15行 ⟶ 第13行:
else
-- current module included by other module, get its title from ...
title = module_argarg
end
 
if not i18n then
i18nPathi18n = require(title .. "/i18n").init(aliasesP)
i18n = require(i18nPath).init(aliasesP)
end
end
第59行 ⟶ 第56行:
edit = "edit",
editAtEnd = "edit@end",
-- mdy = "mdy",
single = "single",
sourced = "sourced"
第67行 ⟶ 第64行:
eid = "eid",
page = "page",
date = "date",
globalSiteId = "globalSiteId"
}
 
第76行 ⟶ 第72行:
image = "P18",
author = "P50",
authorNameString = "P2093",
publisher = "P123",
importedFrom = "P143",
wikimediaImportURL = "P4656",
statedIn = "P248",
pages = "P304",
language = "P407",
wikimediaLanguageCode = "P424",
hasPart = "P527",
publicationDate = "P577",
第101行 ⟶ 第94行:
inferredFrom = "P3452",
typeOfReference = "P3865",
column = "P3903",
subjectNamedAs = "P1810",
wikidataProperty = "P1687",
publishedIn = "P1433",
lastUpdate = "P5017"
}
 
第145行 ⟶ 第134行:
-- default value objects, should NOT be mutated but instead copied
local defaultSeparators = {
["sep"] = {" "},
["sep%s"] = {",、"},
["sep%q"] = {"; ;"},
["sep%q\\d"] = {", 、"},
["sep%r"] = nil, -- none
["punc"] = nil -- none
第158行 ⟶ 第147行:
["deprecated"] = 3
}
 
local Config = {}
 
-- allows for recursive calls
function Config:new()
local cfg = {}
setmetatable(cfg, self)
self.__index = self
 
cfg.separators = {
-- single value objects wrapped in arrays so that we can pass by reference
["sep"] = {copyTable(defaultSeparators["sep"])},
["sep%s"] = {copyTable(defaultSeparators["sep%s"])},
["sep%q"] = {copyTable(defaultSeparators["sep%q"])},
["sep%r"] = {copyTable(defaultSeparators["sep%r"])},
["punc"] = {copyTable(defaultSeparators["punc"])}
}
 
cfg.entity = nil
cfg.entityID = nil
cfg.propertyID = nil
cfg.propertyValue = nil
cfg.qualifierIDs = {}
cfg.qualifierIDsAndValues = {}
 
cfg.bestRank = true
cfg.ranks = {true, true, false} -- preferred = true, normal = true, deprecated = false
cfg.foundRank = #cfg.ranks
cfg.flagBest = false
cfg.flagRank = false
 
cfg.periods = {true, true, true} -- future = true, current = true, former = true
cfg.flagPeriod = false
cfg.atDate = {parseDate(os.date('!%Y-%m-%d'))} -- today as {year, month, day}
 
-- cfg.mdyDate = false
cfg.singleClaim = false
cfg.sourcedOnly = false
cfg.editable = false
cfg.editAtEnd = false
 
cfg.inSitelinks = false
 
cfg.langCode = mw.language.getContentLanguage().code
cfg.langName = mw.language.fetchLanguageName(cfg.langCode, cfg.langCode)
cfg.langObj = mw.language.new(cfg.langCode)
 
cfg.siteID = mw.wikibase.getGlobalSiteId()
 
cfg.states = {}
cfg.states.qualifiersCount = 0
cfg.curState = nil
 
cfg.prefetchedRefs = nil
 
return cfg
end
 
local State = {}
 
function State:new(cfg, type)
local stt = {}
setmetatable(stt, self)
self.__index = self
 
stt.conf = cfg
stt.type = type
 
stt.results = {}
 
stt.parsedFormat = {}
stt.separator = {}
stt.movSeparator = {}
stt.puncMark = {}
 
stt.linked = false
stt.rawValue = false
stt.shortName = false
stt.anyLanguage = false
stt.unitOnly = false
stt.singleValue = false
 
return stt
end
 
local function replaceAlias(id)
第167行 ⟶ 第240行:
end
 
local function errorText(code, ...param)
local text = i18n["errors"][code]
if argparam then text = mw.ustring.formatgsub(text, unpack(arg)"$1", param) end
return text
end
 
local function throwError(errorMessage, ...param)
error(errorText(errorMessage, unpack(arg)param))
end
 
第246行 ⟶ 第319行:
-- used to make frame.args mutable, to replace #frame.args (which is always 0)
-- with the actual amount and to simply copy tables
local function copyTable(tIn)
if not tIn then
return nil
第298行 ⟶ 第371行:
end
 
local function parseDate(dateStr, precision)
precision = precision or "d"
 
第329行 ⟶ 第402行:
if i then
-- year
parts[index] = tonumber(mw.ustring.gsub(dateStr:sub(ptr, i-1), "^\+(.+)$", "%1"), 10) -- remove '+' sign (explicitly give base 10 to prevent error)
 
if parts[index] == -0 then
第575行 ⟶ 第648行:
 
return sorted
end
 
local function isValueInTable(searchedItem, inputTable)
for _, item in pairs(inputTable) do
if item == searchedItem then
return true
end
end
return false
end
 
local Config = {}
 
-- allows for recursive calls
function Config:new()
local cfg = {}
setmetatable(cfg, self)
self.__index = self
 
cfg.separators = {
-- single value objects wrapped in arrays so that we can pass by reference
["sep"] = {copyTable(defaultSeparators["sep"])},
["sep%s"] = {copyTable(defaultSeparators["sep%s"])},
["sep%q"] = {copyTable(defaultSeparators["sep%q"])},
["sep%r"] = {copyTable(defaultSeparators["sep%r"])},
["punc"] = {copyTable(defaultSeparators["punc"])}
}
 
cfg.entity = nil
cfg.entityID = nil
cfg.propertyID = nil
cfg.propertyValue = nil
cfg.qualifierIDs = {}
cfg.qualifierIDsAndValues = {}
 
cfg.bestRank = true
cfg.ranks = {true, true, false} -- preferred = true, normal = true, deprecated = false
cfg.foundRank = #cfg.ranks
cfg.flagBest = false
cfg.flagRank = false
 
cfg.periods = {true, true, true} -- future = true, current = true, former = true
cfg.flagPeriod = false
cfg.atDate = {parseDate(os.date('!%Y-%m-%d'))} -- today as {year, month, day}
 
cfg.mdyDate = false
cfg.singleClaim = false
cfg.sourcedOnly = false
cfg.editable = false
cfg.editAtEnd = false
 
cfg.inSitelinks = false
 
cfg.langCode = mw.language.getContentLanguage().code
cfg.langName = mw.language.fetchLanguageName(cfg.langCode, cfg.langCode)
cfg.langObj = mw.language.new(cfg.langCode)
 
cfg.siteID = mw.wikibase.getGlobalSiteId()
 
cfg.states = {}
cfg.states.qualifiersCount = 0
cfg.curState = nil
 
cfg.prefetchedRefs = nil
 
return cfg
end
 
local State = {}
 
function State:new(cfg, type)
local stt = {}
setmetatable(stt, self)
self.__index = self
 
stt.conf = cfg
stt.type = type
 
stt.results = {}
 
stt.parsedFormat = {}
stt.separator = {}
stt.movSeparator = {}
stt.puncMark = {}
 
stt.linked = false
stt.rawValue = false
stt.shortName = false
stt.anyLanguage = false
stt.unitOnly = false
stt.singleValue = false
 
return stt
end
 
第704行 ⟶ 第684行:
-- get label
if not label then
label = mw.wikibase.getLabelgetLabelByLang(id, self.langCode) -- XXX: should use fallback labels?
end
end
第733行 ⟶ 第713行:
local value = ""
local prefix = ""
local front = "" -- " "
local back = ""
 
第867行 ⟶ 第847行:
return mw.getCurrentFrame():extensionTag("math", datavalue, attribute)
elseif subtype == 'external-id' and link then
local url = p._property{p.flags.raw, aliasesP.formatterURL, [p.args.eid] = snak.property} -- get formatter URL
 
if url ~= "" then
第890行 ⟶ 第870行:
if not unitOnly then
-- get value and strip + signs from front
value = mw.ustring.gsub(datavalue['amount'], "^%\+(.+)$", "%1")
 
if raw then
第1,092行 ⟶ 第1,072行:
 
if d then
ifdateStr self= dateStr .. d ..mdyDate then"日"
-- if self.mdyDate then
dateStr = dateStr .. " " .. d .. ","
-- dateStr = dateStr .. " " .. d .. ","
else
-- else
dateStr = d .. " " .. dateStr
-- dateStr = d .. " " .. dateStr
end
-- end
end
 
value = dateStrvalue .. " 年" .. valuedateStr
-- value = dateStr .. " " .. value
end
 
第1,302行 ⟶ 第1,284行:
lonLink = table.concat({lonDegrees, lonMinutes, lonSeconds}, "_")
 
value = "[https://geohacktools.toolforgewmflabs.org/geohack/geohack.php?language="..self.langCode.."&params="..latLink.."_"..latDirectionEN.."_"..lonLink.."_"..lonDirectionEN.."_globe:"..globe.." "..value.."]"
end
 
第1,535行 ⟶ 第1,517行:
self.curState.unitOnly = true
return true
-- elseif flag == p.flags.mdy then
-- self.mdyDate = true
-- return true
elseif flag == p.flags.single then
self.singleClaim = true
第1,816行 ⟶ 第1,798行:
-- level 2 hook
function State:getReference(statement)
local key, citeWeb, citeQ, label
local citeParamMapping = i18n['cite']['param-mapping']
local citeConfigparams = i18n['cite']['config']{}
local citeTypesciteParams = i18n{['citeweb'] = {}, ['output-typesq'] = {}}
local citeMismatch = {}
local useCite = nil
-- for each citation type, there will be an associative array that associates lists of rendered properties
local useParams = nil
-- to citation-template parameters
local candidateParamsvalue = {}""
local ref = {}
-- like above, but only associates one rendered property to each parameter; if the above variable
-- contains more strings for a parameter, the strings will be assigned to numbered params (e.g. "author1")
local citeParams = {}
 
local version = 1 -- increment this each time the below logic is changed to avoid conflict errors
local citeErrors = {}
local referenceEmpty = true -- will be set to false if at least one parameter is left unremoved
 
if statement.snaks then
local version = 13 -- increment this each time the below logic is changed to avoid conflict errors
-- don't include "imported from", which is added by a bot
if statement.snaks[aliasesP.importedFrom] then
statement.snaks[aliasesP.importedFrom] = nil
end
 
-- don't include "inferred from", which is added by a bot
if not statement.snaks then
if statement.snaks[aliasesP.inferredFrom] then
return {}
statement.snaks[aliasesP.inferredFrom] = nil
end
end
 
-- don't include "type of reference"
-- don't use bot-added references referencing Wikimedia projects or containing "inferred from" (such references are not usable on Wikipedia)
if statement.snaks[aliasesP.importedFrom] or statement.snaks[aliasesP.wikimediaImportURL] or statement.snaks[aliasesP.inferredFromtypeOfReference] then
statement.snaks[aliasesP.typeOfReference] = nil
return {}
end
-- don't include "type of reference"
if statement.snaks[aliasesP.typeOfReference] then
statement.snaks[aliasesP.typeOfReference] = nil
end
 
-- don't include "image" to prevent littering
if statement.snaks[aliasesP.image] then
statement.snaks[aliasesP.image] = nil
end
 
-- don't include "language" if it is equal to the local one
-- initialize candidateParams and citeParams
if self:getReferenceDetail(statement.snaks, aliasesP.language) == self.conf.langName then
for _, citeType in ipairs(citeTypes) do
statement.snaks[aliasesP.language] = nil
candidateParams[citeType] = {}
end
citeParams[citeType] = {}
end
 
-- retrieve all the parameters
-- fill candidateParams
for _, citeTypei in ipairspairs(citeTypesstatement.snaks) do
label = ""
-- This will contain value--priority pairs for each param name.
local candidateValuesAndPriorities = {}
 
-- multiple authors may be given
-- fill candidateValuesAndPriorities
if i == aliasesP.author then
for refProperty in pairs(statement.snaks) do
params[i] = self:getReferenceDetails(statement.snaks, i, false, self.linked, true) -- link = true/false, anyLang = true
if citeErrors[citeType] then
breakelse
params[i] = {self:getReferenceDetail(statement.snaks, i, false, (self.linked or (i == aliasesP.statedIn)) and (statement.snaks[i][1].datatype ~= 'url'), true)} -- link = true/false, anyLang = true
end
 
repeat -- just a simple wrapper to emulate "continue"
if #params[i] == 0 then
-- set mappingKey
localparams[i] mappingKey= nil
else
if statement.snaks[refProperty][1].datatype == 'external-id' then
mappingKeyif statement.snaks[i][1].datatype == "'external-id"' then
key = "external-id"
label = self.conf:getLabel(i)
 
if label ~= "" then
label = label .. " "
end
else
mappingKeykey = refPropertyi
end
 
-- add the parameter to each matching type of citation
local paramName = citeParamMapping[citeType][mappingKey]
for j in pairs(citeParams) do
-- skip properties with empty parameter name
-- do so if there was no mismatch with a previous parameter
if paramName == "" then
if not citeMismatch[j] then
break -- skip this property for this value of citeType
-- check if this parameter is not mismatching itself
if i18n['cite'][j][key] then
-- continue if an option is available in the corresponding cite template
if i18n['cite'][j][key] ~= "" then
citeParams[j][i18n['cite'][j][key]] = label .. params[i][1]
 
-- if there are multiple parameter values (authors), add those too
for k=2, #params[i] do
citeParams[j][i18n['cite'][j][key]..k] = label .. params[i][k]
end
end
else
citeMismatch[j] = true
end
end
end
end
-- handle unknown properties in the reference
if not paramName then
referenceEmpty = false
local propertyWikitext = "[[d:Special:EntityPage/" .. refProperty .. "|" .. self.conf:getLabel(refProperty) .. " (" .. refProperty .. ")]]"
local error_message = errorText("unknown-property-in-ref", propertyWikitext)
assert(error_message) -- Should not be nil
citeErrors[citeType] = error_message
break
end
-- set processedProperty
local processedProperty
local raw = false -- if the value is wanted raw
if isValueInTable(paramName, citeConfig[citeType]["raw-value-params"] or {}) then
raw = true
end
local customRenderer = nil
if citeConfig[citeType]["customRenderers"] then
customRenderer = citeConfig[citeType]["customRenderers"][paramName]
end
if isValueInTable(paramName, citeConfig[citeType]["numbered-params"] or {}) then
-- Multiple values may be given.
processedProperty = self:getReferenceDetails(statement.snaks, refProperty, raw, self.linked, true, customRenderer) -- anyLang = true
else
-- If multiple values are given, all but the first suitable one are discarted.
processedProperty = {self:getReferenceDetail(statement.snaks, refProperty, raw, self.linked and (statement.snaks[refProperty][1].datatype ~= 'url'), true, customRenderer)} -- link = true/false, anyLang = true
end
if #processedProperty == 0 then
break
end
referenceEmpty = false
-- add an empty entry to candidateValuesAndPriorities, if there isn't one already
if not candidateValuesAndPriorities[paramName] then
candidateValuesAndPriorities[paramName] = {}
end
-- find the priority of refProperty
-- (the actual index is mappingKey, not refProperty, because of external IDs)
local thisPropertyPriority = -1
local thisParamPrioritization = (citeConfig[citeType]["prioritization"] or {})[paramName]
if thisParamPrioritization then
for i_priority, i_key in ipairs(thisParamPrioritization) do
if i_key == mappingKey then
thisPropertyPriority = i_priority
end
end
end
for _, propertyValue in pairs(processedProperty) do
table.insert(
candidateValuesAndPriorities[paramName],
{propertyValue, thisPropertyPriority}
)
end
until true
end
 
-- get title of general template for citing web references
-- fill candidateParams[citeType]
citeWeb = split(mw.wikibase.getSitelink(aliasesQ.citeWeb) or "", ":")[2] -- split off namespace from front
if not citeErrors[citeType] then
 
local compareValuePriorities = function(pair1, pair2)
-- get title of template that expands stated-in references into citations
if pair1[2] == -1 and pair2[2] ~= -1 then
citeQ = split(mw.wikibase.getSitelink(aliasesQ.citeQ) or "", ":")[2] -- split off namespace from front
return false
 
end
-- (1) use the general template for citing web references if there is a match and if at least both "reference URL" and "title" are present
if pair1[2] ~= -1 and pair2[2] == -1 then
if citeWeb and not citeMismatch['web'] and citeParams['web'][i18n['cite']['web'][aliasesP.referenceURL]] and citeParams['web'][i18n['cite']['web'][aliasesP.title]] then
return true
useCite = citeWeb
useParams = citeParams['web']
 
-- (2) use the template that expands stated-in references into citations if there is a match and if at least "stated in" is present
elseif citeQ and not citeMismatch['q'] and citeParams['q'][i18n['cite']['q'][aliasesP.statedIn]] then
-- we need the raw "stated in" Q-identifier for the this template
citeParams['q'][i18n['cite']['q'][aliasesP.statedIn]] = self:getReferenceDetail(statement.snaks, aliasesP.statedIn, true) -- raw = true
 
useCite = citeQ
useParams = citeParams['q']
end
 
if useCite and useParams then
-- if this module is being substituted then build a regular template call, otherwise expand the template
if mw.isSubsting() then
for i, v in pairs(useParams) do
value = value .. "|" .. i .. "=" .. v
end
 
return pair1[2] < pair2[2]
value = "{{" .. useCite .. value .. "}}"
else
value = mw.getCurrentFrame():expandTemplate{title=useCite, args=useParams}
end
 
-- (3) else, do some default rendering of name-value pairs, but only if at least "stated in", "reference URL" or "title" is present
-- fill candidateParams[citeType][paramName] for each used param
elseif params[aliasesP.statedIn] or params[aliasesP.referenceURL] or params[aliasesP.title] then
for paramName, _ in pairs(candidateValuesAndPriorities) do
citeParams['default'] = {}
table.sort(candidateValuesAndPriorities[paramName], compareValuePriorities)
 
candidateParams[citeType][paramName] = {}
-- start by adding authors up front
for _, valuePriorityPair in ipairs(candidateValuesAndPriorities[paramName]) do
if params[aliasesP.author] and #params[aliasesP.author] > 0 then
table.insert(candidateParams[citeType][paramName], valuePriorityPair[1])
citeParams['default'][#citeParams['default'] + 1] = table.concat(params[aliasesP.author], " & ")
end
end
 
end
-- combine "reference URL" and "title" into one link if both are present
end
if params[aliasesP.referenceURL] and params[aliasesP.title] then
citeParams['default'][#citeParams['default'] + 1] = '[' .. params[aliasesP.referenceURL][1] .. ' "' .. params[aliasesP.title][1] .. '"]'
-- fill citeParams
elseif params[aliasesP.referenceURL] then
for _, citeType in ipairs(citeTypes) do
citeParams['default'][#citeParams['default'] + 1] = params[aliasesP.referenceURL][1]
for paramName, paramValues in pairs(candidateParams[citeType]) do
elseif params[aliasesP.title] then
if #paramValues == 1 or not isValueInTable(paramName, citeConfig[citeType]["numbered-params"] or {}) then
citeParams[citeType'default'][paramName#citeParams['default'] + 1] = paramValues'"' .. params[aliasesP.title][1] .. '"'
else
-- There is more than one value for this parameter - the values will
-- go into separate numbered parameters (e.g. "author1", "author2")
for paramNum, paramValue in pairs(paramValues) do
citeParams[citeType][paramName .. paramNum] = paramValue
end
end
 
end
-- then add "stated in"
end
if params[aliasesP.statedIn] then
citeParams['default'][#citeParams['default'] + 1] = "''" .. params[aliasesP.statedIn][1] .. "''"
-- handle missing mandatory parameters for the templates
for _, citeType in ipairs(citeTypes) do
for _, requiredCiteParam in pairs(citeConfig[citeType]["mandatory-params"] or {}) do
if not citeParams[citeType][requiredCiteParam] then -- The required param is not present.
if citeErrors[citeType] then -- Do not override the previous error, if it exists.
break
end
local error_message = errorText("missing-mandatory-param", requiredCiteParam)
assert(error_message) -- Should not be nil
citeErrors[citeType] = error_message
end
end
end
local citeTypeToUse = nil
 
-- remove previously added parameters so that they won't be added a second time
-- choose the output template
params[aliasesP.author] = nil
for _, citeType in ipairs(citeTypes) do
params[aliasesP.referenceURL] = nil
if not citeErrors[citeType] then
params[aliasesP.title] = nil
citeTypeToUse = citeType
params[aliasesP.statedIn] = nil
break
end
end
 
-- add the rest of the parameters
-- set refContent
for i, v in pairs(params) do
local refContent = ""
i = self.conf:getLabel(i)
if citeTypeToUse then
 
local templateToUse = citeConfig[citeTypeToUse]["template"]
if i ~= "" then
local paramsToUse = citeParams[citeTypeToUse]
citeParams['default'][#citeParams['default'] + 1] = i .. ": " .. v[1]
end
if not templateToUse or templateToUse == "" then
throwError("no-such-reference-template", tostring(templateToUse), i18nPath, citeTypeToUse)
end
-- if this module is being substituted then build a regular template call, otherwise expand the template
if mw.isSubsting() then
for i, v in pairs(paramsToUse) do
refContent = refContent .. "|" .. i .. "=" .. v
end
 
value = table.concat(citeParams['default'], "; ")
refContent = "{{" .. templateToUse .. refContent .. "}}"
 
else
if value ~= "" then
xpcall(
value = value .. "."
function () refContent = mw.getCurrentFrame():expandTemplate{title=templateToUse, args=paramsToUse} end,
end
function () throwError("no-such-reference-template", templateToUse, i18nPath, citeTypeToUse) end
)
end
 
if value ~= "" then
-- If the citation couldn't be displayed using any template, but is not empty (barring ignored propeties), throw an error.
value = {value} -- create one value object
elseif not referenceEmpty then
refContent = errorText("malformed-reference-header")
for _, citeType in ipairs(citeTypes) do
local templateWikitext = "<nowiki>{{</nowiki>[[Template:" .. citeConfig[citeType]["template"] .. "|" .. citeConfig[citeType]["template"] .. "]]<nowiki>}}</nowiki>"
refContent = refContent .. errorText("template-failure-reason", templateWikitext, citeErrors[citeType])
end
refContent = refContent .. errorText("malformed-reference-footer")
end
 
if not self.rawValue then
-- wrap refContent
-- this should become a <ref> tag, so save the reference's hash for later
local ref = {}
value.refHash = "wikidata-" .. statement.hash .. "-v" .. (tonumber(i18n['cite']['version']) + version)
if refContent ~= "" then
end
ref = {refContent}
 
ref = {value} -- wrap the value object in an array
if not self.rawValue then
-- this should become a <ref> tag, so save the reference's hash for later
ref.refHash = "wikidata-" .. statement.hash .. "-v" .. (tonumber(i18n['version']) + version)
end
return {ref}
else
return {}
end
 
return ref
end
 
-- gets a detail of one particular type for a reference
function State:getReferenceDetail(snaks, dType, raw, link, anyLang, customRenderer)
local switchLang = anyLang
local value = nil
第2,065行 ⟶ 第1,987行:
repeat
for _, v in ipairs(snaks[dType]) do
value = self.conf:getValue(v, raw, link, false, anyLang and not switchLang, false, true) -- noSpecial = true
local defaultRenderer = function ()
return self.conf:getValue(v, raw, link, false, anyLang and not switchLang, false, true) -- noSpecial = true
end
if customRenderer then
value = customRenderer(
v, dType,
defaultRenderer,
p._properties,
function (...) return self.conf:getValue(unpack(arg)) end,
snaks
)
else
value = defaultRenderer()
end
 
if value then
第2,096行 ⟶ 第2,005行:
 
-- gets the details of one particular type for a reference
function State:getReferenceDetails(snaks, dType, raw, link, anyLang, customRenderer)
local values = {}
 
第2,104行 ⟶ 第2,013行:
 
for _, v in ipairs(snaks[dType]) do
-- if nil is returned then it will not be added to the table
local defaultRenderer = function ()
returnvalues[#values + 1] = self.conf:getValue(v, raw, link, false, anyLang, false, true) -- noSpecial = true
end
local value
if customRenderer then
value = customRenderer(
v, dType,
defaultRenderer,
p._properties,
function (...) return self.conf:getValue(unpack(arg)) end,
snaks
)
else
value = defaultRenderer()
end
-- if value is nil then it will not be added to the table
values[#values + 1] = value
end
 
第2,171行 ⟶ 第2,064行:
 
function State:callHook(param, hooks, statement, result)
local valuesArray, refHash
 
-- call a parameter's hook if it has been defined and if it has not been called before
if not result[param] and hooks[param] then
local valuesArray = self[hooks[param]](self, statement, param, result, hooks) -- array with value objects
 
-- add to the result
第2,259行 ⟶ 第2,154行:
end
 
local function getEntityId(arg, eid, page, allowOmitPropPrefix, globalSiteId)
local id = nil
local prop = nil
第2,290行 ⟶ 第2,185行:
end
 
id = mw.wikibase.getEntityIdForTitle(page, globalSiteId) or ""
end
 
第2,337行 ⟶ 第2,232行:
 
-- get the entity ID from either the positional argument, the eid argument or the page argument
cfg.entityID, cfg.propertyID = getEntityId(lastArg, args[p.args.eid], args[p.args.page], false, args[p.args.globalSiteId])
 
if cfg.entityID == "" then
第2,410行 ⟶ 第2,305行:
-- if a "qualifier(s)" command and no "propert(y|ies)" command has been given, make the movable separator a semicolon
if cfg.states.qualifiersCount > 0 and not cfg.states[parameters.property] then
cfg.separators["sep"..parameters.separator][1] = {";;"}
end
 
第2,509行 ⟶ 第2,404行:
 
-- get the entity ID from either the positional argument, the eid argument or the page argument
cfg.entityID = getEntityId(lastArg, args[p.args.eid], args[p.args.page], true, args[p.args.globalSiteId])
 
if cfg.entityID == "" or not mw.wikibase.entityExists(cfg.entityID) then
第2,669行 ⟶ 第2,564行:
 
return p["_"..f](args)
end
 
if not mw.wikibase then
for k, v in pairs(p) do
if type(v) == 'function' then
p[k] = function() return '' end
end
end
end