url = mw.message.newRawMessage(props.url, verified_value):plain
if props.track and not string.find(props.langcode, "(SL%l+)") then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-local-wd'), props.prop):plain
elseif props.track then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-wd-wd'), props.prop):plain
end
else
url = verified_value:gsub(' ','_')
if props.track then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-wd-wd'), props.prop):plain
end
end
if url ~= '' then
local this_wiki = mw.getContentLanguage
local this_wiki_code = this_wiki:getCode
local langlink = (value.langcode and value.langcode ~= '' and value.langcode ~= this_wiki_code) and mw.message.newRawMessage(conf:g('msg-langcode'), value.langcode, mw.language.fetchLanguageName(value.langcode, this_wiki_code)) or ""
if short_links and props.short then
output[#output].text =
mw.message.newRawMessage(props.short,
getLabel(entity, props.genitive, pagetitle),
url,
langlink,
verified_value,
mw.uri.encode(verified_value, 'PATH'))
:plain
else
output[#output].text =
mw.message.newRawMessage(props.message,
getLabel(entity, props.genitive, pagetitle),
url,
langlink,
verified_value,
mw.uri.encode(verified_value, 'PATH'))
:plain
end
end
end
end
--mw.log("findSiteLinksOnWikidata returning="..dump(output))
return output
end  
local function findMainLinksLocal(props, pagetitle, short_links, local_value)
local output = {}
-- to avoid deep tests
if not props.prop then
return nil
end
if not local_value or local_value == '' then
-- bail out if no value is present
return output
end
-- get the formatvalue from the property
local verified_value = local_value
if props.regex and props.regex ~= '' then
-- let's verify the id
-- maybe we'll have to convert the regex to Lua-style
local regex = regexConverter(props.regex)
local test = string.match( local_value, '^'..regex..'$' )
if test then
-- it matched, this is correct
verified_value = local_value
else
verified_value = nil
end  
end
if not verified_value then
return output
end
local wikidata_property = string.find(props.prop, "([pP]%d+)")
local wikidata_values = {}
if wikidata_property then
-- get any wikidata values to see if they are equal to local values
wikidata_values = getValuesFromWikidata(props)
end
if wikidata_property or (props.url and props.url ~= '') or (props.url_f) then
output[#output+1] = {}
output[#output].langcode = string.find(props.langcode, "([pP]%d+)") and "" or props.langcode
--mw.log("findMainLinksLocal - props="..dump(props).." langcode="..output[#output].langcode)
output[#output].category = {}
local url = ''
if props.track and wikidata_property and wikidata_values and #wikidata_values then
local local_value_in_wikidata = false
for _,value in ipairs( wikidata_values ) do
if value.value == verified_value then
local_value_in_wikidata = true
end
end
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, (local_value_in_wikidata and 'track-cat-local-wd-equal' or 'track-cat-local-wd-unequal')), props.prop):plain
end
if wikidata_property and wikidata_values and #wikidata_values then
hasdatafromwikidata = true -- signal up the chain this article has a wikidata claim
end
if props.url_f then
-- we have a local defined url-formatter function, use it as first priority
url = props.url_f(verified_value)
if props.track then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-local-local'), props.prop):plain
end
elseif props.url then
-- we have a local defined url-formatter string, use it as second priority
url = mw.message.newRawMessage(props.url, verified_value):plain
if props.track then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-local-local'), props.prop):plain
end
elseif wikidata_property then
-- get the formatvalue from the property, if it exists
local formatterUrl = getFormatterUrl(props.prop, verified_value)
if formatterUrl ~= '' then
url = mw.message.newRawMessage(formatterUrl, verified_value):plain
if props.track then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-wd-local'), props.prop):plain
end
end
else
-- no other choice, bail out
return {}
end
local this_wiki = mw.getContentLanguage
local this_wiki_code = this_wiki:getCode
local langlink = (output[#output].langcode and output[#output].langcode ~= '' and output[#output].langcode ~= this_wiki_code) and mw.message.newRawMessage(conf:g('msg-langcode'), props.langcode, mw.language.fetchLanguageName(props.langcode, this_wiki_code)) or ""
if short_links and props.short then
output[#output].text =
mw.message.newRawMessage(props.short,
getLabel(nil, props.genitive, pagetitle),
url,
langlink,
verified_value,
mw.uri.encode(verified_value, 'PATH'))
:plain
else
output[#output].text =
mw.message.newRawMessage(props.message,
getLabel(nil, props.genitive, pagetitle),
url,
langlink,
verified_value,
mw.uri.encode(verified_value, 'PATH'))
:plain
end
end
--mw.log("findMainLinksLocal returning="..dump(output))
return output
end  
local function findSiteLinksLocal(props, pagetitle, short_links, local_value)
local output = {}
-- to avoid deep tests
if not props.prop then
return nil
end
if not local_value or local_value == '' then
-- bail out if no value is present
return output
end
-- get the formatvalue from the property
local verified_value = local_value
if props.regex and props.regex ~= '' then
-- let's verify the id
-- maybe we'll have to convert the regex to Lua-style
local regex = regexConverter(props.regex)
local test = string.match( local_value, '^'..regex..'$' )
if test then
-- it matched, this is correct
verified_value = local_value
else
verified_value = nil
end  
end
if not verified_value then
return output
end
local wikidata_property = string.find(props.prop, "(SL.+)")
local wikidata_values = {}
if wikidata_property then
-- get any wikidata values to see if they are equal to local values
wikidata_values = getSitelinksFromWikidata(props)
end
if wikidata_property or (props.url and props.url ~= '') or (props.url_f) then
output[#output+1] = {}
output[#output].langcode = string.find(props.langcode, "(SL.+)") and "" or props.langcode
--mw.log("findSiteLinksLocal - props="..dump(props).." langcode="..output[#output].langcode .." wikidata_values="..dump(wikidata_values))
output[#output].category = {}
local url = ''
if props.track and wikidata_property and wikidata_values and #wikidata_values then
local local_value_in_wikidata = false
for _,value in ipairs( wikidata_values ) do
if value.value == verified_value then
local_value_in_wikidata = true
end
end
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, (local_value_in_wikidata and 'track-cat-local-wd-equal' or 'track-cat-local-wd-unequal')), props.prop):plain
end
if wikidata_property and wikidata_values and #wikidata_values then
hasdatafromwikidata = true -- signal up the chain this article has a wikidata claim
end
if props.url_f then
-- we have a local defined url-formatter function, use it as first priority
url = props.url_f(verified_value)
if props.track then
output[#output].category[#output[#output].category+1] = mw.message.newRawMessage(cmodule:getMessage(contLang:getCode, 'track-cat-local-local'), props.prop):plain
end
elseif props.url then
-- we have a local defined url-formatter string, use it as second priority
url = mw.message.newRawMessage(props.url, verified_value):plain
if props.track then