אונטערשייד צווישן ווערסיעס פון "יחידה:עיר"

839 בייטן צוגעלייגט ,  פֿאַר 2 יאָר
אפדעיט
(אימפארטירט, פאדערט צופאסונג)
 
(אפדעיט)
 
(2 צווישנדיגע ווערסיעס פונעם זעלבן באַניצער נישט געוויזן)
שורה 467: שורה 467:
end
end


local function findTheLatestDate(dateList)
local function removeSpanTagsAndKeepText(html)
local iso8601DateList = {}
    local pattern = '<span[^>]*>(.-)</span>'
local latestIsoDate = 0
    local cleanedHtml = html
local indexOfLatestIsoDate = 0
   
    repeat
        local newHtml, count = string.gsub(cleanedHtml, pattern, "%1")
        if count > 0 then
            cleanedHtml = newHtml
        else
            break  -- Exit the loop when no more span tags are found
        end
    until false
   
    return cleanedHtml
end
 
local function isNumber(str)
if str == nil or str == "" then return false end
    -- Remove thousands separators (commas) and replace any commas with periods
    local r = string.gsub(str, ",", "")
    r = string.gsub(r, "%.", ".")
 
    return tonumber(r)
end


-- Convert the dates to ISO 8601 format
local function extractFirstNumber(inputString)
for i, isoDate in ipairs(dateList) do
if inputString == nil or inputString == "" then return inputString end
local successOfIso8601DateList
    local number = inputString:match("[%d,.]+")
    successOfIso8601DateList, iso8601DateList[i] = pcall(dateModule.parseStrDate, isoDate, 'TS')
    if number then
    if (i == 1) then
    return tonumber(number)
    latestIsoDate = iso8601DateList[1]
    else
    indexOfLatestIsoDate = 1
        return inputString  -- No number found, return the original text
    else
    end
    if (latestIsoDate > iso8601DateList[i]) then
    latestIsoDate = iso8601DateList[i]
    indexOfLatestIsoDate = i
    end
    end
end
return latestIsoDate, indexOfLatestIsoDate
end
end


function returnLatestData(property)
function returnLatestData(frame, property)
local dateModule = require('Module:תאריך')
local dateModule = require('Module:תאריך')
local propertyLink = require('Module:PropertyLink')
local propertyLink = require('Module:PropertyLink')
local parenthesis = require('Module:סוגריים')
local parenthesis = require('Module:סוגריים')


local timeProperty = { 'P582', 'P580', 'P585' }
local timeProperty = { 'P585', 'P580', 'P582' }
local options = {
local options = {
['entity-gender-aware'] =  true,
['qualifiers'] = timeProperty,
['qualifiers'] = timeProperty,
['allowMulti'] = true,
['allowMulti'] = true,
['seperator'] = ';'
['seperator'] = ';',
['sort'] = timeProperty
}
}
local entityId = frame:getParent().args['qid'] or mw.wikibase.getEntityIdForCurrentPage()
local entityId = mw.wikibase.getEntityIdForCurrentPage()
local res = propertyLink.getPropertyByOptions(property, entityId, options)
local res = propertyLink.getPropertyByOptions(property, entityId, options)
if res == nil or res == "" then
local propertyList = splitString(res, ';')
return nil
end
if #propertyList == 0 then return end
local resArray = splitString(res, ";")
local dateList = {}
local latestData = resArray[#resArray]
latestData = removeSpanTagsAndKeepText(latestData)
for i, listPro in ipairs(propertyList) do
local lastData = parenthesis.remove_parents_internal(latestData)
local temp = pcall(parenthesis.only_parents_contents_internal, listPro)
local lastDate = parenthesis.only_parents_contents_internal(latestData)
local temp2 = splitString(temp, ',')
local resData = lastData
dateList[i] = findTheLatestDate(temp2)
local resDate = lastDate
if isNumber(extractFirstNumber(lastData)) then
for i = #resArray, 1, -1 do
local ins = resArray[i]
ins = removeSpanTagsAndKeepText(ins)
local insData = parenthesis.remove_parents_internal(ins)
local insDate = parenthesis.only_parents_contents_internal(ins)
    if lastDate ~= insDate then
        break
    end
    if extractFirstNumber(resData) < extractFirstNumber(insData) then
    resData = insData
    end
end
end
end
return resData, resDate
local latestIsoDate, indexOfLatestIsoDate = findTheLatestDate(dateList)
end
 
-- If needed, you can convert the latest ISO 8601 date back to a readable format
function returnLatestArea(frame)
return propertyList[indexOfLatestIsoDate], dateList[indexOfLatestIsoDate]
local area, latestAreaDate = returnLatestData(frame, 'P2046')
return area
end
end


function returnLatestMayor(frame)
function returnLatestMayor(frame)
local mayor, latestMayorDate = returnLatestData('P6')
local mayor, latestMayorDate = returnLatestData(frame, 'P6')
return mayor
return mayor
end
end


function returnLatestPopulation(frame)
function returnLatestPopulation(frame)
local population, latestPopulationDate = returnLatestData('P1082')
local population, latestPopulationDate = returnLatestData(frame, 'P1082')
return population
return population
end
end


function returnLatestPopulationDate(frame)
function returnLatestPopulationDate(frame)
local population, latestPopulationDate = returnLatestData('P1082')
local population, latestPopulationDate = returnLatestData(frame, 'P1082')
return latestPopulationDate
return latestPopulationDate
end
end
שורה 540: שורה 566:
['חלוקה מנהלית']=adminDistTranslateWrapper,
['חלוקה מנהלית']=adminDistTranslateWrapper,
['צבע רקע לפי חלוקה מנהלית']=adminDistTranslateColorWrapper,
['צבע רקע לפי חלוקה מנהלית']=adminDistTranslateColorWrapper,
['שטח']=returnLatestArea,
['ראש העיר']=returnLatestMayor,
['ראש העיר']=returnLatestMayor,
['אוכלוסייה']=returnLatestPopulation,
['אוכלוסייה']=returnLatestPopulation,
['תאריך אוכלוסייה']=returnLatestPopulationDate
['תאריך אוכלוסייה']=returnLatestPopulationDate
}
}