پرش به محتوا

پودمان:پدیدآورنده: تفاوت میان نسخه‌ها

از سورسکال
صفحه‌ای تازه حاوی «local translate2bn = require('پودمان:Number Converter')._translate2bn function errorMessage(text) -- Return a html formated version of text stylized as an error. local html = mw.html.create('div') html:addClass('error') :wikitext(text) :wikitext('Category:Wrong author templates') return tostring(html) end function createLinkRow(link, site) -- Return some html stylised formated text of link local html = mw.html.cre...» ایجاد کرد
 
بدون خلاصۀ ویرایش
خط ۱: خط ۱:
local translate2bn = require('پودمان:Number Converter')._translate2bn


function errorMessage(text)
local p = {}
-- Return a html formated version of text stylized as an error.
local cfg = require('Module:پدیدآورنده/تنظیمات')
local html = mw.html.create('div')
 
html:addClass('error')
local function filled(v)
:wikitext(text)
    return type(v) == 'string'
:wikitext('[[Category:Wrong author templates]]')
        and mw.text.trim(v) ~= ''
return tostring(html)
end
 
local function safe(v)
    return mw.text.nowiki(tostring(v or ''))
end
end


function createLinkRow(link, site)
local function statementValue(entity, property)
-- Return some html stylised formated text of link
    if not filled(property) then
local html = mw.html.create('div')
        return nil
     if site == 'پدیدآورنده' then
    end
         logo_file_name = 'Font_Awesome_5_regular_list-alt.svg'
 
    elseif site == 'Inventory' then
    local statements = entity:getBestStatements(property)
        logo_file_name = 'Inv-icon-192.svg'
 
    else
     for _, s in ipairs(statements or {}) do
         logo_file_name = site .. '-logo.svg'
         local snak = s.mainsnak
 
        if snak and snak.snaktype == 'value'
            and snak.datavalue then
            return snak.datavalue.value
         end
     end
     end
html:tag('span')
 
:css({['color'] = '#232388', ['font-size'] = '140%', ['line-height'] = '150%'})
    return nil
:wikitext('[[File:' .. logo_file_name .. '|20px|' .. site .. ']]  ')
html:wikitext(link)
return html
end
end


function categorization(baseName, parameter)
local function deathInfo(value, frame)
-- Return the categorisation wikitext for each element of parameter prefixed with baseName
    if type(value) ~= 'table' or not value.time then
if parameter == nil then
        return nil, nil
return ''
    end
end


local wikitext = ''
    local y, m, d = value.time:match(
for _,param in pairs(mw.text.split(parameter, '/', true)) do
        '^[%+%-]?(%d+)%-(%d%d)%-(%d%d)'
wikitext = wikitext .. '[[رده:' .. baseName .. ' ' .. param .. ']]'
    )
end
return wikitext
end


function computeCenturypaomYear(year)
    y, m, d = tonumber(y), tonumber(m), tonumber(d)
-- Return the correpsonding century for the given year
if year >= 0 then
return math.ceil(year / 100)
else
return -math.ceil(-year / 100)
end
end


function getTextForCentury(century, withHtml)
    if not y or y < 1 or y > 9999 then
-- Return a roman ordinal of century appended with a trailing text precising
        return nil, nil
-- if the date is before of after the calendar reference point.
    end
local romanNumbers1 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'}
local romanNumbers2 = {'', '1', '2', '3', '4', '5', '6', '7', '8', '9'}


local text = romanNumbers2[math.floor(math.abs(century) / 10) + 1] .. romanNumbers1[math.floor(math.abs(century) % 10) + 1]
    local precision = tonumber(value.precision) or 9
if withHtml then
    if precision < 9 then
text = text .. ''
        return nil, nil
else
    end
text = text .. ''
end
if century < 0 then
text = 'پیش از میلاد' .. text
century = -century
end
if century == 1 then
return 'سدهٔ ' .. text
elseif century == 2 then
return 'سدهٔ ' .. text
elseif century == 3 then
return 'سدهٔ ' .. text
elseif century == 4 then
return 'سدهٔ ' .. text
elseif century == 5 then
return 'سدهٔ ' .. text
elseif century == 6 then
return 'سدهٔ ' .. text
elseif century >= 7 and century <=10 then
return 'سدهٔ ' .. text
elseif century > 10 then
return 'سدهٔ ' .. text
end
end


function getTextForYear(year)
    local today = frame:callParserFunction(
local text = math.abs(year)
        '#time', 'Y-m-d'
if year < 0 then
    )
