پودمان:پدیدآورنده
توضیحات این پودمان میتواند در پودمان:پدیدآورنده/توضیحات قرار گیرد.
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.create('div')
if site == 'پدیدآورنده' then
logo_file_name = 'Font_Awesome_5_regular_list-alt.svg'
elseif site == 'Inventory' then
logo_file_name = 'Inv-icon-192.svg'
else
logo_file_name = site .. '-logo.svg'
end
html:tag('span')
:css({['color'] = '#232388', ['font-size'] = '140%', ['line-height'] = '150%'})
:wikitext('[[File:' .. logo_file_name .. '|20px|' .. site .. ']] ')
html:wikitext(link)
return html
end
function categorization(baseName, parameter)
-- Return the categorisation wikitext for each element of parameter prefixed with baseName
if parameter == nil then
return ''
end
local wikitext = ''
for _,param in pairs(mw.text.split(parameter, '/', true)) do
wikitext = wikitext .. '[[رده:' .. baseName .. ' ' .. param .. ']]'
end
return wikitext
end
function computeCenturypaomYear(year)
-- 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)
-- Return a roman ordinal of century appended with a trailing text precising
-- if the date is before of after the calendar reference point.
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]
if withHtml then
text = text .. ''
else
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 text = math.abs(year)
if year < 0 then
text = text .. ' پیش از میلاد'
end
return translate2bn(text)
end
function getDatepaomArgs(args, field, fieldUpper)
local struct = {
year = nil,
century = nil,
text = nil,
precision = 0
}
--extract year or century
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 struct.year ~= nil then
struct.text = getTextForYear(struct.year)
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
end
function getDatepaomTimeStatements(statements, field)
if #statements == 0 then
return {
precision = 0,
statementcount = 0
}
end
local time = nil
for _, statement in pairs(statements) do
local newTime = getDatepaomTimeStatement(statement, field)
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
return {
precision = 0
}
end
return time
end
function parseWbTime(value)
local _,_, year = string.find(value.time, '([%+%-]%d%d%d+)%-')
year = tonumber(year)
return {
year = year,
century = computeCenturypaomYear(year),
text = nil,
precision = value.precision
}
end
function getDatepaomTimeStatement(statement, field)
local struct = {
year = nil,
century = nil,
text = nil,
precision = 0
}
local snak = statement.mainsnak
if snak.snaktype == 'novalue' then
return struct
end
if snak.snaktype == 'somevalue' then
struct.text = '?'
return struct.text
end
struct = parseWbTime(snak.datavalue.value)
local prefix = ''
if struct.precision == 8 then
prefix = 'حدود '
end
--Extract circa
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
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
function formatDates(birth, death, floruits, class)
if birth.text == nil and birth ~= '?' and death.text == nil and death ~= '?' then
return ''
end
local text = '('
if birth == '?' and death == '?' and floruits ~= nil and floruits.text ~= nil then
text = text .. floruits.text
else
if birth == '?' then
text = text .. birth .. ' '
elseif birth.precision >= 9 then
local annotation = 'class="bday" itemprop="birthDate"'
if class ~= "Q5" and class ~= nil then
annotation = 'itemprop="foundingDate'
end
text = text .. '<time datetime=' .. birth.year .. ' class="bday" itemprop="birthDate">' .. birth.text .. '</time> '
elseif birth.text ~= nil then
text = text .. birth.text .. ' '
end
text = text .. '–'
if death == '?' then
text = text .. ' ' .. death
elseif death.precision >= 9 then
local annotation = 'class="dday" itemprop="deathDate"'
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
return translate2bn(text) .. ')'
end
function qidForProperty(item, property)
local statements = item:getBestStatements(property)
if statements[1] ~= nil and statements[1].mainsnak.datavalue ~= nil then
return statements[1].mainsnak.datavalue.value.id
end
return nil
end
function searchKey(key)
-- normally the key does not contain any diacritic but it's a common misuse
-- 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)
--create a keyan table of parameters with blank parameters removed
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 death = getDatepaomArgs(args, 'death', 'Death')
local floruits = nil
local gender = nil
local html = mw.html.create()
--Use Wikidata if parameters not filled in
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
return errorMessage('The "name" parameter is mandatory and must contain the name of the author')
end
--sort key and initial
local firstName = ''
local familyName = ''
if item ~= nil and item:getId() ~= 'Q4233718' then
--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
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')
:addClass('vcard')
:attr('itemscope', '')
:attr('itemtype', 'http://schema.org/Person')
:css({['background-color'] = '#F1F1DE', ['overflow'] = 'auto', ['border-radius'] = '0.7em', ['box-shadow'] = '0.2em 0.3em 0.2em #B7B7B7'})
if item ~= nil and item.id ~= nil then
main:attr('itemid', 'http://www.wikidata.org/entity/' .. item.id)
end
--Image
local image = args.image
if image == nil then
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
local firstRow = main:tag('div')
:css({ ['margin'] = '2em'})
--رده پدیدآورنده-X
firstRow:tag('div')
:css({['float'] = 'left', ['font-size'] = '115%', ['text-indent'] = '1em'})
:tag('span')
:css('color', '#aaaa66')
:wikitext('◄')
:done()
:wikitext(' [[:رده:پدیدآورندگان-' .. args.initial .. '|' .. args.initial .. ']]')
--Title
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
local interwikis = secondRow:tag('div')
:css({['float'] = 'left', ['height'] = '50%', ['font-size'] = '90%', ['text-indent'] = '2em'})
if item ~= nil and item:getSitelink('fawiki') ~= nil then
interwikis:node(createLinkRow('[[w:' .. item:getSitelink('fawiki') .. '|ویکیپدیا]]', 'wikipedia'))
else
end
if item ~= nil then
local commonsCat = item:formatPropertyValues('P373').value
if commonsCat ~= '' then
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
interwikis:node(createLinkRow('[[d:' .. item.id .. '|دادهها]]', 'wikidata'))
else
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 structurées</span>]</span>', 'ویکیداده'))
end
--Description
local fullDescription = secondRow:tag('div')
:css({['text-align'] = 'center', ['font-size'] = '110%', ['line-height'] = '110%', ['padding'] = '1em'})
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
--رده
html:wikitext('[[رده:پدیدآورندگان-' .. args.initial .. '|' .. firstName .. ']]')
--category dates
local withoutEpoque = true
if birth.year ~= nil then
if birth.precision >= 9 and birth.year > 0 then
html:wikitext(translate2bn('[[رده: زادگان ' .. birth.year .. ' (میلادی)|' .. firstName .. ']]'))
elseif birth.precision >= 9 and birth.year < 0 then
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 args.key ~= nil then
html:wikitext(frame:preprocess('{{DEFAULTSORT:' .. args.key .. '}}'))
end
]]
--contenu
html:wikitext('\n__NOTOC__')
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 = {};
function p.Author( frame )
return main( frame )
end
function p.getDatepaomTimeStatements(statements, field)
return getDatepaomTimeStatements(statements, field)
end
return p