Moduli:Water2
Tämän moduulin ohjeistuksen voi tehdä sivulle Moduli:Water2/ohje
local p = {}
local wiki = {
langcode = mw.language.getContentLanguage().code
}
local i18n = require('Module:Water2/i18n/' .. wiki.langcode)
local sources = require('Module:Sources')
local instanceTypes = {
['Q4022'] = 'river', -- река
['Q47521'] = 'river', -- поток
['Q373315'] = 'river', -- балка
['Q573344'] = 'river', -- основное русло
['Q591942'] = 'river', -- рукав реки
['Q661702'] = 'river', -- протока
['Q1140845'] = 'river', -- подземная река
['Q1165822'] = 'river', -- меромиктический водоём
['Q1361400'] = 'river', -- овраг
['Q4366834'] = 'river', -- трансграничная река
['Q16465938'] = 'river', -- пересыхающая река
['Q27067659'] = 'river', -- бывшая река
['Q63565252'] = 'river', -- ручей
['Q12284'] = 'canal', -- канал
['Q949819'] = 'canal', -- судоходный канал
['Q6129871'] = 'canal', -- оросительная система
['Q2935978'] = 'canal', -- ирригационный канал
['Q23397'] = 'lake', -- озеро
['Q188025'] = 'lake', -- минеральное озеро
['Q209333'] = 'lake', -- старица
['Q2912558'] = 'lake', -- сверхсолёное озеро
['Q3215290'] = 'lake', -- искусственное озеро
['Q11726988'] = 'lake', -- метеоритное озеро
['Q47486890'] = 'lake', -- бывшее озеро
['Q5926864'] = 'group_of_lakes', -- группа озёр
['Q42055295'] = 'group_of_lakes', -- группа прудов
['Q37901'] = 'strait', -- пролив
['Q124714'] = 'spring', -- родник
['Q131681'] = 'reservoir', -- водохранилище
['Q3253281'] = 'reservoir', -- пруд
['Q188040'] = 'reservoir', -- карьер
['Q166735'] = 'wetland', -- заболоченный лес
['Q187223'] = 'bay', -- лагуна
['Q156030'] = 'bay', -- лиман
['Q986177'] = 'sea', -- внутреннее море
}
local entityId = mw.wikibase.getEntityIdForCurrentPage()
local myEntity
if entityId ~= '' and entityId ~= nil then
myEntity = mw.wikibase.getEntity(entityId)
end
local function preprocess(sText)
if mw.getCurrentFrame() then
sText = mw.getCurrentFrame():preprocess(sText)
end
return sText
end
local function getFirstClaim(myEntity, prop)
local instanceOf0 = nil
if myEntity and myEntity.claims and myEntity.claims[prop] then
local instanceOf = myEntity.claims[prop]
for _, claim in ipairs(instanceOf) do
local rank = claim.rank
if rank == 'preferred' then
return claim
end
end
for _, claim in ipairs(instanceOf) do
local rank = claim.rank
if rank == 'normal' then
return claim
end
end
end
return nil
end
local function getBestClaimsFromEntry(myEntity, prop)
local result = {}
local count = 0
if myEntity and myEntity.claims and myEntity.claims[prop] then
local instanceOf = myEntity.claims[prop]
for _, claim in ipairs(instanceOf) do
local rank = claim.rank
if rank == 'preferred' then
table.insert(result, claim)
count = count + 1
end
end
if count == 0 then
for _, claim in ipairs(instanceOf) do
local rank = claim.rank
if rank == 'normal' then
table.insert(result, claim)
count = count + 1
end
end
end
end
return result
end
local function checkUnit(inputUnit, expectedUnit)
if (inputUnit == 'https://data.ruwiki.ru/entity/' .. expectedUnit) or (inputUnit == 'http://www.wikidata.org/entity/' .. expectedUnit) then
return true
end
return false
end
local function printReferences(frame, claim)
local tmpStr = ''
if claim.references then
for _, reference in ipairs(claim.references) do
tmpStr = tmpStr .. sources.renderReference(frame, entityId, reference)
end
end
return tmpStr
end
function removePrefix(inputString, prefix)
if inputString:sub(1, #prefix) == prefix then
return inputString:sub(#prefix+1)
else
return inputString
end
end
function printPageLabel(qid)
local sitelinkResult = mw.wikibase.getSitelink(qid, wiki.langcode .. 'wiki')
if sitelinkResult ~= nil then
return sitelinkResult
end
local labelResult = mw.wikibase.getLabel(qid, wiki.langcode .. 'wiki')
if labelResult ~= nil then
return labelResult
end
if wiki.langcode ~= 'ru' then
sitelinkResult = mw.wikibase.getSitelink(qid , 'ruwiki')
if sitelinkResult ~= nil then
return sitelinkResult
end
local labelResult = mw.wikibase.getLabel(qid, 'ruwiki')
if labelResult ~= nil then
return labelResult
end
end
return ''
end
function printPageLabel2(qid)
local labelResult = mw.wikibase.getLabel(qid, wiki.langcode .. 'wiki')
if labelResult ~= nil then
return labelResult
end
local sitelinkResult = mw.wikibase.getSitelink(qid, wiki.langcode .. 'wiki')
if sitelinkResult ~= nil then
return sitelinkResult
end
if wiki.langcode ~= 'ru' then
local labelResult = mw.wikibase.getLabel(qid, 'ruwiki')
if labelResult ~= nil then
return labelResult
end
sitelinkResult = mw.wikibase.getSitelink(qid , 'ruwiki')
if sitelinkResult ~= nil then
return sitelinkResult
end
end
return ''
end
function printSiteLink(qid, link, title, secondLang)
local currentItem = mw.wikibase.getEntity(qid)
if currentItem == nil then
return '{{' .. i18n.template.iw .. '|' .. qid .. '||d|' .. qid .. '}}'
end
local sitelinkResult = mw.wikibase.getSitelink(qid, wiki.langcode .. 'wiki')
if sitelinkResult ~= nil then
if title then
return '[[' .. sitelinkResult .. '|' .. title .. ']]'
else
return '[[' .. sitelinkResult .. ']]'
end
end
if secondLang and wiki.langcode ~= secondLang then
sitelinkResult = mw.wikibase.getSitelink(qid , 'ruwiki')
if sitelinkResult ~= nil then
if title then
return '[[' .. sitelinkResult .. '|' .. title .. ']]'
else
return '[[:ru:' .. sitelinkResult .. '|' .. sitelinkResult .. ']]'
end
end
end
if title then
return '{{' .. i18n.template.iw .. '|' .. link .. '|' .. title .. '|d|' .. qid .. '}}'
end
label = mw.wikibase.getLabel(qid)
if label then
return '{{' .. i18n.template.iw .. '|' .. label .. '||d|' .. qid .. '}}'
end
return nil
end;
local function instanceType(instanceOf0)
if instanceOf0 == nil then
return nil
end
local t = instanceTypes[instanceOf0.mainsnak.datavalue.value.id]
if t ~= nil then
return t
end
end
function p.getTemplateWater(frame)
local result = ''
local categories = {}
local RussiaFound = false
local country = {}
local instanceOf0 = getFirstClaim(myEntity, 'P31')
local instanceType = instanceType(instanceOf0)
if instanceOf0 == nil then
result = result .. '{{' .. i18n.infobox.default .. '}}'
table.insert(categories, '[[' .. i18n.category.no_water_type .. ']]')
elseif instanceType == 'river' then
result = result .. '{{' .. i18n.infobox[instanceType]
result = result .. '|' .. i18n.template_arg.name .. '=' .. mw.wikibase.label(entityId)
-- Национальное название (обработка случая для редких языков)
local nativeLabel = getFirstClaim(myEntity, 'P1705')
local nativeLangCode, nativeLangText
if nativeLabel and nativeLabel.mainsnak and nativeLabel.mainsnak.datavalue and nativeLabel.mainsnak.datavalue.value and nativeLabel.mainsnak.datavalue.value.text then
nativeLangText = nativeLabel.mainsnak.datavalue.value.text
end
if nativeLabel then
local nativeLangClaim
if nativeLabel.qualifiers and nativeLabel.qualifiers.P407 and nativeLabel.qualifiers.P407[1] and nativeLabel.qualifiers.P407[1].datavalue and nativeLabel.qualifiers.P407[1].datavalue.value and nativeLabel.qualifiers.P407[1].datavalue.value.id then
nativeLangClaim = mw.wikibase.getBestStatements(nativeLabel.qualifiers.P407[1].datavalue.value.id, 'P220') or nil
if nativeLangClaim and nativeLangClaim[1] and nativeLangClaim[1].mainsnak and nativeLangClaim[1].mainsnak.datavalue and nativeLangClaim[1].mainsnak.datavalue.value then
nativeLangCode = nativeLangClaim[1].mainsnak.datavalue.value
end
else
nativeLangCode = nativeLabel.mainsnak.datavalue.value.language
nativeLangText = nativeLabel.mainsnak.datavalue.value.text
end
end
if nativeLangCode and nativeLangText then
nativeLangText = nativeLangCode .. '/' .. nativeLangText
end
if nativeLangText then
result = result .. '|' .. i18n.template_arg.native_label .. '=' .. nativeLangText
end
-- Длина реки
local riverLen = getFirstClaim(myEntity, 'P2043')
if riverLen ~= nil then
if checkUnit(riverLen.mainsnak.datavalue.value.unit, 'Q828224') then
result = result .. '|' .. i18n.template_arg.length .. '=' .. removePrefix(riverLen.mainsnak.datavalue.value.amount, '+')
else
table.insert(categories, '[[' .. i18n.category.unknown_length_unit .. ']]')
end
end
-- Площадь бассейна
local watershedArea = getFirstClaim(myEntity, 'P2053')
if watershedArea ~= nil then
if checkUnit(watershedArea.mainsnak.datavalue.value.unit, 'Q712226') then
result = result .. '|' .. i18n.template_arg.watershed_area .. '=' .. removePrefix(watershedArea.mainsnak.datavalue.value.amount, '+')
else
table.insert(categories, '[[' .. i18n.category.unknown_watershed_area_unit .. ']]')
end
end
local coords = getBestClaimsFromEntry(myEntity, 'P625')
local unknownHeightUnit = ''
local tmp = ''
local mouth = getFirstClaim(myEntity, 'P403')
if mouth and mouth.mainsnak and mouth.mainsnak.datavalue and mouth.mainsnak.datavalue.value and mouth.mainsnak.datavalue.value.id then
result = result .. '|' .. i18n.template_arg.river_mouth .. '=' .. printPageLabel(mouth.mainsnak.datavalue.value.id)
end
for _, coord in ipairs(coords) do
local coordStr = coord.mainsnak.datavalue.value.latitude .. '/' .. coord.mainsnak.datavalue.value.longitude
local coordType = nil
local coordLocation = nil
local coordSource = nil
local coordHeight = nil
local coordHeightError = false
local qualifiers = coord.qualifiers
if qualifiers then
if qualifiers.P518 then
for _, qualifier in ipairs(qualifiers.P518) do
coordType = qualifier.datavalue.value.id
end
end
if qualifiers.P276 then
for _, qualifier in ipairs(qualifiers.P276) do
coordLocation = qualifier.datavalue.value.id
end
end
if qualifiers.P276 then
for _, qualifier in ipairs(qualifiers.P276) do
coordLocation = qualifier.datavalue.value.id
end
end
if qualifiers.P885 then
for _, qualifier in ipairs(qualifiers.P885) do
coordSource = qualifier.datavalue.value.id
end
end
if (not coordMouth) and (qualifiers.P403) then
for _, qualifier in ipairs(qualifiers.P403) do
coordMouth = qualifier.datavalue.value.id
end
end
if qualifiers.P2044 then
for _, qualifier in ipairs(qualifiers.P2044) do
if checkUnit(qualifier.datavalue.value.unit, 'Q11573') then
coordHeight = removePrefix(qualifier.datavalue.value.amount, '+')
else
table.insert(categories, '[[' .. i18n.category.unknown_elevation_unit .. ']]')
end
end
end
end
if coordType == 'Q7376362' then -- исток
if coordLocation ~= nil then
result = result .. '|' .. i18n.template_arg.place_river_source .. '=[[' .. printPageLabel(coordLocation) .. ']]'
end
if coordHeight ~= nil then
result = result .. '|' .. i18n.template_arg.height_river_source .. '=' .. coordHeight .. ''
end
if coordStr ~= nil then
result = result .. '|' .. i18n.template_arg.coord_river_source .. '=' .. coordStr .. ''
end
elseif coordType == 'Q1233637' then -- устье
if coordLocation ~= nil then
result = result .. '|' .. i18n.template_arg.river_mouth .. '=' .. printPageLabel(coordMouth)
end
if coordHeight ~= nil then
result = result .. '|' .. i18n.template_arg.height_river_mouth .. '=' .. coordHeight .. ''
end
if coordStr ~= nil then
result = result .. '|' .. i18n.template_arg.coord_river_mouth .. '=' .. coordStr .. ''
end
end
end
country = getBestClaimsFromEntry(myEntity, 'P17')
if #country == 0 then -- государство не указано
result = result .. '|' .. i18n.template_arg.country .. '=' .. i18n.word.country_RU_0
RussiaFound = true
else
local countryList = {}
for _, claim in ipairs(country) do
if claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value.id then
table.insert(countryList, mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id))
if claim.mainsnak.datavalue.value.id == 'Q159' then
RussiaFound = true
end
end
end
result = result .. '|' .. i18n.template_arg.country .. '=' .. table.concat(countryList, '/')
end
local regions = getBestClaimsFromEntry(myEntity, 'P131')
if #regions ~= 0 then
local regionStr = mw.wikibase.sitelink(regions[1].mainsnak.datavalue.value.id)
if not region then
regionStr = mw.wikibase.label(regions[1].mainsnak.datavalue.value.id)
end
result = result .. '|' .. i18n.template_arg.state .. '=' .. regionStr
end
-- TODO: result = result .. '|Район=Карагинский район'
-- Позиционная карта
local reliefMap = getFirstClaim(myEntity, 'P1944')
if reliefMap then
local reliefMapStr = (i18n.template.relief_location_map or {})[reliefMap.mainsnak.datavalue.value] or ''
if reliefMapStr and reliefMapStr ~= '' then
result = result .. '|' .. i18n.template_arg.location_map .. '=' .. reliefMapStr
end
end
result = result .. '}}' .. unknownHeightUnit .. tmp
if #country == 0 then
table.insert(categories, '[[' .. i18n.category.unknown_country .. ']]')
end
if not RussiaFound then
table.insert(categories, '[[' .. i18n.category.check_country .. ']]')
end
if #country > 1 then
table.insert(categories, '[[' .. i18n.category.few_countries .. ']]')
end
elseif instanceType == 'canal' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
elseif instanceType == 'lake' then
result = result .. '{{' .. i18n.infobox[instanceType]
result = result .. '|' .. i18n.template_arg.name .. '=' .. mw.wikibase.label(entityId)
-- впадающие в озеро реки
local inflows = getBestClaimsFromEntry(myEntity, 'P200')
if #inflows ~= 0 then
local inflowsList = {}
for _, claim in ipairs(inflows) do
table.insert(inflowsList, mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id))
end
result = result .. '|' .. i18n.template_arg.inflows .. '=' .. table.concat(inflowsList, '/')
end
-- впадающие в озеро реки
local outflows = getBestClaimsFromEntry(myEntity, 'P201')
if #outflows ~= 0 then
local outflowsList = {}
for _, claim in ipairs(outflows) do
table.insert(outflowsList, mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id))
end
result = result .. '|' .. i18n.template_arg.outflows .. '=' .. table.concat(outflowsList, '/')
end
RussiaFound = false
country = getBestClaimsFromEntry(myEntity, 'P17')
if #country == 0 then -- государство не указано
result = result .. '|' .. i18n.template_arg.country .. '=' .. i18n.word.country_RU_0
RussiaFound = true
else
local countryList = {}
for _, claim in ipairs(country) do
if claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value.id then
table.insert(countryList, mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id))
if claim.mainsnak.datavalue.value.id == 'Q159' then
RussiaFound = true
end
end
end
result = result .. '|' .. i18n.template_arg.country .. '=' .. table.concat(countryList, '/')
end
local regions = getBestClaimsFromEntry(myEntity, 'P131')
if #regions ~= 0 then
regionStr = mw.wikibase.sitelink(regions[1].mainsnak.datavalue.value.id)
if not regionStr then
regionStr = mw.wikibase.label(regions[1].mainsnak.datavalue.value.id)
end
result = result .. '|' .. i18n.template_arg.state .. '=' .. regionStr
end
local coord = getFirstClaim(myEntity, 'P625')
if coord ~= nil then
local coordStr = coord.mainsnak.datavalue.value.latitude .. '/' .. coord.mainsnak.datavalue.value.longitude
result = result .. '|' .. i18n.template_arg.coord .. '=' .. coordStr .. ''
end
result = result .. '}}'
elseif instanceType == 'group_of_lakes' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
elseif instanceType == 'strait' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
elseif instanceType == 'spring' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
elseif instanceType == 'reservoir' then
result = result .. '{{' .. i18n.infobox[instanceType]
-- год наполнения
local inception = getFirstClaim(myEntity, 'P571')
if inception ~= nil then
local inceptionStr = inception.mainsnak.datavalue.value.time:sub(2,5)
result = result .. '|' .. i18n.template_arg.inception .. '=' .. inceptionStr
end
-- впадающие в озеро реки
local inflows = getBestClaimsFromEntry(myEntity, 'P200')
if #inflows ~= 0 then
local inflowsList = {}
for _, claim in ipairs(inflows) do
table.insert(inflowsList, mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id))
end
result = result .. '|' .. i18n.template_arg.inflows .. '=' .. table.concat(inflowsList, '/')
end
-- впадающие в озеро реки
local outflows = getBestClaimsFromEntry(myEntity, 'P201')
if #outflows ~= 0 then
local outflowsList = {}
for _, claim in ipairs(outflows) do
table.insert(outflowsList, mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id))
end
result = result .. '|' .. i18n.template_arg.outflows .. '=' .. table.concat(outflowsList, '/')
end
local regions = getBestClaimsFromEntry(myEntity, 'P131')
if #regions ~= 0 then
local regionStr = mw.wikibase.sitelink(regions[1].mainsnak.datavalue.value.id)
if not region then
regionStr = mw.wikibase.label(regions[1].mainsnak.datavalue.value.id)
end
result = result .. '|' .. i18n.template_arg.state .. '=' .. regionStr
end
result = result ..'}}'
elseif instanceType == 'wetland' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
elseif instanceType == 'bay' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
elseif instanceType == 'sea' then
result = result .. '{{' .. i18n.infobox[instanceType] .. '}}'
else
result = result .. '{{' .. i18n.infobox.default .. '}}'
table.insert(categories, '[[' .. i18n.category.no_water_type .. ']]')
end
if #country == 0 then
table.insert(categories, '[[' .. i18n.category.unknown_country .. ']]')
end
if not RussiaFound then
table.insert(categories, '[[' .. i18n.category.check_country .. ']]')
end
if #country > 1 then
table.insert(categories, '[[' .. i18n.category.few_countries .. ']]')
end
return preprocess(result .. table.concat(categories))
end
function p.getWaterDesctiption(frame)
local result = ''
local instanceOf = getFirstClaim(myEntity, 'P31')
local instanceType = instanceType(instanceOf)
local water_object_action = i18n.word.lake_located
if water_object_action == false then
local lake_located_by_type = i18n.word.lake_located_by_type or {}
water_object_action = lake_located_by_type[instanceType] or ''
end
local water_object_preposition = i18n.word.lake_located_preposition
if instanceType == 'river' then
water_object_action = i18n.word.river_flowing
water_object_preposition = i18n.word.river_flowing_preposition
end
local territorialEntity = {}
local territorialQids = getBestClaimsFromEntry(myEntity, 'P131')
local located = i18n.word.located or {}
local locatedStr = located[instanceType] or ''
local locatedLocative = i18n.word.located_locative or {}
local locatedLocativeBool = locatedLocative[instanceType] or false
for _, claim in ipairs(territorialQids) do
if claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value then
if locatedLocativeBool and i18n.template.locative then
local objectLink = mw.wikibase.sitelink(claim.mainsnak.datavalue.value.id)
local objectCaption = mw.wikibase.getLabel(claim.mainsnak.datavalue.value.id)
if objectLink then
table.insert(territorialEntity, '[[' .. objectLink .. '|{{' .. i18n.template.locative .. '|' .. objectCaption .. '}}]]')
else
table.insert(territorialEntity, '[[' .. objectCaption .. ']]')
end
else
table.insert(territorialEntity, printSiteLink(claim.mainsnak.datavalue.value.id))
end
end
end
local water_object_location = mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(i18n.text.water_object_location, '%%water_object_action', water_object_action), '%%water_object_type', i18n.word[instanceType]), '%%water_object_preposition', water_object_preposition), '%%territorial_entity', table.concat(territorialEntity, ', '))
result = result .. mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(i18n.text.general_description, '%%pagenamebase', i18n.template.pagenamebase), '%%watertype', i18n.word[instanceType]), '%%country', i18n.word.country_RU_5), '%%water_object_location', water_object_location), '%%territorial_location', locatedStr) .. '\n\n'
if instanceType == 'river' then
-- Длина реки
local riverLen = getFirstClaim(myEntity, 'P2043')
if riverLen ~= nil then
if checkUnit(riverLen.mainsnak.datavalue.value.unit, 'Q828224') then
result = result .. mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(i18n.text.river_len_value, '%%river_len', i18n.word.river_len), '%%template_num', i18n.template.num), '%%value_amount', removePrefix(riverLen.mainsnak.datavalue.value.amount, '+')), '%%value_unit', i18n.word.km), '%%references', printReferences(frame, riverLen)) .. '\n'
end
end
-- Площадь бассейна
local watershedArea = getFirstClaim(myEntity, 'P2053')
if watershedArea ~= nil then
if checkUnit(watershedArea.mainsnak.datavalue.value.unit, 'Q712226') then
result = result .. mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(i18n.text.watershed_area_value, '%%watershed_area', i18n.word.watershed_area), '%%template_num', i18n.template.num), '%%value_amount', removePrefix(watershedArea.mainsnak.datavalue.value.amount, '+')), '%%value_unit', i18n.word.km2), '%%references', printReferences(frame, watershedArea)) .. '\n'
end
end
-- Впадает в
local mouthOfTheWatercourse = getFirstClaim(myEntity, 'P403')
if mouthOfTheWatercourse ~= nil then
local objectLink = printPageLabel2(mouthOfTheWatercourse.mainsnak.datavalue.value.id)
local objectCaption = objectLink
if wiki.langcode == 'ba' then
objectCaption = '{{локатив:Ba|' .. objectCaption .. '}}'
elseif wiki.langcode == 'cv' then
objectCaption = '{{локатив:Cv2|' .. objectCaption .. '}}'
end
result = result .. mw.ustring.gsub(i18n.text.mouth_of_the_watercourse, '%%mouth_of_the_watercourse', printSiteLink(mouthOfTheWatercourse.mainsnak.datavalue.value.id, objectLink, objectCaption)) .. '\n\n'
end
end
return preprocess(result)
end
function p.getStateWaterRegister(frame)
local result = ''
local categories = {}
local watershedDistricts = getBestClaimsFromEntry(myEntity, 'P361')
local StateWaterRegister = getBestClaimsFromEntry(myEntity, 'P884')
if (#StateWaterRegister ~= 0) or (#StateWaterRegister ~= 0) then
result = result .. '== ' .. i18n.word.state_water_register .. ' ==\n'
end
if #watershedDistricts == 0 then
table.insert(categories, '[[' .. i18n.category.no_watershed_districts .. ']]')
else
local watershedDistrictsStr = {}
for _, claim in ipairs(watershedDistricts) do
if claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value then
table.insert(watershedDistrictsStr, printSiteLink(claim.mainsnak.datavalue.value.id))
end
end
result = result .. mw.ustring.gsub(i18n.text.river_watershed_districts, '%%watershed_districts', table.concat(watershedDistrictsStr, ', ')) .. '\n\n'
if #watershedDistricts > 1 then
table.insert(categories, '[[' .. i18n.category.unknown_watershed_district .. ']]')
end
end
if #StateWaterRegister == 0 then
table.insert(categories, '[[' .. i18n.category.no_gvr_code .. ']]')
else
local StateWaterRegisterCodes = {}
for _, claim in ipairs(StateWaterRegister) do
if claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value then
table.insert(StateWaterRegisterCodes, claim.mainsnak.datavalue.value .. printReferences(frame, claim))
end
end
if #StateWaterRegister ~= 0 then
local code_s = i18n.word.gvr_code
if #StateWaterRegister > 1 then
code_s = i18n.word.gvr_codes
table.insert(categories, '[[' .. i18n.category.few_gvr_codes .. ']]')
end
result = result .. mw.ustring.gsub(mw.ustring.gsub(i18n.text.gvr_codes, '%%gvr_code_word', code_s), '%%gvr_codes_list', table.concat(StateWaterRegisterCodes, ', ')) .. '\n\n'
end
end
return preprocess(result .. table.concat(categories))
end
function p.getFooter(frame)
local result = '== ' .. i18n.word.reflist .. ' ==\n{{' .. i18n.template.reflist .. '}}\n'
return preprocess(result)
end
return p