text = text .. ' پیش از میلاد'
end
return translate2bn(text)
end


function getDatepaomArgs(args, field, fieldUpper)
    local cy, cm, cd = today:match(
local struct = {
        '^(%d+)%-(%d+)%-(%d+)'
year = nil,
    )
century = nil,
text = nil,
precision = 0
}


--extract year or century
    cy, cm, cd = tonumber(cy), tonumber(cm), tonumber(cd)
local date = args['year' .. fieldUpper]
if date == nil then
date = args[field]
end
if tonumber(date) ~= nil then
struct.year = tonumber(date)
if struct.year == 0 then
struct.text = errorMessage("The Gregorian calendar does not have a year 0!")
return struct
end
struct.century = computeCenturypaomYear(struct.year)
struct.precision = 9
elseif args['century' .. fieldUpper] ~= nil then
struct.century = tonumber(args['century' .. fieldUpper])
struct.precision = 7
end


--build text
    if not cy then
if struct.year ~= nil then
        return tostring(y), nil
struct.text = getTextForYear(struct.year)
    end
elseif struct.century ~= nil then
struct.text = getTextForCentury(struct.century, true)
else
struct.text = date
end
if args['text' .. fieldUpper] ~= nil then
struct.precision = 0 --we don't know anything
struct.text = args['text' .. fieldUpper] .. ' ' .. struct.text
end
if args['uncertainty' .. fieldUpper] ~= nil and struct.text ~= nil then
struct.precision = 0 --we don't know anything
struct.text = args['uncertainty' .. fieldUpper] .. ' ' .. struct.text
end


return struct
    local years = cy - y
end


function getDatepaomTimeStatements(statements, field)
    if precision >= 11 and m and d
if #statements == 0 then
        and m >= 1 and m <= 12
return {
        and d >= 1 and d <= 31 then
precision = 0,
statementcount = 0
}
end


local time = nil
        if cm < m or (cm == m and cd < d) then
for _, statement in pairs(statements) do
            years = years - 1
local newTime = getDatepaomTimeStatement(statement, field)
        end
if time == nil then
time = newTime
elseif time.year ~= newTime.year then --années contradictoires
mw.addWarning('Several years of ' .. field .. ' possible on Wikidata. A simple way to solve problems is to set the date to display the rank "preferred".')
end
end


if time == nil then
    else
return {
        -- محاسبه محافظه‌کارانه برای تاریخ ناقص
precision = 0
        years = years - 1
}
    end
end


return time
    return tostring(y), math.max(0, years)
end
end


function parseWbTime(value)
local function addRow(rows, label, value)
local _,_, year = string.find(value.time, '([%+%-]%d%d%d+)%-')
    if not filled(value) then
year = tonumber(year)
        return
    end
