پودمان:ArticleInfoBox
توضیحات این پودمان میتواند در پودمان:ArticleInfoBox/توضیحات قرار گیرد.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local html = mw.html
----------------------------------------------------------
-- Helpers
----------------------------------------------------------
local function norm(value)
if not value then
return nil
end
value = mw.text.trim(tostring(value))
if value == '' then
return nil
end
return value
end
local function getValue(args, ...)
for i = 1, select('#', ...) do
local key = select(i, ...)
local value = norm(args[key])
if value then
return value
end
end
return nil
end
----------------------------------------------------------
-- Table
----------------------------------------------------------
local function addRow(box, label, value)
if not value then
return
end
box:tag('tr')
:tag('th')
:addClass('article-infobox-label')
:wikitext(label)
:done()
:tag('td')
:addClass('article-infobox-data')
:wikitext(value)
end
local function addSection(box, title)
box:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('article-infobox-header')
:wikitext(title)
end
----------------------------------------------------------
-- Image
----------------------------------------------------------
local function addImage(box, args)
local image = getValue(args, 'تصویر', 'image')
if not image then
return
end
box:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('article-infobox-image')
:wikitext(
'[[File:' ..
image ..
'|' ..
(getValue(args, 'اندازه تصویر', 'image_size') or '250px') ..
']]'
)
local caption = getValue(args, 'توضیح تصویر', 'image_caption')
if caption then
box:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('article-infobox-caption')
:wikitext(caption)
end
end
----------------------------------------------------------
-- Main
----------------------------------------------------------
function p.main(frame)
local args = getArgs(frame)
local box = html.create('table')
:addClass('infobox')
:addClass('article-infobox')
------------------------------------------------------
-- Title
------------------------------------------------------
local title = getValue(args, 'عنوان', 'title')
if title then
box:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('article-infobox-title')
:wikitext(title)
end
------------------------------------------------------
-- Image
------------------------------------------------------
addImage(box, args)
------------------------------------------------------
-- Author Information
------------------------------------------------------
local authorFields = {
{'نویسنده', {'نویسنده', 'نویسندگان', 'author'}},
{'وابستگی سازمانی', {'وابستگی', 'وابستگی سازمانی', 'affiliation'}},
{'سال انتشار', {'سال انتشار', 'سال', 'year'}},
{'تاریخ انتشار', {'تاریخ انتشار', 'تاریخ', 'date'}}
}
local hasAuthor = false
for _, item in ipairs(authorFields) do
if getValue(args, unpack(item[2])) then
hasAuthor = true
break
end
end
if hasAuthor then
addSection(box, 'اطلاعات نویسنده')
for _, item in ipairs(authorFields) do
addRow(
box,
item[1],
getValue(args, unpack(item[2]))
)
end
end
------------------------------------------------------
-- Publication Information
------------------------------------------------------
local publicationFields = {
{'نشریه', {'نشریه', 'نام نشریه', 'journal'}},
{'ناشر', {'ناشر', 'publisher'}},
{'دوره', {'دوره', 'volume'}},
{'شماره', {'شماره', 'issue'}},
{'صفحات', {'صفحات', 'صفحهها', 'pages'}},
{'زبان', {'زبان', 'language'}},
{'ISSN', {'ISSN', 'شابک نشریه'}}
}
local hasPublication = false
for _, item in ipairs(publicationFields) do
if getValue(args, unpack(item[2])) then
hasPublication = true
break
end
end
if hasPublication then
addSection(box, 'اطلاعات انتشار')
for _, item in ipairs(publicationFields) do
addRow(
box,
item[1],
getValue(args, unpack(item[2]))
)
end
end
------------------------------------------------------
-- Scientific Information
------------------------------------------------------
local scientificFields = {
{'موضوع', {'موضوع', 'subject'}},
{'کلیدواژهها', {'کلیدواژهها', 'کلیدواژه', 'keywords'}},
{'DOI', {'DOI', 'doi'}}
}
local hasScientific = false
for _, item in ipairs(scientificFields) do
if getValue(args, unpack(item[2])) then
hasScientific = true
break
end
end
if hasScientific then
addSection(box, 'مشخصات علمی')
for _, item in ipairs(scientificFields) do
addRow(
box,
item[1],
getValue(args, unpack(item[2]))
)
end
end
------------------------------------------------------
-- Article Links
------------------------------------------------------
local articleLink = getValue(
args,
'لینک مقاله',
'پیوند مقاله',
'article_url'
)
local downloadLink = getValue(
args,
'لینک دانلود',
'دانلود',
'download_url'
)
if articleLink or downloadLink then
addSection(box, 'دسترسی به مقاله')
if articleLink then
addRow(
box,
'صفحه مقاله',
'[' .. articleLink .. ' مشاهده مقاله]'
)
end
if downloadLink then
addRow(
box,
'دریافت فایل',
'[' .. downloadLink .. ' دریافت نسخه PDF]'
)
end
end
------------------------------------------------------
-- Return
------------------------------------------------------
return tostring(box)
end
return p