وحدة:وثيقة
المظهر

-- وحدة:وثيقة
local p = {}
local translation = require('Module:وثيقة/ترجمة')
-- إنشاء صف جديد في الجدول
local function new_row(style, sort)
local html = '\n| '
if style then
html = html .. 'style="' .. style .. '" '
end
if sort then
html = html .. 'data-sort-value="' .. mw.text.nowiki(sort) .. '" '
end
return html .. '|'
end
-- تحليل التاريخ
function date_link(date)
if tonumber(date) ~= nil then
if tonumber(date) < 0 then
date = tostring(math.abs(tonumber(date))) .. ' ق. م'
end
--TODO elzevir
local categorie_date = mw.title.makeTitle('تصنيف', date)
if categorie_date then
return '[[:' .. categorie_date.fullText .. '|' .. date .. ']]'
else
return date
end
else
return date
end
end
-- تحليل العنوان
local function analyser_titre(titre)
-- التأكد من أن العنوان غير فارغ
if not titre or titre == "" then
return {titre, titre, "", nil}
end
local doc_title = titre
local doc_text = titre
local doc_comment = ''
local item_id = nil
-- البحث عن روابط داخل النص
if mw.ustring.match(titre .. ' ', '^%s*%[%[[^%]]*%]%][^%[]*$') then
for c1, c2, c3 in mw.ustring.gmatch(titre .. ' ', '%[%[([^|]*)|(.*)%]%](.*)') do
doc_title = c1
doc_text = c2
doc_comment = c3
end
for c, c0 in mw.ustring.gmatch(titre .. ' ', '%[%[([^|]*)%]%](.*)') do
doc_title = c
doc_text = c
doc_comment = c0
end
end
local mw_title = mw.title.new(doc_title)
if mw_title then
doc_title = translation.normalize_title(mw_title)
item_id = mw.wikibase.getEntityIdForTitle(doc_title.fullText)
end
return {doc_title, doc_text, doc_comment, item_id}
end
-- عرض الوثيقة
function p.document(frame)
local parentFrame = frame:getParent()
local args = translation.clean_args(parentFrame.args)
local html = '\n|- style="vertical-align:top;" '
-- جلب القيم المدخلة سواء بالعربية أو الفرنسية
local date = translation.get_value_from_aliases(args, "date")
local titre = translation.get_value_from_aliases(args, "titre")
local auteur = translation.get_value_from_aliases(args, "auteur")
local genre = translation.get_value_from_aliases(args, "genre")
local livre = translation.get_value_from_aliases(args, "livre")
local avancement = translation.get_value_from_aliases(args, "avancement")
local scan = translation.get_value_from_aliases(args, "scan")
if args.date and (args.livre or args['éditions'] or args.traduction) then
html = html .. new_row('white-space:nowrap;min-width:5em', nil)
else
html = html .. new_row('white-space:nowrap;', nil)
end
if args.date then
html = html .. date_link(args.date) .. ' :'
elseif args.dates then
local formatted = {}
local node = mw.html.create('div')
:css('line-height', '90%')
:css('font-size', '100%')
:css('float', 'left')
for k,date in pairs(mw.text.split(args.dates, '/')) do
formatted[k] = date_link(date)
end
node:wikitext(table.concat(formatted, '<br/>') ..' :')
html = html .. tostring(node)
end
local item_id = nil
if args['éditions'] then
local doc_info = analyser_titre(args['éditions'])
local doc_title = doc_info[1]
local doc_text = doc_info[2]
local doc_comment = doc_info[3]
item_id = doc_info[4]
html = html .. '<div style="float:right">[[ملف:Disambig.svg|عدة إصدارات متاحة|link=|20px]] </div>'
html = html .. new_row('padding-right: 2em;', args['titre alpha']) .. '<span class="lien-oeuvre">'
if doc_title and doc_title.exists then
html = html .. '[[' .. doc_title.fullText .. '|' .. doc_text .. ']]' .. doc_comment .. ' '
else
html = html .. doc_text .. doc_comment .. ' '
end
html = html .. '</span> '
elseif args.traductions then
local doc_info = analyser_titre(args.traductions)
local doc_title = doc_info[1]
local doc_text = doc_info[2]
local doc_comment = doc_info[3]
item_id = doc_info[4]
html = html .. '<div style="float:right">[[ملف:Disambig.svg|Plusieurs éditions disponibles|link=|20px]] </div>'
html = html .. new_row('padding-right: 2em;', args['titre alpha']) .. '<span class="lien-oeuvre">'
if doc_title and doc_title.exists then
html = html .. '[[' .. doc_title.fullText .. '|' .. doc_text .. ']]' .. doc_comment .. ' '
else
html = html .. doc_text .. doc_comment .. ' '
end
html = html .. '</span> '
elseif args.titre then
local doc_info = analyser_titre(args.titre)
local doc_title = doc_info[1]
local doc_text = doc_info[2]
local doc_comment = doc_info[3]
item_id = doc_info[4]
if args.livre then
html = html .. '<div style="float:right">[[ملف:Open book nae 02.svg|20px|link=فهرس:' .. args.livre .. ']] </div>'
end
html = html .. new_row('padding-right:2em;', args['titre alpha'])
if doc_title and doc_title.exists then
html = html .. '[[' .. doc_title.fullText .. '|' .. doc_text .. ']]' .. doc_comment .. ' '
else
html = html .. doc_text .. doc_comment .. ' '
end
else
return '|-'
--TODO: return an error? return error_message('يجب إدخال معلمة "العنوان".')
end
if not args.avancement and item_id then
item = mw.wikibase.getEntity(item_id)
if item and item.sitelinks and item.sitelinks["arwikisource"] then
for _,badge in pairs(item.sitelinks["arwikisource"].badges) do
if badge == 'Q20748091' then
args.avancement = '2'
elseif badge == 'Q20748094' then
args.avancement = '1'
elseif badge == 'Q20748092' then
args.avancement = '4'
elseif badge == 'Q20748093' then
args.avancement = '5'
end
end
end
end
if args.avancement == '0' then
html = html .. frame:expandTemplate{title = '0/4'}
elseif args.avancement == '1' then
html = html .. frame:expandTemplate{title = '1/4'}
elseif args.avancement == '2' then
html = html .. frame:expandTemplate{title = '2/4'}
elseif args.avancement == '3' then
html = html .. frame:expandTemplate{title = '3/4'}
elseif args.avancement == '4' then
html = html .. frame:expandTemplate{title = '4/4'}
elseif args.avancement == '5' then
html = html .. frame:expandTemplate{title = 'validé'}
elseif args.avancement then
mw.addWarning( 'La valeur' .. mw.text.jsonEncode(args.avancement) .. 'لا تُدعم معلمة التقدم بواسطة نموذج المستند' )
end
if args[1] == 'epub' or args[1] == 'export' then
html = html .. ' ' .. frame:expandTemplate{title = args[1], args = {args.titre}}
elseif args[1] then
html = html .. error_message('Paramètre non nommé inconnu: ' .. args[1])
end
if args['epub'] then
html = html .. ' ' .. frame:expandTemplate{title = 'epub', args = {args.epub}}
end
if args['export'] then
html = html .. ' ' .. frame:expandTemplate{title = 'export', args = {args.export}}
end
if args.DP == 'EU' then
html = html .. frame:expandTemplate{title = 'DP-EU-Icon'}
end
if item_id then
html = html .. ' [[ملف:Blue pencil.svg|10px|link=d:' .. item_id .. '|انظر وعدّل البيانات على ويكي بيانات]]'
end
if args.vo then
html = html .. new_row('font-size:90%; padding-right:2em:', args['vo alpha']) .. args.vo
end
if args.auteur then
local auteur_title = args.auteur
local auteur_text = args.auteur
for c1, c2 in mw.ustring.gmatch( args.auteur, '%[%[([^|]*)|(.*)%]%]') do
auteur_title = c1
auteur_text = c2
end
for c in mw.ustring.gmatch( args.auteur, '%[%[([^|]*)%]%]') do
auteur_title = c
auteur_text = c
end
html = html .. new_row('font-size:90%; padding-right:2em;', args['auteur alpha'])
local auteur_title = mw.title.new(auteur_title, 'مؤلف')
if auteur_title and auteur_title.exists then
html = html .. '[[' .. auteur_title.fullText .. '|' .. auteur_text .. ']]'
else
html = html .. auteur_text
end
end
if args.genre then
html = html .. new_row('font-size:90%; padding-right:2em;', nil) .. args.genre
end
if args.scan then
html = html .. new_row('font-size:90%; padding-right:2em;', nil) .. '<span class="plainlink">' .. args.scan .. '</span>'
end
if args.divers then
html = html .. new_row('font-size:90%; padding-right:2em;', args['divers alpha']) .. args.divers
end
if args.revue then
local revue_parts = mw.text.split(args.revue, '/')
if revue_parts[1] == 'RDDM' and len(revue_parts) == 2 then
html = html .. new_row('font-size:90%; padding-right:2em;', nil) .. args.divers .. "''Revue des Deux Mondes'', n°" .. revue_parts[2] .. ', ' .. args.date
end
end
return html
end
return p