return {
 
year = year,
    rows[#rows + 1] =
century = computeCenturypaomYear(year),
        '<tr><th style="padding:9px;text-align:right;' ..
text = nil,
        'width:34%;color:#66776f;font-weight:normal;' ..
precision = value.precision
        'border-bottom:1px solid #edf0ee;">' ..
}
        safe(label) ..
        '</th><td style="padding:9px;' ..
        'border-bottom:1px solid #edf0ee;">' ..
        value .. '</td></tr>'
end
end


function getDatepaomTimeStatement(statement, field)
local function projectLink(entity, site, base, label)
local struct = {
    if not filled(site) or not filled(base) then
year = nil,
        return nil
century = nil,
    end
text = nil,
 
precision = 0
    local ok, title = pcall(function()
}
        return entity:getSitelink(site)
local snak = statement.mainsnak
    end)
if snak.snaktype == 'novalue' then
 
return struct
    if not ok or not filled(title) then
end
        return nil
if snak.snaktype == 'somevalue' then
    end
struct.text = '?'
return struct.text
end
struct = parseWbTime(snak.datavalue.value)
local prefix = ''
if struct.precision == 8 then
prefix = 'حدود '
end


--Extract circa
    local url = base .. mw.uri.encode(title, 'PATH')
if statement.qualifiers ~= nil and statement.qualifiers.P1480 ~= nil then
for _,qualifier in pairs(statement.qualifiers.P1480) do
if qualifier.datavalue.value.id == 'Q5727902' then
prefix = 'حدود '
struct.precision = 8 --TODO: hacky
end
end
end
--Use before and after if precision <= century
if statement.qualifiers ~= nil and struct.precision <= 7 then
if statement.qualifiers.P1319 ~= nil then
for _,qualifier in pairs(statement.qualifiers.P1319) do
struct = parseWbTime(qualifier.datavalue.value)
prefix = 'حدود '
struct.precision = 8 --TODO: hacky
end
elseif statement.qualifiers.P1326 ~= nil then
for _,qualifier in pairs(statement.qualifiers.P1326) do
struct = parseWbTime(qualifier.datavalue.value)
prefix = 'حدود '
struct.precision = 8 --TODO: hacky
end
elseif statement.qualifiers.P1317 ~= nil then
for _,qualifier in pairs(statement.qualifiers.P1317) do
struct = parseWbTime(qualifier.datavalue.value)
prefix = 'حدود '
struct.precision = 8 --TODO: hacky
end
end
end


--Create text
    return '[' .. url .. ' ' .. label .. ']'
if struct.precision >= 9 then
struct.text = prefix .. getTextForYear(struct.year)
elseif struct.precision == 8 then
struct.text = prefix .. getTextForYear(struct.year)
elseif struct.precision == 7 then
struct.text = prefix .. getTextForCentury(struct.century, true)
else
struct.text = errorMessage('The date of ' .. field .. ' has too low accuracy on Wikidata')
end
return struct
end
end


function formatDates(birth, death, floruits, class)
p['نمایش'] = function(frame)
if birth.text == nil and birth ~= '?' and death.text == nil and death ~= '?' then
    local args = frame:getParent()
return ''
        and frame:getParent().args or frame.args
end
 
    local title = mw.title.getCurrentTitle()
 
    local name = mw.text.trim(args['نام'] or '')
 
    if name == '' then
        name = title.text
    end


local text = '('
    local wb = mw.wikibase
     if birth == '?' and death == '?' and floruits ~= nil and floruits.text ~= nil then
 
         text = text .. floruits.text
    -- اگر صفحه به آیتم متصل نیست، هیچ داده‌ای نخوان.
     else
     local id = wb and wb.getEntityIdForCurrentPage
if birth == '?' then
         and wb.getEntityIdForCurrentPage()
text = text .. birth .. ' '
 
elseif birth.precision >= 9 then
     if not id then
local annotation = 'class="bday" itemprop="birthDate"'
        return '<div class="sourcical-author" ' ..
if class ~= "Q5" and class ~= nil then
            'style="direction:rtl;max-width:310px;' ..
annotation = 'itemprop="foundingDate'
            'padding:16px;border:1px solid #dce7e1;' ..
end
            'border-radius:12px;text-align:center;">' ..
text = text .. '<time datetime=' .. birth.year .. ' class="bday" itemprop="birthDate">' .. birth.text .. '</time> '
            '<strong>' .. safe(name) .. '</strong></div>'
elseif birth.text ~= nil then
    end
text = text .. birth.text .. ' '
 
end
    local ok, entity = pcall(function()
text = text .. '–'
        return wb.getEntity(id)
if death == '?' then
    end)
text = text .. ' ' .. death
 
elseif death.precision >= 9 then
    if not ok or not entity then
local annotation = 'class="dday" itemprop="deathDate"'
        return '<strong>' .. safe(name) .. '</strong>'
if class ~= "Q5" and class ~= nil then
annotation = 'itemprop="dissolutionDate'
end
text = text .. ' <time datetime=' .. death.year .. '  class="dday" itemprop="deathDate">' .. death.text .. '</time>'
elseif death.text ~= nil then
text = text .. ' ' .. death.text
end
     end
     end
return translate2bn(text) .. ')'
end


function qidForProperty(item, property)
    local description = entity.descriptions
local statements = item:getBestStatements(property)
        and entity.descriptions.fa
if statements[1] ~= nil and statements[1].mainsnak.datavalue ~= nil then
        and entity.descriptions.fa.value
return statements[1].mainsnak.datavalue.value.id
 
end
    local birth = statementValue(
return nil
        entity, cfg.birthProperty
end
    )


function searchKey(key)
    local death = statementValue(
-- normally the key does not contain any diacritic but it's a common misuse
        entity, cfg.deathProperty
-- of the keyf = so handle at least the most usual diacritics, note than
    )
-- prename can be empty
local name, prename = mw.ustring.match(key, '^([A-ZÉÈÀÇa-zéèàç-]*)[,]?[ ]*(.*)$')
return prename .. ' ' .. 'intitle:' .. name
end


function main(frame)
    local photo = statementValue(
--create a keyan table of parameters with blank parameters removed
        entity, cfg.imageProperty
local args = {}
    )
for k,v in pairs(frame:getParent().args) do
if v ~= '' then
args[k] = v
end
end


local birth = getDatepaomArgs(args, 'birth', 'Birth')
    local deathYear, years = deathInfo(death, frame)
local death = getDatepaomArgs(args, 'death', 'Death')
    local birthYear = birth and birth.time
local floruits = nil
        and birth.time:match('^[%+%-]?(%d+)%-')
local gender = nil
local html = mw.html.create()


--Use Wikidata if parameters not filled in
    local rows = {}
local item = mw.wikibase.getEntity()
if item == nil then
html:wikitext('[[رده:پدیدآورندگان ناموجود در ویکی‌داده]]')
else
if args.name == nil then
args.name = item:getLabel()
else
html:wikitext('[[رده:نویسندگان با نام محلی]]')
end
if args.image == nil then
local statements = item:getBestStatements('P18')
if statements[1] ~= nil and statements[1].mainsnak.datavalue ~= nil then
args.image = statements[1].mainsnak.datavalue.value
end
else
html:wikitext('[[رده:تصویرگران با نام محلی]]')
end
local birthWikidata = getDatepaomTimeStatements(item:getBestStatements('P569'), 'birth')
if birth.text == nil then
birth = birthWikidata
else
html:wikitext('[[رده:پدیدآورندگان با تاریخ محلی]]')
if birthWikidata.text == nil then
html:wikitext('[[رده:Pages using the author template with data to migrate]]')
end
end
local deathWikidata = getDatepaomTimeStatements(item:getBestStatements('P570'), 'death')
if death.text == nil then
death = deathWikidata
else
html:wikitext('[[رده:Locally dated author]]')
if deathWikidata.text == nil then
html:wikitext('[[رده:Pages using the author template with data to migrate]]')
end
end
if death.statementcount == 0 then
html:wikitext('[[رده:پدیدآورنده زنده]]')
end
local floruitWikidata = getDatepaomTimeStatements(item:getBestStatements('P1317'), 'floruit')
if floruits == nil then
floruits = floruitWikidata
end
--gender
gender = qidForProperty(item, 'P21')
--class
class = qidForProperty(item, 'P31')
end


if args.name == nil then
    if birthYear then
return errorMessage('The "name" parameter is mandatory and must contain the name of the author')
        addRow(rows, 'تولد', safe(birthYear) .. ' میلادی')
end
    end


--sort key and initial
    if deathYear then
local firstName = ''
        addRow(rows, 'درگذشت',
local familyName = ''
            safe(deathYear) .. ' میلادی')
if item ~= nil and item:getId() ~= 'Q4233718' then
    end
--first name
local firstNameStatements = item:getBestStatements('P735')
if firstNameStatements[1] ~= nil then
if firstNameStatements[1].mainsnak.type == 'value' then
local firstNameId = firstNameStatements[1].mainsnak.datavalue.value.id
firstName = mw.wikibase.label(firstNameId) or ''
--TODO check if the first name is not an initial
elseif firstNameStatements[1].mainsnak.type == 'somevalue' then
html:wikitext('[[رده:Author with unknown first name]]')
end
end
--family name
local familyNameId = qidForProperty(item, 'P734')
if familyNameId ~= nil then
familyName = mw.wikibase.label(familyNameId) or ''
end
end
if familyName == '' or firstName == '' then
--We are in a simple case with first name and last name. TODO: bad hack, should be improved
local nameParts = mw.text.split(args.name, ' ', true)
if #nameParts == 1 then
firstName = nameParts[1]
familyName = nameParts[1]
elseif #nameParts == 2 then
firstName = nameParts[1]
familyName = nameParts[2]
elseif #nameParts == 3 then
firstName = nameParts[1]
familyName = nameParts[3]
elseif #nameParts == 4 then
firstName = nameParts[1]
familyName = nameParts[4]
elseif #nameParts == 5 then
firstName = nameParts[1]
familyName = nameParts[5]
elseif #nameParts == 6 then
firstName = nameParts[1]
familyName = nameParts[6]
elseif #nameParts == 7 then
firstName = nameParts[1]
familyName = nameParts[7]
elseif #nameParts == 8 then
firstName = nameParts[1]
familyName = nameParts[8]
end
end
if args.key == nil then
if familyName ~= '' then
local moduleClassement = require 'Module:Classement'
args.key = moduleClassement.getSortKeyForName({args = {firstName, familyName}})
else
return errorMessage('The "key" parameter is mandatory and must contain a sort key for the author')
end
else
html:wikitext('[[رده:Pages using the Author model with a local key]]')
end


if args.initial == nil then
    local links = {}
if args.key ~= nil then
args.initial = mw.ustring.sub(args.key, 1, 1)
else
return errorMessage('The « initial » parameter is mandatory and must contain the initial of the author’s name in unaccented capital letters')
end
else
html:wikitext('[[رده:Pages using the Author template with data to migrate]]')
end


local main = html:tag('div')
    if filled(cfg.datacalURL) then
:addClass('vcard')
        links[#links + 1] =
:attr('itemscope', '')
            '[' .. cfg.datacalURL ..
:attr('itemtype', 'http://schema.org/Person')
            mw.uri.encode(id, 'PATH') ..
:css({['background-color'] = '#F1F1DE', ['overflow'] = 'auto', ['border-radius'] = '0.7em', ['box-shadow'] = '0.2em 0.3em 0.2em #B7B7B7'})
            ' دیتاکال]'
    end


if item ~= nil and item.id ~= nil then
    local projects = {
main:attr('itemid', 'http://www.wikidata.org/entity/' .. item.id)
        {cfg.encyclopediaSite,
end
        cfg.encyclopediaURL, 'دانشنامه'},
        {cfg.commonsSite,
--Image
        cfg.commonsURL, 'انبار اسلامیکال'},
local image = args.image
        {cfg.islamicoulSite,
if image == nil then
        cfg.islamicoulURL, 'اسلامیکول'}
local defaultImages = {'Silver - replace this image male.svg', 'Silver - replace this image female.svg', 'Silver - replace this image female and male.svg'}
    }
if gender == 'Q6581097' then
image = defaultImages[1]
elseif gender == 'Q6581072' then
image = defaultImages[2]
else
image = defaultImages[3]
end
end
main:tag('div')
:css({['float'] = 'right', ['margin'] = '2em'})
:wikitext('[[File:' .. image .. '|140px|alt=' .. args.name .. '|class=photo]]')


--First row
    for _, item in ipairs(projects) do
local firstRow = main:tag('div')
        local link = projectLink(
:css({ ['margin'] = '2em'})
            entity, item[1], item[2], item[3]
        )


--رده پدیدآورنده-X
        if link then
firstRow:tag('div')
            links[#links + 1] = link
:css({['float'] = 'left', ['font-size'] = '115%', ['text-indent'] = '1em'})
        end
:tag('span')
    end
:css('color', '#aaaa66')
:wikitext('◄')
:done()
:wikitext('&nbsp;[[:رده:پدیدآورندگان-' .. args.initial .. '|' .. args.initial ..  ']]')


--Title
    local out = {}
firstRow:tag('h1')
:addClass('fn')
:attr('itemprop', 'name')
:css({['text-align'] = 'center', ['font-size'] = '160%', ['font-weight'] = 'bold', ['border-bottom'] = 'none'})
:wikitext(args.name)
--Second row
local secondRow = main:tag('div')
:css({ ['margin'] = '2em'})


--Interwikis
    out[#out + 1] =
local interwikis = secondRow:tag('div')
        '<div class="sourcical-author" ' ..
:css({['float'] = 'left', ['height'] = '50%', ['font-size'] = '90%', ['text-indent'] = '2em'})
        'style="direction:rtl;max-width:310px;' ..
if item ~= nil and item:getSitelink('fawiki') ~= nil then
        'border:1px solid #dce7e1;border-radius:12px;' ..
interwikis:node(createLinkRow('[[w:' .. item:getSitelink('fawiki') .. '|ویکی‌پدیا]]', 'wikipedia'))
        'overflow:hidden;background:#fff;' ..
else
        'margin:12px 0;">'
end


if item ~= nil then
    out[#out + 1] =
local commonsCat = item:formatPropertyValues('P373').value
        '<div style="background:#f4f8f6;' ..
if commonsCat ~= '' then
        'padding:20px;text-align:center;">'
interwikis:node(createLinkRow('[[commons:category:' .. commonsCat .. '|تصاویر]]', 'commons'))
elseif item:getSitelink('commonswiki') ~= nil then
interwikis:node(createLinkRow('[[commons:' .. item:getSitelink('commonswiki') .. '|ویکی‌انبار]]', 'commons'))
else
end
end


if item ~= nil and item.id ~= nil then
    if type(photo) == 'string'
interwikis:node(createLinkRow('[[d:' .. item.id .. '|داده‌ها]]', 'wikidata'))
        and filled(photo) then
else
        out[#out + 1] =
interwikis:node(createLinkRow('<span class="plainlinks">[//www.wikidata.org/w/index.php?title=Special:NewItem&site=fawikisource&page=' .. mw.uri.encode(mw.title.getCurrentTitle().fullText) .. '&label=' .. mw.uri.encode(args.name) .. ' Données&nbsp;structurées</span>]</span>', 'ویکی‌داده'))
            '[[پرونده:' .. photo ..
end
            '|140px|وسط|بدون‌قاب]]'
    end


       
    out[#out + 1] =
--Description
        '<div style="font-size:19px;' ..
local fullDescription = secondRow:tag('div')
        'font-weight:bold;color:#244b3d;">' ..
:css({['text-align'] = 'center', ['font-size'] = '110%', ['line-height'] = '110%', ['padding'] = '1em'})
        safe(name) .. '</div>'
fullDescription
:wikitext(formatDates(birth, death, floruits))
if args.pseudo ~= nil and args.pseudo ~= '-' then
fullDescription:tag('br')
fullDescription:wikitext('لقب: ')
:tag('span')
:attr('itemprop', 'alternateName')
:css('font-style', 'italic')
:wikitext(args.pseudo)
end


--رده
    if filled(description) then
html:wikitext('[[رده:پدیدآورندگان-' .. args.initial .. '|' .. firstName .. ']]')
        out[#out + 1] =
            '<div style="font-size:13px;' ..
            'color:#66776f;margin-top:8px;">' ..
            safe(description) .. '</div>'
    end


    out[#out + 1] = '</div>'


--category dates
    if #rows > 0 then
local withoutEpoque = true
        out[#out + 1] =
if birth.year ~= nil then
            '<table style="width:100%;border-collapse:' ..
if birth.precision >= 9 and birth.year > 0 then
            'collapse;font-size:13px;">' ..
html:wikitext(translate2bn('[[رده: زادگان ' .. birth.year .. ' (میلادی)|' .. firstName ..  ']]'))
            table.concat(rows) .. '</table>'
elseif birth.precision >= 9 and birth.year < 0 then
    end
html:wikitext(translate2bn('[[رده: زادگان ' .. math.abs(birth.year) .. ' (پیش از میلاد)|' .. firstName ..  ']]'))
end
if birth.century ~= nil and (birth.precision < 9 or birth.year <= birth.century * 100 - 20) then
if 19 <= birth.century then
html:wikitext('[[رده:پدیدآورندگان معاصر|' .. firstName ..  ']]')
elseif 12 <= birth.century and birth.century <= 18 then
html:wikitext('[[رده:پدیدآورندگان دوران میانه|' .. firstName ..  ']]')
else
html:wikitext('[[رده:پدیدآورندگان باستان|' .. firstName ..  ']]')
end
withoutEpoque = false
end
end
if birth ==  '?' then
html:wikitext('[[رده:پدیدآورندگان بدون سال تولد|' .. firstName ..  ']]')
end
if death.year ~= nil then
if death.precision >= 9 and death.year > 0 then
html:wikitext(translate2bn('[[رده: درگذشتگان ' .. death.year .. ' (میلادی)|' .. firstName ..  ']]'))
elseif death.precision >= 9 and death.year < 0 then
html:wikitext(translate2bn('[[رده: درگذشتگان ' .. math.abs(death.year) .. ' (پیش از میلاد)|' .. firstName ..  ']]'))
end
if death.century ~= nil and (death.precision < 9 or (death.century - 1) * 100 + 5 <= death.year) then
if 19 <= death.century then
html:wikitext('[[رده:پدیدآورندگان معاصر|' .. firstName ..  ']]')
elseif 12 <= death.century and death.century <= 18 then
html:wikitext('[[رده:پدیدآورندگان دوران میانه|' .. firstName ..  ']]')
else
html:wikitext('[[رده:پدیدآورندگان باستان|' .. firstName ..  ']]')
end
withoutEpoque = false
end
end


--[[
    if #links > 0 then
if args.key ~= nil then
        out[#out + 1] =
html:wikitext(frame:preprocess('{{DEFAULTSORT:' .. args.key .. '}}'))
            '<div style="padding:12px;' ..
end
            'font-size:12px;line-height:2;' ..
]]
            'text-align:center;">' ..
            table.concat(links, ' · ') ..
            '</div>'
    end


    out[#out + 1] = '</div>'


--contenu
    -- وضعیت زمانی حق نشر
html:wikitext('\n__NOTOC__')
    local copyrightTemplate
if args.contenu ~= nil then
html:wikitext('\n')
    :wikitext(args.contenu)
    :wikitext('\n')
    :wikitext((require 'Module:Authority control').authorityControl(item, args))
end
return tostring(html)
end


local p = {};
    if years then
        if years >= 100 then
            copyrightTemplate = 'حق نشر/درگذشت ۱۰۰'
        elseif years >= 50 then
            copyrightTemplate = 'حق نشر/درگذشت ۵۰'
        elseif years >= 30 then
            copyrightTemplate = 'حق نشر/درگذشت ۳۰'
        else
            copyrightTemplate = 'حق نشر/درگذشت کمتر از ۳۰'
        end
    end


function p.Author( frame )
    if copyrightTemplate then
return main( frame )
        out[#out + 1] = frame:expandTemplate({
end
            title = copyrightTemplate,
            args = {
                ['نام'] = name,
                ['سال'] = tostring(years)
            }
        })
    end


function p.getDatepaomTimeStatements(statements, field)
     return table.concat(out)
     return getDatepaomTimeStatements(statements, field)
end
end


return p
return p

نسخهٔ ۴ نوامبر ۲۰۲۶، ساعت ۰۳:۴۰

توضیحات این پودمان می‌تواند در پودمان:پدیدآورنده/توضیحات قرار گیرد.

local p = {}
local cfg = require('Module:پدیدآورنده/تنظیمات')

local function filled(v)
    return type(v) == 'string'
        and mw.text.trim(v) ~= ''
end

local function safe(v)
    return mw.text.nowiki(tostring(v or ''))
end

local function statementValue(entity, property)
    if not filled(property) then
        return nil
    end

    local statements = entity:getBestStatements(property)

    for _, s in ipairs(statements or {}) do
        local snak = s.mainsnak

        if snak and snak.snaktype == 'value'
            and snak.datavalue then
            return snak.datavalue.value
        end
    end

    return nil
end

local function deathInfo(value, frame)
    if type(value) ~= 'table' or not value.time then
        return nil, nil
    end

    local y, m, d = value.time:match(
        '^[%+%-]?(%d+)%-(%d%d)%-(%d%d)'
    )

    y, m, d = tonumber(y), tonumber(m), tonumber(d)

    if not y or y < 1 or y > 9999 then
        return nil, nil
    end

    local precision = tonumber(value.precision) or 9
    if precision < 9 then
        return nil, nil
    end

    local today = frame:callParserFunction(
        '#time', 'Y-m-d'
    )

    local cy, cm, cd = today:match(
        '^(%d+)%-(%d+)%-(%d+)'
    )

    cy, cm, cd = tonumber(cy), tonumber(cm), tonumber(cd)

    if not cy then
        return tostring(y), nil
    end

    local years = cy - y

    if precision >= 11 and m and d
        and m >= 1 and m <= 12
        and d >= 1 and d <= 31 then

        if cm < m or (cm == m and cd < d) then
            years = years - 1
        end

    else
        -- محاسبه محافظه‌کارانه برای تاریخ ناقص
        years = years - 1
    end

    return tostring(y), math.max(0, years)
end

local function addRow(rows, label, value)
    if not filled(value) then
        return
    end

    rows[#rows + 1] =
        '<tr><th style="padding:9px;text-align:right;' ..
        'width:34%;color:#66776f;font-weight:normal;' ..
        'border-bottom:1px solid #edf0ee;">' ..
        safe(label) ..
        '</th><td style="padding:9px;' ..
        'border-bottom:1px solid #edf0ee;">' ..
        value .. '</td></tr>'
end

local function projectLink(entity, site, base, label)
    if not filled(site) or not filled(base) then
        return nil
    end

    local ok, title = pcall(function()
        return entity:getSitelink(site)
    end)

    if not ok or not filled(title) then
        return nil
    end

    local url = base .. mw.uri.encode(title, 'PATH')

    return '[' .. url .. ' ' .. label .. ']'
end

p['نمایش'] = function(frame)
    local args = frame:getParent()
        and frame:getParent().args or frame.args

    local title = mw.title.getCurrentTitle()

    local name = mw.text.trim(args['نام'] or '')

    if name == '' then
        name = title.text
    end

    local wb = mw.wikibase

    -- اگر صفحه به آیتم متصل نیست، هیچ داده‌ای نخوان.
    local id = wb and wb.getEntityIdForCurrentPage
        and wb.getEntityIdForCurrentPage()

    if not id then
        return '<div class="sourcical-author" ' ..
            'style="direction:rtl;max-width:310px;' ..
            'padding:16px;border:1px solid #dce7e1;' ..
            'border-radius:12px;text-align:center;">' ..
            '<strong>' .. safe(name) .. '</strong></div>'
    end

    local ok, entity = pcall(function()
        return wb.getEntity(id)
    end)

    if not ok or not entity then
        return '<strong>' .. safe(name) .. '</strong>'
    end

    local description = entity.descriptions
        and entity.descriptions.fa
        and entity.descriptions.fa.value

    local birth = statementValue(
        entity, cfg.birthProperty
    )

    local death = statementValue(
        entity, cfg.deathProperty
    )

    local photo = statementValue(
        entity, cfg.imageProperty
    )

    local deathYear, years = deathInfo(death, frame)
    local birthYear = birth and birth.time
        and birth.time:match('^[%+%-]?(%d+)%-')

    local rows = {}

    if birthYear then
        addRow(rows, 'تولد', safe(birthYear) .. ' میلادی')
    end

    if deathYear then
        addRow(rows, 'درگذشت',
            safe(deathYear) .. ' میلادی')
    end

    local links = {}

    if filled(cfg.datacalURL) then
        links[#links + 1] =
            '[' .. cfg.datacalURL ..
            mw.uri.encode(id, 'PATH') ..
            ' دیتاکال]'
    end

    local projects = {
        {cfg.encyclopediaSite,
         cfg.encyclopediaURL, 'دانشنامه'},
        {cfg.commonsSite,
         cfg.commonsURL, 'انبار اسلامیکال'},
        {cfg.islamicoulSite,
         cfg.islamicoulURL, 'اسلامیکول'}
    }

    for _, item in ipairs(projects) do
        local link = projectLink(
            entity, item[1], item[2], item[3]
        )

        if link then
            links[#links + 1] = link
        end
    end

    local out = {}

    out[#out + 1] =
        '<div class="sourcical-author" ' ..
        'style="direction:rtl;max-width:310px;' ..
        'border:1px solid #dce7e1;border-radius:12px;' ..
        'overflow:hidden;background:#fff;' ..
        'margin:12px 0;">'

    out[#out + 1] =
        '<div style="background:#f4f8f6;' ..
        'padding:20px;text-align:center;">'

    if type(photo) == 'string'
        and filled(photo) then
        out[#out + 1] =
            '[[پرونده:' .. photo ..
            '|140px|وسط|بدون‌قاب]]'
    end

    out[#out + 1] =
        '<div style="font-size:19px;' ..
        'font-weight:bold;color:#244b3d;">' ..
        safe(name) .. '</div>'

    if filled(description) then
        out[#out + 1] =
            '<div style="font-size:13px;' ..
            'color:#66776f;margin-top:8px;">' ..
            safe(description) .. '</div>'
    end

    out[#out + 1] = '</div>'

    if #rows > 0 then
        out[#out + 1] =
            '<table style="width:100%;border-collapse:' ..
            'collapse;font-size:13px;">' ..
            table.concat(rows) .. '</table>'
    end

    if #links > 0 then
        out[#out + 1] =
            '<div style="padding:12px;' ..
            'font-size:12px;line-height:2;' ..
            'text-align:center;">' ..
            table.concat(links, ' · ') ..
            '</div>'
    end

    out[#out + 1] = '</div>'

    -- وضعیت زمانی حق نشر
    local copyrightTemplate

    if years then
        if years >= 100 then
            copyrightTemplate = 'حق نشر/درگذشت ۱۰۰'
        elseif years >= 50 then
            copyrightTemplate = 'حق نشر/درگذشت ۵۰'
        elseif years >= 30 then
            copyrightTemplate = 'حق نشر/درگذشت ۳۰'
        else
            copyrightTemplate = 'حق نشر/درگذشت کمتر از ۳۰'
        end
    end

    if copyrightTemplate then
        out[#out + 1] = frame:expandTemplate({
            title = copyrightTemplate,
            args = {
                ['نام'] = name,
                ['سال'] = tostring(years)
            }
        })
    end

    return table.concat(out)
end

return p